Skip to content

Commit

Permalink
Merge branch 'dev' of https://github.com/telegramdesktop/tdesktop int…
Browse files Browse the repository at this point in the history
…o dev
  • Loading branch information
c0re100 committed Aug 17, 2024
2 parents ec6feae + 2c1788a commit fd921a6
Show file tree
Hide file tree
Showing 23 changed files with 213 additions and 208 deletions.
49 changes: 9 additions & 40 deletions Telegram/SourceFiles/api/api_sending.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,25 +165,15 @@ void SendExistingMedia(
flags |= MessageFlag::HasReplyInfo;
sendFlags |= MTPmessages_SendMedia::Flag::f_reply_to;
}
const auto anonymousPost = peer->amAnonymous();
const auto silentPost = ShouldSendSilent(peer, action.options);
InnerFillMessagePostFlags(action.options, peer, flags);
if (silentPost) {
sendFlags |= MTPmessages_SendMedia::Flag::f_silent;
}
const auto sendAs = action.options.sendAs;
const auto messageFromId = sendAs
? sendAs->id
: anonymousPost
? 0
: session->userPeerId();
if (sendAs) {
sendFlags |= MTPmessages_SendMedia::Flag::f_send_as;
}
const auto messagePostAuthor = peer->isBroadcast()
? session->user()->name()
: QString();

auto caption = TextWithEntities{
message.textWithTags.text,
TextUtilities::ConvertTextTagsToEntities(message.textWithTags.tags)
Expand Down Expand Up @@ -219,11 +209,11 @@ void SendExistingMedia(
history->addNewLocalMessage({
.id = newId.msg,
.flags = flags,
.from = messageFromId,
.from = NewMessageFromId(action),
.replyTo = action.replyTo,
.date = HistoryItem::NewMessageDate(action.options),
.date = NewMessageDate(action.options),
.shortcutId = action.options.shortcutId,
.postAuthor = messagePostAuthor,
.postAuthor = NewMessagePostAuthor(action),
.effectId = action.options.effectId,
}, media, caption);

Expand Down Expand Up @@ -361,25 +351,15 @@ bool SendDice(MessageToSend &message) {
flags |= MessageFlag::HasReplyInfo;
sendFlags |= MTPmessages_SendMedia::Flag::f_reply_to;
}
const auto anonymousPost = peer->amAnonymous();
const auto silentPost = ShouldSendSilent(peer, action.options);
InnerFillMessagePostFlags(action.options, peer, flags);
if (silentPost) {
sendFlags |= MTPmessages_SendMedia::Flag::f_silent;
}
const auto sendAs = action.options.sendAs;
const auto messageFromId = sendAs
? sendAs->id
: anonymousPost
? 0
: session->userPeerId();
if (sendAs) {
sendFlags |= MTPmessages_SendMedia::Flag::f_send_as;
}
const auto messagePostAuthor = peer->isBroadcast()
? session->user()->name()
: QString();

if (action.options.scheduled) {
flags |= MessageFlag::IsOrWasScheduled;
sendFlags |= MTPmessages_SendMedia::Flag::f_schedule_date;
Expand All @@ -401,11 +381,11 @@ bool SendDice(MessageToSend &message) {
history->addNewLocalMessage({
.id = newId.msg,
.flags = flags,
.from = messageFromId,
.from = NewMessageFromId(action),
.replyTo = action.replyTo,
.date = HistoryItem::NewMessageDate(action.options),
.date = NewMessageDate(action.options),
.shortcutId = action.options.shortcutId,
.postAuthor = messagePostAuthor,
.postAuthor = NewMessagePostAuthor(action),
.effectId = action.options.effectId,
}, TextWithEntities(), MTP_messageMediaDice(
MTP_int(0),
Expand Down Expand Up @@ -529,7 +509,6 @@ void SendConfirmedFile(
if (file->to.replyTo) {
flags |= MessageFlag::HasReplyInfo;
}
const auto anonymousPost = peer->amAnonymous();
FillMessagePostFlags(action, peer, flags);
if (file->to.options.scheduled) {
flags |= MessageFlag::IsOrWasScheduled;
Expand All @@ -551,16 +530,6 @@ void SendConfirmedFile(
if (file->to.options.invertCaption) {
flags |= MessageFlag::InvertMedia;
}

const auto messageFromId = file->to.options.sendAs
? file->to.options.sendAs->id
: anonymousPost
? PeerId()
: session->userPeerId();
const auto messagePostAuthor = peer->isBroadcast()
? session->user()->name()
: QString();

const auto media = MTPMessageMedia([&] {
if (file->type == SendMediaType::Photo) {
using Flag = MTPDmessageMediaPhoto::Flag;
Expand Down Expand Up @@ -626,11 +595,11 @@ void SendConfirmedFile(
history->addNewLocalMessage({
.id = newId.msg,
.flags = flags,
.from = messageFromId,
.from = NewMessageFromId(action),
.replyTo = file->to.replyTo,
.date = HistoryItem::NewMessageDate(file->to.options),
.date = NewMessageDate(file->to.options),
.shortcutId = file->to.options.shortcutId,
.postAuthor = messagePostAuthor,
.postAuthor = NewMessagePostAuthor(action),
.groupedId = groupId,
.effectId = file->to.options.effectId,
}, caption, media);
Expand Down
62 changes: 12 additions & 50 deletions Telegram/SourceFiles/apiwrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3293,7 +3293,6 @@ void ApiWrap::forwardMessages(
histories.readInbox(history);
}
const auto sendAs = action.options.sendAs;
const auto anonymousPost = peer->amAnonymous();
const auto silentPost = ShouldSendSilent(peer, action.options);

using SendFlag = MTPmessages_ForwardMessages::Flag;
Expand Down Expand Up @@ -3385,23 +3384,14 @@ void ApiWrap::forwardMessages(
const auto newId = FullMsgId(
peer->id,
_session->data().nextLocalMessageId());
const auto self = _session->user();
const auto messageFromId = sendAs
? sendAs->id
: anonymousPost
? PeerId(0)
: self->id;
const auto messagePostAuthor = peer->isBroadcast()
? self->name()
: QString();
history->addNewLocalMessage({
.id = newId.msg,
.flags = flags,
.from = messageFromId,
.from = NewMessageFromId(action),
.replyTo = { .topicRootId = topMsgId },
.date = HistoryItem::NewMessageDate(action.options),
.date = NewMessageDate(action.options),
.shortcutId = action.options.shortcutId,
.postAuthor = messagePostAuthor,
.postAuthor = NewMessagePostAuthor(action),

// forwarded messages don't have effects
//.effectId = action.options.effectId,
Expand Down Expand Up @@ -3476,8 +3466,6 @@ void ApiWrap::sendSharedContact(
const auto newId = FullMsgId(
peer->id,
_session->data().nextLocalMessageId());
const auto anonymousPost = peer->amAnonymous();

auto flags = NewMessageFlags(peer);
if (action.replyTo) {
flags |= MessageFlag::HasReplyInfo;
Expand All @@ -3489,22 +3477,14 @@ void ApiWrap::sendSharedContact(
if (action.options.shortcutId) {
flags |= MessageFlag::ShortcutMessage;
}
const auto messageFromId = action.options.sendAs
? action.options.sendAs->id
: anonymousPost
? PeerId()
: _session->userPeerId();
const auto messagePostAuthor = peer->isBroadcast()
? _session->user()->name()
: QString();
const auto item = history->addNewLocalMessage({
.id = newId.msg,
.flags = flags,
.from = messageFromId,
.from = NewMessageFromId(action),
.replyTo = action.replyTo,
.date = HistoryItem::NewMessageDate(action.options),
.date = NewMessageDate(action.options),
.shortcutId = action.options.shortcutId,
.postAuthor = messagePostAuthor,
.postAuthor = NewMessagePostAuthor(action),
.effectId = action.options.effectId,
}, TextWithEntities(), MTP_messageMediaContact(
MTP_string(phone),
Expand Down Expand Up @@ -3790,7 +3770,6 @@ void ApiWrap::sendMessage(MessageToSend &&message) {
MTP_string(fields.url),
MTP_int(page->pendingTill)));
}
const auto anonymousPost = peer->amAnonymous();
const auto silentPost = ShouldSendSilent(peer, action.options);
FillMessagePostFlags(action, peer, flags);
if ((exactWebPage && !ignoreWebPage && message.webPage.invert)
Expand Down Expand Up @@ -3818,18 +3797,10 @@ void ApiWrap::sendMessage(MessageToSend &&message) {
history->startSavingCloudDraft(draftTopicRootId);
}
const auto sendAs = action.options.sendAs;
const auto messageFromId = sendAs
? sendAs->id
: anonymousPost
? PeerId()
: _session->userPeerId();
if (sendAs) {
sendFlags |= MTPmessages_SendMessage::Flag::f_send_as;
mediaFlags |= MTPmessages_SendMedia::Flag::f_send_as;
}
const auto messagePostAuthor = peer->isBroadcast()
? _session->user()->name()
: QString();
if (action.options.scheduled) {
flags |= MessageFlag::IsOrWasScheduled;
sendFlags |= MTPmessages_SendMessage::Flag::f_schedule_date;
Expand All @@ -3847,11 +3818,11 @@ void ApiWrap::sendMessage(MessageToSend &&message) {
lastMessage = history->addNewLocalMessage({
.id = newId.msg,
.flags = flags,
.from = messageFromId,
.from = NewMessageFromId(action),
.replyTo = action.replyTo,
.date = HistoryItem::NewMessageDate(action.options),
.date = NewMessageDate(action.options),
.shortcutId = action.options.shortcutId,
.postAuthor = messagePostAuthor,
.postAuthor = NewMessagePostAuthor(action),
.effectId = action.options.effectId,
}, sending, media);
const auto done = [=](
Expand Down Expand Up @@ -3997,7 +3968,6 @@ void ApiWrap::sendInlineResult(
flags |= MessageFlag::HasReplyInfo;
sendFlags |= SendFlag::f_reply_to;
}
const auto anonymousPost = peer->amAnonymous();
const auto silentPost = ShouldSendSilent(peer, action.options);
FillMessagePostFlags(action, peer, flags);
if (silentPost) {
Expand All @@ -4016,30 +3986,22 @@ void ApiWrap::sendInlineResult(
}

const auto sendAs = action.options.sendAs;
const auto messageFromId = sendAs
? sendAs->id
: anonymousPost ? PeerId()
: _session->userPeerId();
if (sendAs) {
sendFlags |= MTPmessages_SendInlineBotResult::Flag::f_send_as;
}
const auto messagePostAuthor = peer->isBroadcast()
? _session->user()->name()
: QString();

_session->data().registerMessageRandomId(randomId, newId);

data->addToHistory(history, {
.id = newId.msg,
.flags = flags,
.from = messageFromId,
.from = NewMessageFromId(action),
.replyTo = action.replyTo,
.date = HistoryItem::NewMessageDate(action.options),
.date = NewMessageDate(action.options),
.shortcutId = action.options.shortcutId,
.viaBotId = ((bot && !action.options.hideViaBot)
? peerToUser(bot->id)
: UserId()),
.postAuthor = messagePostAuthor,
.postAuthor = NewMessagePostAuthor(action),
});

history->clearCloudDraft(topicRootId);
Expand Down
8 changes: 5 additions & 3 deletions Telegram/SourceFiles/boxes/peers/edit_peer_invite_link.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1577,9 +1577,11 @@ object_ptr<Ui::BoxContent> EditLinkBox(
const auto isGroup = !peer->isBroadcast();
const auto isPublic = peer->isChannel() && peer->asChannel()->isPublic();
auto object = Box([=](not_null<Ui::GenericBox*> box) {
const auto fill = [=] {
return Ui::FillCreateInviteLinkSubscriptionToggle(box, peer);
};
const auto fill = isGroup
? Fn<Ui::InviteLinkSubscriptionToggle()>(nullptr)
: [=] {
return Ui::FillCreateInviteLinkSubscriptionToggle(box, peer);
};
if (creating) {
Ui::CreateInviteLinkBox(box, fill, isGroup, isPublic, done);
} else {
Expand Down
25 changes: 5 additions & 20 deletions Telegram/SourceFiles/data/components/credits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ For license and copyright information please follow this link:

#include "api/api_credits.h"
#include "data/data_user.h"
#include "main/main_app_config.h"
#include "main/main_session.h"

namespace Data {
Expand All @@ -31,26 +32,10 @@ void Credits::apply(const MTPDupdateStarsBalance &data) {

rpl::producer<float64> Credits::rateValue(
not_null<PeerData*> ownedBotOrChannel) {
// Should be replaced in the future.
if (_rate > 0) {
return rpl::single(_rate);
}
return [=](auto consumer) {
auto lifetime = rpl::lifetime();

const auto api = lifetime.make_state<Api::CreditsEarnStatistics>(
ownedBotOrChannel);
api->request(
) | rpl::start_with_done([=] {
_rate = api->data().usdRate;
if (_rate > 0) {
consumer.put_next_copy(_rate);
consumer.put_done();
}
}, lifetime);

return lifetime;
};
return rpl::single(
_session->appConfig().get<float64>(
u"stars_usd_withdraw_rate_x1000"_q,
1200) / 1000.);
}

void Credits::load(bool force) {
Expand Down
27 changes: 17 additions & 10 deletions Telegram/SourceFiles/data/data_session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1295,24 +1295,31 @@ History *Session::historyLoaded(const PeerData *peer) {
}

void Session::deleteConversationLocally(not_null<PeerData*> peer) {
const auto history = historyLoaded(peer);
if (history) {
const auto markLeft = [&] {
if (const auto channel = peer->asMegagroup()) {
channel->addFlags(ChannelDataFlag::Left);
if (const auto from = channel->getMigrateFromChat()) {
if (const auto migrated = historyLoaded(from)) {
migrated->updateChatListExistence();
}
}
}
};
if (const auto history = historyLoaded(peer)) {
if (history->folderKnown()) {
setChatPinned(history, FilterId(), false);
}
removeChatListEntry(history);
history->clearFolder();

// We want to mark the channel as left before unloading the history,
// otherwise some parts of updating may return us to the chats list.
markLeft();
history->clear(peer->isChannel()
? History::ClearType::Unload
: History::ClearType::DeleteChat);
}
if (const auto channel = peer->asMegagroup()) {
channel->addFlags(ChannelDataFlag::Left);
if (const auto from = channel->getMigrateFromChat()) {
if (const auto migrated = historyLoaded(from)) {
migrated->updateChatListExistence();
}
}
} else {
markLeft();
}
}

Expand Down
Loading

0 comments on commit fd921a6

Please sign in to comment.