mirror of https://github.com/procxx/kepka.git
Use Main::Session in entities parsing.
This commit is contained in:
parent
7a5f4e8a01
commit
bdbcd8e540
|
@ -93,6 +93,7 @@ void SendExistingMedia(
|
|||
};
|
||||
TextUtilities::Trim(caption);
|
||||
auto sentEntities = EntitiesToMTP(
|
||||
session,
|
||||
caption.entities,
|
||||
ConvertOption::SkipLocal);
|
||||
if (!sentEntities.v.isEmpty()) {
|
||||
|
|
|
@ -18,11 +18,13 @@ using namespace TextUtilities;
|
|||
|
||||
} // namespace
|
||||
|
||||
EntitiesInText EntitiesFromMTP(const QVector<MTPMessageEntity> &entities) {
|
||||
EntitiesInText EntitiesFromMTP(
|
||||
Main::Session *session,
|
||||
const QVector<MTPMessageEntity> &entities) {
|
||||
auto result = EntitiesInText();
|
||||
if (!entities.isEmpty()) {
|
||||
result.reserve(entities.size());
|
||||
for_const (auto &entity, entities) {
|
||||
for (const auto &entity : entities) {
|
||||
switch (entity.type()) {
|
||||
case mtpc_messageEntityUrl: { auto &d = entity.c_messageEntityUrl(); result.push_back({ EntityType::Url, d.voffset().v, d.vlength().v }); } break;
|
||||
case mtpc_messageEntityTextUrl: { auto &d = entity.c_messageEntityTextUrl(); result.push_back({ EntityType::CustomUrl, d.voffset().v, d.vlength().v, Clean(qs(d.vurl())) }); } break;
|
||||
|
@ -32,28 +34,30 @@ EntitiesInText EntitiesFromMTP(const QVector<MTPMessageEntity> &entities) {
|
|||
case mtpc_messageEntityPhone: break; // Skipping phones.
|
||||
case mtpc_messageEntityMention: { auto &d = entity.c_messageEntityMention(); result.push_back({ EntityType::Mention, d.voffset().v, d.vlength().v }); } break;
|
||||
case mtpc_messageEntityMentionName: {
|
||||
auto &d = entity.c_messageEntityMentionName();
|
||||
auto data = [&d] {
|
||||
if (auto user = Auth().data().userLoaded(d.vuser_id().v)) {
|
||||
return MentionNameDataFromFields({
|
||||
d.vuser_id().v,
|
||||
user->accessHash() });
|
||||
const auto &d = entity.c_messageEntityMentionName();
|
||||
const auto data = [&] {
|
||||
if (session) {
|
||||
if (const auto user = session->data().userLoaded(d.vuser_id().v)) {
|
||||
return MentionNameDataFromFields({
|
||||
d.vuser_id().v,
|
||||
user->accessHash() });
|
||||
}
|
||||
}
|
||||
return MentionNameDataFromFields(d.vuser_id().v);
|
||||
};
|
||||
result.push_back({ EntityType::MentionName, d.voffset().v, d.vlength().v, data() });
|
||||
}();
|
||||
result.push_back({ EntityType::MentionName, d.voffset().v, d.vlength().v, data });
|
||||
} break;
|
||||
case mtpc_inputMessageEntityMentionName: {
|
||||
auto &d = entity.c_inputMessageEntityMentionName();
|
||||
auto data = ([&d]() -> QString {
|
||||
if (d.vuser_id().type() == mtpc_inputUserSelf) {
|
||||
return MentionNameDataFromFields(Auth().userId());
|
||||
const auto &d = entity.c_inputMessageEntityMentionName();
|
||||
const auto data = [&] {
|
||||
if (session && d.vuser_id().type() == mtpc_inputUserSelf) {
|
||||
return MentionNameDataFromFields(session->userId());
|
||||
} else if (d.vuser_id().type() == mtpc_inputUser) {
|
||||
auto &user = d.vuser_id().c_inputUser();
|
||||
return MentionNameDataFromFields({ user.vuser_id().v, user.vaccess_hash().v });
|
||||
}
|
||||
return QString();
|
||||
})();
|
||||
}();
|
||||
if (!data.isEmpty()) {
|
||||
result.push_back({ EntityType::MentionName, d.voffset().v, d.vlength().v, data });
|
||||
}
|
||||
|
@ -74,11 +78,12 @@ EntitiesInText EntitiesFromMTP(const QVector<MTPMessageEntity> &entities) {
|
|||
}
|
||||
|
||||
MTPVector<MTPMessageEntity> EntitiesToMTP(
|
||||
not_null<Main::Session*> session,
|
||||
const EntitiesInText &entities,
|
||||
ConvertOption option) {
|
||||
auto v = QVector<MTPMessageEntity>();
|
||||
v.reserve(entities.size());
|
||||
for_const (auto &entity, entities) {
|
||||
for (const auto &entity : entities) {
|
||||
if (entity.length() <= 0) continue;
|
||||
if (option == ConvertOption::SkipLocal
|
||||
&& entity.type() != EntityType::Bold
|
||||
|
@ -103,15 +108,15 @@ MTPVector<MTPMessageEntity> EntitiesToMTP(
|
|||
case EntityType::Cashtag: v.push_back(MTP_messageEntityCashtag(offset, length)); break;
|
||||
case EntityType::Mention: v.push_back(MTP_messageEntityMention(offset, length)); break;
|
||||
case EntityType::MentionName: {
|
||||
auto inputUser = ([](const QString &data) -> MTPInputUser {
|
||||
auto inputUser = [&](const QString &data) -> MTPInputUser {
|
||||
auto fields = MentionNameDataToFields(data);
|
||||
if (fields.userId == Auth().userId()) {
|
||||
if (session && fields.userId == session->userId()) {
|
||||
return MTP_inputUserSelf();
|
||||
} else if (fields.userId) {
|
||||
return MTP_inputUser(MTP_int(fields.userId), MTP_long(fields.accessHash));
|
||||
}
|
||||
return MTP_inputUserEmpty();
|
||||
})(entity.data());
|
||||
}(entity.data());
|
||||
if (inputUser.type() != mtpc_inputUserEmpty) {
|
||||
v.push_back(MTP_inputMessageEntityMentionName(offset, length, inputUser));
|
||||
}
|
||||
|
|
|
@ -9,14 +9,23 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
|
||||
#include "ui/text/text_entity.h"
|
||||
|
||||
namespace Main {
|
||||
class Session;
|
||||
} // namespace Main
|
||||
|
||||
namespace Api {
|
||||
|
||||
EntitiesInText EntitiesFromMTP(const QVector<MTPMessageEntity> &entities);
|
||||
enum class ConvertOption {
|
||||
WithLocal,
|
||||
SkipLocal,
|
||||
};
|
||||
MTPVector<MTPMessageEntity> EntitiesToMTP(
|
||||
|
||||
[[nodiscard]] EntitiesInText EntitiesFromMTP(
|
||||
Main::Session *session,
|
||||
const QVector<MTPMessageEntity> &entities);
|
||||
|
||||
[[nodiscard]] MTPVector<MTPMessageEntity> EntitiesToMTP(
|
||||
not_null<Main::Session*> session,
|
||||
const EntitiesInText &entities,
|
||||
ConvertOption option = ConvertOption::WithLocal);
|
||||
|
||||
|
|
|
@ -411,7 +411,7 @@ void ApiWrap::requestTermsUpdate() {
|
|||
const auto &terms = data.vterms_of_service();
|
||||
const auto &fields = terms.c_help_termsOfService();
|
||||
Core::App().lockByTerms(
|
||||
Window::TermsLock::FromMTP(fields));
|
||||
Window::TermsLock::FromMTP(&session(), fields));
|
||||
requestNext(data);
|
||||
} break;
|
||||
default: Unexpected("Type in requestTermsUpdate().");
|
||||
|
@ -2442,6 +2442,7 @@ void ApiWrap::saveDraftsToCloud() {
|
|||
flags |= MTPmessages_SaveDraft::Flag::f_entities;
|
||||
}
|
||||
auto entities = Api::EntitiesToMTP(
|
||||
&session(),
|
||||
TextUtilities::ConvertTextTagsToEntities(textWithTags.tags),
|
||||
Api::ConvertOption::SkipLocal);
|
||||
|
||||
|
@ -4674,6 +4675,7 @@ void ApiWrap::editUploadedFile(
|
|||
}
|
||||
|
||||
auto sentEntities = Api::EntitiesToMTP(
|
||||
&session(),
|
||||
item->originalText().entities,
|
||||
Api::ConvertOption::SkipLocal);
|
||||
|
||||
|
@ -4826,8 +4828,11 @@ void ApiWrap::sendMessage(MessageToSend &&message) {
|
|||
if (silentPost) {
|
||||
sendFlags |= MTPmessages_SendMessage::Flag::f_silent;
|
||||
}
|
||||
auto localEntities = Api::EntitiesToMTP(sending.entities);
|
||||
auto localEntities = Api::EntitiesToMTP(
|
||||
&session(),
|
||||
sending.entities);
|
||||
auto sentEntities = Api::EntitiesToMTP(
|
||||
&session(),
|
||||
sending.entities,
|
||||
Api::ConvertOption::SkipLocal);
|
||||
if (!sentEntities.v.isEmpty()) {
|
||||
|
@ -5118,6 +5123,7 @@ void ApiWrap::sendMediaWithRandomId(
|
|||
auto caption = item->originalText();
|
||||
TextUtilities::Trim(caption);
|
||||
auto sentEntities = Api::EntitiesToMTP(
|
||||
&session(),
|
||||
caption.entities,
|
||||
Api::ConvertOption::SkipLocal);
|
||||
|
||||
|
@ -5794,6 +5800,7 @@ void ApiWrap::rescheduleMessage(
|
|||
Api::SendOptions options) {
|
||||
const auto text = item->originalText().text;
|
||||
const auto sentEntities = Api::EntitiesToMTP(
|
||||
&session(),
|
||||
item->originalText().entities,
|
||||
Api::ConvertOption::SkipLocal);
|
||||
const auto media = item->media();
|
||||
|
|
|
@ -934,6 +934,7 @@ void EditCaptionBox::save() {
|
|||
TextUtilities::Trim(sending);
|
||||
|
||||
const auto sentEntities = Api::EntitiesToMTP(
|
||||
&item->history()->session(),
|
||||
sending.entities,
|
||||
Api::ConvertOption::SkipLocal);
|
||||
if (!sentEntities.v.isEmpty()) {
|
||||
|
|
|
@ -383,7 +383,9 @@ bool HandleUnknown(
|
|||
const auto callback = [=](const MTPDhelp_deepLinkInfo &result) {
|
||||
const auto text = TextWithEntities{
|
||||
qs(result.vmessage()),
|
||||
Api::EntitiesFromMTP(result.ventities().value_or_empty())
|
||||
Api::EntitiesFromMTP(
|
||||
session,
|
||||
result.ventities().value_or_empty())
|
||||
};
|
||||
if (result.is_update_app()) {
|
||||
const auto box = std::make_shared<QPointer<Ui::BoxContent>>();
|
||||
|
|
|
@ -45,14 +45,19 @@ Draft::Draft(
|
|||
, previewCancelled(previewCancelled) {
|
||||
}
|
||||
|
||||
void applyPeerCloudDraft(PeerId peerId, const MTPDdraftMessage &draft) {
|
||||
const auto history = Auth().data().history(peerId);
|
||||
void ApplyPeerCloudDraft(
|
||||
not_null<Main::Session*> session,
|
||||
PeerId peerId,
|
||||
const MTPDdraftMessage &draft) {
|
||||
const auto history = session->data().history(peerId);
|
||||
const auto textWithTags = TextWithTags {
|
||||
qs(draft.vmessage()),
|
||||
TextUtilities::ConvertEntitiesToTextTags(
|
||||
Api::EntitiesFromMTP(draft.ventities().value_or_empty()))
|
||||
Api::EntitiesFromMTP(
|
||||
session,
|
||||
draft.ventities().value_or_empty()))
|
||||
};
|
||||
auto replyTo = draft.vreply_to_msg_id().value_or_empty();
|
||||
const auto replyTo = draft.vreply_to_msg_id().value_or_empty();
|
||||
if (history->skipCloudDraft(textWithTags.text, replyTo, draft.vdate().v)) {
|
||||
return;
|
||||
}
|
||||
|
@ -67,8 +72,11 @@ void applyPeerCloudDraft(PeerId peerId, const MTPDdraftMessage &draft) {
|
|||
history->applyCloudDraft();
|
||||
}
|
||||
|
||||
void clearPeerCloudDraft(PeerId peerId, TimeId date) {
|
||||
const auto history = Auth().data().history(peerId);
|
||||
void ClearPeerCloudDraft(
|
||||
not_null<Main::Session*> session,
|
||||
PeerId peerId,
|
||||
TimeId date) {
|
||||
const auto history = session->data().history(peerId);
|
||||
if (history->skipCloudDraft(QString(), MsgId(0), date)) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -11,10 +11,20 @@ namespace Ui {
|
|||
class InputField;
|
||||
} // namespace Ui
|
||||
|
||||
namespace Main {
|
||||
class Session;
|
||||
} // namespace Main
|
||||
|
||||
namespace Data {
|
||||
|
||||
void applyPeerCloudDraft(PeerId peerId, const MTPDdraftMessage &draft);
|
||||
void clearPeerCloudDraft(PeerId peerId, TimeId date);
|
||||
void ApplyPeerCloudDraft(
|
||||
not_null<Main::Session*> session,
|
||||
PeerId peerId,
|
||||
const MTPDdraftMessage &draft);
|
||||
void ClearPeerCloudDraft(
|
||||
not_null<Main::Session*> session,
|
||||
PeerId peerId,
|
||||
TimeId date);
|
||||
|
||||
struct Draft {
|
||||
Draft() = default;
|
||||
|
|
|
@ -45,6 +45,14 @@ PollData::PollData(not_null<Data::Session*> owner, PollId id)
|
|||
, _owner(owner) {
|
||||
}
|
||||
|
||||
Data::Session &PollData::owner() const {
|
||||
return *_owner;
|
||||
}
|
||||
|
||||
Main::Session &PollData::session() const {
|
||||
return _owner->session();
|
||||
}
|
||||
|
||||
bool PollData::closeByTimer() {
|
||||
if (closed()) {
|
||||
return false;
|
||||
|
@ -151,6 +159,7 @@ bool PollData::applyResults(const MTPPollResults &results) {
|
|||
auto newSolution = TextWithEntities{
|
||||
results.vsolution().value_or_empty(),
|
||||
Api::EntitiesFromMTP(
|
||||
&_owner->session(),
|
||||
results.vsolution_entities().value_or_empty())
|
||||
};
|
||||
if (solution != newSolution) {
|
||||
|
@ -293,6 +302,7 @@ MTPInputMedia PollDataToInputMedia(
|
|||
TextUtilities::PrepareForSending(solution, prepareFlags);
|
||||
TextUtilities::Trim(solution);
|
||||
const auto sentEntities = Api::EntitiesToMTP(
|
||||
&poll->session(),
|
||||
solution.entities,
|
||||
Api::ConvertOption::SkipLocal);
|
||||
if (!solution.text.isEmpty()) {
|
||||
|
|
|
@ -11,6 +11,10 @@ namespace Data {
|
|||
class Session;
|
||||
} // namespace Data
|
||||
|
||||
namespace Main {
|
||||
class Session;
|
||||
} // namespace Main
|
||||
|
||||
struct PollAnswer {
|
||||
QString text;
|
||||
QByteArray option;
|
||||
|
@ -31,6 +35,9 @@ inline bool operator!=(const PollAnswer &a, const PollAnswer &b) {
|
|||
struct PollData {
|
||||
PollData(not_null<Data::Session*> owner, PollId id);
|
||||
|
||||
[[nodiscard]] Data::Session &owner() const;
|
||||
[[nodiscard]] Main::Session &session() const;
|
||||
|
||||
enum class Flag {
|
||||
Closed = 0x01,
|
||||
PublicVotes = 0x02,
|
||||
|
|
|
@ -152,7 +152,7 @@ void ScheduledMessages::sendNowSimpleMessage(
|
|||
// we know for sure that a message can't have fields such as the author,
|
||||
// views count, etc.
|
||||
|
||||
const auto &history = local->history();
|
||||
const auto history = local->history();
|
||||
auto flags = NewMessageFlags(history->peer)
|
||||
| MTPDmessage::Flag::f_entities
|
||||
| MTPDmessage::Flag::f_from_id
|
||||
|
@ -175,7 +175,9 @@ void ScheduledMessages::sendNowSimpleMessage(
|
|||
MTP_string(local->originalText().text),
|
||||
MTP_messageMediaEmpty(),
|
||||
MTPReplyMarkup(),
|
||||
Api::EntitiesToMTP(local->originalText().entities),
|
||||
Api::EntitiesToMTP(
|
||||
&history->session(),
|
||||
local->originalText().entities),
|
||||
MTP_int(1),
|
||||
MTPint(),
|
||||
MTP_string(),
|
||||
|
@ -234,7 +236,7 @@ void ScheduledMessages::checkEntitiesAndUpdate(const MTPDmessage &data) {
|
|||
Assert(existing->date() == kScheduledUntilOnlineTimestamp);
|
||||
existing->updateSentContent({
|
||||
qs(data.vmessage()),
|
||||
Api::EntitiesFromMTP(data.ventities().value_or_empty())
|
||||
Api::EntitiesFromMTP(_session, data.ventities().value_or_empty())
|
||||
}, data.vmedia());
|
||||
existing->updateReplyMarkup(data.vreply_markup());
|
||||
existing->updateForwardedInfo(data.vfwd_from());
|
||||
|
@ -410,7 +412,9 @@ HistoryItem *ScheduledMessages::append(
|
|||
message.match([&](const MTPDmessage &data) {
|
||||
existing->updateSentContent({
|
||||
qs(data.vmessage()),
|
||||
Api::EntitiesFromMTP(data.ventities().value_or_empty())
|
||||
Api::EntitiesFromMTP(
|
||||
_session,
|
||||
data.ventities().value_or_empty())
|
||||
}, data.vmedia());
|
||||
existing->updateReplyMarkup(data.vreply_markup());
|
||||
existing->updateForwardedInfo(data.vfwd_from());
|
||||
|
|
|
@ -1703,7 +1703,9 @@ bool Session::checkEntitiesAndViewsUpdate(const MTPDmessage &data) {
|
|||
if (const auto existing = message(peerToChannel(peer), data.vid().v)) {
|
||||
existing->updateSentContent({
|
||||
qs(data.vmessage()),
|
||||
Api::EntitiesFromMTP(data.ventities().value_or_empty())
|
||||
Api::EntitiesFromMTP(
|
||||
&session(),
|
||||
data.ventities().value_or_empty())
|
||||
}, data.vmedia());
|
||||
existing->updateReplyMarkup(data.vreply_markup());
|
||||
existing->updateForwardedInfo(data.vfwd_from());
|
||||
|
@ -3725,7 +3727,7 @@ void Session::insertCheckedServiceNotification(
|
|||
MTP_string(sending.text),
|
||||
media,
|
||||
MTPReplyMarkup(),
|
||||
Api::EntitiesToMTP(sending.entities),
|
||||
Api::EntitiesToMTP(&session(), sending.entities),
|
||||
MTPint(),
|
||||
MTPint(),
|
||||
MTPstring(),
|
||||
|
|
|
@ -111,14 +111,16 @@ bool MediaCanHaveCaption(const MTPMessage &message) {
|
|||
return (mediaType == mtpc_messageMediaDocument || mediaType == mtpc_messageMediaPhoto);
|
||||
}
|
||||
|
||||
TextWithEntities ExtractEditedText(const MTPMessage &message) {
|
||||
TextWithEntities ExtractEditedText(
|
||||
not_null<Main::Session*> session,
|
||||
const MTPMessage &message) {
|
||||
if (message.type() != mtpc_message) {
|
||||
return TextWithEntities();
|
||||
}
|
||||
const auto &data = message.c_message();
|
||||
return {
|
||||
TextUtilities::Clean(qs(data.vmessage())),
|
||||
Api::EntitiesFromMTP(data.ventities().value_or_empty())
|
||||
Api::EntitiesFromMTP(session, data.ventities().value_or_empty())
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -376,19 +378,20 @@ void GenerateItems(
|
|||
Fn<void(OwnedItem item)> callback) {
|
||||
Expects(history->peer->isChannel());
|
||||
|
||||
auto id = event.vid().v;
|
||||
auto from = Auth().data().user(event.vuser_id().v);
|
||||
auto channel = history->peer->asChannel();
|
||||
auto &action = event.vaction();
|
||||
auto date = event.vdate().v;
|
||||
auto addPart = [&](not_null<HistoryItem*> item) {
|
||||
const auto session = &history->session();
|
||||
const auto id = event.vid().v;
|
||||
const auto from = Auth().data().user(event.vuser_id().v);
|
||||
const auto channel = history->peer->asChannel();
|
||||
const auto &action = event.vaction();
|
||||
const auto date = event.vdate().v;
|
||||
const auto addPart = [&](not_null<HistoryItem*> item) {
|
||||
return callback(OwnedItem(delegate, item));
|
||||
};
|
||||
|
||||
using Flag = MTPDmessage::Flag;
|
||||
auto fromName = from->name;
|
||||
auto fromLink = from->createOpenLink();
|
||||
auto fromLinkText = textcmdLink(1, fromName);
|
||||
const auto fromName = from->name;
|
||||
const auto fromLink = from->createOpenLink();
|
||||
const auto fromLinkText = textcmdLink(1, fromName);
|
||||
|
||||
auto addSimpleServiceMessage = [&](const QString &text, PhotoData *photo = nullptr) {
|
||||
auto message = HistoryService::PreparedText { text };
|
||||
|
@ -542,7 +545,7 @@ void GenerateItems(
|
|||
};
|
||||
|
||||
auto createEditMessage = [&](const MTPDchannelAdminLogEventActionEditMessage &action) {
|
||||
auto newValue = ExtractEditedText(action.vnew_message());
|
||||
auto newValue = ExtractEditedText(session, action.vnew_message());
|
||||
auto canHaveCaption = MediaCanHaveCaption(action.vnew_message());
|
||||
auto text = (!canHaveCaption
|
||||
? tr::lng_admin_log_edited_message
|
||||
|
@ -554,7 +557,7 @@ void GenerateItems(
|
|||
fromLinkText);
|
||||
addSimpleServiceMessage(text);
|
||||
|
||||
auto oldValue = ExtractEditedText(action.vprev_message());
|
||||
auto oldValue = ExtractEditedText(session, action.vprev_message());
|
||||
auto detachExistingItem = false;
|
||||
auto body = history->createItem(
|
||||
PrepareLogMessage(
|
||||
|
|
|
@ -2700,7 +2700,10 @@ void History::applyDialog(
|
|||
|
||||
const auto draft = data.vdraft();
|
||||
if (draft && draft->type() == mtpc_draftMessage) {
|
||||
Data::applyPeerCloudDraft(peer->id, draft->c_draftMessage());
|
||||
Data::ApplyPeerCloudDraft(
|
||||
&session(),
|
||||
peer->id,
|
||||
draft->c_draftMessage());
|
||||
}
|
||||
owner().histories().dialogEntryApplied(this);
|
||||
}
|
||||
|
|
|
@ -458,7 +458,9 @@ HistoryMessage::HistoryMessage(
|
|||
}
|
||||
const auto textWithEntities = TextWithEntities{
|
||||
TextUtilities::Clean(qs(data.vmessage())),
|
||||
Api::EntitiesFromMTP(data.ventities().value_or_empty())
|
||||
Api::EntitiesFromMTP(
|
||||
&history->session(),
|
||||
data.ventities().value_or_empty())
|
||||
};
|
||||
setText(_media ? textWithEntities : EnsureNonEmpty(textWithEntities));
|
||||
if (const auto groupedId = data.vgrouped_id()) {
|
||||
|
@ -1072,7 +1074,9 @@ void HistoryMessage::applyEdition(const MTPDmessage &message) {
|
|||
|
||||
const auto textWithEntities = TextWithEntities{
|
||||
qs(message.vmessage()),
|
||||
Api::EntitiesFromMTP(message.ventities().value_or_empty())
|
||||
Api::EntitiesFromMTP(
|
||||
&history()->session(),
|
||||
message.ventities().value_or_empty())
|
||||
};
|
||||
setReplyMarkup(message.vreply_markup());
|
||||
if (!isLocalUpdateMedia()) {
|
||||
|
|
|
@ -2984,8 +2984,9 @@ void HistoryWidget::saveEditMsg() {
|
|||
if (webPageId == CancelledWebPageId) {
|
||||
sendFlags |= MTPmessages_EditMessage::Flag::f_no_webpage;
|
||||
}
|
||||
auto localEntities = Api::EntitiesToMTP(sending.entities);
|
||||
auto localEntities = Api::EntitiesToMTP(&session(), sending.entities);
|
||||
auto sentEntities = Api::EntitiesToMTP(
|
||||
&session(),
|
||||
sending.entities,
|
||||
Api::ConvertOption::SkipLocal);
|
||||
if (!sentEntities.v.isEmpty()) {
|
||||
|
@ -4660,7 +4661,7 @@ void HistoryWidget::sendFileConfirmed(
|
|||
session().user()).flags;
|
||||
TextUtilities::PrepareForSending(caption, prepareFlags);
|
||||
TextUtilities::Trim(caption);
|
||||
auto localEntities = Api::EntitiesToMTP(caption.entities);
|
||||
auto localEntities = Api::EntitiesToMTP(&session(), caption.entities);
|
||||
|
||||
if (itemToEdit) {
|
||||
if (const auto id = itemToEdit->groupId()) {
|
||||
|
|
|
@ -175,24 +175,28 @@ std::unique_ptr<Result> Result::Create(
|
|||
const auto &r = message->c_botInlineMessageMediaAuto();
|
||||
const auto message = qs(r.vmessage());
|
||||
const auto entities = Api::EntitiesFromMTP(
|
||||
session,
|
||||
r.ventities().value_or_empty());
|
||||
if (result->_type == Type::Photo) {
|
||||
if (!result->_photo) {
|
||||
return nullptr;
|
||||
}
|
||||
result->sendData = std::make_unique<internal::SendPhoto>(
|
||||
session,
|
||||
result->_photo,
|
||||
message,
|
||||
entities);
|
||||
} else if (result->_type == Type::Game) {
|
||||
result->createGame();
|
||||
result->sendData = std::make_unique<internal::SendGame>(
|
||||
session,
|
||||
result->_game);
|
||||
} else {
|
||||
if (!result->_document) {
|
||||
return nullptr;
|
||||
}
|
||||
result->sendData = std::make_unique<internal::SendFile>(
|
||||
session,
|
||||
result->_document,
|
||||
message,
|
||||
entities);
|
||||
|
@ -205,8 +209,9 @@ std::unique_ptr<Result> Result::Create(
|
|||
case mtpc_botInlineMessageText: {
|
||||
const auto &r = message->c_botInlineMessageText();
|
||||
result->sendData = std::make_unique<internal::SendText>(
|
||||
session,
|
||||
qs(r.vmessage()),
|
||||
Api::EntitiesFromMTP(r.ventities().value_or_empty()),
|
||||
Api::EntitiesFromMTP(session, r.ventities().value_or_empty()),
|
||||
r.is_no_webpage());
|
||||
if (result->_type == Type::Photo) {
|
||||
if (!result->_photo) {
|
||||
|
@ -230,7 +235,9 @@ std::unique_ptr<Result> Result::Create(
|
|||
// #TODO layer 72 save period and send live location?..
|
||||
auto &r = message->c_botInlineMessageMediaGeo();
|
||||
if (r.vgeo().type() == mtpc_geoPoint) {
|
||||
result->sendData = std::make_unique<internal::SendGeo>(r.vgeo().c_geoPoint());
|
||||
result->sendData = std::make_unique<internal::SendGeo>(
|
||||
session,
|
||||
r.vgeo().c_geoPoint());
|
||||
} else {
|
||||
badAttachment = true;
|
||||
}
|
||||
|
@ -242,7 +249,13 @@ std::unique_ptr<Result> Result::Create(
|
|||
case mtpc_botInlineMessageMediaVenue: {
|
||||
auto &r = message->c_botInlineMessageMediaVenue();
|
||||
if (r.vgeo().type() == mtpc_geoPoint) {
|
||||
result->sendData = std::make_unique<internal::SendVenue>(r.vgeo().c_geoPoint(), qs(r.vvenue_id()), qs(r.vprovider()), qs(r.vtitle()), qs(r.vaddress()));
|
||||
result->sendData = std::make_unique<internal::SendVenue>(
|
||||
session,
|
||||
r.vgeo().c_geoPoint(),
|
||||
qs(r.vvenue_id()),
|
||||
qs(r.vprovider()),
|
||||
qs(r.vtitle()),
|
||||
qs(r.vaddress()));
|
||||
} else {
|
||||
badAttachment = true;
|
||||
}
|
||||
|
@ -253,7 +266,11 @@ std::unique_ptr<Result> Result::Create(
|
|||
|
||||
case mtpc_botInlineMessageMediaContact: {
|
||||
auto &r = message->c_botInlineMessageMediaContact();
|
||||
result->sendData = std::make_unique<internal::SendContact>(qs(r.vfirst_name()), qs(r.vlast_name()), qs(r.vphone_number()));
|
||||
result->sendData = std::make_unique<internal::SendContact>(
|
||||
session,
|
||||
qs(r.vfirst_name()),
|
||||
qs(r.vlast_name()),
|
||||
qs(r.vphone_number()));
|
||||
if (const auto markup = r.vreply_markup()) {
|
||||
result->_mtpKeyboard = std::make_unique<MTPReplyMarkup>(*markup);
|
||||
}
|
||||
|
|
|
@ -79,7 +79,7 @@ QString SendDataCommon::getErrorOnSend(
|
|||
SendDataCommon::SentMTPMessageFields SendText::getSentMessageFields() const {
|
||||
SentMTPMessageFields result;
|
||||
result.text = MTP_string(_message);
|
||||
result.entities = Api::EntitiesToMTP(_entities);
|
||||
result.entities = Api::EntitiesToMTP(&session(), _entities);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -9,6 +9,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
|
||||
#include "history/history_location_manager.h"
|
||||
|
||||
namespace Main {
|
||||
class Session;
|
||||
} // namespace Main
|
||||
|
||||
class History;
|
||||
|
||||
namespace InlineBots {
|
||||
|
@ -22,11 +26,16 @@ namespace internal {
|
|||
// For each type of message that can be sent there will be a subclass.
|
||||
class SendData {
|
||||
public:
|
||||
SendData() = default;
|
||||
explicit SendData(not_null<Main::Session*> session) : _session(session) {
|
||||
}
|
||||
SendData(const SendData &other) = delete;
|
||||
SendData &operator=(const SendData &other) = delete;
|
||||
virtual ~SendData() = default;
|
||||
|
||||
[[nodiscard]] Main::Session &session() const {
|
||||
return *_session;
|
||||
}
|
||||
|
||||
virtual bool isValid() const = 0;
|
||||
|
||||
virtual void addToHistory(
|
||||
|
@ -54,6 +63,9 @@ public:
|
|||
virtual QString getLayoutTitle(const Result *owner) const;
|
||||
virtual QString getLayoutDescription(const Result *owner) const;
|
||||
|
||||
private:
|
||||
not_null<Main::Session*> _session;
|
||||
|
||||
};
|
||||
|
||||
// This class implements addHistory() for most of the types hiding
|
||||
|
@ -61,6 +73,8 @@ public:
|
|||
// Only SendFile and SendPhoto work by their own.
|
||||
class SendDataCommon : public SendData {
|
||||
public:
|
||||
using SendData::SendData;
|
||||
|
||||
struct SentMTPMessageFields {
|
||||
MTPString text = MTP_string();
|
||||
MTPVector<MTPMessageEntity> entities = MTP_vector<MTPMessageEntity>();
|
||||
|
@ -91,10 +105,12 @@ public:
|
|||
class SendText : public SendDataCommon {
|
||||
public:
|
||||
SendText(
|
||||
not_null<Main::Session*> session,
|
||||
const QString &message,
|
||||
const EntitiesInText &entities,
|
||||
bool/* noWebPage*/)
|
||||
: _message(message)
|
||||
: SendDataCommon(session)
|
||||
, _message(message)
|
||||
, _entities(entities) {
|
||||
}
|
||||
|
||||
|
@ -113,7 +129,11 @@ private:
|
|||
// Message with geo location point media.
|
||||
class SendGeo : public SendDataCommon {
|
||||
public:
|
||||
explicit SendGeo(const MTPDgeoPoint &point) : _location(point) {
|
||||
SendGeo(
|
||||
not_null<Main::Session*> session,
|
||||
const MTPDgeoPoint &point)
|
||||
: SendDataCommon(session)
|
||||
, _location(point) {
|
||||
}
|
||||
|
||||
bool isValid() const override {
|
||||
|
@ -137,13 +157,19 @@ private:
|
|||
// Message with venue media.
|
||||
class SendVenue : public SendDataCommon {
|
||||
public:
|
||||
SendVenue(const MTPDgeoPoint &point, const QString &venueId,
|
||||
const QString &provider, const QString &title, const QString &address)
|
||||
: _location(point)
|
||||
, _venueId(venueId)
|
||||
, _provider(provider)
|
||||
, _title(title)
|
||||
, _address(address) {
|
||||
SendVenue(
|
||||
not_null<Main::Session*> session,
|
||||
const MTPDgeoPoint &point,
|
||||
const QString &venueId,
|
||||
const QString &provider,
|
||||
const QString &title,
|
||||
const QString &address)
|
||||
: SendDataCommon(session)
|
||||
, _location(point)
|
||||
, _venueId(venueId)
|
||||
, _provider(provider)
|
||||
, _title(title)
|
||||
, _address(address) {
|
||||
}
|
||||
|
||||
bool isValid() const override {
|
||||
|
@ -168,10 +194,15 @@ private:
|
|||
// Message with shared contact media.
|
||||
class SendContact : public SendDataCommon {
|
||||
public:
|
||||
SendContact(const QString &firstName, const QString &lastName, const QString &phoneNumber)
|
||||
: _firstName(firstName)
|
||||
, _lastName(lastName)
|
||||
, _phoneNumber(phoneNumber) {
|
||||
SendContact(
|
||||
not_null<Main::Session*> session,
|
||||
const QString &firstName,
|
||||
const QString &lastName,
|
||||
const QString &phoneNumber)
|
||||
: SendDataCommon(session)
|
||||
, _firstName(firstName)
|
||||
, _lastName(lastName)
|
||||
, _phoneNumber(phoneNumber) {
|
||||
}
|
||||
|
||||
bool isValid() const override {
|
||||
|
@ -191,10 +222,12 @@ private:
|
|||
class SendPhoto : public SendData {
|
||||
public:
|
||||
SendPhoto(
|
||||
not_null<Main::Session*> session,
|
||||
PhotoData *photo,
|
||||
const QString &message,
|
||||
const EntitiesInText &entities)
|
||||
: _photo(photo)
|
||||
: SendData(session)
|
||||
, _photo(photo)
|
||||
, _message(message)
|
||||
, _entities(entities) {
|
||||
}
|
||||
|
@ -231,10 +264,12 @@ private:
|
|||
class SendFile : public SendData {
|
||||
public:
|
||||
SendFile(
|
||||
not_null<Main::Session*> session,
|
||||
DocumentData *document,
|
||||
const QString &message,
|
||||
const EntitiesInText &entities)
|
||||
: _document(document)
|
||||
: SendData(session)
|
||||
, _document(document)
|
||||
, _message(message)
|
||||
, _entities(entities) {
|
||||
}
|
||||
|
@ -270,8 +305,9 @@ private:
|
|||
// Message with game.
|
||||
class SendGame : public SendData {
|
||||
public:
|
||||
SendGame(GameData *game)
|
||||
: _game(game) {
|
||||
SendGame(not_null<Main::Session*> session, GameData *game)
|
||||
: SendData(session)
|
||||
, _game(game) {
|
||||
}
|
||||
|
||||
bool isValid() const override {
|
||||
|
|
|
@ -248,7 +248,9 @@ void CodeWidget::codeSubmitDone(const MTPauth_Authorization &result) {
|
|||
}, [&](const MTPDauth_authorizationSignUpRequired &data) {
|
||||
if (const auto terms = data.vterms_of_service()) {
|
||||
terms->match([&](const MTPDhelp_termsOfService &data) {
|
||||
getData()->termsLock = Window::TermsLock::FromMTP(data);
|
||||
getData()->termsLock = Window::TermsLock::FromMTP(
|
||||
nullptr,
|
||||
data);
|
||||
});
|
||||
} else {
|
||||
getData()->termsLock = Window::TermsLock();
|
||||
|
|
|
@ -146,7 +146,7 @@ void Widget::handleUpdate(const MTPUpdate &update) {
|
|||
}, [&](const MTPDupdateServiceNotification &data) {
|
||||
const auto text = TextWithEntities{
|
||||
qs(data.vmessage()),
|
||||
Api::EntitiesFromMTP(data.ventities().v)
|
||||
Api::EntitiesFromMTP(nullptr, data.ventities().v)
|
||||
};
|
||||
Ui::show(Box<InformBox>(text));
|
||||
}, [](const auto &) {});
|
||||
|
|
|
@ -3788,7 +3788,7 @@ void MainWidget::feedUpdates(const MTPUpdates &updates, uint64 randomId) {
|
|||
}
|
||||
item->updateSentContent({
|
||||
sent.text,
|
||||
Api::EntitiesFromMTP(list.value_or_empty())
|
||||
Api::EntitiesFromMTP(&session(), list.value_or_empty())
|
||||
}, d.vmedia());
|
||||
item->contributeToSlowmode(d.vdate().v);
|
||||
if (!wasAlready) {
|
||||
|
@ -4297,7 +4297,7 @@ void MainWidget::feedUpdate(const MTPUpdate &update) {
|
|||
const auto &d = update.c_updateServiceNotification();
|
||||
const auto text = TextWithEntities {
|
||||
qs(d.vmessage()),
|
||||
Api::EntitiesFromMTP(d.ventities().v)
|
||||
Api::EntitiesFromMTP(&session(), d.ventities().v)
|
||||
};
|
||||
if (IsForceLogoutNotification(d)) {
|
||||
Core::App().forceLogOut(text);
|
||||
|
@ -4571,9 +4571,10 @@ void MainWidget::feedUpdate(const MTPUpdate &update) {
|
|||
const auto &data = update.c_updateDraftMessage();
|
||||
const auto peerId = peerFromMTP(data.vpeer());
|
||||
data.vdraft().match([&](const MTPDdraftMessage &data) {
|
||||
Data::applyPeerCloudDraft(peerId, data);
|
||||
Data::ApplyPeerCloudDraft(&session(), peerId, data);
|
||||
}, [&](const MTPDdraftMessageEmpty &data) {
|
||||
Data::clearPeerCloudDraft(
|
||||
Data::ClearPeerCloudDraft(
|
||||
&session(),
|
||||
peerId,
|
||||
data.vdate().value_or_empty());
|
||||
});
|
||||
|
|
|
@ -17,6 +17,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "media/clip/media_clip_reader.h"
|
||||
#include "mtproto/facade.h"
|
||||
#include "lottie/lottie_animation.h"
|
||||
#include "history/history.h"
|
||||
#include "history/history_item.h"
|
||||
#include "boxes/send_files_box.h"
|
||||
#include "boxes/confirm_box.h"
|
||||
|
@ -129,6 +130,7 @@ MTPInputSingleMedia PrepareAlbumItemMedia(
|
|||
auto caption = item->originalText();
|
||||
TextUtilities::Trim(caption);
|
||||
auto sentEntities = Api::EntitiesToMTP(
|
||||
&item->history()->session(),
|
||||
caption.entities,
|
||||
Api::ConvertOption::SkipLocal);
|
||||
const auto flags = !sentEntities.v.isEmpty()
|
||||
|
|
|
@ -453,7 +453,7 @@ void Helper::applyInfo(
|
|||
info.date = data.vdate().v;
|
||||
info.text = TextWithEntities{
|
||||
qs(data.vmessage()),
|
||||
Api::EntitiesFromMTP(data.ventities().v) };
|
||||
Api::EntitiesFromMTP(&user->session(), data.ventities().v) };
|
||||
if (info.text.empty()) {
|
||||
remove();
|
||||
} else if (_userInformation[user] != info) {
|
||||
|
@ -544,6 +544,7 @@ void Helper::saveInfo(
|
|||
TextUtilities::Trim(text);
|
||||
|
||||
const auto entities = Api::EntitiesToMTP(
|
||||
&user->session(),
|
||||
text.entities,
|
||||
Api::ConvertOption::SkipLocal);
|
||||
_userInfoSaving[user].requestId = _api.request(MTPhelp_EditUserInfo(
|
||||
|
|
|
@ -185,13 +185,15 @@ void PasscodeLockWidget::setInnerFocus() {
|
|||
_passcode->setFocusFast();
|
||||
}
|
||||
|
||||
TermsLock TermsLock::FromMTP(const MTPDhelp_termsOfService &data) {
|
||||
TermsLock TermsLock::FromMTP(
|
||||
Main::Session *session,
|
||||
const MTPDhelp_termsOfService &data) {
|
||||
const auto minAge = data.vmin_age_confirm();
|
||||
return {
|
||||
bytes::make_vector(data.vid().c_dataJSON().vdata().v),
|
||||
TextWithEntities {
|
||||
TextUtilities::Clean(qs(data.vtext())),
|
||||
Api::EntitiesFromMTP(data.ventities().v) },
|
||||
Api::EntitiesFromMTP(session, data.ventities().v) },
|
||||
(minAge ? std::make_optional(minAge->v) : std::nullopt),
|
||||
data.is_popup()
|
||||
};
|
||||
|
|
|
@ -19,6 +19,10 @@ class RoundButton;
|
|||
class CheckView;
|
||||
} // namespace Ui
|
||||
|
||||
namespace Main {
|
||||
class Session;
|
||||
} // namespace Main
|
||||
|
||||
namespace Window {
|
||||
|
||||
class Controller;
|
||||
|
@ -83,7 +87,9 @@ struct TermsLock {
|
|||
return !(*this == other);
|
||||
}
|
||||
|
||||
static TermsLock FromMTP(const MTPDhelp_termsOfService &data);
|
||||
static TermsLock FromMTP(
|
||||
Main::Session *session,
|
||||
const MTPDhelp_termsOfService &data);
|
||||
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue