Don't use MTP* for Message flags.

This commit is contained in:
John Preston
2021-07-28 14:55:02 +03:00
parent 22e77bf3af
commit 116a768fde
30 changed files with 638 additions and 841 deletions
@@ -30,7 +30,7 @@ constexpr auto kMessagesPerPage = 50;
const QString &text) {
return history->makeServiceMessage(
history->session().data().nextNonHistoryEntryId(),
MTPDmessage_ClientFlag::f_fake_history_item,
MessageFlag::FakeHistoryItem,
date,
HistoryService::PreparedText{ text });
}
@@ -538,7 +538,7 @@ bool RepliesList::processMessagesIsEmpty(const MTPmessages_Messages &result) {
const auto maxId = IdFromMessage(list.front());
const auto wasSize = int(_list.size());
const auto toFront = (wasSize > 0) && (maxId > _list.front());
const auto clientFlags = MTPDmessage_ClientFlags();
const auto localFlags = MessageFlags();
const auto type = NewMessageType::Existing;
auto refreshed = std::vector<MsgId>();
if (toFront) {
@@ -546,7 +546,7 @@ bool RepliesList::processMessagesIsEmpty(const MTPmessages_Messages &result) {
}
auto skipped = 0;
for (const auto &message : list) {
if (const auto item = owner.addNewMessage(message, clientFlags, type)) {
if (const auto item = owner.addNewMessage(message, localFlags, type)) {
if (item->replyToTop() == _rootId) {
if (toFront) {
refreshed.push_back(item->id);
@@ -158,6 +158,7 @@ void ScheduledMessages::sendNowSimpleMessage(
not_null<HistoryItem*> local) {
Expects(local->isSending());
Expects(local->isScheduled());
if (HasScheduledDate(local)) {
LOG(("Error: trying to put to history a new local message, "
"that has scheduled date."));
@@ -175,17 +176,19 @@ void ScheduledMessages::sendNowSimpleMessage(
auto action = Api::SendAction(history);
action.replyTo = local->replyToId();
const auto replyHeader = NewMessageReplyHeader(action);
auto flags = NewMessageFlags(history->peer)
| MTPDmessage::Flag::f_entities
const auto localFlags = NewMessageFlags(history->peer)
| MessageFlag::LocalHistoryEntry;
const auto flags = MTPDmessage::Flag::f_entities
| MTPDmessage::Flag::f_from_id
| (local->replyToId()
? MTPDmessage::Flag::f_reply_to
: MTPDmessage::Flag(0))
| (update.vttl_period()
? MTPDmessage::Flag::f_ttl_period
: MTPDmessage::Flag(0))
| ((localFlags & MessageFlag::Outgoing)
? MTPDmessage::Flag::f_out
: MTPDmessage::Flag(0));
auto clientFlags = NewMessageClientFlags()
| MTPDmessage_ClientFlag::f_local_history_entry;
const auto views = 1;
const auto forwards = 0;
history->addNewMessage(
@@ -213,7 +216,7 @@ void ScheduledMessages::sendNowSimpleMessage(
//MTPMessageReactions(),
MTPVector<MTPRestrictionReason>(),
MTP_int(update.vttl_period().value_or_empty())),
clientFlags,
localFlags,
NewMessageType::Unread);
local->destroy();
@@ -459,7 +462,7 @@ HistoryItem *ScheduledMessages::append(
const auto item = _session->data().addNewMessage(
PrepareMessage(message, history->nextNonHistoryEntryId()),
MTPDmessage_ClientFlags(),
MessageFlags(), // localFlags
NewMessageType::Existing);
if (!item || item->history() != history) {
LOG(("API Error: Bad data received in scheduled messages."));
@@ -161,7 +161,7 @@ SearchResult ParseSearchResult(
for (const auto &message : *messages) {
const auto item = peer->owner().addNewMessage(
message,
MTPDmessage_ClientFlags(),
MessageFlags(),
addType);
if (item) {
const auto itemId = item->id;
+6 -6
View File
@@ -1964,7 +1964,7 @@ void Session::processMessages(
for (const auto &[position, index] : indices) {
addNewMessage(
data[index],
MTPDmessage_ClientFlags(),
MessageFlags(),
type);
}
}
@@ -2281,7 +2281,7 @@ void Session::unmuteByFinished() {
HistoryItem *Session::addNewMessage(
const MTPMessage &data,
MTPDmessage_ClientFlags clientFlags,
MessageFlags localFlags,
NewMessageType type) {
const auto peerId = PeerFromMessage(data);
if (!peerId) {
@@ -2290,7 +2290,7 @@ HistoryItem *Session::addNewMessage(
const auto result = history(peerId)->addNewMessage(
data,
clientFlags,
localFlags,
type);
if (result && type == NewMessageType::Unread) {
CheckForSwitchInlineButton(result);
@@ -4062,8 +4062,8 @@ void Session::insertCheckedServiceNotification(
const auto flags = MTPDmessage::Flag::f_entities
| MTPDmessage::Flag::f_from_id
| MTPDmessage::Flag::f_media;
const auto clientFlags = MTPDmessage_ClientFlag::f_clientside_unread
| MTPDmessage_ClientFlag::f_local_history_entry;
const auto localFlags = MessageFlag::ClientSideUnread
| MessageFlag::LocalHistoryEntry;
auto sending = TextWithEntities(), left = message;
while (TextUtilities::CutPart(sending, left, MaxMessageSize)) {
addNewMessage(
@@ -4089,7 +4089,7 @@ void Session::insertCheckedServiceNotification(
//MTPMessageReactions(),
MTPVector<MTPRestrictionReason>(),
MTPint()), // ttl_period
clientFlags,
localFlags,
NewMessageType::Unread);
}
sendHistoryChangeNotifications();
+1 -1
View File
@@ -400,7 +400,7 @@ public:
HistoryItem *addNewMessage(
const MTPMessage &data,
MTPDmessage_ClientFlags flags,
MessageFlags localFlags,
NewMessageType type);
struct SendActionAnimationUpdate {
+58
View File
@@ -364,3 +364,61 @@ struct StickerSetIdentifier {
return !empty();
}
};
enum class MessageFlag : uint32 {
HideEdited = (1U << 0),
Legacy = (1U << 1),
HasReplyMarkup = (1U << 2),
HasFromId = (1U << 3),
HasPostAuthor = (1U << 4),
HasViews = (1U << 5),
HasReplyInfo = (1U << 6),
HasViaBot = (1U << 7),
AdminLogEntry = (1U << 8),
Post = (1U << 9),
Silent = (1U << 10),
Outgoing = (1U << 11),
Pinned = (1U << 12),
MediaIsUnread = (1U << 13),
MentionsMe = (1U << 14),
IsOrWasScheduled = (1U << 15),
// Needs to return back to inline mode.
HasSwitchInlineButton = (1U << 16),
// For "shared links" indexing.
HasTextLinks = (1U << 17),
// Group / channel create or migrate service message.
IsGroupEssential = (1U << 18),
// Edited media is generated on the client
// and should not update media from server.
IsLocalUpdateMedia = (1U << 19),
// Sent from inline bot, need to re-set media when sent.
FromInlineBot = (1U << 20),
// Generated on the client side and should be unread.
ClientSideUnread = (1U << 21),
// In a supergroup.
HasAdminBadge = (1U << 22),
// Outgoing message that is being sent.
BeingSent = (1U << 23),
// Outgoing message and failed to be sent.
SendingFailed = (1U << 24),
// No media and only a several emoji text.
IsolatedEmoji = (1U << 25),
// Local message existing in the message history.
LocalHistoryEntry = (1U << 26),
// Fake message for some UI element.
FakeHistoryItem = (1U << 27),
};
inline constexpr bool is_flag_type(MessageFlag) { return true; }
using MessageFlags = base::flags<MessageFlag>;