mirror of
https://github.com/kotatogram/kotatogram-desktop
synced 2025-08-31 14:45:14 +00:00
Move sendMessage and sendInlineResult to ApiWrap.
This commit is contained in:
@@ -1275,158 +1275,6 @@ Dialogs::IndexedList *MainWidget::contactsNoDialogsList() {
|
||||
return _dialogs->contactsNoDialogsList();
|
||||
}
|
||||
|
||||
void MainWidget::sendMessage(const MessageToSend &message) {
|
||||
const auto history = message.history;
|
||||
const auto peer = history->peer;
|
||||
auto &textWithTags = message.textWithTags;
|
||||
|
||||
auto options = ApiWrap::SendOptions(history);
|
||||
options.clearDraft = message.clearDraft;
|
||||
options.replyTo = message.replyTo;
|
||||
options.generateLocal = true;
|
||||
options.webPageId = message.webPageId;
|
||||
Auth().api().sendAction(options);
|
||||
|
||||
if (!peer->canWrite()) {
|
||||
return;
|
||||
}
|
||||
saveRecentHashtags(textWithTags.text);
|
||||
|
||||
auto sending = TextWithEntities();
|
||||
auto left = TextWithEntities {
|
||||
textWithTags.text,
|
||||
ConvertTextTagsToEntities(textWithTags.tags)
|
||||
};
|
||||
auto prepareFlags = Ui::ItemTextOptions(history, App::self()).flags;
|
||||
TextUtilities::PrepareForSending(left, prepareFlags);
|
||||
|
||||
HistoryItem *lastMessage = nullptr;
|
||||
|
||||
while (TextUtilities::CutPart(sending, left, MaxMessageSize)) {
|
||||
auto newId = FullMsgId(peerToChannel(peer->id), clientMsgId());
|
||||
auto randomId = rand_value<uint64>();
|
||||
|
||||
TextUtilities::Trim(sending);
|
||||
|
||||
App::historyRegRandom(randomId, newId);
|
||||
App::historyRegSentData(randomId, peer->id, sending.text);
|
||||
|
||||
MTPstring msgText(MTP_string(sending.text));
|
||||
auto flags = NewMessageFlags(peer) | MTPDmessage::Flag::f_entities;
|
||||
auto sendFlags = MTPmessages_SendMessage::Flags(0);
|
||||
if (message.replyTo) {
|
||||
flags |= MTPDmessage::Flag::f_reply_to_msg_id;
|
||||
sendFlags |= MTPmessages_SendMessage::Flag::f_reply_to_msg_id;
|
||||
}
|
||||
MTPMessageMedia media = MTP_messageMediaEmpty();
|
||||
if (message.webPageId == CancelledWebPageId) {
|
||||
sendFlags |= MTPmessages_SendMessage::Flag::f_no_webpage;
|
||||
} else if (message.webPageId) {
|
||||
auto page = Auth().data().webpage(message.webPageId);
|
||||
media = MTP_messageMediaWebPage(
|
||||
MTP_webPagePending(
|
||||
MTP_long(page->id),
|
||||
MTP_int(page->pendingTill)));
|
||||
flags |= MTPDmessage::Flag::f_media;
|
||||
}
|
||||
bool channelPost = peer->isChannel() && !peer->isMegagroup();
|
||||
bool silentPost = channelPost
|
||||
&& Auth().data().notifySilentPosts(peer);
|
||||
if (channelPost) {
|
||||
flags |= MTPDmessage::Flag::f_views;
|
||||
flags |= MTPDmessage::Flag::f_post;
|
||||
}
|
||||
if (!channelPost) {
|
||||
flags |= MTPDmessage::Flag::f_from_id;
|
||||
} else if (peer->asChannel()->addsSignature()) {
|
||||
flags |= MTPDmessage::Flag::f_post_author;
|
||||
}
|
||||
if (silentPost) {
|
||||
sendFlags |= MTPmessages_SendMessage::Flag::f_silent;
|
||||
}
|
||||
auto localEntities = TextUtilities::EntitiesToMTP(sending.entities);
|
||||
auto sentEntities = TextUtilities::EntitiesToMTP(sending.entities, TextUtilities::ConvertOption::SkipLocal);
|
||||
if (!sentEntities.v.isEmpty()) {
|
||||
sendFlags |= MTPmessages_SendMessage::Flag::f_entities;
|
||||
}
|
||||
if (message.clearDraft) {
|
||||
sendFlags |= MTPmessages_SendMessage::Flag::f_clear_draft;
|
||||
history->clearCloudDraft();
|
||||
}
|
||||
auto messageFromId = channelPost ? 0 : Auth().userId();
|
||||
auto messagePostAuthor = channelPost
|
||||
? App::peerName(Auth().user())
|
||||
: QString();
|
||||
lastMessage = history->addNewMessage(
|
||||
MTP_message(
|
||||
MTP_flags(flags),
|
||||
MTP_int(newId.msg),
|
||||
MTP_int(messageFromId),
|
||||
peerToMTP(peer->id),
|
||||
MTPnullFwdHeader,
|
||||
MTPint(),
|
||||
MTP_int(message.replyTo),
|
||||
MTP_int(unixtime()),
|
||||
msgText,
|
||||
media,
|
||||
MTPnullMarkup,
|
||||
localEntities,
|
||||
MTP_int(1),
|
||||
MTPint(),
|
||||
MTP_string(messagePostAuthor),
|
||||
MTPlong()),
|
||||
NewMessageUnread);
|
||||
history->sendRequestId = MTP::send(
|
||||
MTPmessages_SendMessage(
|
||||
MTP_flags(sendFlags),
|
||||
peer->input,
|
||||
MTP_int(message.replyTo),
|
||||
msgText,
|
||||
MTP_long(randomId),
|
||||
MTPnullMarkup,
|
||||
sentEntities),
|
||||
rpcDone(&MainWidget::sentUpdatesReceived, randomId),
|
||||
rpcFail(&MainWidget::sendMessageFail),
|
||||
0,
|
||||
0,
|
||||
history->sendRequestId);
|
||||
}
|
||||
|
||||
finishForwarding(history);
|
||||
}
|
||||
|
||||
void MainWidget::saveRecentHashtags(const QString &text) {
|
||||
bool found = false;
|
||||
QRegularExpressionMatch m;
|
||||
RecentHashtagPack recent(cRecentWriteHashtags());
|
||||
for (int32 i = 0, next = 0; (m = TextUtilities::RegExpHashtag().match(text, i)).hasMatch(); i = next) {
|
||||
i = m.capturedStart();
|
||||
next = m.capturedEnd();
|
||||
if (m.hasMatch()) {
|
||||
if (!m.capturedRef(1).isEmpty()) {
|
||||
++i;
|
||||
}
|
||||
if (!m.capturedRef(2).isEmpty()) {
|
||||
--next;
|
||||
}
|
||||
}
|
||||
const auto tag = text.mid(i + 1, next - i - 1);
|
||||
if (TextUtilities::RegExpHashtagExclude().match(tag).hasMatch()) {
|
||||
continue;
|
||||
}
|
||||
if (!found && cRecentWriteHashtags().isEmpty() && cRecentSearchHashtags().isEmpty()) {
|
||||
Local::readRecentHashtagsAndBots();
|
||||
recent = cRecentWriteHashtags();
|
||||
}
|
||||
found = true;
|
||||
Stickers::IncrementRecentHashtag(recent, tag);
|
||||
}
|
||||
if (found) {
|
||||
cSetRecentWriteHashtags(recent);
|
||||
Local::writeRecentHashtagsAndBots();
|
||||
}
|
||||
}
|
||||
|
||||
void MainWidget::unreadCountChanged(not_null<History*> history) {
|
||||
_history->unreadCountChanged(history);
|
||||
}
|
||||
|
Reference in New Issue
Block a user