mirror of https://github.com/procxx/kepka.git
Move sendMessage and sendInlineResult to ApiWrap.
This commit is contained in:
parent
ff53404d5b
commit
33095966af
|
@ -37,8 +37,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "window/notifications_manager.h"
|
||||
#include "window/window_lock_widgets.h"
|
||||
#include "window/window_controller.h"
|
||||
#include "inline_bots/inline_bot_result.h"
|
||||
#include "chat_helpers/message_field.h"
|
||||
#include "chat_helpers/stickers.h"
|
||||
#include "ui/text_options.h"
|
||||
#include "storage/localimageloader.h"
|
||||
#include "storage/storage_facade.h"
|
||||
#include "storage/storage_shared_media.h"
|
||||
|
@ -126,15 +128,15 @@ MTPVector<MTPDocumentAttribute> ComposeSendingDocumentAttributes(
|
|||
return MTP_vector<MTPDocumentAttribute>(attributes);
|
||||
}
|
||||
|
||||
FileLoadTo FileLoadTaskOptions(const ApiWrap::SendOptions &options) {
|
||||
const auto peer = options.history->peer;
|
||||
return FileLoadTo(
|
||||
peer->id,
|
||||
Auth().data().notifySilentPosts(peer),
|
||||
options.replyTo);
|
||||
} // namespace
|
||||
|
||||
ApiWrap::SendOptions::SendOptions(not_null<History*> history)
|
||||
: history(history) {
|
||||
}
|
||||
|
||||
} // namespace
|
||||
ApiWrap::MessageToSend::MessageToSend(not_null<History*> history)
|
||||
: history(history) {
|
||||
}
|
||||
|
||||
ApiWrap::ApiWrap(not_null<AuthSession*> session)
|
||||
: _session(session)
|
||||
|
@ -230,7 +232,7 @@ void ApiWrap::proxyPromotionDone(const MTPhelp_ProxyData &proxy) {
|
|||
const auto peer = App::peer(peerId);
|
||||
_session->data().setProxyPromoted(peer);
|
||||
if (const auto history = App::historyLoaded(peer)) {
|
||||
_session->api().requestDialogEntry(history);
|
||||
requestDialogEntry(history);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3826,7 +3828,7 @@ void ApiWrap::sendVoiceMessage(
|
|||
int duration,
|
||||
const SendOptions &options) {
|
||||
const auto caption = TextWithTags();
|
||||
const auto to = FileLoadTaskOptions(options);
|
||||
const auto to = fileLoadTaskOptions(options);
|
||||
_fileLoader->addTask(std::make_unique<FileLoadTask>(
|
||||
result,
|
||||
duration,
|
||||
|
@ -3842,15 +3844,15 @@ void ApiWrap::sendFiles(
|
|||
std::shared_ptr<SendingAlbum> album,
|
||||
const SendOptions &options) {
|
||||
if (list.files.size() > 1 && !caption.text.isEmpty()) {
|
||||
auto message = MainWidget::MessageToSend(options.history);
|
||||
auto message = MessageToSend(options.history);
|
||||
message.textWithTags = std::move(caption);
|
||||
message.replyTo = options.replyTo;
|
||||
message.clearDraft = false;
|
||||
App::main()->sendMessage(message);
|
||||
sendMessage(std::move(message));
|
||||
caption = TextWithTags();
|
||||
}
|
||||
|
||||
const auto to = FileLoadTaskOptions(options);
|
||||
const auto to = fileLoadTaskOptions(options);
|
||||
if (album) {
|
||||
album->silent = to.silent;
|
||||
}
|
||||
|
@ -3891,7 +3893,7 @@ void ApiWrap::sendFile(
|
|||
const QByteArray &fileContent,
|
||||
SendMediaType type,
|
||||
const SendOptions &options) {
|
||||
auto to = FileLoadTaskOptions(options);
|
||||
const auto to = fileLoadTaskOptions(options);
|
||||
auto caption = TextWithTags();
|
||||
_fileLoader->addTask(std::make_unique<FileLoadTask>(
|
||||
QString(),
|
||||
|
@ -3961,6 +3963,202 @@ void ApiWrap::cancelLocalItem(not_null<HistoryItem*> item) {
|
|||
}
|
||||
}
|
||||
|
||||
void ApiWrap::sendMessage(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;
|
||||
sendAction(options);
|
||||
|
||||
if (!peer->canWrite()) {
|
||||
return;
|
||||
}
|
||||
Local::saveRecentSentHashtags(textWithTags.text);
|
||||
|
||||
auto sending = TextWithEntities();
|
||||
auto left = TextWithEntities {
|
||||
textWithTags.text,
|
||||
ConvertTextTagsToEntities(textWithTags.tags)
|
||||
};
|
||||
auto prepareFlags = Ui::ItemTextOptions(
|
||||
history,
|
||||
_session->user()).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 = _session->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
|
||||
&& _session->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 : _session->userId();
|
||||
auto messagePostAuthor = channelPost
|
||||
? App::peerName(_session->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 = request(MTPmessages_SendMessage(
|
||||
MTP_flags(sendFlags),
|
||||
peer->input,
|
||||
MTP_int(message.replyTo),
|
||||
msgText,
|
||||
MTP_long(randomId),
|
||||
MTPnullMarkup,
|
||||
sentEntities
|
||||
)).done([=](const MTPUpdates &result) {
|
||||
applyUpdates(result, randomId);
|
||||
}).fail([=](const RPCError &error) { sendMessageFail(error);
|
||||
}).afterRequest(history->sendRequestId
|
||||
).send();
|
||||
}
|
||||
|
||||
if (const auto main = App::main()) {
|
||||
main->finishForwarding(history);
|
||||
}
|
||||
}
|
||||
|
||||
void ApiWrap::sendInlineResult(
|
||||
not_null<UserData*> bot,
|
||||
not_null<InlineBots::Result*> data,
|
||||
const SendOptions &options) {
|
||||
Auth().api().sendAction(options);
|
||||
|
||||
const auto history = options.history;
|
||||
const auto peer = history->peer;
|
||||
const auto newId = FullMsgId(peerToChannel(peer->id), clientMsgId());
|
||||
const auto randomId = rand_value<uint64>();
|
||||
|
||||
auto flags = NewMessageFlags(peer) | MTPDmessage::Flag::f_media;
|
||||
auto sendFlags = MTPmessages_SendInlineBotResult::Flag::f_clear_draft | 0;
|
||||
if (options.replyTo) {
|
||||
flags |= MTPDmessage::Flag::f_reply_to_msg_id;
|
||||
sendFlags |= MTPmessages_SendInlineBotResult::Flag::f_reply_to_msg_id;
|
||||
}
|
||||
bool channelPost = peer->isChannel() && !peer->isMegagroup();
|
||||
bool silentPost = channelPost && _session->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_SendInlineBotResult::Flag::f_silent;
|
||||
}
|
||||
if (bot) {
|
||||
flags |= MTPDmessage::Flag::f_via_bot_id;
|
||||
}
|
||||
|
||||
auto messageFromId = channelPost ? 0 : Auth().userId();
|
||||
auto messagePostAuthor = channelPost
|
||||
? App::peerName(Auth().user())
|
||||
: QString();
|
||||
MTPint messageDate = MTP_int(unixtime());
|
||||
UserId messageViaBotId = bot ? peerToUser(bot->id) : 0;
|
||||
MsgId messageId = newId.msg;
|
||||
|
||||
App::historyRegRandom(randomId, newId);
|
||||
|
||||
data->addToHistory(
|
||||
history,
|
||||
flags,
|
||||
messageId,
|
||||
messageFromId,
|
||||
messageDate,
|
||||
messageViaBotId,
|
||||
options.replyTo,
|
||||
messagePostAuthor);
|
||||
|
||||
history->sendRequestId = request(MTPmessages_SendInlineBotResult(
|
||||
MTP_flags(sendFlags),
|
||||
peer->input,
|
||||
MTP_int(options.replyTo),
|
||||
MTP_long(randomId),
|
||||
MTP_long(data->getQueryId()),
|
||||
MTP_string(data->getId())
|
||||
)).done([=](const MTPUpdates &result) {
|
||||
applyUpdates(result, randomId);
|
||||
}).fail([=](const RPCError &error) { sendMessageFail(error);
|
||||
}).afterRequest(history->sendRequestId
|
||||
).send();
|
||||
|
||||
if (const auto main = App::main()) {
|
||||
main->finishForwarding(history);
|
||||
}
|
||||
}
|
||||
|
||||
void ApiWrap::uploadAlbumMedia(
|
||||
not_null<HistoryItem*> item,
|
||||
const MessageGroupId &groupId,
|
||||
|
@ -4196,6 +4394,14 @@ void ApiWrap::sendAlbumIfReady(not_null<SendingAlbum*> album) {
|
|||
).send();
|
||||
}
|
||||
|
||||
FileLoadTo ApiWrap::fileLoadTaskOptions(const SendOptions &options) const {
|
||||
const auto peer = options.history->peer;
|
||||
return FileLoadTo(
|
||||
peer->id,
|
||||
_session->data().notifySilentPosts(peer),
|
||||
options.replyTo);
|
||||
}
|
||||
|
||||
void ApiWrap::readServerHistory(not_null<History*> history) {
|
||||
if (history->unreadCount()) {
|
||||
readServerHistoryForce(history);
|
||||
|
|
|
@ -21,6 +21,11 @@ class AuthSession;
|
|||
struct MessageGroupId;
|
||||
struct SendingAlbum;
|
||||
enum class SendMediaType;
|
||||
struct FileLoadTo;
|
||||
|
||||
namespace InlineBots {
|
||||
class Result;
|
||||
} // namespace InlineBots
|
||||
|
||||
namespace Storage {
|
||||
enum class SharedMediaType : signed char;
|
||||
|
@ -221,8 +226,7 @@ public:
|
|||
Fn<void()> callbackNotModified = nullptr);
|
||||
|
||||
struct SendOptions {
|
||||
SendOptions(not_null<History*> history) : history(history) {
|
||||
}
|
||||
SendOptions(not_null<History*> history);
|
||||
|
||||
not_null<History*> history;
|
||||
MsgId replyTo = 0;
|
||||
|
@ -277,6 +281,21 @@ public:
|
|||
bool silent);
|
||||
void cancelLocalItem(not_null<HistoryItem*> item);
|
||||
|
||||
struct MessageToSend {
|
||||
MessageToSend(not_null<History*> history);
|
||||
|
||||
not_null<History*> history;
|
||||
TextWithTags textWithTags;
|
||||
MsgId replyTo = 0;
|
||||
WebPageId webPageId = 0;
|
||||
bool clearDraft = true;
|
||||
};
|
||||
void sendMessage(MessageToSend &&message);
|
||||
void sendInlineResult(
|
||||
not_null<UserData*> bot,
|
||||
not_null<InlineBots::Result*> data,
|
||||
const SendOptions &options);
|
||||
|
||||
~ApiWrap();
|
||||
|
||||
private:
|
||||
|
@ -439,6 +458,7 @@ private:
|
|||
const MTPInputMedia &media,
|
||||
bool silent,
|
||||
uint64 randomId);
|
||||
FileLoadTo fileLoadTaskOptions(const SendOptions &options) const;
|
||||
|
||||
void readFeeds();
|
||||
|
||||
|
|
|
@ -860,7 +860,14 @@ void GifsListWidget::sendInlineRequest() {
|
|||
}
|
||||
|
||||
_footer->setLoading(true);
|
||||
_inlineRequestId = request(MTPmessages_GetInlineBotResults(MTP_flags(0), _searchBot->inputUser, _inlineQueryPeer->input, MTPInputGeoPoint(), MTP_string(_inlineQuery), MTP_string(nextOffset))).done([this](const MTPmessages_BotResults &result, mtpRequestId requestId) {
|
||||
_inlineRequestId = request(MTPmessages_GetInlineBotResults(
|
||||
MTP_flags(0),
|
||||
_searchBot->inputUser,
|
||||
_inlineQueryPeer->input,
|
||||
MTPInputGeoPoint(),
|
||||
MTP_string(_inlineQuery),
|
||||
MTP_string(nextOffset)
|
||||
)).done([this](const MTPmessages_BotResults &result) {
|
||||
inlineResultsDone(result);
|
||||
}).fail([this](const RPCError &error) {
|
||||
// show error?
|
||||
|
|
|
@ -1011,39 +1011,4 @@ RecentStickerPack &GetRecentPack() {
|
|||
return cRefRecentStickers();
|
||||
}
|
||||
|
||||
void IncrementRecentHashtag(RecentHashtagPack &recent, const QString &tag) {
|
||||
auto i = recent.begin(), e = recent.end();
|
||||
for (; i != e; ++i) {
|
||||
if (i->first == tag) {
|
||||
++i->second;
|
||||
if (qAbs(i->second) > 0x4000) {
|
||||
for (auto j = recent.begin(); j != e; ++j) {
|
||||
if (j->second > 1) {
|
||||
j->second /= 2;
|
||||
} else if (j->second > 0) {
|
||||
j->second = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (; i != recent.begin(); --i) {
|
||||
if (qAbs((i - 1)->second) > qAbs(i->second)) {
|
||||
break;
|
||||
}
|
||||
qSwap(*i, *(i - 1));
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (i == e) {
|
||||
while (recent.size() >= 64) recent.pop_back();
|
||||
recent.push_back(qMakePair(tag, 1));
|
||||
for (i = recent.end() - 1; i != recent.begin(); --i) {
|
||||
if ((i - 1)->second > i->second) {
|
||||
break;
|
||||
}
|
||||
qSwap(*i, *(i - 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Stickers
|
||||
|
|
|
@ -99,6 +99,4 @@ QString GetSetTitle(const MTPDstickerSet &s);
|
|||
|
||||
RecentStickerPack &GetRecentPack();
|
||||
|
||||
void IncrementRecentHashtag(RecentHashtagPack &recent, const QString &tag);
|
||||
|
||||
} // namespace Stickers
|
||||
|
|
|
@ -2403,7 +2403,7 @@ bool DialogsInner::chooseHashtag() {
|
|||
_mouseSelection = true;
|
||||
updateSelected();
|
||||
} else {
|
||||
saveRecentHashtags('#' + hashtag->tag);
|
||||
Local::saveRecentSearchHashtags('#' + hashtag->tag);
|
||||
emit completeHashtag(hashtag->tag);
|
||||
}
|
||||
return true;
|
||||
|
@ -2456,7 +2456,7 @@ bool DialogsInner::chooseRow() {
|
|||
const auto chosen = computeChosenRow();
|
||||
if (chosen.key) {
|
||||
if (IsServerMsgId(chosen.message.fullId.msg)) {
|
||||
saveRecentHashtags(_filter);
|
||||
Local::saveRecentSearchHashtags(_filter);
|
||||
}
|
||||
const auto openSearchResult = !App::main()->selectingPeer(true)
|
||||
&& (_state == State::Filtered)
|
||||
|
@ -2485,38 +2485,6 @@ bool DialogsInner::chooseRow() {
|
|||
return false;
|
||||
}
|
||||
|
||||
void DialogsInner::saveRecentHashtags(const QString &text) {
|
||||
auto found = false;
|
||||
QRegularExpressionMatch m;
|
||||
auto recent = cRecentSearchHashtags();
|
||||
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 = cRecentSearchHashtags();
|
||||
}
|
||||
found = true;
|
||||
Stickers::IncrementRecentHashtag(recent, tag);
|
||||
}
|
||||
if (found) {
|
||||
cSetRecentSearchHashtags(recent);
|
||||
Local::writeRecentHashtagsAndBots();
|
||||
}
|
||||
}
|
||||
|
||||
void DialogsInner::destroyData() {
|
||||
_selected = nullptr;
|
||||
_hashtagSelected = -1;
|
||||
|
|
|
@ -63,11 +63,9 @@ public:
|
|||
void refresh(bool toTop = false);
|
||||
|
||||
bool chooseRow();
|
||||
void saveRecentHashtags(const QString &text);
|
||||
|
||||
void destroyData();
|
||||
|
||||
|
||||
Dialogs::RowDescriptor chatListEntryBefore(
|
||||
const Dialogs::RowDescriptor &which) const;
|
||||
Dialogs::RowDescriptor chatListEntryAfter(
|
||||
|
|
|
@ -30,6 +30,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "window/window_connecting_widget.h"
|
||||
#include "profile/profile_channel_controllers.h"
|
||||
#include "storage/storage_media_prepare.h"
|
||||
#include "storage/localstorage.h"
|
||||
#include "data/data_session.h"
|
||||
#include "styles/style_dialogs.h"
|
||||
#include "styles/style_window.h"
|
||||
|
@ -637,7 +638,7 @@ void DialogsWidget::searchMessages(
|
|||
_searchTimer.stop();
|
||||
onSearchMessages();
|
||||
|
||||
_inner->saveRecentHashtags(query);
|
||||
Local::saveRecentSearchHashtags(query);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3004,13 +3004,17 @@ void HistoryWidget::send() {
|
|||
return;
|
||||
}
|
||||
|
||||
WebPageId webPageId = _previewCancelled ? CancelledWebPageId : ((_previewData && _previewData->pendingTill >= 0) ? _previewData->id : 0);
|
||||
WebPageId webPageId = _previewCancelled
|
||||
? CancelledWebPageId
|
||||
: ((_previewData && _previewData->pendingTill >= 0)
|
||||
? _previewData->id
|
||||
: 0);
|
||||
|
||||
auto message = MainWidget::MessageToSend(_history);
|
||||
auto message = ApiWrap::MessageToSend(_history);
|
||||
message.textWithTags = _field->getTextWithAppliedMarkdown();
|
||||
message.replyTo = replyToId();
|
||||
message.webPageId = webPageId;
|
||||
App::main()->sendMessage(message);
|
||||
Auth().api().sendMessage(std::move(message));
|
||||
|
||||
clearFieldText();
|
||||
_saveDraftText = true;
|
||||
|
@ -3398,14 +3402,14 @@ void HistoryWidget::sendBotCommand(PeerData *peer, UserData *bot, const QString
|
|||
toSend += '@' + username;
|
||||
}
|
||||
|
||||
auto message = MainWidget::MessageToSend(_history);
|
||||
auto message = ApiWrap::MessageToSend(_history);
|
||||
message.textWithTags = { toSend, TextWithTags::Tags() };
|
||||
message.replyTo = replyTo
|
||||
? ((!_peer->isUser()/* && (botStatus == 0 || botStatus == 2)*/)
|
||||
? replyTo
|
||||
: replyToId())
|
||||
: 0;
|
||||
App::main()->sendMessage(message);
|
||||
Auth().api().sendMessage(std::move(message));
|
||||
if (replyTo) {
|
||||
if (_replyToId == replyTo) {
|
||||
cancelReply();
|
||||
|
@ -5398,7 +5402,10 @@ void HistoryWidget::onPhotoSend(PhotoData *photo) {
|
|||
void HistoryWidget::onInlineResultSend(
|
||||
InlineBots::Result *result,
|
||||
UserData *bot) {
|
||||
if (!_peer || !_peer->canWrite() || !result) {
|
||||
Expects(result != nullptr);
|
||||
Expects(bot != nullptr);
|
||||
|
||||
if (!_peer || !_peer->canWrite()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -5412,77 +5419,15 @@ void HistoryWidget::onInlineResultSend(
|
|||
options.clearDraft = true;
|
||||
options.replyTo = replyToId();
|
||||
options.generateLocal = true;
|
||||
Auth().api().sendAction(options);
|
||||
|
||||
uint64 randomId = rand_value<uint64>();
|
||||
FullMsgId newId(_channel, clientMsgId());
|
||||
|
||||
auto flags = NewMessageFlags(_peer) | MTPDmessage::Flag::f_media;
|
||||
auto sendFlags = MTPmessages_SendInlineBotResult::Flag::f_clear_draft | 0;
|
||||
if (options.replyTo) {
|
||||
flags |= MTPDmessage::Flag::f_reply_to_msg_id;
|
||||
sendFlags |= MTPmessages_SendInlineBotResult::Flag::f_reply_to_msg_id;
|
||||
}
|
||||
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_SendInlineBotResult::Flag::f_silent;
|
||||
}
|
||||
if (bot) {
|
||||
flags |= MTPDmessage::Flag::f_via_bot_id;
|
||||
}
|
||||
|
||||
auto messageFromId = channelPost ? 0 : Auth().userId();
|
||||
auto messagePostAuthor = channelPost
|
||||
? App::peerName(Auth().user())
|
||||
: QString();
|
||||
MTPint messageDate = MTP_int(unixtime());
|
||||
UserId messageViaBotId = bot ? peerToUser(bot->id) : 0;
|
||||
MsgId messageId = newId.msg;
|
||||
|
||||
result->addToHistory(
|
||||
_history,
|
||||
flags,
|
||||
messageId,
|
||||
messageFromId,
|
||||
messageDate,
|
||||
messageViaBotId,
|
||||
options.replyTo,
|
||||
messagePostAuthor);
|
||||
|
||||
_history->sendRequestId = MTP::send(
|
||||
MTPmessages_SendInlineBotResult(
|
||||
MTP_flags(sendFlags),
|
||||
_peer->input,
|
||||
MTP_int(options.replyTo),
|
||||
MTP_long(randomId),
|
||||
MTP_long(result->getQueryId()),
|
||||
MTP_string(result->getId())),
|
||||
App::main()->rpcDone(&MainWidget::sentUpdatesReceived),
|
||||
App::main()->rpcFail(&MainWidget::sendMessageFail),
|
||||
0,
|
||||
0,
|
||||
_history->sendRequestId);
|
||||
App::main()->finishForwarding(_history);
|
||||
|
||||
App::historyRegRandom(randomId, newId);
|
||||
Auth().api().sendInlineResult(bot, result, options);
|
||||
|
||||
clearFieldText();
|
||||
_saveDraftText = true;
|
||||
_saveDraftStart = getms();
|
||||
onDraftSave();
|
||||
|
||||
RecentInlineBots &bots(cRefRecentInlineBots());
|
||||
int32 index = bots.indexOf(bot);
|
||||
auto &bots = cRefRecentInlineBots();
|
||||
const auto index = bots.indexOf(bot);
|
||||
if (index) {
|
||||
if (index > 0) {
|
||||
bots.removeAt(index);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -222,19 +222,6 @@ public:
|
|||
Dialogs::IndexedList *dialogsList();
|
||||
Dialogs::IndexedList *contactsNoDialogsList();
|
||||
|
||||
struct MessageToSend {
|
||||
MessageToSend(not_null<History*> history) : history(history) {
|
||||
}
|
||||
|
||||
not_null<History*> history;
|
||||
TextWithTags textWithTags;
|
||||
MsgId replyTo = 0;
|
||||
WebPageId webPageId = 0;
|
||||
bool clearDraft = true;
|
||||
};
|
||||
void sendMessage(const MessageToSend &message);
|
||||
void saveRecentHashtags(const QString &text);
|
||||
|
||||
void unreadCountChanged(not_null<History*> history);
|
||||
|
||||
// While HistoryInner is not HistoryView::ListWidget.
|
||||
|
|
|
@ -4625,6 +4625,94 @@ void readRecentHashtagsAndBots() {
|
|||
}
|
||||
}
|
||||
|
||||
void incrementRecentHashtag(RecentHashtagPack &recent, const QString &tag) {
|
||||
auto i = recent.begin(), e = recent.end();
|
||||
for (; i != e; ++i) {
|
||||
if (i->first == tag) {
|
||||
++i->second;
|
||||
if (qAbs(i->second) > 0x4000) {
|
||||
for (auto j = recent.begin(); j != e; ++j) {
|
||||
if (j->second > 1) {
|
||||
j->second /= 2;
|
||||
} else if (j->second > 0) {
|
||||
j->second = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (; i != recent.begin(); --i) {
|
||||
if (qAbs((i - 1)->second) > qAbs(i->second)) {
|
||||
break;
|
||||
}
|
||||
qSwap(*i, *(i - 1));
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (i == e) {
|
||||
while (recent.size() >= 64) recent.pop_back();
|
||||
recent.push_back(qMakePair(tag, 1));
|
||||
for (i = recent.end() - 1; i != recent.begin(); --i) {
|
||||
if ((i - 1)->second > i->second) {
|
||||
break;
|
||||
}
|
||||
qSwap(*i, *(i - 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
base::optional<RecentHashtagPack> saveRecentHashtags(
|
||||
Fn<RecentHashtagPack()> getPack,
|
||||
const QString &text) {
|
||||
auto found = false;
|
||||
auto m = QRegularExpressionMatch();
|
||||
auto recent = getPack();
|
||||
for (auto 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 = getPack();
|
||||
}
|
||||
found = true;
|
||||
incrementRecentHashtag(recent, tag);
|
||||
}
|
||||
return found ? base::make_optional(recent) : base::none;
|
||||
}
|
||||
|
||||
void saveRecentSentHashtags(const QString &text) {
|
||||
const auto result = saveRecentHashtags(
|
||||
[] { return cRecentWriteHashtags(); },
|
||||
text);
|
||||
if (result) {
|
||||
cSetRecentWriteHashtags(*result);
|
||||
Local::writeRecentHashtagsAndBots();
|
||||
}
|
||||
}
|
||||
|
||||
void saveRecentSearchHashtags(const QString &text) {
|
||||
const auto result = saveRecentHashtags(
|
||||
[] { return cRecentSearchHashtags(); },
|
||||
text);
|
||||
if (result) {
|
||||
cSetRecentSearchHashtags(*result);
|
||||
Local::writeRecentHashtagsAndBots();
|
||||
}
|
||||
}
|
||||
|
||||
void WriteExportSettings(const Export::Settings &settings) {
|
||||
if (!_working()) return;
|
||||
|
||||
|
|
|
@ -165,6 +165,8 @@ void writeLangPack();
|
|||
|
||||
void writeRecentHashtagsAndBots();
|
||||
void readRecentHashtagsAndBots();
|
||||
void saveRecentSentHashtags(const QString &text);
|
||||
void saveRecentSearchHashtags(const QString &text);
|
||||
|
||||
void WriteExportSettings(const Export::Settings &settings);
|
||||
Export::Settings ReadExportSettings();
|
||||
|
|
|
@ -445,15 +445,13 @@ void Manager::notificationReplied(
|
|||
const TextWithTags &reply) {
|
||||
if (!peerId) return;
|
||||
|
||||
auto history = App::history(peerId);
|
||||
const auto history = App::history(peerId);
|
||||
|
||||
auto message = MainWidget::MessageToSend(history);
|
||||
auto message = ApiWrap::MessageToSend(history);
|
||||
message.textWithTags = reply;
|
||||
message.replyTo = (msgId > 0 && !history->peer->isUser()) ? msgId : 0;
|
||||
message.clearDraft = false;
|
||||
if (auto main = App::main()) {
|
||||
main->sendMessage(message);
|
||||
}
|
||||
Auth().api().sendMessage(std::move(message));
|
||||
}
|
||||
|
||||
void NativeManager::doShowNotification(HistoryItem *item, int forwardedCount) {
|
||||
|
|
Loading…
Reference in New Issue