Fix sending bot inline preview in replies and scheduled messages
This commit is contained in:
parent
4b7a6b82c0
commit
53178bab02
4 changed files with 70 additions and 25 deletions
|
|
@ -47,6 +47,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "core/file_utilities.h"
|
#include "core/file_utilities.h"
|
||||||
#include "main/main_session.h"
|
#include "main/main_session.h"
|
||||||
#include "data/data_session.h"
|
#include "data/data_session.h"
|
||||||
|
#include "data/data_document.h"
|
||||||
#include "data/data_user.h"
|
#include "data/data_user.h"
|
||||||
#include "data/data_chat.h"
|
#include "data/data_chat.h"
|
||||||
#include "data/data_channel.h"
|
#include "data/data_channel.h"
|
||||||
|
|
@ -486,7 +487,20 @@ void RepliesWidget::setupComposeControls() {
|
||||||
|
|
||||||
_composeControls->inlineResultChosen(
|
_composeControls->inlineResultChosen(
|
||||||
) | rpl::start_with_next([=](Selector::InlineChosen chosen) {
|
) | rpl::start_with_next([=](Selector::InlineChosen chosen) {
|
||||||
|
if (chosen.sendPreview) {
|
||||||
|
const auto request = chosen.result->openRequest();
|
||||||
|
if (const auto photo = request.photo()) {
|
||||||
|
sendExistingPhoto(photo, chosen.options);
|
||||||
|
} else if (const auto document = request.document()) {
|
||||||
|
sendExistingDocument(document, chosen.options);
|
||||||
|
}
|
||||||
|
|
||||||
|
addRecentBot(chosen.bot);
|
||||||
|
_composeControls->clear();
|
||||||
|
finishSending();
|
||||||
|
} else {
|
||||||
sendInlineResult(chosen.result, chosen.bot, chosen.options);
|
sendInlineResult(chosen.result, chosen.bot, chosen.options);
|
||||||
|
}
|
||||||
}, lifetime());
|
}, lifetime());
|
||||||
|
|
||||||
_composeControls->scrollRequests(
|
_composeControls->scrollRequests(
|
||||||
|
|
@ -855,6 +869,20 @@ bool RepliesWidget::showSendingFilesError(
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RepliesWidget::addRecentBot(not_null<UserData*> bot) {
|
||||||
|
auto &bots = cRefRecentInlineBots();
|
||||||
|
const auto index = bots.indexOf(bot);
|
||||||
|
if (index) {
|
||||||
|
if (index > 0) {
|
||||||
|
bots.removeAt(index);
|
||||||
|
} else if (bots.size() >= RecentInlineBotsLimit) {
|
||||||
|
bots.resize(RecentInlineBotsLimit - 1);
|
||||||
|
}
|
||||||
|
bots.push_front(bot);
|
||||||
|
bot->session().local().writeRecentHashtagsAndBots();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void RepliesWidget::send() {
|
void RepliesWidget::send() {
|
||||||
if (_composeControls->getTextWithAppliedMarkdown().text.isEmpty()) {
|
if (_composeControls->getTextWithAppliedMarkdown().text.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
|
|
@ -1025,7 +1053,12 @@ bool RepliesWidget::sendExistingDocument(
|
||||||
auto message = Api::MessageToSend(_history);
|
auto message = Api::MessageToSend(_history);
|
||||||
message.action.replyTo = replyToId();
|
message.action.replyTo = replyToId();
|
||||||
message.action.options = options;
|
message.action.options = options;
|
||||||
|
|
||||||
|
if (document->hasRemoteLocation()) {
|
||||||
Api::SendExistingDocument(std::move(message), document);
|
Api::SendExistingDocument(std::move(message), document);
|
||||||
|
} else {
|
||||||
|
Api::SendWebDocument(std::move(message), document);
|
||||||
|
}
|
||||||
|
|
||||||
_composeControls->cancelReplyMessage();
|
_composeControls->cancelReplyMessage();
|
||||||
finishSending();
|
finishSending();
|
||||||
|
|
@ -1100,17 +1133,7 @@ void RepliesWidget::sendInlineResult(
|
||||||
//_saveDraftStart = crl::now();
|
//_saveDraftStart = crl::now();
|
||||||
//onDraftSave();
|
//onDraftSave();
|
||||||
|
|
||||||
auto &bots = cRefRecentInlineBots();
|
addRecentBot(bot);
|
||||||
const auto index = bots.indexOf(bot);
|
|
||||||
if (index) {
|
|
||||||
if (index > 0) {
|
|
||||||
bots.removeAt(index);
|
|
||||||
} else if (bots.size() >= RecentInlineBotsLimit) {
|
|
||||||
bots.resize(RecentInlineBotsLimit - 1);
|
|
||||||
}
|
|
||||||
bots.push_front(bot);
|
|
||||||
bot->session().local().writeRecentHashtagsAndBots();
|
|
||||||
}
|
|
||||||
finishSending();
|
finishSending();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -183,6 +183,8 @@ private:
|
||||||
void clearSelected();
|
void clearSelected();
|
||||||
void setPinnedVisibility(bool shown);
|
void setPinnedVisibility(bool shown);
|
||||||
|
|
||||||
|
void addRecentBot(not_null<UserData*> bot);
|
||||||
|
|
||||||
void send();
|
void send();
|
||||||
void send(Api::SendOptions options);
|
void send(Api::SendOptions options);
|
||||||
void sendVoice(Controls::VoiceToSend &&data);
|
void sendVoice(Controls::VoiceToSend &&data);
|
||||||
|
|
|
||||||
|
|
@ -229,7 +229,21 @@ void ScheduledWidget::setupComposeControls() {
|
||||||
|
|
||||||
_composeControls->inlineResultChosen(
|
_composeControls->inlineResultChosen(
|
||||||
) | rpl::start_with_next([=](Selector::InlineChosen chosen) {
|
) | rpl::start_with_next([=](Selector::InlineChosen chosen) {
|
||||||
|
if (chosen.sendPreview) {
|
||||||
|
const auto request = chosen.result->openRequest();
|
||||||
|
if (const auto photo = request.photo()) {
|
||||||
|
sendExistingPhoto(photo);
|
||||||
|
} else if (const auto document = request.document()) {
|
||||||
|
sendExistingDocument(document);
|
||||||
|
}
|
||||||
|
|
||||||
|
addRecentBot(chosen.bot);
|
||||||
|
_composeControls->clear();
|
||||||
|
_composeControls->hidePanelsAnimated();
|
||||||
|
_composeControls->focus();
|
||||||
|
} else {
|
||||||
sendInlineResult(chosen.result, chosen.bot);
|
sendInlineResult(chosen.result, chosen.bot);
|
||||||
|
}
|
||||||
}, lifetime());
|
}, lifetime());
|
||||||
|
|
||||||
_composeControls->scrollRequests(
|
_composeControls->scrollRequests(
|
||||||
|
|
@ -494,6 +508,20 @@ bool ScheduledWidget::showSendingFilesError(
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ScheduledWidget::addRecentBot(not_null<UserData*> bot) {
|
||||||
|
auto &bots = cRefRecentInlineBots();
|
||||||
|
const auto index = bots.indexOf(bot);
|
||||||
|
if (index) {
|
||||||
|
if (index > 0) {
|
||||||
|
bots.removeAt(index);
|
||||||
|
} else if (bots.size() >= RecentInlineBotsLimit) {
|
||||||
|
bots.resize(RecentInlineBotsLimit - 1);
|
||||||
|
}
|
||||||
|
bots.push_front(bot);
|
||||||
|
bot->session().local().writeRecentHashtagsAndBots();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void ScheduledWidget::send() {
|
void ScheduledWidget::send() {
|
||||||
if (_composeControls->getTextWithAppliedMarkdown().text.isEmpty()) {
|
if (_composeControls->getTextWithAppliedMarkdown().text.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
|
|
@ -729,17 +757,7 @@ void ScheduledWidget::sendInlineResult(
|
||||||
//_saveDraftStart = crl::now();
|
//_saveDraftStart = crl::now();
|
||||||
//onDraftSave();
|
//onDraftSave();
|
||||||
|
|
||||||
auto &bots = cRefRecentInlineBots();
|
addRecentBot(bot);
|
||||||
const auto index = bots.indexOf(bot);
|
|
||||||
if (index) {
|
|
||||||
if (index > 0) {
|
|
||||||
bots.removeAt(index);
|
|
||||||
} else if (bots.size() >= RecentInlineBotsLimit) {
|
|
||||||
bots.resize(RecentInlineBotsLimit - 1);
|
|
||||||
}
|
|
||||||
bots.push_front(bot);
|
|
||||||
bot->session().local().writeRecentHashtagsAndBots();
|
|
||||||
}
|
|
||||||
|
|
||||||
_composeControls->hidePanelsAnimated();
|
_composeControls->hidePanelsAnimated();
|
||||||
_composeControls->focus();
|
_composeControls->focus();
|
||||||
|
|
|
||||||
|
|
@ -149,6 +149,8 @@ private:
|
||||||
void confirmDeleteSelected();
|
void confirmDeleteSelected();
|
||||||
void clearSelected();
|
void clearSelected();
|
||||||
|
|
||||||
|
void addRecentBot(not_null<UserData*> bot);
|
||||||
|
|
||||||
void send();
|
void send();
|
||||||
void send(Api::SendOptions options);
|
void send(Api::SendOptions options);
|
||||||
void sendVoice(QByteArray bytes, VoiceWaveform waveform, int duration);
|
void sendVoice(QByteArray bytes, VoiceWaveform waveform, int duration);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue