mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-15 21:57:10 +02:00
parent
6c0dccd9ff
commit
816f422e21
11 changed files with 118 additions and 73 deletions
|
@ -645,6 +645,8 @@ PRIVATE
|
|||
history/history_item.h
|
||||
history/history_item_components.cpp
|
||||
history/history_item_components.h
|
||||
history/history_item_edition.cpp
|
||||
history/history_item_edition.h
|
||||
history/history_item_reply_markup.cpp
|
||||
history/history_item_reply_markup.h
|
||||
history/history_item_text.cpp
|
||||
|
|
|
@ -335,7 +335,7 @@ void SendConfirmedFile(
|
|||
isEditing
|
||||
? file->to.replaceMediaOf
|
||||
: session->data().nextLocalMessageId());
|
||||
auto groupId = file->album ? file->album->groupId : uint64(0);
|
||||
const auto groupId = file->album ? file->album->groupId : uint64(0);
|
||||
if (file->album) {
|
||||
const auto proj = [](const SendingAlbum::Item &item) {
|
||||
return item.taskId;
|
||||
|
@ -370,13 +370,6 @@ void SendConfirmedFile(
|
|||
session->user()).flags;
|
||||
TextUtilities::PrepareForSending(caption, prepareFlags);
|
||||
TextUtilities::Trim(caption);
|
||||
auto localEntities = Api::EntitiesToMTP(session, caption.entities);
|
||||
|
||||
if (itemToEdit) {
|
||||
if (const auto id = itemToEdit->groupId()) {
|
||||
groupId = id.value;
|
||||
}
|
||||
}
|
||||
|
||||
auto flags = isEditing ? MessageFlags() : NewMessageFlags(peer);
|
||||
if (file->to.replyTo) {
|
||||
|
@ -408,7 +401,7 @@ void SendConfirmedFile(
|
|||
? session->user()->name
|
||||
: QString();
|
||||
|
||||
const auto media = [&] {
|
||||
const auto media = MTPMessageMedia([&] {
|
||||
if (file->type == SendMediaType::Photo) {
|
||||
return MTP_messageMediaPhoto(
|
||||
MTP_flags(MTPDmessageMediaPhoto::Flag::f_photo),
|
||||
|
@ -427,38 +420,21 @@ void SendConfirmedFile(
|
|||
} else {
|
||||
Unexpected("Type in sendFilesConfirmed.");
|
||||
}
|
||||
}();
|
||||
}());
|
||||
|
||||
if (itemToEdit) {
|
||||
itemToEdit->savePreviousMedia();
|
||||
itemToEdit->applyEdition(MTP_message(
|
||||
MTP_flags(MTPDmessage::Flag::f_media
|
||||
| ((flags & MessageFlag::HideEdited)
|
||||
? MTPDmessage::Flag::f_edit_hide
|
||||
: MTPDmessage::Flag())
|
||||
| (localEntities.v.isEmpty()
|
||||
? MTPDmessage::Flag()
|
||||
: MTPDmessage::Flag::f_entities)),
|
||||
MTP_int(0), // Not used (would've been trimmed to 32 bits).
|
||||
peerToMTP(messageFromId),
|
||||
peerToMTP(file->to.peer),
|
||||
MTPMessageFwdHeader(),
|
||||
MTPlong(), // via_bot_id
|
||||
replyHeader,
|
||||
MTP_int(HistoryItem::NewMessageDate(file->to.options.scheduled)),
|
||||
MTP_string(caption.text),
|
||||
media,
|
||||
MTPReplyMarkup(),
|
||||
localEntities,
|
||||
MTPint(), // views
|
||||
MTPint(), // forwards
|
||||
MTPMessageReplies(),
|
||||
MTPint(), // edit_date
|
||||
MTP_string(messagePostAuthor),
|
||||
MTP_long(groupId),
|
||||
//MTPMessageReactions(),
|
||||
MTPVector<MTPRestrictionReason>(),
|
||||
MTPint()).c_message());
|
||||
auto edition = HistoryMessageEdition();
|
||||
edition.isEditHide = (flags & MessageFlag::HideEdited);
|
||||
edition.editDate = 0;
|
||||
edition.views = 0;
|
||||
edition.forwards = 0;
|
||||
edition.ttl = 0;
|
||||
edition.mtpMedia = &media;
|
||||
edition.textWithEntities = caption;
|
||||
edition.useSameMarkup = true;
|
||||
edition.useSameReplies = true;
|
||||
itemToEdit->applyEdition(std::move(edition));
|
||||
} else {
|
||||
const auto viaBotId = UserId();
|
||||
history->addNewLocalMessage(
|
||||
|
|
|
@ -448,7 +448,7 @@ HistoryItem *ScheduledMessages::append(
|
|||
// so if we receive a flag about it,
|
||||
// probably this message was edited.
|
||||
if (data.is_edit_hide()) {
|
||||
existing->applyEdition(data);
|
||||
existing->applyEdition(HistoryMessageEdition(_session, data));
|
||||
}
|
||||
existing->updateSentContent({
|
||||
qs(data.vmessage()),
|
||||
|
|
|
@ -1826,8 +1826,10 @@ void Session::updateEditedMessage(const MTPMessage &data) {
|
|||
checkEntitiesAndViewsUpdate(data.c_message());
|
||||
}
|
||||
data.match([](const MTPDmessageEmpty &) {
|
||||
}, [&](const auto &data) {
|
||||
}, [&](const MTPDmessageService &data) {
|
||||
existing->applyEdition(data);
|
||||
}, [&](const auto &data) {
|
||||
existing->applyEdition(HistoryMessageEdition(_session, data));
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "base/flags.h"
|
||||
#include "base/value_ordering.h"
|
||||
#include "data/data_media_types.h"
|
||||
#include "history/history_item_edition.h"
|
||||
#include "history/history_item_reply_markup.h"
|
||||
|
||||
#include <any>
|
||||
|
@ -277,7 +278,7 @@ public:
|
|||
[[nodiscard]] virtual bool serviceMsg() const {
|
||||
return false;
|
||||
}
|
||||
virtual void applyEdition(const MTPDmessage &message) {
|
||||
virtual void applyEdition(HistoryMessageEdition &&edition) {
|
||||
}
|
||||
virtual void applyEdition(const MTPDmessageService &message) {
|
||||
}
|
||||
|
|
34
Telegram/SourceFiles/history/history_item_edition.cpp
Normal file
34
Telegram/SourceFiles/history/history_item_edition.cpp
Normal file
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
This file is part of Telegram Desktop,
|
||||
the official desktop application for the Telegram messaging service.
|
||||
|
||||
For license and copyright information please follow this link:
|
||||
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
*/
|
||||
#include "history/history_item_edition.h"
|
||||
|
||||
#include "api/api_text_entities.h"
|
||||
#include "main/main_session.h"
|
||||
|
||||
HistoryMessageEdition::HistoryMessageEdition(
|
||||
not_null<Main::Session*> session,
|
||||
const MTPDmessage &message) {
|
||||
isEditHide = message.is_edit_hide();
|
||||
editDate = message.vedit_date().value_or(-1);
|
||||
textWithEntities = TextWithEntities{
|
||||
qs(message.vmessage()),
|
||||
Api::EntitiesFromMTP(
|
||||
session,
|
||||
message.ventities().value_or_empty())
|
||||
};
|
||||
replyMarkup = HistoryMessageMarkupData(message.vreply_markup());
|
||||
mtpMedia = message.vmedia();
|
||||
views = message.vviews().value_or(-1);
|
||||
forwards = message.vforwards().value_or(-1);
|
||||
if (const auto mtpReplies = message.vreplies()) {
|
||||
replies = HistoryMessageRepliesData(mtpReplies);
|
||||
}
|
||||
|
||||
const auto period = message.vttl_period();
|
||||
ttl = (period && period->v > 0) ? (message.vdate().v + period->v) : 0;
|
||||
}
|
33
Telegram/SourceFiles/history/history_item_edition.h
Normal file
33
Telegram/SourceFiles/history/history_item_edition.h
Normal file
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
This file is part of Telegram Desktop,
|
||||
the official desktop application for the Telegram messaging service.
|
||||
|
||||
For license and copyright information please follow this link:
|
||||
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "history/history_item_reply_markup.h"
|
||||
|
||||
namespace Main {
|
||||
class Session;
|
||||
} // namespace Main
|
||||
|
||||
struct HistoryMessageEdition {
|
||||
explicit HistoryMessageEdition() = default;
|
||||
HistoryMessageEdition(
|
||||
not_null<Main::Session*> session,
|
||||
const MTPDmessage &message);
|
||||
|
||||
bool isEditHide = false;
|
||||
int editDate = 0;
|
||||
int views = -1;
|
||||
int forwards = -1;
|
||||
int ttl = 0;
|
||||
bool useSameReplies = false;
|
||||
bool useSameMarkup = false;
|
||||
TextWithEntities textWithEntities;
|
||||
HistoryMessageMarkupData replyMarkup;
|
||||
HistoryMessageRepliesData replies;
|
||||
const MTPMessageMedia *mtpMedia = nullptr;
|
||||
};
|
|
@ -213,4 +213,5 @@ HistoryMessageRepliesData::HistoryMessageRepliesData(
|
|||
readMaxId = fields.vread_max_id().value_or_empty();
|
||||
maxId = fields.vmax_id().value_or_empty();
|
||||
isNull = false;
|
||||
pts = fields.vreplies_pts().v;
|
||||
}
|
||||
|
|
|
@ -92,4 +92,5 @@ struct HistoryMessageRepliesData {
|
|||
MsgId maxId = 0;
|
||||
int repliesCount = 0;
|
||||
bool isNull = true;
|
||||
int pts = 0;
|
||||
};
|
||||
|
|
|
@ -1156,15 +1156,13 @@ void HistoryMessage::createComponents(CreateConfig &&config) {
|
|||
_fromNameVersion = from ? from->nameVersion : 1;
|
||||
}
|
||||
|
||||
bool HistoryMessage::checkRepliesPts(const MTPMessageReplies &data) const {
|
||||
bool HistoryMessage::checkRepliesPts(
|
||||
const HistoryMessageRepliesData &data) const {
|
||||
const auto channel = history()->peer->asChannel();
|
||||
const auto pts = channel
|
||||
? channel->pts()
|
||||
: history()->session().updates().pts();
|
||||
const auto repliesPts = data.match([&](const MTPDmessageReplies &data) {
|
||||
return data.vreplies_pts().v;
|
||||
});
|
||||
return (repliesPts >= pts);
|
||||
return (data.pts >= pts);
|
||||
}
|
||||
|
||||
void HistoryMessage::setupForwardedComponent(const CreateConfig &config) {
|
||||
|
@ -1380,7 +1378,7 @@ void HistoryMessage::replaceBuyWithReceiptInMarkup() {
|
|||
}
|
||||
}
|
||||
|
||||
void HistoryMessage::applyEdition(const MTPDmessage &message) {
|
||||
void HistoryMessage::applyEdition(HistoryMessageEdition &&edition) {
|
||||
int keyboardTop = -1;
|
||||
//if (!pendingResize()) {// #TODO edit bot message
|
||||
// if (auto keyboard = inlineReplyKeyboard()) {
|
||||
|
@ -1389,47 +1387,43 @@ void HistoryMessage::applyEdition(const MTPDmessage &message) {
|
|||
// }
|
||||
//}
|
||||
|
||||
if (message.is_edit_hide()) {
|
||||
if (edition.isEditHide) {
|
||||
_flags |= MessageFlag::HideEdited;
|
||||
} else {
|
||||
_flags &= ~MessageFlag::HideEdited;
|
||||
}
|
||||
|
||||
if (const auto editDate = message.vedit_date()) {
|
||||
if (edition.editDate != -1) {
|
||||
//_flags |= MTPDmessage::Flag::f_edit_date;
|
||||
if (!Has<HistoryMessageEdited>()) {
|
||||
AddComponents(HistoryMessageEdited::Bit());
|
||||
}
|
||||
auto edited = Get<HistoryMessageEdited>();
|
||||
edited->date = editDate->v;
|
||||
edited->date = edition.editDate;
|
||||
}
|
||||
|
||||
const auto textWithEntities = TextWithEntities{
|
||||
qs(message.vmessage()),
|
||||
Api::EntitiesFromMTP(
|
||||
&history()->session(),
|
||||
message.ventities().value_or_empty())
|
||||
};
|
||||
setReplyMarkup(HistoryMessageMarkupData(message.vreply_markup()));
|
||||
if (!edition.useSameMarkup) {
|
||||
setReplyMarkup(base::take(edition.replyMarkup));
|
||||
}
|
||||
if (!isLocalUpdateMedia()) {
|
||||
refreshMedia(message.vmedia());
|
||||
refreshMedia(edition.mtpMedia);
|
||||
}
|
||||
setViewsCount(message.vviews().value_or(-1));
|
||||
setForwardsCount(message.vforwards().value_or(-1));
|
||||
setText(_media ? textWithEntities : EnsureNonEmpty(textWithEntities));
|
||||
if (const auto replies = message.vreplies()) {
|
||||
if (checkRepliesPts(*replies)) {
|
||||
setReplies(HistoryMessageRepliesData(replies));
|
||||
setViewsCount(edition.views);
|
||||
setForwardsCount(edition.forwards);
|
||||
setText(_media
|
||||
? edition.textWithEntities
|
||||
: EnsureNonEmpty(edition.textWithEntities));
|
||||
if (!edition.useSameReplies) {
|
||||
if (!edition.replies.isNull) {
|
||||
if (checkRepliesPts(edition.replies)) {
|
||||
setReplies(base::take(edition.replies));
|
||||
}
|
||||
} else {
|
||||
clearReplies();
|
||||
}
|
||||
} else {
|
||||
clearReplies();
|
||||
}
|
||||
|
||||
if (const auto period = message.vttl_period(); period && period->v > 0) {
|
||||
applyTTL(message.vdate().v + period->v);
|
||||
} else {
|
||||
applyTTL(0);
|
||||
}
|
||||
applyTTL(edition.ttl);
|
||||
|
||||
finishEdition(keyboardTop);
|
||||
}
|
||||
|
|
|
@ -159,7 +159,7 @@ public:
|
|||
// f_forwards
|
||||
// f_replies
|
||||
// f_ttl_period
|
||||
void applyEdition(const MTPDmessage &message) override;
|
||||
void applyEdition(HistoryMessageEdition &&edition) override;
|
||||
|
||||
void applyEdition(const MTPDmessageService &message) override;
|
||||
void updateSentContent(
|
||||
|
@ -269,7 +269,8 @@ private:
|
|||
const TextWithEntities &textWithEntities) const;
|
||||
void reapplyText();
|
||||
|
||||
[[nodiscard]] bool checkRepliesPts(const MTPMessageReplies &data) const;
|
||||
[[nodiscard]] bool checkRepliesPts(
|
||||
const HistoryMessageRepliesData &data) const;
|
||||
|
||||
QString _timeText;
|
||||
int _timeWidth = 0;
|
||||
|
|
Loading…
Add table
Reference in a new issue