mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-15 21:57:10 +02:00
Don't use MTP* for Message flags.
This commit is contained in:
parent
22e77bf3af
commit
116a768fde
30 changed files with 638 additions and 841 deletions
|
@ -40,22 +40,22 @@ namespace {
|
|||
void InnerFillMessagePostFlags(
|
||||
const Api::SendOptions &options,
|
||||
not_null<PeerData*> peer,
|
||||
MTPDmessage::Flags &flags) {
|
||||
MessageFlags &flags) {
|
||||
const auto anonymousPost = peer->amAnonymous();
|
||||
if (!anonymousPost) {
|
||||
flags |= MTPDmessage::Flag::f_from_id;
|
||||
flags |= MessageFlag::HasFromId;
|
||||
return;
|
||||
} else if (peer->asMegagroup()) {
|
||||
return;
|
||||
}
|
||||
flags |= MTPDmessage::Flag::f_post;
|
||||
flags |= MessageFlag::Post;
|
||||
// Don't display views and author of a new post when it's scheduled.
|
||||
if (options.scheduled) {
|
||||
return;
|
||||
}
|
||||
flags |= MTPDmessage::Flag::f_views;
|
||||
flags |= MessageFlag::HasViews;
|
||||
if (peer->asChannel()->addsSignature()) {
|
||||
flags |= MTPDmessage::Flag::f_post_author;
|
||||
flags |= MessageFlag::HasPostAuthor;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -79,11 +79,10 @@ void SendExistingMedia(
|
|||
session->data().nextLocalMessageId());
|
||||
const auto randomId = openssl::RandomValue<uint64>();
|
||||
|
||||
auto flags = NewMessageFlags(peer) | MTPDmessage::Flag::f_media;
|
||||
auto clientFlags = NewMessageClientFlags();
|
||||
auto flags = NewMessageFlags(peer);
|
||||
auto sendFlags = MTPmessages_SendMedia::Flags(0);
|
||||
if (message.action.replyTo) {
|
||||
flags |= MTPDmessage::Flag::f_reply_to;
|
||||
flags |= MessageFlag::HasReplyInfo;
|
||||
sendFlags |= MTPmessages_SendMedia::Flag::f_reply_to_msg_id;
|
||||
}
|
||||
const auto anonymousPost = peer->amAnonymous();
|
||||
|
@ -111,19 +110,19 @@ void SendExistingMedia(
|
|||
const auto captionText = caption.text;
|
||||
|
||||
if (message.action.options.scheduled) {
|
||||
flags |= MTPDmessage::Flag::f_from_scheduled;
|
||||
flags |= MessageFlag::IsOrWasScheduled;
|
||||
sendFlags |= MTPmessages_SendMedia::Flag::f_schedule_date;
|
||||
} else {
|
||||
clientFlags |= MTPDmessage_ClientFlag::f_local_history_entry;
|
||||
flags |= MessageFlag::LocalHistoryEntry;
|
||||
}
|
||||
|
||||
session->data().registerMessageRandomId(randomId, newId);
|
||||
|
||||
const auto viaBotId = UserId();
|
||||
history->addNewLocalMessage(
|
||||
newId.msg,
|
||||
flags,
|
||||
clientFlags,
|
||||
0,
|
||||
viaBotId,
|
||||
replyTo,
|
||||
HistoryItem::NewMessageDate(message.action.options.scheduled),
|
||||
messageFromId,
|
||||
|
@ -253,11 +252,10 @@ bool SendDice(Api::MessageToSend &message) {
|
|||
const auto randomId = openssl::RandomValue<uint64>();
|
||||
|
||||
auto &histories = history->owner().histories();
|
||||
auto flags = NewMessageFlags(peer) | MTPDmessage::Flag::f_media;
|
||||
auto clientFlags = NewMessageClientFlags();
|
||||
auto flags = NewMessageFlags(peer);
|
||||
auto sendFlags = MTPmessages_SendMedia::Flags(0);
|
||||
if (message.action.replyTo) {
|
||||
flags |= MTPDmessage::Flag::f_reply_to;
|
||||
flags |= MessageFlag::HasReplyInfo;
|
||||
sendFlags |= MTPmessages_SendMedia::Flag::f_reply_to_msg_id;
|
||||
}
|
||||
const auto replyHeader = NewMessageReplyHeader(message.action);
|
||||
|
@ -272,42 +270,26 @@ bool SendDice(Api::MessageToSend &message) {
|
|||
const auto replyTo = message.action.replyTo;
|
||||
|
||||
if (message.action.options.scheduled) {
|
||||
flags |= MTPDmessage::Flag::f_from_scheduled;
|
||||
flags |= MessageFlag::IsOrWasScheduled;
|
||||
sendFlags |= MTPmessages_SendMedia::Flag::f_schedule_date;
|
||||
} else {
|
||||
clientFlags |= MTPDmessage_ClientFlag::f_local_history_entry;
|
||||
flags |= MessageFlag::LocalHistoryEntry;
|
||||
}
|
||||
|
||||
session->data().registerMessageRandomId(randomId, newId);
|
||||
|
||||
const auto views = 1;
|
||||
const auto forwards = 0;
|
||||
history->addNewMessage(
|
||||
MTP_message(
|
||||
MTP_flags(flags),
|
||||
MTP_int(newId.msg),
|
||||
peerToMTP(messageFromId),
|
||||
peerToMTP(history->peer->id),
|
||||
MTPMessageFwdHeader(),
|
||||
MTPint(), // via_bot_id
|
||||
replyHeader,
|
||||
MTP_int(HistoryItem::NewMessageDate(
|
||||
message.action.options.scheduled)),
|
||||
MTP_string(),
|
||||
MTP_messageMediaDice(MTP_int(0), MTP_string(emoji)),
|
||||
MTPReplyMarkup(),
|
||||
MTP_vector<MTPMessageEntity>(),
|
||||
MTP_int(views),
|
||||
MTP_int(forwards),
|
||||
MTPMessageReplies(),
|
||||
MTPint(), // edit_date
|
||||
MTP_string(messagePostAuthor),
|
||||
MTPlong(),
|
||||
//MTPMessageReactions(),
|
||||
MTPVector<MTPRestrictionReason>(),
|
||||
MTPint()), // ttl_period
|
||||
clientFlags,
|
||||
NewMessageType::Unread);
|
||||
const auto viaBotId = UserId();
|
||||
history->addNewLocalMessage(
|
||||
newId.msg,
|
||||
flags,
|
||||
viaBotId,
|
||||
message.action.replyTo,
|
||||
HistoryItem::NewMessageDate(message.action.options.scheduled),
|
||||
messageFromId,
|
||||
messagePostAuthor,
|
||||
TextWithEntities(),
|
||||
MTP_messageMediaDice(MTP_int(0), MTP_string(emoji)),
|
||||
MTPReplyMarkup());
|
||||
|
||||
const auto requestType = Data::Histories::RequestType::Send;
|
||||
histories.sendRequest(history, requestType, [=](Fn<void()> finish) {
|
||||
|
@ -338,14 +320,15 @@ bool SendDice(Api::MessageToSend &message) {
|
|||
void FillMessagePostFlags(
|
||||
const Api::SendAction &action,
|
||||
not_null<PeerData*> peer,
|
||||
MTPDmessage::Flags &flags) {
|
||||
MessageFlags &flags) {
|
||||
InnerFillMessagePostFlags(action.options, peer, flags);
|
||||
}
|
||||
|
||||
void SendConfirmedFile(
|
||||
not_null<Main::Session*> session,
|
||||
const std::shared_ptr<FileLoadResult> &file) {
|
||||
const auto isEditing = file->to.replaceMediaOf != 0;
|
||||
const auto isEditing = (file->type != SendMediaType::Audio)
|
||||
&& (file->to.replaceMediaOf != 0);
|
||||
const auto channelId = peerToChannel(file->to.peer);
|
||||
|
||||
const auto newId = FullMsgId(
|
||||
|
@ -396,29 +379,24 @@ void SendConfirmedFile(
|
|||
}
|
||||
}
|
||||
|
||||
auto flags = (isEditing ? MTPDmessage::Flags() : NewMessageFlags(peer))
|
||||
| MTPDmessage::Flag::f_entities
|
||||
| MTPDmessage::Flag::f_media;
|
||||
auto clientFlags = NewMessageClientFlags();
|
||||
auto flags = isEditing ? MessageFlags() : NewMessageFlags(peer);
|
||||
if (file->to.replyTo) {
|
||||
flags |= MTPDmessage::Flag::f_reply_to;
|
||||
flags |= MessageFlag::HasReplyInfo;
|
||||
}
|
||||
const auto replyHeader = NewMessageReplyHeader(action);
|
||||
const auto anonymousPost = peer->amAnonymous();
|
||||
const auto silentPost = ShouldSendSilent(peer, file->to.options);
|
||||
Api::FillMessagePostFlags(action, peer, flags);
|
||||
FillMessagePostFlags(action, peer, flags);
|
||||
if (silentPost) {
|
||||
flags |= MTPDmessage::Flag::f_silent;
|
||||
}
|
||||
if (groupId) {
|
||||
flags |= MTPDmessage::Flag::f_grouped_id;
|
||||
flags |= MessageFlag::Silent;
|
||||
}
|
||||
if (file->to.options.scheduled) {
|
||||
flags |= MTPDmessage::Flag::f_from_scheduled;
|
||||
flags |= MessageFlag::IsOrWasScheduled;
|
||||
|
||||
// Scheduled messages have no the 'edited' badge.
|
||||
flags |= MTPDmessage::Flag::f_edit_hide;
|
||||
flags |= MessageFlag::HideEdited;
|
||||
} else {
|
||||
clientFlags |= MTPDmessage_ClientFlag::f_local_history_entry;
|
||||
flags |= MessageFlag::LocalHistoryEntry;
|
||||
}
|
||||
|
||||
const auto messageFromId = anonymousPost ? 0 : session->userPeerId();
|
||||
|
@ -426,17 +404,37 @@ void SendConfirmedFile(
|
|||
? session->user()->name
|
||||
: QString();
|
||||
|
||||
const auto views = 1;
|
||||
const auto forwards = 0;
|
||||
if (file->type == SendMediaType::Photo) {
|
||||
const auto photoFlags = MTPDmessageMediaPhoto::Flag::f_photo | 0;
|
||||
const auto photo = MTP_messageMediaPhoto(
|
||||
MTP_flags(photoFlags),
|
||||
file->photo,
|
||||
MTPint());
|
||||
const auto media = [&] {
|
||||
if (file->type == SendMediaType::Photo) {
|
||||
return MTP_messageMediaPhoto(
|
||||
MTP_flags(MTPDmessageMediaPhoto::Flag::f_photo),
|
||||
file->photo,
|
||||
MTPint());
|
||||
} else if (file->type == SendMediaType::File) {
|
||||
return MTP_messageMediaDocument(
|
||||
MTP_flags(MTPDmessageMediaDocument::Flag::f_document),
|
||||
file->document,
|
||||
MTPint());
|
||||
} else if (file->type == SendMediaType::Audio) {
|
||||
return MTP_messageMediaDocument(
|
||||
MTP_flags(MTPDmessageMediaDocument::Flag::f_document),
|
||||
file->document,
|
||||
MTPint());
|
||||
} else {
|
||||
Unexpected("Type in sendFilesConfirmed.");
|
||||
}
|
||||
}();
|
||||
|
||||
const auto mtpMessage = MTP_message(
|
||||
MTP_flags(flags),
|
||||
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(newId.msg),
|
||||
peerToMTP(messageFromId),
|
||||
peerToMTP(file->to.peer),
|
||||
|
@ -445,105 +443,32 @@ void SendConfirmedFile(
|
|||
replyHeader,
|
||||
MTP_int(HistoryItem::NewMessageDate(file->to.options.scheduled)),
|
||||
MTP_string(caption.text),
|
||||
photo,
|
||||
media,
|
||||
MTPReplyMarkup(),
|
||||
localEntities,
|
||||
MTP_int(views),
|
||||
MTP_int(forwards),
|
||||
MTPint(), // views
|
||||
MTPint(), // forwards
|
||||
MTPMessageReplies(),
|
||||
MTPint(), // edit_date
|
||||
MTP_string(messagePostAuthor),
|
||||
MTP_long(groupId),
|
||||
//MTPMessageReactions(),
|
||||
MTPVector<MTPRestrictionReason>(),
|
||||
MTPint()); // ttl_period
|
||||
|
||||
if (itemToEdit) {
|
||||
itemToEdit->savePreviousMedia();
|
||||
itemToEdit->applyEdition(mtpMessage.c_message());
|
||||
} else {
|
||||
history->addNewMessage(
|
||||
mtpMessage,
|
||||
clientFlags,
|
||||
NewMessageType::Unread);
|
||||
}
|
||||
} else if (file->type == SendMediaType::File) {
|
||||
const auto documentFlags = MTPDmessageMediaDocument::Flag::f_document | 0;
|
||||
const auto document = MTP_messageMediaDocument(
|
||||
MTP_flags(documentFlags),
|
||||
file->document,
|
||||
MTPint());
|
||||
|
||||
const auto mtpMessage = MTP_message(
|
||||
MTP_flags(flags),
|
||||
MTP_int(newId.msg),
|
||||
peerToMTP(messageFromId),
|
||||
peerToMTP(file->to.peer),
|
||||
MTPMessageFwdHeader(),
|
||||
MTPint(),
|
||||
replyHeader,
|
||||
MTP_int(HistoryItem::NewMessageDate(file->to.options.scheduled)),
|
||||
MTP_string(caption.text),
|
||||
document,
|
||||
MTPReplyMarkup(),
|
||||
localEntities,
|
||||
MTP_int(views),
|
||||
MTP_int(forwards),
|
||||
MTPMessageReplies(),
|
||||
MTPint(), // edit_date
|
||||
MTP_string(messagePostAuthor),
|
||||
MTP_long(groupId),
|
||||
//MTPMessageReactions(),
|
||||
MTPVector<MTPRestrictionReason>(),
|
||||
MTPint()); // ttl_period
|
||||
|
||||
if (itemToEdit) {
|
||||
itemToEdit->savePreviousMedia();
|
||||
itemToEdit->applyEdition(mtpMessage.c_message());
|
||||
} else {
|
||||
history->addNewMessage(
|
||||
mtpMessage,
|
||||
clientFlags,
|
||||
NewMessageType::Unread);
|
||||
}
|
||||
} else if (file->type == SendMediaType::Audio) {
|
||||
if (!peer->isChannel() || peer->isMegagroup()) {
|
||||
flags |= MTPDmessage::Flag::f_media_unread;
|
||||
}
|
||||
const auto documentFlags = MTPDmessageMediaDocument::Flag::f_document | 0;
|
||||
const auto document = MTP_messageMediaDocument(
|
||||
MTP_flags(documentFlags),
|
||||
file->document,
|
||||
MTPint());
|
||||
history->addNewMessage(
|
||||
MTP_message(
|
||||
MTP_flags(flags),
|
||||
MTP_int(newId.msg),
|
||||
peerToMTP(messageFromId),
|
||||
peerToMTP(file->to.peer),
|
||||
MTPMessageFwdHeader(),
|
||||
MTPint(),
|
||||
replyHeader,
|
||||
MTP_int(
|
||||
HistoryItem::NewMessageDate(file->to.options.scheduled)),
|
||||
MTP_string(caption.text),
|
||||
document,
|
||||
MTPReplyMarkup(),
|
||||
localEntities,
|
||||
MTP_int(views),
|
||||
MTP_int(forwards),
|
||||
MTPMessageReplies(),
|
||||
MTPint(), // edit_date
|
||||
MTP_string(messagePostAuthor),
|
||||
MTP_long(groupId),
|
||||
//MTPMessageReactions(),
|
||||
MTPVector<MTPRestrictionReason>(),
|
||||
MTPint()), // ttl_period
|
||||
clientFlags,
|
||||
NewMessageType::Unread);
|
||||
// Voices can't be edited.
|
||||
MTPint()).c_message());
|
||||
} else {
|
||||
Unexpected("Type in sendFilesConfirmed.");
|
||||
const auto viaBotId = UserId();
|
||||
history->addNewLocalMessage(
|
||||
newId.msg,
|
||||
flags,
|
||||
viaBotId,
|
||||
file->to.replyTo,
|
||||
HistoryItem::NewMessageDate(file->to.options.scheduled),
|
||||
messageFromId,
|
||||
messagePostAuthor,
|
||||
caption,
|
||||
media,
|
||||
MTPReplyMarkup(),
|
||||
groupId);
|
||||
}
|
||||
|
||||
if (isEditing) {
|
||||
|
|
|
@ -30,7 +30,7 @@ bool SendDice(Api::MessageToSend &message);
|
|||
void FillMessagePostFlags(
|
||||
const SendAction &action,
|
||||
not_null<PeerData*> peer,
|
||||
MTPDmessage::Flags &flags);
|
||||
MessageFlags &flags);
|
||||
|
||||
void SendConfirmedFile(
|
||||
not_null<Main::Session*> session,
|
||||
|
|
|
@ -1055,7 +1055,7 @@ void Updates::applyUpdatesNoPtsCheck(const MTPUpdates &updates) {
|
|||
//MTPMessageReactions(),
|
||||
MTPVector<MTPRestrictionReason>(),
|
||||
MTP_int(d.vttl_period().value_or_empty())),
|
||||
MTPDmessage_ClientFlags(),
|
||||
MessageFlags(),
|
||||
NewMessageType::Unread);
|
||||
} break;
|
||||
|
||||
|
@ -1086,7 +1086,7 @@ void Updates::applyUpdatesNoPtsCheck(const MTPUpdates &updates) {
|
|||
//MTPMessageReactions(),
|
||||
MTPVector<MTPRestrictionReason>(),
|
||||
MTP_int(d.vttl_period().value_or_empty())),
|
||||
MTPDmessage_ClientFlags(),
|
||||
MessageFlags(),
|
||||
NewMessageType::Unread);
|
||||
} break;
|
||||
|
||||
|
@ -1115,7 +1115,7 @@ void Updates::applyUpdateNoPtsCheck(const MTPUpdate &update) {
|
|||
if (needToAdd) {
|
||||
_session->data().addNewMessage(
|
||||
d.vmessage(),
|
||||
MTPDmessage_ClientFlags(),
|
||||
MessageFlags(),
|
||||
NewMessageType::Unread);
|
||||
}
|
||||
} break;
|
||||
|
@ -1209,7 +1209,7 @@ void Updates::applyUpdateNoPtsCheck(const MTPUpdate &update) {
|
|||
if (needToAdd) {
|
||||
_session->data().addNewMessage(
|
||||
d.vmessage(),
|
||||
MTPDmessage_ClientFlags(),
|
||||
MessageFlags(),
|
||||
NewMessageType::Unread);
|
||||
}
|
||||
} break;
|
||||
|
|
|
@ -3783,18 +3783,17 @@ void ApiWrap::forwardMessages(
|
|||
const auto anonymousPost = peer->amAnonymous();
|
||||
const auto silentPost = ShouldSendSilent(peer, action.options);
|
||||
|
||||
auto flags = MTPDmessage::Flags(0);
|
||||
auto clientFlags = MTPDmessage_ClientFlags();
|
||||
auto flags = MessageFlags();
|
||||
auto sendFlags = MTPmessages_ForwardMessages::Flags(0);
|
||||
FillMessagePostFlags(action, peer, flags);
|
||||
if (silentPost) {
|
||||
sendFlags |= MTPmessages_ForwardMessages::Flag::f_silent;
|
||||
}
|
||||
if (action.options.scheduled) {
|
||||
flags |= MTPDmessage::Flag::f_from_scheduled;
|
||||
flags |= MessageFlag::IsOrWasScheduled;
|
||||
sendFlags |= MTPmessages_ForwardMessages::Flag::f_schedule_date;
|
||||
} else {
|
||||
clientFlags |= MTPDmessage_ClientFlag::f_local_history_entry;
|
||||
flags |= MessageFlag::LocalHistoryEntry;
|
||||
}
|
||||
|
||||
auto forwardFrom = items.front()->history()->peer;
|
||||
|
@ -3861,7 +3860,6 @@ void ApiWrap::forwardMessages(
|
|||
history->addNewLocalMessage(
|
||||
newId.msg,
|
||||
flags,
|
||||
clientFlags,
|
||||
HistoryItem::NewMessageDate(action.options.scheduled),
|
||||
messageFromId,
|
||||
messagePostAuthor,
|
||||
|
@ -3926,61 +3924,44 @@ void ApiWrap::sendSharedContact(
|
|||
_session->data().nextLocalMessageId());
|
||||
const auto anonymousPost = peer->amAnonymous();
|
||||
|
||||
auto flags = NewMessageFlags(peer) | MTPDmessage::Flag::f_media;
|
||||
auto clientFlags = NewMessageClientFlags();
|
||||
auto flags = NewMessageFlags(peer);
|
||||
if (action.replyTo) {
|
||||
flags |= MTPDmessage::Flag::f_reply_to;
|
||||
flags |= MessageFlag::HasReplyInfo;
|
||||
}
|
||||
const auto replyHeader = NewMessageReplyHeader(action);
|
||||
FillMessagePostFlags(action, peer, flags);
|
||||
if (action.options.scheduled) {
|
||||
flags |= MTPDmessage::Flag::f_from_scheduled;
|
||||
flags |= MessageFlag::IsOrWasScheduled;
|
||||
} else {
|
||||
clientFlags |= MTPDmessage_ClientFlag::f_local_history_entry;
|
||||
flags |= MessageFlag::LocalHistoryEntry;
|
||||
}
|
||||
const auto messageFromId = anonymousPost ? 0 : _session->userPeerId();
|
||||
const auto messagePostAuthor = peer->isBroadcast()
|
||||
? _session->user()->name
|
||||
: QString();
|
||||
const auto vcard = QString();
|
||||
const auto views = 1;
|
||||
const auto forwards = 0;
|
||||
const auto item = history->addNewMessage(
|
||||
MTP_message(
|
||||
MTP_flags(flags),
|
||||
MTP_int(newId.msg),
|
||||
peerToMTP(messageFromId),
|
||||
peerToMTP(peer->id),
|
||||
MTPMessageFwdHeader(),
|
||||
MTPint(), // via_bot_id
|
||||
replyHeader,
|
||||
MTP_int(HistoryItem::NewMessageDate(action.options.scheduled)),
|
||||
MTP_string(),
|
||||
MTP_messageMediaContact(
|
||||
MTP_string(phone),
|
||||
MTP_string(firstName),
|
||||
MTP_string(lastName),
|
||||
MTP_string(vcard),
|
||||
MTP_int(userId.bare)), // #TODO ids
|
||||
MTPReplyMarkup(),
|
||||
MTPVector<MTPMessageEntity>(),
|
||||
MTP_int(views),
|
||||
MTP_int(forwards),
|
||||
MTPMessageReplies(),
|
||||
MTPint(), // edit_date
|
||||
MTP_string(messagePostAuthor),
|
||||
MTPlong(),
|
||||
//MTPMessageReactions(),
|
||||
MTPVector<MTPRestrictionReason>(),
|
||||
MTPint()), // ttl_period
|
||||
clientFlags,
|
||||
NewMessageType::Unread);
|
||||
const auto viaBotId = UserId();
|
||||
const auto item = history->addNewLocalMessage(
|
||||
newId.msg,
|
||||
flags,
|
||||
viaBotId,
|
||||
action.replyTo,
|
||||
HistoryItem::NewMessageDate(action.options.scheduled),
|
||||
messageFromId,
|
||||
messagePostAuthor,
|
||||
TextWithEntities(),
|
||||
MTP_messageMediaContact(
|
||||
MTP_string(phone),
|
||||
MTP_string(firstName),
|
||||
MTP_string(lastName),
|
||||
MTP_string(), // vcard
|
||||
MTP_int(userId.bare)), // #TODO ids
|
||||
MTPReplyMarkup());
|
||||
|
||||
const auto media = MTP_inputMediaContact(
|
||||
MTP_string(phone),
|
||||
MTP_string(firstName),
|
||||
MTP_string(lastName),
|
||||
MTP_string(vcard));
|
||||
MTP_string()); // vcard
|
||||
sendMedia(item, media, action.options);
|
||||
|
||||
_session->data().sendHistoryChangeNotifications();
|
||||
|
@ -4181,11 +4162,10 @@ void ApiWrap::sendMessage(MessageToSend &&message) {
|
|||
_session->data().registerMessageSentData(randomId, peer->id, sending.text);
|
||||
|
||||
MTPstring msgText(MTP_string(sending.text));
|
||||
auto flags = NewMessageFlags(peer) | MTPDmessage::Flag::f_entities;
|
||||
auto clientFlags = NewMessageClientFlags();
|
||||
auto flags = NewMessageFlags(peer);
|
||||
auto sendFlags = MTPmessages_SendMessage::Flags(0);
|
||||
if (action.replyTo) {
|
||||
flags |= MTPDmessage::Flag::f_reply_to;
|
||||
flags |= MessageFlag::HasReplyInfo;
|
||||
sendFlags |= MTPmessages_SendMessage::Flag::f_reply_to_msg_id;
|
||||
}
|
||||
const auto replyHeader = NewMessageReplyHeader(action);
|
||||
|
@ -4198,7 +4178,6 @@ void ApiWrap::sendMessage(MessageToSend &&message) {
|
|||
MTP_webPagePending(
|
||||
MTP_long(page->id),
|
||||
MTP_int(page->pendingTill)));
|
||||
flags |= MTPDmessage::Flag::f_media;
|
||||
}
|
||||
const auto anonymousPost = peer->amAnonymous();
|
||||
const auto silentPost = ShouldSendSilent(peer, action.options);
|
||||
|
@ -4206,10 +4185,7 @@ void ApiWrap::sendMessage(MessageToSend &&message) {
|
|||
if (silentPost) {
|
||||
sendFlags |= MTPmessages_SendMessage::Flag::f_silent;
|
||||
}
|
||||
auto localEntities = Api::EntitiesToMTP(
|
||||
_session,
|
||||
sending.entities);
|
||||
auto sentEntities = Api::EntitiesToMTP(
|
||||
const auto sentEntities = Api::EntitiesToMTP(
|
||||
_session,
|
||||
sending.entities,
|
||||
Api::ConvertOption::SkipLocal);
|
||||
|
@ -4227,39 +4203,23 @@ void ApiWrap::sendMessage(MessageToSend &&message) {
|
|||
? _session->user()->name
|
||||
: QString();
|
||||
if (action.options.scheduled) {
|
||||
flags |= MTPDmessage::Flag::f_from_scheduled;
|
||||
flags |= MessageFlag::IsOrWasScheduled;
|
||||
sendFlags |= MTPmessages_SendMessage::Flag::f_schedule_date;
|
||||
} else {
|
||||
clientFlags |= MTPDmessage_ClientFlag::f_local_history_entry;
|
||||
flags |= MessageFlag::LocalHistoryEntry;
|
||||
}
|
||||
const auto views = 1;
|
||||
const auto forwards = 0;
|
||||
lastMessage = history->addNewMessage(
|
||||
MTP_message(
|
||||
MTP_flags(flags),
|
||||
MTP_int(newId.msg),
|
||||
peerToMTP(messageFromId),
|
||||
peerToMTP(peer->id),
|
||||
MTPMessageFwdHeader(),
|
||||
MTPint(), // via_bot_id
|
||||
replyHeader,
|
||||
MTP_int(
|
||||
HistoryItem::NewMessageDate(action.options.scheduled)),
|
||||
msgText,
|
||||
media,
|
||||
MTPReplyMarkup(),
|
||||
localEntities,
|
||||
MTP_int(views),
|
||||
MTP_int(forwards),
|
||||
MTPMessageReplies(),
|
||||
MTPint(), // edit_date
|
||||
MTP_string(messagePostAuthor),
|
||||
MTPlong(),
|
||||
//MTPMessageReactions(),
|
||||
MTPVector<MTPRestrictionReason>(),
|
||||
MTPint()), // ttl_period
|
||||
clientFlags,
|
||||
NewMessageType::Unread);
|
||||
const auto viaBotId = UserId();
|
||||
lastMessage = history->addNewLocalMessage(
|
||||
newId.msg,
|
||||
flags,
|
||||
viaBotId,
|
||||
action.replyTo,
|
||||
HistoryItem::NewMessageDate(action.options.scheduled),
|
||||
messageFromId,
|
||||
messagePostAuthor,
|
||||
sending,
|
||||
media,
|
||||
MTPReplyMarkup());
|
||||
histories.sendRequest(history, requestType, [=](Fn<void()> finish) {
|
||||
history->sendRequestId = request(MTPmessages_SendMessage(
|
||||
MTP_flags(sendFlags),
|
||||
|
@ -4346,11 +4306,10 @@ void ApiWrap::sendInlineResult(
|
|||
_session->data().nextLocalMessageId());
|
||||
const auto randomId = openssl::RandomValue<uint64>();
|
||||
|
||||
auto flags = NewMessageFlags(peer) | MTPDmessage::Flag::f_media;
|
||||
auto clientFlags = NewMessageClientFlags();
|
||||
auto flags = NewMessageFlags(peer);
|
||||
auto sendFlags = MTPmessages_SendInlineBotResult::Flag::f_clear_draft | 0;
|
||||
if (action.replyTo) {
|
||||
flags |= MTPDmessage::Flag::f_reply_to;
|
||||
flags |= MessageFlag::HasReplyInfo;
|
||||
sendFlags |= MTPmessages_SendInlineBotResult::Flag::f_reply_to_msg_id;
|
||||
}
|
||||
const auto anonymousPost = peer->amAnonymous();
|
||||
|
@ -4360,13 +4319,13 @@ void ApiWrap::sendInlineResult(
|
|||
sendFlags |= MTPmessages_SendInlineBotResult::Flag::f_silent;
|
||||
}
|
||||
if (bot) {
|
||||
flags |= MTPDmessage::Flag::f_via_bot_id;
|
||||
flags |= MessageFlag::HasViaBot;
|
||||
}
|
||||
if (action.options.scheduled) {
|
||||
flags |= MTPDmessage::Flag::f_from_scheduled;
|
||||
flags |= MessageFlag::IsOrWasScheduled;
|
||||
sendFlags |= MTPmessages_SendInlineBotResult::Flag::f_schedule_date;
|
||||
} else {
|
||||
clientFlags |= MTPDmessage_ClientFlag::f_local_history_entry;
|
||||
flags |= MessageFlag::LocalHistoryEntry;
|
||||
}
|
||||
|
||||
const auto messageFromId = anonymousPost ? 0 : _session->userPeerId();
|
||||
|
@ -4379,10 +4338,9 @@ void ApiWrap::sendInlineResult(
|
|||
data->addToHistory(
|
||||
history,
|
||||
flags,
|
||||
clientFlags,
|
||||
newId.msg,
|
||||
messageFromId,
|
||||
MTP_int(HistoryItem::NewMessageDate(action.options.scheduled)),
|
||||
HistoryItem::NewMessageDate(action.options.scheduled),
|
||||
bot ? peerToUser(bot->id) : 0,
|
||||
action.replyTo,
|
||||
messagePostAuthor);
|
||||
|
|
|
@ -286,24 +286,25 @@ AdminLog::OwnedItem GenerateTextItem(
|
|||
bool out) {
|
||||
Expects(history->peer->isUser());
|
||||
|
||||
using Flag = MTPDmessage::Flag;
|
||||
static auto id = ServerMaxMsgId + (ServerMaxMsgId / 3);
|
||||
const auto flags = Flag::f_entities
|
||||
| Flag::f_from_id
|
||||
| (out ? Flag::f_out : Flag(0));
|
||||
const auto clientFlags = MTPDmessage_ClientFlag::f_fake_history_item;
|
||||
const auto replyTo = 0;
|
||||
const auto viaBotId = UserId(0);
|
||||
const auto flags = MessageFlag::FakeHistoryItem
|
||||
| MessageFlag::HasFromId
|
||||
| (out ? MessageFlag::Outgoing : MessageFlag(0));
|
||||
const auto replyTo = MsgId();
|
||||
const auto viaBotId = UserId();
|
||||
const auto groupedId = uint64();
|
||||
const auto item = history->makeMessage(
|
||||
++id,
|
||||
flags,
|
||||
clientFlags,
|
||||
replyTo,
|
||||
viaBotId,
|
||||
base::unixtime::now(),
|
||||
out ? history->session().userId() : peerToUser(history->peer->id),
|
||||
QString(),
|
||||
TextWithEntities{ TextUtilities::Clean(text) });
|
||||
TextWithEntities{ TextUtilities::Clean(text) },
|
||||
MTP_messageMediaEmpty(),
|
||||
MTPReplyMarkup(),
|
||||
groupedId);
|
||||
return AdminLog::OwnedItem(delegate, item);
|
||||
}
|
||||
|
||||
|
|
|
@ -398,7 +398,7 @@ void BoxController::receivedCalls(const QVector<MTPMessage> &result) {
|
|||
if (const auto peer = session().data().peerLoaded(peerId)) {
|
||||
const auto item = session().data().addNewMessage(
|
||||
message,
|
||||
MTPDmessage_ClientFlags(),
|
||||
MessageFlags(),
|
||||
NewMessageType::Existing);
|
||||
insertRow(item, InsertWay::Append);
|
||||
} else {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -400,7 +400,7 @@ public:
|
|||
|
||||
HistoryItem *addNewMessage(
|
||||
const MTPMessage &data,
|
||||
MTPDmessage_ClientFlags flags,
|
||||
MessageFlags localFlags,
|
||||
NewMessageType type);
|
||||
|
||||
struct SendActionAnimationUpdate {
|
||||
|
|
|
@ -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>;
|
||||
|
|
|
@ -2047,7 +2047,7 @@ bool InnerWidget::searchReceived(
|
|||
if (lastDate) {
|
||||
const auto item = session().data().addNewMessage(
|
||||
message,
|
||||
MTPDmessage_ClientFlags(),
|
||||
MessageFlags(),
|
||||
NewMessageType::Existing);
|
||||
const auto history = item->history();
|
||||
if (!uniquePeers || !hasHistoryInResults(history)) {
|
||||
|
|
|
@ -520,10 +520,9 @@ void GenerateItems(
|
|||
message.links.push_back(fromLink);
|
||||
addPart(history->makeServiceMessage(
|
||||
history->nextNonHistoryEntryId(),
|
||||
MTPDmessage_ClientFlag::f_admin_log_entry,
|
||||
MessageFlag::AdminLogEntry,
|
||||
date,
|
||||
message,
|
||||
MTPDmessage::Flags(0),
|
||||
peerToUser(from->id),
|
||||
photo));
|
||||
};
|
||||
|
@ -540,6 +539,29 @@ void GenerateItems(
|
|||
addSimpleServiceMessage(text);
|
||||
};
|
||||
|
||||
auto makeSimpleTextMessage = [&](TextWithEntities &&text) {
|
||||
auto bodyFlags = MessageFlag::HasFromId | MessageFlag::AdminLogEntry;
|
||||
auto bodyReplyTo = MsgId();
|
||||
auto bodyViaBotId = UserId();
|
||||
auto bodyGroupedId = uint64();
|
||||
return history->makeMessage(
|
||||
history->nextNonHistoryEntryId(),
|
||||
bodyFlags,
|
||||
bodyReplyTo,
|
||||
bodyViaBotId,
|
||||
date,
|
||||
peerToUser(from->id),
|
||||
QString(),
|
||||
std::move(text),
|
||||
MTP_messageMediaEmpty(),
|
||||
MTPReplyMarkup(),
|
||||
bodyGroupedId);
|
||||
};
|
||||
|
||||
auto addSimpleTextMessage = [&](TextWithEntities &&text) {
|
||||
addPart(makeSimpleTextMessage(std::move(text)));
|
||||
};
|
||||
|
||||
auto createChangeAbout = [&](const MTPDchannelAdminLogEventActionChangeAbout &action) {
|
||||
auto newValue = qs(action.vnew_value());
|
||||
auto oldValue = qs(action.vprev_value());
|
||||
|
@ -553,21 +575,8 @@ void GenerateItems(
|
|||
)(tr::now, lt_from, fromLinkText);
|
||||
addSimpleServiceMessage(text);
|
||||
|
||||
auto bodyFlags = Flag::f_entities | Flag::f_from_id;
|
||||
auto bodyClientFlags = MTPDmessage_ClientFlag::f_admin_log_entry;
|
||||
auto bodyReplyTo = 0;
|
||||
auto bodyViaBotId = 0;
|
||||
auto newDescription = PrepareText(newValue, QString());
|
||||
auto body = history->makeMessage(
|
||||
history->nextNonHistoryEntryId(),
|
||||
bodyFlags,
|
||||
bodyClientFlags,
|
||||
bodyReplyTo,
|
||||
bodyViaBotId,
|
||||
date,
|
||||
peerToUser(from->id),
|
||||
QString(),
|
||||
newDescription);
|
||||
auto body = makeSimpleTextMessage(PrepareText(newValue, QString()));
|
||||
if (!oldValue.isEmpty()) {
|
||||
auto oldDescription = PrepareText(oldValue, QString());
|
||||
body->addLogEntryOriginal(id, tr::lng_admin_log_previous_description(tr::now), oldDescription);
|
||||
|
@ -588,25 +597,20 @@ void GenerateItems(
|
|||
)(tr::now, lt_from, fromLinkText);
|
||||
addSimpleServiceMessage(text);
|
||||
|
||||
auto bodyFlags = Flag::f_entities | Flag::f_from_id;
|
||||
auto bodyClientFlags = MTPDmessage_ClientFlag::f_admin_log_entry;
|
||||
auto bodyReplyTo = 0;
|
||||
auto bodyViaBotId = 0;
|
||||
auto bodyFlags = MessageFlag::Outgoing | MessageFlag::AdminLogEntry;
|
||||
auto bodyReplyTo = MsgId();
|
||||
auto bodyViaBotId = UserId();
|
||||
auto bodyGroupedId = uint64();
|
||||
auto newLink = newValue.isEmpty()
|
||||
? TextWithEntities()
|
||||
: PrepareText(
|
||||
history->session().createInternalLinkFull(newValue),
|
||||
QString());
|
||||
auto body = history->makeMessage(
|
||||
history->nextNonHistoryEntryId(),
|
||||
bodyFlags,
|
||||
bodyClientFlags,
|
||||
bodyReplyTo,
|
||||
bodyViaBotId,
|
||||
date,
|
||||
peerToUser(from->id),
|
||||
QString(),
|
||||
newLink);
|
||||
auto body = makeSimpleTextMessage(newValue.isEmpty()
|
||||
? TextWithEntities()
|
||||
: PrepareText(
|
||||
history->session().createInternalLinkFull(newValue),
|
||||
QString()));
|
||||
if (!oldValue.isEmpty()) {
|
||||
auto oldLink = PrepareText(
|
||||
history->session().createInternalLinkFull(oldValue),
|
||||
|
@ -668,7 +672,7 @@ void GenerateItems(
|
|||
action.vmessage(),
|
||||
history->nextNonHistoryEntryId(),
|
||||
date),
|
||||
MTPDmessage_ClientFlag::f_admin_log_entry,
|
||||
MessageFlag::AdminLogEntry,
|
||||
detachExistingItem),
|
||||
ExtractSentDate(action.vmessage()));
|
||||
}, [&](const auto &) {
|
||||
|
@ -697,7 +701,7 @@ void GenerateItems(
|
|||
action.vnew_message(),
|
||||
history->nextNonHistoryEntryId(),
|
||||
date),
|
||||
MTPDmessage_ClientFlag::f_admin_log_entry,
|
||||
MessageFlag::AdminLogEntry,
|
||||
detachExistingItem);
|
||||
if (oldValue.text.isEmpty()) {
|
||||
oldValue = PrepareText(QString(), tr::lng_admin_log_empty_text(tr::now));
|
||||
|
@ -723,7 +727,7 @@ void GenerateItems(
|
|||
action.vmessage(),
|
||||
history->nextNonHistoryEntryId(),
|
||||
date),
|
||||
MTPDmessage_ClientFlag::f_admin_log_entry,
|
||||
MessageFlag::AdminLogEntry,
|
||||
detachExistingItem),
|
||||
ExtractSentDate(action.vmessage()));
|
||||
};
|
||||
|
@ -743,39 +747,13 @@ void GenerateItems(
|
|||
};
|
||||
|
||||
auto createParticipantInvite = [&](const MTPDchannelAdminLogEventActionParticipantInvite &action) {
|
||||
auto bodyFlags = Flag::f_entities | Flag::f_from_id;
|
||||
auto bodyClientFlags = MTPDmessage_ClientFlag::f_admin_log_entry;
|
||||
auto bodyReplyTo = 0;
|
||||
auto bodyViaBotId = 0;
|
||||
auto bodyText = GenerateParticipantChangeText(channel, action.vparticipant());
|
||||
addPart(history->makeMessage(
|
||||
history->nextNonHistoryEntryId(),
|
||||
bodyFlags,
|
||||
bodyClientFlags,
|
||||
bodyReplyTo,
|
||||
bodyViaBotId,
|
||||
date,
|
||||
peerToUser(from->id),
|
||||
QString(),
|
||||
bodyText));
|
||||
addSimpleTextMessage(
|
||||
GenerateParticipantChangeText(channel, action.vparticipant()));
|
||||
};
|
||||
|
||||
auto createParticipantToggleBan = [&](const MTPDchannelAdminLogEventActionParticipantToggleBan &action) {
|
||||
auto bodyFlags = Flag::f_entities | Flag::f_from_id;
|
||||
auto bodyClientFlags = MTPDmessage_ClientFlag::f_admin_log_entry;
|
||||
auto bodyReplyTo = 0;
|
||||
auto bodyViaBotId = 0;
|
||||
auto bodyText = GenerateParticipantChangeText(channel, action.vnew_participant(), &action.vprev_participant());
|
||||
addPart(history->makeMessage(
|
||||
history->nextNonHistoryEntryId(),
|
||||
bodyFlags,
|
||||
bodyClientFlags,
|
||||
bodyReplyTo,
|
||||
bodyViaBotId,
|
||||
date,
|
||||
peerToUser(from->id),
|
||||
QString(),
|
||||
bodyText));
|
||||
addSimpleTextMessage(
|
||||
GenerateParticipantChangeText(channel, action.vnew_participant(), &action.vprev_participant()));
|
||||
};
|
||||
|
||||
auto createParticipantToggleAdmin = [&](const MTPDchannelAdminLogEventActionParticipantToggleAdmin &action) {
|
||||
|
@ -785,21 +763,8 @@ void GenerateItems(
|
|||
// the "User > Creator" part and skip the "Creator > Admin" part.
|
||||
return;
|
||||
}
|
||||
auto bodyFlags = Flag::f_entities | Flag::f_from_id;
|
||||
auto bodyClientFlags = MTPDmessage_ClientFlag::f_admin_log_entry;
|
||||
auto bodyReplyTo = 0;
|
||||
auto bodyViaBotId = 0;
|
||||
auto bodyText = GenerateParticipantChangeText(channel, action.vnew_participant(), &action.vprev_participant());
|
||||
addPart(history->makeMessage(
|
||||
history->nextNonHistoryEntryId(),
|
||||
bodyFlags,
|
||||
bodyClientFlags,
|
||||
bodyReplyTo,
|
||||
bodyViaBotId,
|
||||
date,
|
||||
peerToUser(from->id),
|
||||
QString(),
|
||||
bodyText));
|
||||
addSimpleTextMessage(
|
||||
GenerateParticipantChangeText(channel, action.vnew_participant(), &action.vprev_participant()));
|
||||
};
|
||||
|
||||
auto createChangeStickerSet = [&](const MTPDchannelAdminLogEventActionChangeStickerSet &action) {
|
||||
|
@ -825,10 +790,9 @@ void GenerateItems(
|
|||
message.links.push_back(setLink);
|
||||
addPart(history->makeServiceMessage(
|
||||
history->nextNonHistoryEntryId(),
|
||||
MTPDmessage_ClientFlag::f_admin_log_entry,
|
||||
MessageFlag::AdminLogEntry,
|
||||
date,
|
||||
message,
|
||||
MTPDmessage::Flags(0),
|
||||
peerToUser(from->id)));
|
||||
}
|
||||
};
|
||||
|
@ -842,24 +806,11 @@ void GenerateItems(
|
|||
};
|
||||
|
||||
auto createDefaultBannedRights = [&](const MTPDchannelAdminLogEventActionDefaultBannedRights &action) {
|
||||
auto bodyFlags = Flag::f_entities | Flag::f_from_id;
|
||||
auto bodyClientFlags = MTPDmessage_ClientFlag::f_admin_log_entry;
|
||||
auto bodyReplyTo = 0;
|
||||
auto bodyViaBotId = 0;
|
||||
auto bodyText = GenerateDefaultBannedRightsChangeText(
|
||||
channel,
|
||||
ChatRestrictionsInfo(action.vnew_banned_rights()),
|
||||
ChatRestrictionsInfo(action.vprev_banned_rights()));
|
||||
addPart(history->makeMessage(
|
||||
history->nextNonHistoryEntryId(),
|
||||
bodyFlags,
|
||||
bodyClientFlags,
|
||||
bodyReplyTo,
|
||||
bodyViaBotId,
|
||||
date,
|
||||
peerToUser(from->id),
|
||||
QString(),
|
||||
bodyText));
|
||||
addSimpleTextMessage(
|
||||
GenerateDefaultBannedRightsChangeText(
|
||||
channel,
|
||||
ChatRestrictionsInfo(action.vnew_banned_rights()),
|
||||
ChatRestrictionsInfo(action.vprev_banned_rights())));
|
||||
};
|
||||
|
||||
auto createStopPoll = [&](const MTPDchannelAdminLogEventActionStopPoll &action) {
|
||||
|
@ -873,7 +824,7 @@ void GenerateItems(
|
|||
action.vmessage(),
|
||||
history->nextNonHistoryEntryId(),
|
||||
date),
|
||||
MTPDmessage_ClientFlag::f_admin_log_entry,
|
||||
MessageFlag::AdminLogEntry,
|
||||
detachExistingItem),
|
||||
ExtractSentDate(action.vmessage()));
|
||||
};
|
||||
|
@ -906,10 +857,9 @@ void GenerateItems(
|
|||
message.links.push_back(chatLink);
|
||||
addPart(history->makeServiceMessage(
|
||||
history->nextNonHistoryEntryId(),
|
||||
MTPDmessage_ClientFlag::f_admin_log_entry,
|
||||
MessageFlag::AdminLogEntry,
|
||||
date,
|
||||
message,
|
||||
MTPDmessage::Flags(0),
|
||||
peerToUser(from->id)));
|
||||
}
|
||||
};
|
||||
|
@ -977,10 +927,9 @@ void GenerateItems(
|
|||
message.links.push_back(link);
|
||||
addPart(history->makeServiceMessage(
|
||||
history->nextNonHistoryEntryId(),
|
||||
MTPDmessage_ClientFlag::f_admin_log_entry,
|
||||
MessageFlag::AdminLogEntry,
|
||||
date,
|
||||
message,
|
||||
MTPDmessage::Flags(0),
|
||||
peerToUser(from->id)));
|
||||
};
|
||||
|
||||
|
@ -1025,10 +974,9 @@ void GenerateItems(
|
|||
}
|
||||
addPart(history->makeServiceMessage(
|
||||
history->nextNonHistoryEntryId(),
|
||||
MTPDmessage_ClientFlag::f_admin_log_entry,
|
||||
MessageFlag::AdminLogEntry,
|
||||
date,
|
||||
message,
|
||||
MTPDmessage::Flags(0),
|
||||
peerToUser(from->id),
|
||||
nullptr));
|
||||
};
|
||||
|
@ -1070,21 +1018,8 @@ void GenerateItems(
|
|||
};
|
||||
|
||||
auto createExportedInviteEdit = [&](const MTPDchannelAdminLogEventActionExportedInviteEdit &data) {
|
||||
auto bodyFlags = Flag::f_entities | Flag::f_from_id;
|
||||
auto bodyClientFlags = MTPDmessage_ClientFlag::f_admin_log_entry;
|
||||
auto bodyReplyTo = 0;
|
||||
auto bodyViaBotId = 0;
|
||||
auto bodyText = GenerateInviteLinkChangeText(data.vnew_invite(), data.vprev_invite());
|
||||
addPart(history->makeMessage(
|
||||
history->nextNonHistoryEntryId(),
|
||||
bodyFlags,
|
||||
bodyClientFlags,
|
||||
bodyReplyTo,
|
||||
bodyViaBotId,
|
||||
date,
|
||||
peerToUser(from->id),
|
||||
QString(),
|
||||
bodyText));
|
||||
addSimpleTextMessage(
|
||||
GenerateInviteLinkChangeText(data.vnew_invite(), data.vprev_invite()));
|
||||
};
|
||||
|
||||
auto createParticipantVolume = [&](const MTPDchannelAdminLogEventActionParticipantVolume &data) {
|
||||
|
|
|
@ -349,7 +349,7 @@ void History::setForwardDraft(MessageIdsList &&items) {
|
|||
|
||||
HistoryItem *History::createItem(
|
||||
const MTPMessage &message,
|
||||
MTPDmessage_ClientFlags clientFlags,
|
||||
MessageFlags localFlags,
|
||||
bool detachExistingItem) {
|
||||
const auto messageId = IdFromMessage(message);
|
||||
if (!messageId) {
|
||||
|
@ -362,17 +362,17 @@ HistoryItem *History::createItem(
|
|||
}
|
||||
return result;
|
||||
}
|
||||
return HistoryItem::Create(this, message, clientFlags);
|
||||
return HistoryItem::Create(this, message, localFlags);
|
||||
}
|
||||
|
||||
std::vector<not_null<HistoryItem*>> History::createItems(
|
||||
const QVector<MTPMessage> &data) {
|
||||
auto result = std::vector<not_null<HistoryItem*>>();
|
||||
result.reserve(data.size());
|
||||
const auto clientFlags = MTPDmessage_ClientFlags();
|
||||
const auto localFlags = MessageFlags();
|
||||
for (auto i = data.cend(), e = data.cbegin(); i != e;) {
|
||||
const auto detachExistingItem = true;
|
||||
const auto item = createItem(*--i, clientFlags, detachExistingItem);
|
||||
const auto item = createItem(*--i, localFlags, detachExistingItem);
|
||||
if (item) {
|
||||
result.emplace_back(item);
|
||||
}
|
||||
|
@ -382,10 +382,10 @@ std::vector<not_null<HistoryItem*>> History::createItems(
|
|||
|
||||
HistoryItem *History::addNewMessage(
|
||||
const MTPMessage &msg,
|
||||
MTPDmessage_ClientFlags clientFlags,
|
||||
MessageFlags localFlags,
|
||||
NewMessageType type) {
|
||||
const auto detachExistingItem = (type == NewMessageType::Unread);
|
||||
const auto item = createItem(msg, clientFlags, detachExistingItem);
|
||||
const auto item = createItem(msg, localFlags, detachExistingItem);
|
||||
if (!item) {
|
||||
return nullptr;
|
||||
}
|
||||
|
@ -515,8 +515,35 @@ void History::checkForLoadedAtTop(not_null<HistoryItem*> added) {
|
|||
|
||||
not_null<HistoryItem*> History::addNewLocalMessage(
|
||||
MsgId id,
|
||||
MTPDmessage::Flags flags,
|
||||
MTPDmessage_ClientFlags clientFlags,
|
||||
MessageFlags flags,
|
||||
UserId viaBotId,
|
||||
MsgId replyTo,
|
||||
TimeId date,
|
||||
PeerId from,
|
||||
const QString &postAuthor,
|
||||
const TextWithEntities &text,
|
||||
const MTPMessageMedia &media,
|
||||
const MTPReplyMarkup &markup,
|
||||
uint64 groupedId) {
|
||||
return addNewItem(
|
||||
makeMessage(
|
||||
id,
|
||||
flags,
|
||||
replyTo,
|
||||
viaBotId,
|
||||
date,
|
||||
from,
|
||||
postAuthor,
|
||||
text,
|
||||
media,
|
||||
markup,
|
||||
groupedId),
|
||||
true);
|
||||
}
|
||||
|
||||
not_null<HistoryItem*> History::addNewLocalMessage(
|
||||
MsgId id,
|
||||
MessageFlags flags,
|
||||
TimeId date,
|
||||
PeerId from,
|
||||
const QString &postAuthor,
|
||||
|
@ -525,7 +552,6 @@ not_null<HistoryItem*> History::addNewLocalMessage(
|
|||
makeMessage(
|
||||
id,
|
||||
flags,
|
||||
clientFlags,
|
||||
date,
|
||||
from,
|
||||
postAuthor,
|
||||
|
@ -535,8 +561,7 @@ not_null<HistoryItem*> History::addNewLocalMessage(
|
|||
|
||||
not_null<HistoryItem*> History::addNewLocalMessage(
|
||||
MsgId id,
|
||||
MTPDmessage::Flags flags,
|
||||
MTPDmessage_ClientFlags clientFlags,
|
||||
MessageFlags flags,
|
||||
UserId viaBotId,
|
||||
MsgId replyTo,
|
||||
TimeId date,
|
||||
|
@ -549,7 +574,6 @@ not_null<HistoryItem*> History::addNewLocalMessage(
|
|||
makeMessage(
|
||||
id,
|
||||
flags,
|
||||
clientFlags,
|
||||
replyTo,
|
||||
viaBotId,
|
||||
date,
|
||||
|
@ -563,8 +587,7 @@ not_null<HistoryItem*> History::addNewLocalMessage(
|
|||
|
||||
not_null<HistoryItem*> History::addNewLocalMessage(
|
||||
MsgId id,
|
||||
MTPDmessage::Flags flags,
|
||||
MTPDmessage_ClientFlags clientFlags,
|
||||
MessageFlags flags,
|
||||
UserId viaBotId,
|
||||
MsgId replyTo,
|
||||
TimeId date,
|
||||
|
@ -577,7 +600,6 @@ not_null<HistoryItem*> History::addNewLocalMessage(
|
|||
makeMessage(
|
||||
id,
|
||||
flags,
|
||||
clientFlags,
|
||||
replyTo,
|
||||
viaBotId,
|
||||
date,
|
||||
|
@ -591,8 +613,7 @@ not_null<HistoryItem*> History::addNewLocalMessage(
|
|||
|
||||
not_null<HistoryItem*> History::addNewLocalMessage(
|
||||
MsgId id,
|
||||
MTPDmessage::Flags flags,
|
||||
MTPDmessage_ClientFlags clientFlags,
|
||||
MessageFlags flags,
|
||||
UserId viaBotId,
|
||||
MsgId replyTo,
|
||||
TimeId date,
|
||||
|
@ -604,7 +625,6 @@ not_null<HistoryItem*> History::addNewLocalMessage(
|
|||
makeMessage(
|
||||
id,
|
||||
flags,
|
||||
clientFlags,
|
||||
replyTo,
|
||||
viaBotId,
|
||||
date,
|
||||
|
@ -696,10 +716,10 @@ void History::addUnreadMentionsSlice(const MTPmessages_Messages &result) {
|
|||
|
||||
auto added = false;
|
||||
if (messages) {
|
||||
const auto clientFlags = MTPDmessage_ClientFlags();
|
||||
const auto localFlags = MessageFlags();
|
||||
const auto type = NewMessageType::Existing;
|
||||
for (const auto &message : *messages) {
|
||||
if (const auto item = addNewMessage(message, clientFlags, type)) {
|
||||
if (const auto item = addNewMessage(message, localFlags, type)) {
|
||||
if (item->isUnreadMention()) {
|
||||
_unreadMentions.insert(item->id);
|
||||
added = true;
|
||||
|
@ -2352,7 +2372,7 @@ void History::setFakeChatListMessageFrom(const MTPmessages_Messages &data) {
|
|||
}
|
||||
const auto item = owner().addNewMessage(
|
||||
*other,
|
||||
MTPDmessage_ClientFlags(),
|
||||
MessageFlags(),
|
||||
NewMessageType::Existing);
|
||||
if (!item || item->isGroupMigrate()) {
|
||||
// Not better than the last one.
|
||||
|
@ -2785,9 +2805,8 @@ HistoryService *History::insertJoinedMessage() {
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
const auto flags = MTPDmessage::Flags();
|
||||
const auto inviteDate = peer->asChannel()->inviteDate;
|
||||
_joinedMessage = GenerateJoinedMessage(this, inviteDate, inviter, flags);
|
||||
_joinedMessage = GenerateJoinedMessage(this, inviteDate, inviter);
|
||||
insertLocalMessage(_joinedMessage);
|
||||
return _joinedMessage;
|
||||
}
|
||||
|
|
|
@ -118,23 +118,33 @@ public:
|
|||
|
||||
HistoryItem *addNewMessage(
|
||||
const MTPMessage &msg,
|
||||
MTPDmessage_ClientFlags clientFlags,
|
||||
MessageFlags localFlags,
|
||||
NewMessageType type);
|
||||
HistoryItem *addToHistory(
|
||||
const MTPMessage &msg,
|
||||
MTPDmessage_ClientFlags clientFlags);
|
||||
MessageFlags localFlags);
|
||||
not_null<HistoryItem*> addNewLocalMessage(
|
||||
MsgId id,
|
||||
MTPDmessage::Flags flags,
|
||||
MTPDmessage_ClientFlags clientFlags,
|
||||
MessageFlags flags,
|
||||
UserId viaBotId,
|
||||
MsgId replyTo,
|
||||
TimeId date,
|
||||
PeerId from,
|
||||
const QString &postAuthor,
|
||||
const TextWithEntities &text,
|
||||
const MTPMessageMedia &media,
|
||||
const MTPReplyMarkup &markup,
|
||||
uint64 groupedId = 0);
|
||||
not_null<HistoryItem*> addNewLocalMessage(
|
||||
MsgId id,
|
||||
MessageFlags flags,
|
||||
TimeId date,
|
||||
PeerId from,
|
||||
const QString &postAuthor,
|
||||
not_null<HistoryMessage*> forwardOriginal);
|
||||
not_null<HistoryItem*> addNewLocalMessage(
|
||||
MsgId id,
|
||||
MTPDmessage::Flags flags,
|
||||
MTPDmessage_ClientFlags clientFlags,
|
||||
MessageFlags flags,
|
||||
UserId viaBotId,
|
||||
MsgId replyTo,
|
||||
TimeId date,
|
||||
|
@ -145,8 +155,7 @@ public:
|
|||
const MTPReplyMarkup &markup);
|
||||
not_null<HistoryItem*> addNewLocalMessage(
|
||||
MsgId id,
|
||||
MTPDmessage::Flags flags,
|
||||
MTPDmessage_ClientFlags clientFlags,
|
||||
MessageFlags flags,
|
||||
UserId viaBotId,
|
||||
MsgId replyTo,
|
||||
TimeId date,
|
||||
|
@ -157,8 +166,7 @@ public:
|
|||
const MTPReplyMarkup &markup);
|
||||
not_null<HistoryItem*> addNewLocalMessage(
|
||||
MsgId id,
|
||||
MTPDmessage::Flags flags,
|
||||
MTPDmessage_ClientFlags clientFlags,
|
||||
MessageFlags flags,
|
||||
UserId viaBotId,
|
||||
MsgId replyTo,
|
||||
TimeId date,
|
||||
|
@ -170,7 +178,7 @@ public:
|
|||
// Used only internally and for channel admin log.
|
||||
HistoryItem *createItem(
|
||||
const MTPMessage &message,
|
||||
MTPDmessage_ClientFlags clientFlags,
|
||||
MessageFlags localFlags,
|
||||
bool detachExistingItem);
|
||||
std::vector<not_null<HistoryItem*>> createItems(
|
||||
const QVector<MTPMessage> &data);
|
||||
|
|
|
@ -59,8 +59,7 @@ enum class MediaCheckResult {
|
|||
not_null<HistoryItem*> CreateUnsupportedMessage(
|
||||
not_null<History*> history,
|
||||
MsgId msgId,
|
||||
MTPDmessage::Flags flags,
|
||||
MTPDmessage_ClientFlags clientFlags,
|
||||
MessageFlags flags,
|
||||
MsgId replyTo,
|
||||
UserId viaBotId,
|
||||
TimeId date,
|
||||
|
@ -72,18 +71,21 @@ not_null<HistoryItem*> CreateUnsupportedMessage(
|
|||
TextUtilities::ParseEntities(text, Ui::ItemTextNoMonoOptions().flags);
|
||||
text.entities.push_front(
|
||||
EntityInText(EntityType::Italic, 0, text.text.size()));
|
||||
flags &= ~MTPDmessage::Flag::f_post_author;
|
||||
flags |= MTPDmessage::Flag::f_legacy;
|
||||
flags &= ~MessageFlag::HasPostAuthor;
|
||||
flags |= MessageFlag::Legacy;
|
||||
const auto groupedId = uint64();
|
||||
return history->makeMessage(
|
||||
msgId,
|
||||
flags,
|
||||
clientFlags,
|
||||
replyTo,
|
||||
viaBotId,
|
||||
date,
|
||||
from,
|
||||
QString(),
|
||||
text);
|
||||
text,
|
||||
MTP_messageMediaEmpty(),
|
||||
MTPReplyMarkup(),
|
||||
groupedId);
|
||||
}
|
||||
|
||||
MediaCheckResult CheckMessageMedia(const MTPMessageMedia &media) {
|
||||
|
@ -170,15 +172,13 @@ void HistoryItem::HistoryItem::Destroyer::operator()(HistoryItem *value) {
|
|||
HistoryItem::HistoryItem(
|
||||
not_null<History*> history,
|
||||
MsgId id,
|
||||
MTPDmessage::Flags flags,
|
||||
MTPDmessage_ClientFlags clientFlags,
|
||||
MessageFlags flags,
|
||||
TimeId date,
|
||||
PeerId from)
|
||||
: id(id)
|
||||
, _history(history)
|
||||
, _from(from ? history->owner().peer(from) : history->peer)
|
||||
, _flags(flags)
|
||||
, _clientFlags(clientFlags)
|
||||
, _date(date) {
|
||||
if (isHistoryEntry() && IsClientMsgId(id)) {
|
||||
_history->registerLocalMessage(this);
|
||||
|
@ -318,11 +318,11 @@ bool HistoryItem::hasUnreadMediaFlag() const {
|
|||
return false;
|
||||
}
|
||||
}
|
||||
return _flags & MTPDmessage::Flag::f_media_unread;
|
||||
return _flags & MessageFlag::MediaIsUnread;
|
||||
}
|
||||
|
||||
bool HistoryItem::isUnreadMention() const {
|
||||
return mentionsMe() && (_flags & MTPDmessage::Flag::f_media_unread);
|
||||
return mentionsMe() && (_flags & MessageFlag::MediaIsUnread);
|
||||
}
|
||||
|
||||
bool HistoryItem::mentionsMe() const {
|
||||
|
@ -330,7 +330,7 @@ bool HistoryItem::mentionsMe() const {
|
|||
&& !Core::App().settings().notifyAboutPinned()) {
|
||||
return false;
|
||||
}
|
||||
return _flags & MTPDmessage::Flag::f_mentioned;
|
||||
return _flags & MessageFlag::MentionsMe;
|
||||
}
|
||||
|
||||
bool HistoryItem::isUnreadMedia() const {
|
||||
|
@ -347,7 +347,7 @@ bool HistoryItem::isUnreadMedia() const {
|
|||
}
|
||||
|
||||
void HistoryItem::markMediaRead() {
|
||||
_flags &= ~MTPDmessage::Flag::f_media_unread;
|
||||
_flags &= ~MessageFlag::MediaIsUnread;
|
||||
|
||||
if (mentionsMe()) {
|
||||
history()->updateChatListEntry();
|
||||
|
@ -358,7 +358,7 @@ void HistoryItem::markMediaRead() {
|
|||
void HistoryItem::setIsPinned(bool pinned) {
|
||||
const auto changed = (isPinned() != pinned);
|
||||
if (pinned) {
|
||||
_flags |= MTPDmessage::Flag::f_pinned;
|
||||
_flags |= MessageFlag::Pinned;
|
||||
history()->session().storage().add(Storage::SharedMediaAddExisting(
|
||||
history()->peer->id,
|
||||
Storage::SharedMediaType::Pinned,
|
||||
|
@ -366,7 +366,7 @@ void HistoryItem::setIsPinned(bool pinned) {
|
|||
{ id, id }));
|
||||
history()->peer->setHasPinnedMessages(true);
|
||||
} else {
|
||||
_flags &= ~MTPDmessage::Flag::f_pinned;
|
||||
_flags &= ~MessageFlag::Pinned;
|
||||
history()->session().storage().remove(Storage::SharedMediaRemoveOne(
|
||||
history()->peer->id,
|
||||
Storage::SharedMediaType::Pinned,
|
||||
|
@ -387,7 +387,7 @@ bool HistoryItem::definesReplyKeyboard() const {
|
|||
|
||||
// optimization: don't create markup component for the case
|
||||
// MTPDreplyKeyboardHide with flags = 0, assume it has f_zero flag
|
||||
return (_flags & MTPDmessage::Flag::f_reply_markup);
|
||||
return (_flags & MessageFlag::HasReplyMarkup);
|
||||
}
|
||||
|
||||
ReplyMarkupFlags HistoryItem::replyKeyboardFlags() const {
|
||||
|
@ -441,22 +441,22 @@ UserData *HistoryItem::getMessageBot() const {
|
|||
|
||||
bool HistoryItem::isHistoryEntry() const {
|
||||
return IsServerMsgId(id)
|
||||
|| (_clientFlags & MTPDmessage_ClientFlag::f_local_history_entry);
|
||||
|| (_flags & MessageFlag::LocalHistoryEntry);
|
||||
}
|
||||
|
||||
bool HistoryItem::isAdminLogEntry() const {
|
||||
return (_clientFlags & MTPDmessage_ClientFlag::f_admin_log_entry);
|
||||
return (_flags & MessageFlag::AdminLogEntry);
|
||||
}
|
||||
|
||||
bool HistoryItem::isFromScheduled() const {
|
||||
return isHistoryEntry()
|
||||
&& (_flags & MTPDmessage::Flag::f_from_scheduled);
|
||||
&& (_flags & MessageFlag::IsOrWasScheduled);
|
||||
}
|
||||
|
||||
bool HistoryItem::isScheduled() const {
|
||||
return !isHistoryEntry()
|
||||
&& !isAdminLogEntry()
|
||||
&& (_flags & MTPDmessage::Flag::f_from_scheduled);
|
||||
&& (_flags & MessageFlag::IsOrWasScheduled);
|
||||
}
|
||||
|
||||
void HistoryItem::destroy() {
|
||||
|
@ -560,11 +560,11 @@ void HistoryItem::indexAsNewItem() {
|
|||
}
|
||||
|
||||
void HistoryItem::setRealId(MsgId newId) {
|
||||
Expects(_clientFlags & MTPDmessage_ClientFlag::f_sending);
|
||||
Expects(_flags & MessageFlag::BeingSent);
|
||||
Expects(IsClientMsgId(id));
|
||||
|
||||
const auto oldId = std::exchange(id, newId);
|
||||
_clientFlags &= ~MTPDmessage_ClientFlag::f_sending;
|
||||
_flags &= ~MessageFlag::BeingSent;
|
||||
if (IsServerMsgId(id)) {
|
||||
_history->unregisterLocalMessage(this);
|
||||
}
|
||||
|
@ -846,11 +846,10 @@ void HistoryItem::applyTTL(TimeId destroyAt) {
|
|||
}
|
||||
|
||||
void HistoryItem::sendFailed() {
|
||||
Expects(_clientFlags & MTPDmessage_ClientFlag::f_sending);
|
||||
Expects(!(_clientFlags & MTPDmessage_ClientFlag::f_failed));
|
||||
Expects(_flags & MessageFlag::BeingSent);
|
||||
Expects(!(_flags & MessageFlag::SendingFailed));
|
||||
|
||||
_clientFlags = (_clientFlags | MTPDmessage_ClientFlag::f_failed)
|
||||
& ~MTPDmessage_ClientFlag::f_sending;
|
||||
_flags = (_flags | MessageFlag::SendingFailed) & ~MessageFlag::BeingSent;
|
||||
history()->session().changes().historyUpdated(
|
||||
history(),
|
||||
Data::HistoryUpdate::Flag::LocalMessages);
|
||||
|
@ -895,7 +894,7 @@ bool HistoryItem::unread() const {
|
|||
}
|
||||
return true;
|
||||
}
|
||||
return (_clientFlags & MTPDmessage_ClientFlag::f_clientside_unread);
|
||||
return (_flags & MessageFlag::ClientSideUnread);
|
||||
}
|
||||
|
||||
bool HistoryItem::showNotification() const {
|
||||
|
@ -909,7 +908,7 @@ bool HistoryItem::showNotification() const {
|
|||
}
|
||||
|
||||
void HistoryItem::markClientSideAsRead() {
|
||||
_clientFlags &= ~MTPDmessage_ClientFlag::f_clientside_unread;
|
||||
_flags &= ~MessageFlag::ClientSideUnread;
|
||||
}
|
||||
|
||||
MessageGroupId HistoryItem::groupId() const {
|
||||
|
@ -1044,10 +1043,43 @@ ClickHandlerPtr goToMessageClickHandler(
|
|||
});
|
||||
}
|
||||
|
||||
MessageFlags FlagsFromMTP(MTPDmessage::Flags flags) {
|
||||
using Flag = MessageFlag;
|
||||
using MTP = MTPDmessage::Flag;
|
||||
return Flag()
|
||||
| ((flags & MTP::f_out) ? Flag::Outgoing : Flag())
|
||||
| ((flags & MTP::f_mentioned) ? Flag::MentionsMe : Flag())
|
||||
| ((flags & MTP::f_media_unread) ? Flag::MediaIsUnread : Flag())
|
||||
| ((flags & MTP::f_silent) ? Flag::Silent : Flag())
|
||||
| ((flags & MTP::f_post) ? Flag::Post : Flag())
|
||||
| ((flags & MTP::f_legacy) ? Flag::Legacy : Flag())
|
||||
| ((flags & MTP::f_edit_hide) ? Flag::HideEdited : Flag())
|
||||
| ((flags & MTP::f_pinned) ? Flag::Pinned : Flag())
|
||||
| ((flags & MTP::f_from_id) ? Flag::HasFromId : Flag())
|
||||
| ((flags & MTP::f_via_bot_id) ? Flag::HasViaBot : Flag())
|
||||
| ((flags & MTP::f_reply_to) ? Flag::HasReplyInfo : Flag())
|
||||
| ((flags & MTP::f_reply_markup) ? Flag::HasReplyMarkup : Flag())
|
||||
| ((flags & MTP::f_views) ? Flag::HasViews : Flag());
|
||||
}
|
||||
|
||||
MessageFlags FlagsFromMTP(MTPDmessageService::Flags flags) {
|
||||
using Flag = MessageFlag;
|
||||
using MTP = MTPDmessageService::Flag;
|
||||
return Flag()
|
||||
| ((flags & MTP::f_out) ? Flag::Outgoing : Flag())
|
||||
| ((flags & MTP::f_mentioned) ? Flag::MentionsMe : Flag())
|
||||
| ((flags & MTP::f_media_unread) ? Flag::MediaIsUnread : Flag())
|
||||
| ((flags & MTP::f_silent) ? Flag::Silent : Flag())
|
||||
| ((flags & MTP::f_post) ? Flag::Post : Flag())
|
||||
| ((flags & MTP::f_legacy) ? Flag::Legacy : Flag())
|
||||
| ((flags & MTP::f_from_id) ? Flag::HasFromId : Flag())
|
||||
| ((flags & MTP::f_reply_to) ? Flag::HasReplyInfo : Flag());
|
||||
}
|
||||
|
||||
not_null<HistoryItem*> HistoryItem::Create(
|
||||
not_null<History*> history,
|
||||
const MTPMessage &message,
|
||||
MTPDmessage_ClientFlags clientFlags) {
|
||||
MessageFlags localFlags) {
|
||||
return message.match([&](const MTPDmessage &data) -> HistoryItem* {
|
||||
const auto media = data.vmedia();
|
||||
const auto checked = media
|
||||
|
@ -1057,8 +1089,7 @@ not_null<HistoryItem*> HistoryItem::Create(
|
|||
return CreateUnsupportedMessage(
|
||||
history,
|
||||
data.vid().v,
|
||||
data.vflags().v,
|
||||
clientFlags,
|
||||
FlagsFromMTP(data.vflags().v) | localFlags,
|
||||
MsgId(0), // No need to pass reply_to data here.
|
||||
data.vvia_bot_id().value_or_empty(),
|
||||
data.vdate().v,
|
||||
|
@ -1069,27 +1100,26 @@ not_null<HistoryItem*> HistoryItem::Create(
|
|||
};
|
||||
return history->makeServiceMessage(
|
||||
data.vid().v,
|
||||
clientFlags,
|
||||
FlagsFromMTP(data.vflags().v) | localFlags,
|
||||
data.vdate().v,
|
||||
text,
|
||||
data.vflags().v,
|
||||
data.vfrom_id() ? peerFromMTP(*data.vfrom_id()) : PeerId(0));
|
||||
} else if (checked == MediaCheckResult::HasTimeToLive) {
|
||||
return history->makeServiceMessage(data, clientFlags);
|
||||
return history->makeServiceMessage(data, localFlags);
|
||||
}
|
||||
return history->makeMessage(data, clientFlags);
|
||||
return history->makeMessage(data, localFlags);
|
||||
}, [&](const MTPDmessageService &data) -> HistoryItem* {
|
||||
if (data.vaction().type() == mtpc_messageActionPhoneCall) {
|
||||
return history->makeMessage(data, clientFlags);
|
||||
return history->makeMessage(data, localFlags);
|
||||
}
|
||||
return history->makeServiceMessage(data, clientFlags);
|
||||
return history->makeServiceMessage(data, localFlags);
|
||||
}, [&](const MTPDmessageEmpty &data) -> HistoryItem* {
|
||||
const auto text = HistoryService::PreparedText{
|
||||
tr::lng_message_empty(tr::now)
|
||||
};
|
||||
return history->makeServiceMessage(
|
||||
data.vid().v,
|
||||
clientFlags,
|
||||
localFlags,
|
||||
TimeId(0),
|
||||
text);
|
||||
});
|
||||
|
|
|
@ -69,12 +69,15 @@ enum class ReplyMarkupFlag : uint32 {
|
|||
inline constexpr bool is_flag_type(ReplyMarkupFlag) { return true; }
|
||||
using ReplyMarkupFlags = base::flags<ReplyMarkupFlag>;
|
||||
|
||||
[[nodiscard]] MessageFlags FlagsFromMTP(MTPDmessage::Flags flags);
|
||||
[[nodiscard]] MessageFlags FlagsFromMTP(MTPDmessageService::Flags flags);
|
||||
|
||||
class HistoryItem : public RuntimeComposer<HistoryItem> {
|
||||
public:
|
||||
static not_null<HistoryItem*> Create(
|
||||
not_null<History*> history,
|
||||
const MTPMessage &message,
|
||||
MTPDmessage_ClientFlags clientFlags);
|
||||
MessageFlags localFlags);
|
||||
|
||||
struct Destroyer {
|
||||
void operator()(HistoryItem *value);
|
||||
|
@ -125,10 +128,10 @@ public:
|
|||
|
||||
void destroy();
|
||||
[[nodiscard]] bool out() const {
|
||||
return _flags & MTPDmessage::Flag::f_out;
|
||||
return _flags & MessageFlag::Outgoing;
|
||||
}
|
||||
[[nodiscard]] bool isPinned() const {
|
||||
return _flags & MTPDmessage::Flag::f_pinned;
|
||||
return _flags & MessageFlag::Pinned;
|
||||
}
|
||||
[[nodiscard]] bool unread() const;
|
||||
[[nodiscard]] bool showNotification() const;
|
||||
|
@ -164,44 +167,44 @@ public:
|
|||
[[nodiscard]] ReplyMarkupFlags replyKeyboardFlags() const;
|
||||
|
||||
[[nodiscard]] bool hasSwitchInlineButton() const {
|
||||
return _clientFlags & MTPDmessage_ClientFlag::f_has_switch_inline_button;
|
||||
return _flags & MessageFlag::HasSwitchInlineButton;
|
||||
}
|
||||
[[nodiscard]] bool hasTextLinks() const {
|
||||
return _clientFlags & MTPDmessage_ClientFlag::f_has_text_links;
|
||||
return _flags & MessageFlag::HasTextLinks;
|
||||
}
|
||||
[[nodiscard]] bool isGroupEssential() const {
|
||||
return _clientFlags & MTPDmessage_ClientFlag::f_is_group_essential;
|
||||
return _flags & MessageFlag::IsGroupEssential;
|
||||
}
|
||||
[[nodiscard]] bool isLocalUpdateMedia() const {
|
||||
return _clientFlags & MTPDmessage_ClientFlag::f_is_local_update_media;
|
||||
return _flags & MessageFlag::IsLocalUpdateMedia;
|
||||
}
|
||||
void setIsLocalUpdateMedia(bool flag) {
|
||||
if (flag) {
|
||||
_clientFlags |= MTPDmessage_ClientFlag::f_is_local_update_media;
|
||||
_flags |= MessageFlag::IsLocalUpdateMedia;
|
||||
} else {
|
||||
_clientFlags &= ~MTPDmessage_ClientFlag::f_is_local_update_media;
|
||||
_flags &= ~MessageFlag::IsLocalUpdateMedia;
|
||||
}
|
||||
}
|
||||
[[nodiscard]] bool isGroupMigrate() const {
|
||||
return isGroupEssential() && isEmpty();
|
||||
}
|
||||
[[nodiscard]] bool isIsolatedEmoji() const {
|
||||
return _clientFlags & MTPDmessage_ClientFlag::f_isolated_emoji;
|
||||
return _flags & MessageFlag::IsolatedEmoji;
|
||||
}
|
||||
[[nodiscard]] bool hasViews() const {
|
||||
return _flags & MTPDmessage::Flag::f_views;
|
||||
return _flags & MessageFlag::HasViews;
|
||||
}
|
||||
[[nodiscard]] bool isPost() const {
|
||||
return _flags & MTPDmessage::Flag::f_post;
|
||||
return _flags & MessageFlag::Post;
|
||||
}
|
||||
[[nodiscard]] bool isSilent() const {
|
||||
return _flags & MTPDmessage::Flag::f_silent;
|
||||
return _flags & MessageFlag::Silent;
|
||||
}
|
||||
[[nodiscard]] bool isSending() const {
|
||||
return _clientFlags & MTPDmessage_ClientFlag::f_sending;
|
||||
return _flags & MessageFlag::BeingSent;
|
||||
}
|
||||
[[nodiscard]] bool hasFailed() const {
|
||||
return _clientFlags & MTPDmessage_ClientFlag::f_failed;
|
||||
return _flags & MessageFlag::SendingFailed;
|
||||
}
|
||||
void sendFailed();
|
||||
[[nodiscard]] virtual int viewsCount() const {
|
||||
|
@ -422,8 +425,7 @@ protected:
|
|||
HistoryItem(
|
||||
not_null<History*> history,
|
||||
MsgId id,
|
||||
MTPDmessage::Flags flags,
|
||||
MTPDmessage_ClientFlags clientFlags,
|
||||
MessageFlags flags,
|
||||
TimeId date,
|
||||
PeerId from);
|
||||
|
||||
|
@ -436,8 +438,7 @@ protected:
|
|||
|
||||
const not_null<History*> _history;
|
||||
not_null<PeerData*> _from;
|
||||
MTPDmessage::Flags _flags = 0;
|
||||
MTPDmessage_ClientFlags _clientFlags = 0;
|
||||
MessageFlags _flags = 0;
|
||||
|
||||
void invalidateChatListEntry();
|
||||
|
||||
|
|
|
@ -56,39 +56,29 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
|
||||
namespace {
|
||||
|
||||
[[nodiscard]] MTPDmessage::Flags NewForwardedFlags(
|
||||
[[nodiscard]] MessageFlags NewForwardedFlags(
|
||||
not_null<PeerData*> peer,
|
||||
PeerId from,
|
||||
not_null<HistoryMessage*> fwd) {
|
||||
auto result = NewMessageFlags(peer) | MTPDmessage::Flag::f_fwd_from;
|
||||
auto result = NewMessageFlags(peer);
|
||||
if (from) {
|
||||
result |= MTPDmessage::Flag::f_from_id;
|
||||
result |= MessageFlag::HasFromId;
|
||||
}
|
||||
if (fwd->Has<HistoryMessageVia>()) {
|
||||
result |= MTPDmessage::Flag::f_via_bot_id;
|
||||
result |= MessageFlag::HasViaBot;
|
||||
}
|
||||
if (const auto media = fwd->media()) {
|
||||
if (dynamic_cast<Data::MediaWebPage*>(media)) {
|
||||
// Drop web page if we're not allowed to send it.
|
||||
if (peer->amRestricted(ChatRestriction::EmbedLinks)) {
|
||||
result &= ~MTPDmessage::Flag::f_media;
|
||||
}
|
||||
}
|
||||
if ((!peer->isChannel() || peer->isMegagroup())
|
||||
&& media->forwardedBecomesUnread()) {
|
||||
result |= MTPDmessage::Flag::f_media_unread;
|
||||
result |= MessageFlag::MediaIsUnread;
|
||||
}
|
||||
}
|
||||
if (fwd->hasViews()) {
|
||||
result |= MTPDmessage::Flag::f_views;
|
||||
result |= MessageFlag::HasViews;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
[[nodiscard]] MTPDmessage_ClientFlags NewForwardedClientFlags() {
|
||||
return NewMessageClientFlags();
|
||||
}
|
||||
|
||||
[[nodiscard]] bool CopyMarkupToForward(not_null<const HistoryItem*> item) {
|
||||
auto mediaOriginal = item->media();
|
||||
if (mediaOriginal && mediaOriginal->game()) {
|
||||
|
@ -369,15 +359,9 @@ Fn<void(ChannelData*, MsgId)> HistoryDependentItemCallback(
|
|||
};
|
||||
}
|
||||
|
||||
MTPDmessage::Flags NewMessageFlags(not_null<PeerData*> peer) {
|
||||
MTPDmessage::Flags result = 0;
|
||||
if (!peer->isSelf()) {
|
||||
result |= MTPDmessage::Flag::f_out;
|
||||
//if (p->isChat() || (p->isUser() && !p->asUser()->isBot())) {
|
||||
// result |= MTPDmessage::Flag::f_unread;
|
||||
//}
|
||||
}
|
||||
return result;
|
||||
MessageFlags NewMessageFlags(not_null<PeerData*> peer) {
|
||||
return MessageFlag::BeingSent
|
||||
| (peer->isSelf() ? MessageFlag() : MessageFlag::Outgoing);
|
||||
}
|
||||
|
||||
bool ShouldSendSilent(
|
||||
|
@ -415,10 +399,6 @@ MTPMessageReplyHeader NewMessageReplyHeader(const Api::SendAction &action) {
|
|||
return MTPMessageReplyHeader();
|
||||
}
|
||||
|
||||
MTPDmessage_ClientFlags NewMessageClientFlags() {
|
||||
return MTPDmessage_ClientFlag::f_sending;
|
||||
}
|
||||
|
||||
QString GetErrorTextForSending(
|
||||
not_null<PeerData*> peer,
|
||||
const HistoryItemsList &items,
|
||||
|
@ -475,12 +455,11 @@ void HistoryMessage::FillForwardedInfo(
|
|||
HistoryMessage::HistoryMessage(
|
||||
not_null<History*> history,
|
||||
const MTPDmessage &data,
|
||||
MTPDmessage_ClientFlags clientFlags)
|
||||
MessageFlags localFlags)
|
||||
: HistoryItem(
|
||||
history,
|
||||
data.vid().v,
|
||||
data.vflags().v,
|
||||
clientFlags,
|
||||
FlagsFromMTP(data.vflags().v) | localFlags,
|
||||
data.vdate().v,
|
||||
data.vfrom_id() ? peerFromMTP(*data.vfrom_id()) : PeerId(0)) {
|
||||
auto config = CreateConfig();
|
||||
|
@ -532,12 +511,11 @@ HistoryMessage::HistoryMessage(
|
|||
HistoryMessage::HistoryMessage(
|
||||
not_null<History*> history,
|
||||
const MTPDmessageService &data,
|
||||
MTPDmessage_ClientFlags clientFlags)
|
||||
MessageFlags localFlags)
|
||||
: HistoryItem(
|
||||
history,
|
||||
data.vid().v,
|
||||
mtpCastFlags(data.vflags().v),
|
||||
clientFlags,
|
||||
FlagsFromMTP(data.vflags().v) | localFlags,
|
||||
data.vdate().v,
|
||||
data.vfrom_id() ? peerFromMTP(*data.vfrom_id()) : PeerId(0)) {
|
||||
auto config = CreateConfig();
|
||||
|
@ -570,8 +548,7 @@ HistoryMessage::HistoryMessage(
|
|||
HistoryMessage::HistoryMessage(
|
||||
not_null<History*> history,
|
||||
MsgId id,
|
||||
MTPDmessage::Flags flags,
|
||||
MTPDmessage_ClientFlags clientFlags,
|
||||
MessageFlags flags,
|
||||
TimeId date,
|
||||
PeerId from,
|
||||
const QString &postAuthor,
|
||||
|
@ -580,7 +557,6 @@ HistoryMessage::HistoryMessage(
|
|||
history,
|
||||
id,
|
||||
NewForwardedFlags(history->peer, from, original) | flags,
|
||||
NewForwardedClientFlags() | clientFlags,
|
||||
date,
|
||||
from) {
|
||||
const auto peer = history->peer;
|
||||
|
@ -615,7 +591,7 @@ HistoryMessage::HistoryMessage(
|
|||
config.savedFromMsgId = original->id;
|
||||
//}
|
||||
}
|
||||
if (flags & MTPDmessage::Flag::f_post_author) {
|
||||
if (flags & MessageFlag::HasPostAuthor) {
|
||||
config.author = postAuthor;
|
||||
}
|
||||
if (const auto fwdViaBot = original->viaBot()) {
|
||||
|
@ -654,36 +630,34 @@ HistoryMessage::HistoryMessage(
|
|||
HistoryMessage::HistoryMessage(
|
||||
not_null<History*> history,
|
||||
MsgId id,
|
||||
MTPDmessage::Flags flags,
|
||||
MTPDmessage_ClientFlags clientFlags,
|
||||
MessageFlags flags,
|
||||
MsgId replyTo,
|
||||
UserId viaBotId,
|
||||
TimeId date,
|
||||
PeerId from,
|
||||
const QString &postAuthor,
|
||||
const TextWithEntities &textWithEntities)
|
||||
const TextWithEntities &textWithEntities,
|
||||
const MTPMessageMedia &media,
|
||||
const MTPReplyMarkup &markup,
|
||||
uint64 groupedId)
|
||||
: HistoryItem(
|
||||
history,
|
||||
id,
|
||||
flags & ~MTPDmessage::Flag::f_reply_markup,
|
||||
clientFlags,
|
||||
flags,
|
||||
date,
|
||||
(flags & MTPDmessage::Flag::f_from_id) ? from : 0) {
|
||||
createComponentsHelper(
|
||||
flags & ~MTPDmessage::Flag::f_reply_markup,
|
||||
replyTo,
|
||||
viaBotId,
|
||||
postAuthor,
|
||||
MTPReplyMarkup());
|
||||
|
||||
(flags & MessageFlag::HasFromId) ? from : 0) {
|
||||
createComponentsHelper(flags, replyTo, viaBotId, postAuthor, markup);
|
||||
setMedia(media);
|
||||
setText(textWithEntities);
|
||||
if (groupedId) {
|
||||
setGroupId(MessageGroupId::FromRaw(history->peer->id, groupedId));
|
||||
}
|
||||
}
|
||||
|
||||
HistoryMessage::HistoryMessage(
|
||||
not_null<History*> history,
|
||||
MsgId id,
|
||||
MTPDmessage::Flags flags,
|
||||
MTPDmessage_ClientFlags clientFlags,
|
||||
MessageFlags flags,
|
||||
MsgId replyTo,
|
||||
UserId viaBotId,
|
||||
TimeId date,
|
||||
|
@ -696,9 +670,8 @@ HistoryMessage::HistoryMessage(
|
|||
history,
|
||||
id,
|
||||
flags,
|
||||
clientFlags,
|
||||
date,
|
||||
(flags & MTPDmessage::Flag::f_from_id) ? from : 0) {
|
||||
(flags & MessageFlag::HasFromId) ? from : 0) {
|
||||
createComponentsHelper(flags, replyTo, viaBotId, postAuthor, markup);
|
||||
|
||||
_media = std::make_unique<Data::MediaFile>(this, document);
|
||||
|
@ -708,8 +681,7 @@ HistoryMessage::HistoryMessage(
|
|||
HistoryMessage::HistoryMessage(
|
||||
not_null<History*> history,
|
||||
MsgId id,
|
||||
MTPDmessage::Flags flags,
|
||||
MTPDmessage_ClientFlags clientFlags,
|
||||
MessageFlags flags,
|
||||
MsgId replyTo,
|
||||
UserId viaBotId,
|
||||
TimeId date,
|
||||
|
@ -722,9 +694,8 @@ HistoryMessage::HistoryMessage(
|
|||
history,
|
||||
id,
|
||||
flags,
|
||||
clientFlags,
|
||||
date,
|
||||
(flags & MTPDmessage::Flag::f_from_id) ? from : 0) {
|
||||
(flags & MessageFlag::HasFromId) ? from : 0) {
|
||||
createComponentsHelper(flags, replyTo, viaBotId, postAuthor, markup);
|
||||
|
||||
_media = std::make_unique<Data::MediaPhoto>(this, photo);
|
||||
|
@ -734,8 +705,7 @@ HistoryMessage::HistoryMessage(
|
|||
HistoryMessage::HistoryMessage(
|
||||
not_null<History*> history,
|
||||
MsgId id,
|
||||
MTPDmessage::Flags flags,
|
||||
MTPDmessage_ClientFlags clientFlags,
|
||||
MessageFlags flags,
|
||||
MsgId replyTo,
|
||||
UserId viaBotId,
|
||||
TimeId date,
|
||||
|
@ -747,9 +717,8 @@ HistoryMessage::HistoryMessage(
|
|||
history,
|
||||
id,
|
||||
flags,
|
||||
clientFlags,
|
||||
date,
|
||||
(flags & MTPDmessage::Flag::f_from_id) ? from : 0) {
|
||||
(flags & MessageFlag::HasFromId) ? from : 0) {
|
||||
createComponentsHelper(flags, replyTo, viaBotId, postAuthor, markup);
|
||||
|
||||
_media = std::make_unique<Data::MediaGame>(this, game);
|
||||
|
@ -757,22 +726,22 @@ HistoryMessage::HistoryMessage(
|
|||
}
|
||||
|
||||
void HistoryMessage::createComponentsHelper(
|
||||
MTPDmessage::Flags flags,
|
||||
MessageFlags flags,
|
||||
MsgId replyTo,
|
||||
UserId viaBotId,
|
||||
const QString &postAuthor,
|
||||
const MTPReplyMarkup &markup) {
|
||||
auto config = CreateConfig();
|
||||
|
||||
if (flags & MTPDmessage::Flag::f_via_bot_id) config.viaBotId = viaBotId;
|
||||
if (flags & MTPDmessage::Flag::f_reply_to) {
|
||||
if (flags & MessageFlag::HasViaBot) config.viaBotId = viaBotId;
|
||||
if (flags & MessageFlag::HasReplyInfo) {
|
||||
config.replyTo = replyTo;
|
||||
const auto replyToTop = LookupReplyToTop(history(), replyTo);
|
||||
config.replyToTop = replyToTop ? replyToTop : replyTo;
|
||||
}
|
||||
if (flags & MTPDmessage::Flag::f_reply_markup) config.mtpMarkup = &markup;
|
||||
if (flags & MTPDmessage::Flag::f_post_author) config.author = postAuthor;
|
||||
if (flags & MTPDmessage::Flag::f_views) config.viewsCount = 1;
|
||||
if (flags & MessageFlag::HasReplyMarkup) config.mtpMarkup = &markup;
|
||||
if (flags & MessageFlag::HasPostAuthor) config.author = postAuthor;
|
||||
if (flags & MessageFlag::HasViews) config.viewsCount = 1;
|
||||
|
||||
createComponents(config);
|
||||
}
|
||||
|
@ -1133,7 +1102,7 @@ void HistoryMessage::createComponents(const CreateConfig &config) {
|
|||
markup->create(*config.inlineMarkup);
|
||||
}
|
||||
if (markup->flags & ReplyMarkupFlag::HasSwitchInlineButton) {
|
||||
_clientFlags |= MTPDmessage_ClientFlag::f_has_switch_inline_button;
|
||||
_flags |= MessageFlag::HasSwitchInlineButton;
|
||||
}
|
||||
}
|
||||
const auto from = displayFrom();
|
||||
|
@ -1341,7 +1310,6 @@ std::unique_ptr<Data::Media> HistoryMessage::CreateMedia(
|
|||
}, [](const MTPDmessageMediaUnsupported &) -> Result {
|
||||
return nullptr;
|
||||
});
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void HistoryMessage::replaceBuyWithReceiptInMarkup() {
|
||||
|
@ -1372,11 +1340,14 @@ void HistoryMessage::applyEdition(const MTPDmessage &message) {
|
|||
// }
|
||||
//}
|
||||
|
||||
const auto copyFlags = MTPDmessage::Flag::f_edit_hide;
|
||||
_flags = (_flags & ~copyFlags) | (message.vflags().v & copyFlags);
|
||||
if (message.is_edit_hide()) {
|
||||
_flags |= MessageFlag::HideEdited;
|
||||
} else {
|
||||
_flags &= ~MessageFlag::HideEdited;
|
||||
}
|
||||
|
||||
if (const auto editDate = message.vedit_date()) {
|
||||
_flags |= MTPDmessage::Flag::f_edit_date;
|
||||
//_flags |= MTPDmessage::Flag::f_edit_date;
|
||||
if (!Has<HistoryMessageEdited>()) {
|
||||
AddComponents(HistoryMessageEdited::Bit());
|
||||
}
|
||||
|
@ -1434,11 +1405,11 @@ void HistoryMessage::updateSentContent(
|
|||
const MTPMessageMedia *media) {
|
||||
const auto isolated = isolatedEmoji();
|
||||
setText(textWithEntities);
|
||||
if (_clientFlags & MTPDmessage_ClientFlag::f_from_inline_bot) {
|
||||
if (_flags & MessageFlag::FromInlineBot) {
|
||||
if (!media || !_media || !_media->updateInlineResultMedia(*media)) {
|
||||
refreshSentMedia(media);
|
||||
}
|
||||
_clientFlags &= ~MTPDmessage_ClientFlag::f_from_inline_bot;
|
||||
_flags &= ~MessageFlag::FromInlineBot;
|
||||
} else if (media || _media || !isolated || isolated != isolatedEmoji()) {
|
||||
if (!media || !_media || !_media->updateSentMedia(*media)) {
|
||||
refreshSentMedia(media);
|
||||
|
@ -1548,7 +1519,7 @@ void HistoryMessage::setText(const TextWithEntities &textWithEntities) {
|
|||
if (type == EntityType::Url
|
||||
|| type == EntityType::CustomUrl
|
||||
|| type == EntityType::Email) {
|
||||
_clientFlags |= MTPDmessage_ClientFlag::f_has_text_links;
|
||||
_flags |= MessageFlag::HasTextLinks;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -1599,16 +1570,16 @@ void HistoryMessage::setEmptyText() {
|
|||
}
|
||||
|
||||
void HistoryMessage::clearIsolatedEmoji() {
|
||||
if (!(_clientFlags & MTPDmessage_ClientFlag::f_isolated_emoji)) {
|
||||
if (!(_flags & MessageFlag::IsolatedEmoji)) {
|
||||
return;
|
||||
}
|
||||
history()->session().emojiStickersPack().remove(this);
|
||||
_clientFlags &= ~MTPDmessage_ClientFlag::f_isolated_emoji;
|
||||
_flags &= ~MessageFlag::IsolatedEmoji;
|
||||
}
|
||||
|
||||
void HistoryMessage::checkIsolatedEmoji() {
|
||||
if (history()->session().emojiStickersPack().add(this)) {
|
||||
_clientFlags |= MTPDmessage_ClientFlag::f_isolated_emoji;
|
||||
_flags |= MessageFlag::IsolatedEmoji;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1620,8 +1591,8 @@ void HistoryMessage::setReplyMarkup(const MTPReplyMarkup *markup) {
|
|||
Data::MessageUpdate::Flag::ReplyMarkup);
|
||||
};
|
||||
if (!markup) {
|
||||
if (_flags & MTPDmessage::Flag::f_reply_markup) {
|
||||
_flags &= ~MTPDmessage::Flag::f_reply_markup;
|
||||
if (_flags & MessageFlag::HasReplyMarkup) {
|
||||
_flags &= ~MessageFlag::HasReplyMarkup;
|
||||
if (Has<HistoryMessageReplyMarkup>()) {
|
||||
RemoveComponents(HistoryMessageReplyMarkup::Bit());
|
||||
}
|
||||
|
@ -1632,22 +1603,23 @@ void HistoryMessage::setReplyMarkup(const MTPReplyMarkup *markup) {
|
|||
|
||||
// optimization: don't create markup component for the case
|
||||
// MTPDreplyKeyboardHide with flags = 0, assume it has f_zero flag
|
||||
if (markup->type() == mtpc_replyKeyboardHide && markup->c_replyKeyboardHide().vflags().v == 0) {
|
||||
if (markup->type() == mtpc_replyKeyboardHide
|
||||
&& markup->c_replyKeyboardHide().vflags().v == 0) {
|
||||
bool changed = false;
|
||||
if (Has<HistoryMessageReplyMarkup>()) {
|
||||
RemoveComponents(HistoryMessageReplyMarkup::Bit());
|
||||
changed = true;
|
||||
}
|
||||
if (!(_flags & MTPDmessage::Flag::f_reply_markup)) {
|
||||
_flags |= MTPDmessage::Flag::f_reply_markup;
|
||||
if (!(_flags & MessageFlag::HasReplyMarkup)) {
|
||||
_flags |= MessageFlag::HasReplyMarkup;
|
||||
changed = true;
|
||||
}
|
||||
if (changed) {
|
||||
requestUpdate();
|
||||
}
|
||||
} else {
|
||||
if (!(_flags & MTPDmessage::Flag::f_reply_markup)) {
|
||||
_flags |= MTPDmessage::Flag::f_reply_markup;
|
||||
if (!(_flags & MessageFlag::HasReplyMarkup)) {
|
||||
_flags |= MessageFlag::HasReplyMarkup;
|
||||
}
|
||||
if (!Has<HistoryMessageReplyMarkup>()) {
|
||||
AddComponents(HistoryMessageReplyMarkup::Bit());
|
||||
|
|
|
@ -24,11 +24,10 @@ struct HistoryMessageViews;
|
|||
|
||||
[[nodiscard]] Fn<void(ChannelData*, MsgId)> HistoryDependentItemCallback(
|
||||
not_null<HistoryItem*> item);
|
||||
[[nodiscard]] MTPDmessage::Flags NewMessageFlags(not_null<PeerData*> peer);
|
||||
[[nodiscard]] MessageFlags NewMessageFlags(not_null<PeerData*> peer);
|
||||
[[nodiscard]] bool ShouldSendSilent(
|
||||
not_null<PeerData*> peer,
|
||||
const Api::SendOptions &options);
|
||||
[[nodiscard]] MTPDmessage_ClientFlags NewMessageClientFlags();
|
||||
[[nodiscard]] MsgId LookupReplyToTop(
|
||||
not_null<History*> history,
|
||||
MsgId replyToId);
|
||||
|
@ -50,16 +49,15 @@ public:
|
|||
HistoryMessage(
|
||||
not_null<History*> history,
|
||||
const MTPDmessage &data,
|
||||
MTPDmessage_ClientFlags clientFlags);
|
||||
MessageFlags localFlags);
|
||||
HistoryMessage(
|
||||
not_null<History*> history,
|
||||
const MTPDmessageService &data,
|
||||
MTPDmessage_ClientFlags clientFlags);
|
||||
MessageFlags localFlags);
|
||||
HistoryMessage(
|
||||
not_null<History*> history,
|
||||
MsgId id,
|
||||
MTPDmessage::Flags flags,
|
||||
MTPDmessage_ClientFlags clientFlags,
|
||||
MessageFlags flags,
|
||||
TimeId date,
|
||||
PeerId from,
|
||||
const QString &postAuthor,
|
||||
|
@ -67,19 +65,20 @@ public:
|
|||
HistoryMessage(
|
||||
not_null<History*> history,
|
||||
MsgId id,
|
||||
MTPDmessage::Flags flags,
|
||||
MTPDmessage_ClientFlags clientFlags,
|
||||
MessageFlags flags,
|
||||
MsgId replyTo,
|
||||
UserId viaBotId,
|
||||
TimeId date,
|
||||
PeerId from,
|
||||
const QString &postAuthor,
|
||||
const TextWithEntities &textWithEntities); // local message
|
||||
const TextWithEntities &textWithEntities,
|
||||
const MTPMessageMedia &media,
|
||||
const MTPReplyMarkup &markup,
|
||||
uint64 groupedId); // local message
|
||||
HistoryMessage(
|
||||
not_null<History*> history,
|
||||
MsgId id,
|
||||
MTPDmessage::Flags flags,
|
||||
MTPDmessage_ClientFlags clientFlags,
|
||||
MessageFlags flags,
|
||||
MsgId replyTo,
|
||||
UserId viaBotId,
|
||||
TimeId date,
|
||||
|
@ -91,8 +90,7 @@ public:
|
|||
HistoryMessage(
|
||||
not_null<History*> history,
|
||||
MsgId id,
|
||||
MTPDmessage::Flags flags,
|
||||
MTPDmessage_ClientFlags clientFlags,
|
||||
MessageFlags flags,
|
||||
MsgId replyTo,
|
||||
UserId viaBotId,
|
||||
TimeId date,
|
||||
|
@ -104,8 +102,7 @@ public:
|
|||
HistoryMessage(
|
||||
not_null<History*> history,
|
||||
MsgId id,
|
||||
MTPDmessage::Flags flags,
|
||||
MTPDmessage_ClientFlags clientFlags,
|
||||
MessageFlags flags,
|
||||
MsgId replyTo,
|
||||
UserId viaBotId,
|
||||
TimeId date,
|
||||
|
@ -129,7 +126,7 @@ public:
|
|||
[[nodiscard]] bool uploading() const;
|
||||
|
||||
[[nodiscard]] bool hideEditedBadge() const {
|
||||
return (_flags & MTPDmessage::Flag::f_edit_hide);
|
||||
return (_flags & MessageFlag::HideEdited);
|
||||
}
|
||||
|
||||
void setViewsCount(int count) override;
|
||||
|
@ -146,7 +143,18 @@ public:
|
|||
|
||||
[[nodiscard]] QString notificationHeader() const override;
|
||||
|
||||
// Looks on:
|
||||
// f_edit_hide
|
||||
// f_edit_date
|
||||
// f_entities
|
||||
// f_reply_markup
|
||||
// f_media
|
||||
// f_views
|
||||
// f_forwards
|
||||
// f_replies
|
||||
// f_ttl_period
|
||||
void applyEdition(const MTPDmessage &message) override;
|
||||
|
||||
void applyEdition(const MTPDmessageService &message) override;
|
||||
void updateSentContent(
|
||||
const TextWithEntities &textWithEntities,
|
||||
|
@ -213,7 +221,7 @@ private:
|
|||
void setEmptyText();
|
||||
[[nodiscard]] bool isTooOldForEdit(TimeId now) const;
|
||||
[[nodiscard]] bool isLegacyMessage() const {
|
||||
return _flags & MTPDmessage::Flag::f_legacy;
|
||||
return _flags & MessageFlag::Legacy;
|
||||
}
|
||||
|
||||
[[nodiscard]] bool checkCommentsLinkedChat(ChannelId id) const;
|
||||
|
@ -228,7 +236,12 @@ private:
|
|||
void setReplyMarkup(const MTPReplyMarkup *markup);
|
||||
|
||||
struct CreateConfig;
|
||||
void createComponentsHelper(MTPDmessage::Flags flags, MsgId replyTo, UserId viaBotId, const QString &postAuthor, const MTPReplyMarkup &markup);
|
||||
void createComponentsHelper(
|
||||
MessageFlags flags,
|
||||
MsgId replyTo,
|
||||
UserId viaBotId,
|
||||
const QString &postAuthor,
|
||||
const MTPReplyMarkup &markup);
|
||||
void createComponents(const CreateConfig &config);
|
||||
void setupForwardedComponent(const CreateConfig &config);
|
||||
void changeReplyToTopCounter(
|
||||
|
|
|
@ -518,13 +518,13 @@ void HistoryService::applyAction(const MTPMessageAction &action) {
|
|||
}, [](const MTPDphotoEmpty &) {
|
||||
});
|
||||
}, [&](const MTPDmessageActionChatCreate &) {
|
||||
_clientFlags |= MTPDmessage_ClientFlag::f_is_group_essential;
|
||||
_flags |= MessageFlag::IsGroupEssential;
|
||||
}, [&](const MTPDmessageActionChannelCreate &) {
|
||||
_clientFlags |= MTPDmessage_ClientFlag::f_is_group_essential;
|
||||
_flags |= MessageFlag::IsGroupEssential;
|
||||
}, [&](const MTPDmessageActionChatMigrateTo &) {
|
||||
_clientFlags |= MTPDmessage_ClientFlag::f_is_group_essential;
|
||||
_flags |= MessageFlag::IsGroupEssential;
|
||||
}, [&](const MTPDmessageActionChannelMigrateFrom &) {
|
||||
_clientFlags |= MTPDmessage_ClientFlag::f_is_group_essential;
|
||||
_flags |= MessageFlag::IsGroupEssential;
|
||||
}, [](const auto &) {
|
||||
});
|
||||
}
|
||||
|
@ -836,12 +836,11 @@ HistoryService::PreparedText HistoryService::prepareCallScheduledText(
|
|||
HistoryService::HistoryService(
|
||||
not_null<History*> history,
|
||||
const MTPDmessage &data,
|
||||
MTPDmessage_ClientFlags clientFlags)
|
||||
MessageFlags localFlags)
|
||||
: HistoryItem(
|
||||
history,
|
||||
data.vid().v,
|
||||
data.vflags().v,
|
||||
clientFlags,
|
||||
FlagsFromMTP(data.vflags().v) | localFlags,
|
||||
data.vdate().v,
|
||||
data.vfrom_id() ? peerFromMTP(*data.vfrom_id()) : PeerId(0)) {
|
||||
createFromMtp(data);
|
||||
|
@ -851,12 +850,11 @@ HistoryService::HistoryService(
|
|||
HistoryService::HistoryService(
|
||||
not_null<History*> history,
|
||||
const MTPDmessageService &data,
|
||||
MTPDmessage_ClientFlags clientFlags)
|
||||
MessageFlags localFlags)
|
||||
: HistoryItem(
|
||||
history,
|
||||
data.vid().v,
|
||||
mtpCastFlags(data.vflags().v),
|
||||
clientFlags,
|
||||
FlagsFromMTP(data.vflags().v) | localFlags,
|
||||
data.vdate().v,
|
||||
data.vfrom_id() ? peerFromMTP(*data.vfrom_id()) : PeerId(0)) {
|
||||
createFromMtp(data);
|
||||
|
@ -866,13 +864,12 @@ HistoryService::HistoryService(
|
|||
HistoryService::HistoryService(
|
||||
not_null<History*> history,
|
||||
MsgId id,
|
||||
MTPDmessage_ClientFlags clientFlags,
|
||||
MessageFlags flags,
|
||||
TimeId date,
|
||||
const PreparedText &message,
|
||||
MTPDmessage::Flags flags,
|
||||
PeerId from,
|
||||
PhotoData *photo)
|
||||
: HistoryItem(history, id, flags, clientFlags, date, from) {
|
||||
: HistoryItem(history, id, flags, date, from) {
|
||||
setServiceText(message);
|
||||
if (photo) {
|
||||
_media = std::make_unique<Data::MediaPhoto>(
|
||||
|
@ -1227,14 +1224,12 @@ HistoryService::PreparedText GenerateJoinedText(
|
|||
not_null<HistoryService*> GenerateJoinedMessage(
|
||||
not_null<History*> history,
|
||||
TimeId inviteDate,
|
||||
not_null<UserData*> inviter,
|
||||
MTPDmessage::Flags flags) {
|
||||
not_null<UserData*> inviter) {
|
||||
return history->makeServiceMessage(
|
||||
history->owner().nextLocalMessageId(),
|
||||
MTPDmessage_ClientFlag::f_local_history_entry,
|
||||
MessageFlag::LocalHistoryEntry,
|
||||
inviteDate,
|
||||
GenerateJoinedText(history, inviter),
|
||||
flags);
|
||||
GenerateJoinedText(history, inviter));
|
||||
}
|
||||
|
||||
std::optional<bool> PeerHasThisCall(
|
||||
|
|
|
@ -70,18 +70,17 @@ public:
|
|||
HistoryService(
|
||||
not_null<History*> history,
|
||||
const MTPDmessage &data,
|
||||
MTPDmessage_ClientFlags clientFlags);
|
||||
MessageFlags localFlags);
|
||||
HistoryService(
|
||||
not_null<History*> history,
|
||||
const MTPDmessageService &data,
|
||||
MTPDmessage_ClientFlags clientFlags);
|
||||
MessageFlags localFlags);
|
||||
HistoryService(
|
||||
not_null<History*> history,
|
||||
MsgId id,
|
||||
MTPDmessage_ClientFlags clientFlags,
|
||||
MessageFlags flags,
|
||||
TimeId date,
|
||||
const PreparedText &message,
|
||||
MTPDmessage::Flags flags = 0,
|
||||
PeerId from = 0,
|
||||
PhotoData *photo = nullptr);
|
||||
|
||||
|
@ -174,8 +173,7 @@ private:
|
|||
[[nodiscard]] not_null<HistoryService*> GenerateJoinedMessage(
|
||||
not_null<History*> history,
|
||||
TimeId inviteDate,
|
||||
not_null<UserData*> inviter,
|
||||
MTPDmessage::Flags flags);
|
||||
not_null<UserData*> inviter);
|
||||
[[nodiscard]] std::optional<bool> PeerHasThisCall(
|
||||
not_null<PeerData*> peer,
|
||||
uint64 id);
|
||||
|
|
|
@ -385,7 +385,7 @@ private:
|
|||
// This should be called only from previousInBlocksChanged() or when
|
||||
// DateBadge or UnreadBar bit is changed in the Composer mask
|
||||
// then the result should be cached in a client side flag
|
||||
// MTPDmessage_ClientFlag::f_attach_to_previous.
|
||||
// HistoryView::Element::Flag::AttachedToPrevious.
|
||||
void recountAttachToPreviousInBlocks();
|
||||
|
||||
QSize countOptimalSize() final override;
|
||||
|
|
|
@ -364,29 +364,27 @@ bool Result::hasThumbDisplay() const {
|
|||
|
||||
void Result::addToHistory(
|
||||
History *history,
|
||||
MTPDmessage::Flags flags,
|
||||
MTPDmessage_ClientFlags clientFlags,
|
||||
MessageFlags flags,
|
||||
MsgId msgId,
|
||||
PeerId fromId,
|
||||
MTPint mtpDate,
|
||||
TimeId date,
|
||||
UserId viaBotId,
|
||||
MsgId replyToId,
|
||||
const QString &postAuthor) const {
|
||||
clientFlags |= MTPDmessage_ClientFlag::f_from_inline_bot;
|
||||
flags |= MessageFlag::FromInlineBot;
|
||||
|
||||
auto markup = MTPReplyMarkup();
|
||||
if (_mtpKeyboard) {
|
||||
flags |= MTPDmessage::Flag::f_reply_markup;
|
||||
flags |= MessageFlag::HasReplyMarkup;
|
||||
markup = *_mtpKeyboard;
|
||||
}
|
||||
sendData->addToHistory(
|
||||
this,
|
||||
history,
|
||||
flags,
|
||||
clientFlags,
|
||||
msgId,
|
||||
fromId,
|
||||
mtpDate,
|
||||
date,
|
||||
viaBotId,
|
||||
replyToId,
|
||||
postAuthor,
|
||||
|
|
|
@ -62,11 +62,10 @@ public:
|
|||
|
||||
void addToHistory(
|
||||
History *history,
|
||||
MTPDmessage::Flags flags,
|
||||
MTPDmessage_ClientFlags clientFlags,
|
||||
MessageFlags flags,
|
||||
MsgId msgId,
|
||||
PeerId fromId,
|
||||
MTPint mtpDate,
|
||||
TimeId date,
|
||||
UserId viaBotId,
|
||||
MsgId replyToId,
|
||||
const QString &postAuthor) const;
|
||||
|
|
|
@ -31,52 +31,29 @@ QString SendData::getLayoutDescription(const Result *owner) const {
|
|||
void SendDataCommon::addToHistory(
|
||||
const Result *owner,
|
||||
not_null<History*> history,
|
||||
MTPDmessage::Flags flags,
|
||||
MTPDmessage_ClientFlags clientFlags,
|
||||
MessageFlags flags,
|
||||
MsgId msgId,
|
||||
PeerId fromId,
|
||||
MTPint mtpDate,
|
||||
TimeId date,
|
||||
UserId viaBotId,
|
||||
MsgId replyToId,
|
||||
const QString &postAuthor,
|
||||
const MTPReplyMarkup &markup) const {
|
||||
auto fields = getSentMessageFields();
|
||||
if (!fields.entities.v.isEmpty()) {
|
||||
flags |= MTPDmessage::Flag::f_entities;
|
||||
}
|
||||
auto action = Api::SendAction(history);
|
||||
action.replyTo = replyToId;
|
||||
const auto replyHeader = NewMessageReplyHeader(action);
|
||||
if (replyToId) {
|
||||
flags |= MTPDmessage::Flag::f_reply_to;
|
||||
flags |= MessageFlag::HasReplyInfo;
|
||||
}
|
||||
const auto views = 1;
|
||||
const auto forwards = 0;
|
||||
history->addNewMessage(
|
||||
MTP_message(
|
||||
MTP_flags(flags),
|
||||
MTP_int(msgId),
|
||||
peerToMTP(fromId),
|
||||
peerToMTP(history->peer->id),
|
||||
MTPMessageFwdHeader(),
|
||||
MTP_int(viaBotId.bare), // #TODO ids
|
||||
replyHeader,
|
||||
mtpDate,
|
||||
fields.text,
|
||||
fields.media,
|
||||
markup,
|
||||
fields.entities,
|
||||
MTP_int(views),
|
||||
MTP_int(forwards),
|
||||
MTPMessageReplies(),
|
||||
MTPint(), // edit_date
|
||||
MTP_string(postAuthor),
|
||||
MTPlong(),
|
||||
//MTPMessageReactions(),
|
||||
MTPVector<MTPRestrictionReason>(),
|
||||
MTPint()), // ttl_period
|
||||
clientFlags,
|
||||
NewMessageType::Unread);
|
||||
history->addNewLocalMessage(
|
||||
msgId,
|
||||
flags,
|
||||
viaBotId,
|
||||
replyToId,
|
||||
date,
|
||||
fromId,
|
||||
postAuthor,
|
||||
std::move(fields.text),
|
||||
std::move(fields.media),
|
||||
markup);
|
||||
}
|
||||
|
||||
QString SendDataCommon::getErrorOnSend(
|
||||
|
@ -88,54 +65,44 @@ QString SendDataCommon::getErrorOnSend(
|
|||
return error.value_or(QString());
|
||||
}
|
||||
|
||||
SendDataCommon::SentMTPMessageFields SendText::getSentMessageFields() const {
|
||||
SentMTPMessageFields result;
|
||||
result.text = MTP_string(_message);
|
||||
result.entities = Api::EntitiesToMTP(&session(), _entities);
|
||||
return result;
|
||||
SendDataCommon::SentMessageFields SendText::getSentMessageFields() const {
|
||||
return { .text = { _message, _entities } };
|
||||
}
|
||||
|
||||
SendDataCommon::SentMTPMessageFields SendGeo::getSentMessageFields() const {
|
||||
SentMTPMessageFields result;
|
||||
SendDataCommon::SentMessageFields SendGeo::getSentMessageFields() const {
|
||||
if (_period) {
|
||||
using Flag = MTPDmessageMediaGeoLive::Flag;
|
||||
result.media = MTP_messageMediaGeoLive(
|
||||
return { .media = MTP_messageMediaGeoLive(
|
||||
MTP_flags((_heading ? Flag::f_heading : Flag(0))
|
||||
| (_proximityNotificationRadius ? Flag::f_proximity_notification_radius : Flag(0))),
|
||||
| (_proximityNotificationRadius
|
||||
? Flag::f_proximity_notification_radius
|
||||
: Flag(0))),
|
||||
_location.toMTP(),
|
||||
MTP_int(_heading.value_or(0)),
|
||||
MTP_int(*_period),
|
||||
MTP_int(_proximityNotificationRadius.value_or(0)));
|
||||
} else {
|
||||
result.media = MTP_messageMediaGeo(_location.toMTP());
|
||||
MTP_int(_proximityNotificationRadius.value_or(0))) };
|
||||
}
|
||||
return result;
|
||||
return { .media = MTP_messageMediaGeo(_location.toMTP()) };
|
||||
}
|
||||
|
||||
SendDataCommon::SentMTPMessageFields SendVenue::getSentMessageFields() const {
|
||||
SentMTPMessageFields result;
|
||||
auto venueType = QString();
|
||||
result.media = MTP_messageMediaVenue(
|
||||
SendDataCommon::SentMessageFields SendVenue::getSentMessageFields() const {
|
||||
const auto venueType = QString();
|
||||
return { .media = MTP_messageMediaVenue(
|
||||
_location.toMTP(),
|
||||
MTP_string(_title),
|
||||
MTP_string(_address),
|
||||
MTP_string(_provider),
|
||||
MTP_string(_venueId),
|
||||
MTP_string(venueType));
|
||||
return result;
|
||||
MTP_string(QString())) }; // venue_type
|
||||
}
|
||||
|
||||
SendDataCommon::SentMTPMessageFields SendContact::getSentMessageFields() const {
|
||||
SentMTPMessageFields result;
|
||||
const auto userId = 0;
|
||||
const auto vcard = QString();
|
||||
result.media = MTP_messageMediaContact(
|
||||
SendDataCommon::SentMessageFields SendContact::getSentMessageFields() const {
|
||||
return { .media = MTP_messageMediaContact(
|
||||
MTP_string(_phoneNumber),
|
||||
MTP_string(_firstName),
|
||||
MTP_string(_lastName),
|
||||
MTP_string(vcard),
|
||||
MTP_int(userId));
|
||||
return result;
|
||||
MTP_string(), // vcard
|
||||
MTP_int(0)) }; // user_id
|
||||
}
|
||||
|
||||
QString SendContact::getLayoutDescription(const Result *owner) const {
|
||||
|
@ -149,11 +116,10 @@ QString SendContact::getLayoutDescription(const Result *owner) const {
|
|||
void SendPhoto::addToHistory(
|
||||
const Result *owner,
|
||||
not_null<History*> history,
|
||||
MTPDmessage::Flags flags,
|
||||
MTPDmessage_ClientFlags clientFlags,
|
||||
MessageFlags flags,
|
||||
MsgId msgId,
|
||||
PeerId fromId,
|
||||
MTPint mtpDate,
|
||||
TimeId date,
|
||||
UserId viaBotId,
|
||||
MsgId replyToId,
|
||||
const QString &postAuthor,
|
||||
|
@ -161,10 +127,9 @@ void SendPhoto::addToHistory(
|
|||
history->addNewLocalMessage(
|
||||
msgId,
|
||||
flags,
|
||||
clientFlags,
|
||||
viaBotId,
|
||||
replyToId,
|
||||
mtpDate.v,
|
||||
date,
|
||||
fromId,
|
||||
postAuthor,
|
||||
_photo,
|
||||
|
@ -184,11 +149,10 @@ QString SendPhoto::getErrorOnSend(
|
|||
void SendFile::addToHistory(
|
||||
const Result *owner,
|
||||
not_null<History*> history,
|
||||
MTPDmessage::Flags flags,
|
||||
MTPDmessage_ClientFlags clientFlags,
|
||||
MessageFlags flags,
|
||||
MsgId msgId,
|
||||
PeerId fromId,
|
||||
MTPint mtpDate,
|
||||
TimeId date,
|
||||
UserId viaBotId,
|
||||
MsgId replyToId,
|
||||
const QString &postAuthor,
|
||||
|
@ -196,10 +160,9 @@ void SendFile::addToHistory(
|
|||
history->addNewLocalMessage(
|
||||
msgId,
|
||||
flags,
|
||||
clientFlags,
|
||||
viaBotId,
|
||||
replyToId,
|
||||
mtpDate.v,
|
||||
date,
|
||||
fromId,
|
||||
postAuthor,
|
||||
_document,
|
||||
|
@ -233,11 +196,10 @@ QString SendFile::getErrorOnSend(
|
|||
void SendGame::addToHistory(
|
||||
const Result *owner,
|
||||
not_null<History*> history,
|
||||
MTPDmessage::Flags flags,
|
||||
MTPDmessage_ClientFlags clientFlags,
|
||||
MessageFlags flags,
|
||||
MsgId msgId,
|
||||
PeerId fromId,
|
||||
MTPint mtpDate,
|
||||
TimeId date,
|
||||
UserId viaBotId,
|
||||
MsgId replyToId,
|
||||
const QString &postAuthor,
|
||||
|
@ -245,10 +207,9 @@ void SendGame::addToHistory(
|
|||
history->addNewLocalMessage(
|
||||
msgId,
|
||||
flags,
|
||||
clientFlags,
|
||||
viaBotId,
|
||||
replyToId,
|
||||
mtpDate.v,
|
||||
date,
|
||||
fromId,
|
||||
postAuthor,
|
||||
_game,
|
||||
|
@ -264,10 +225,8 @@ QString SendGame::getErrorOnSend(
|
|||
return error.value_or(QString());
|
||||
}
|
||||
|
||||
auto SendInvoice::getSentMessageFields() const -> SentMTPMessageFields {
|
||||
SentMTPMessageFields result;
|
||||
result.media = _media;
|
||||
return result;
|
||||
SendDataCommon::SentMessageFields SendInvoice::getSentMessageFields() const {
|
||||
return { .media = _media };
|
||||
}
|
||||
|
||||
QString SendInvoice::getLayoutDescription(const Result *owner) const {
|
||||
|
|
|
@ -41,11 +41,10 @@ public:
|
|||
virtual void addToHistory(
|
||||
const Result *owner,
|
||||
not_null<History*> history,
|
||||
MTPDmessage::Flags flags,
|
||||
MTPDmessage_ClientFlags clientFlags,
|
||||
MessageFlags flags,
|
||||
MsgId msgId,
|
||||
PeerId fromId,
|
||||
MTPint mtpDate,
|
||||
TimeId date,
|
||||
UserId viaBotId,
|
||||
MsgId replyToId,
|
||||
const QString &postAuthor,
|
||||
|
@ -75,21 +74,19 @@ class SendDataCommon : public SendData {
|
|||
public:
|
||||
using SendData::SendData;
|
||||
|
||||
struct SentMTPMessageFields {
|
||||
MTPString text = MTP_string();
|
||||
MTPVector<MTPMessageEntity> entities = MTP_vector<MTPMessageEntity>();
|
||||
struct SentMessageFields {
|
||||
TextWithEntities text;
|
||||
MTPMessageMedia media = MTP_messageMediaEmpty();
|
||||
};
|
||||
virtual SentMTPMessageFields getSentMessageFields() const = 0;
|
||||
virtual SentMessageFields getSentMessageFields() const = 0;
|
||||
|
||||
void addToHistory(
|
||||
const Result *owner,
|
||||
not_null<History*> history,
|
||||
MTPDmessage::Flags flags,
|
||||
MTPDmessage_ClientFlags clientFlags,
|
||||
MessageFlags flags,
|
||||
MsgId msgId,
|
||||
PeerId fromId,
|
||||
MTPint mtpDate,
|
||||
TimeId date,
|
||||
UserId viaBotId,
|
||||
MsgId replyToId,
|
||||
const QString &postAuthor,
|
||||
|
@ -118,7 +115,7 @@ public:
|
|||
return !_message.isEmpty();
|
||||
}
|
||||
|
||||
SentMTPMessageFields getSentMessageFields() const override;
|
||||
SentMessageFields getSentMessageFields() const override;
|
||||
|
||||
private:
|
||||
QString _message;
|
||||
|
@ -152,7 +149,7 @@ public:
|
|||
return true;
|
||||
}
|
||||
|
||||
SentMTPMessageFields getSentMessageFields() const override;
|
||||
SentMessageFields getSentMessageFields() const override;
|
||||
|
||||
bool hasLocationCoords() const override {
|
||||
return true;
|
||||
|
@ -191,7 +188,7 @@ public:
|
|||
return true;
|
||||
}
|
||||
|
||||
SentMTPMessageFields getSentMessageFields() const override;
|
||||
SentMessageFields getSentMessageFields() const override;
|
||||
|
||||
bool hasLocationCoords() const override {
|
||||
return true;
|
||||
|
@ -224,7 +221,7 @@ public:
|
|||
return (!_firstName.isEmpty() || !_lastName.isEmpty()) && !_phoneNumber.isEmpty();
|
||||
}
|
||||
|
||||
SentMTPMessageFields getSentMessageFields() const override;
|
||||
SentMessageFields getSentMessageFields() const override;
|
||||
|
||||
QString getLayoutDescription(const Result *owner) const override;
|
||||
|
||||
|
@ -254,11 +251,10 @@ public:
|
|||
void addToHistory(
|
||||
const Result *owner,
|
||||
not_null<History*> history,
|
||||
MTPDmessage::Flags flags,
|
||||
MTPDmessage_ClientFlags clientFlags,
|
||||
MessageFlags flags,
|
||||
MsgId msgId,
|
||||
PeerId fromId,
|
||||
MTPint mtpDate,
|
||||
TimeId date,
|
||||
UserId viaBotId,
|
||||
MsgId replyToId,
|
||||
const QString &postAuthor,
|
||||
|
@ -296,11 +292,10 @@ public:
|
|||
void addToHistory(
|
||||
const Result *owner,
|
||||
not_null<History*> history,
|
||||
MTPDmessage::Flags flags,
|
||||
MTPDmessage_ClientFlags clientFlags,
|
||||
MessageFlags flags,
|
||||
MsgId msgId,
|
||||
PeerId fromId,
|
||||
MTPint mtpDate,
|
||||
TimeId date,
|
||||
UserId viaBotId,
|
||||
MsgId replyToId,
|
||||
const QString &postAuthor,
|
||||
|
@ -332,11 +327,10 @@ public:
|
|||
void addToHistory(
|
||||
const Result *owner,
|
||||
not_null<History*> history,
|
||||
MTPDmessage::Flags flags,
|
||||
MTPDmessage_ClientFlags clientFlags,
|
||||
MessageFlags flags,
|
||||
MsgId msgId,
|
||||
PeerId fromId,
|
||||
MTPint mtpDate,
|
||||
TimeId date,
|
||||
UserId viaBotId,
|
||||
MsgId replyToId,
|
||||
const QString &postAuthor,
|
||||
|
@ -364,7 +358,7 @@ public:
|
|||
return true;
|
||||
}
|
||||
|
||||
SentMTPMessageFields getSentMessageFields() const override;
|
||||
SentMessageFields getSentMessageFields() const override;
|
||||
|
||||
QString getLayoutDescription(const Result *owner) const override;
|
||||
|
||||
|
|
|
@ -7,8 +7,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
*/
|
||||
#pragma once
|
||||
|
||||
#include "base/flags.h"
|
||||
|
||||
inline MTPbool MTP_bool(bool v) {
|
||||
return v ? MTP_boolTrue() : MTP_boolFalse();
|
||||
}
|
||||
|
@ -19,60 +17,3 @@ inline bool mtpIsTrue(const MTPBool &v) {
|
|||
inline bool mtpIsFalse(const MTPBool &v) {
|
||||
return !mtpIsTrue(v);
|
||||
}
|
||||
|
||||
// we must validate that MTProto scheme flags don't intersect with client side flags
|
||||
// and define common bit operators which allow use Type_ClientFlag together with Type::Flag
|
||||
#define DEFINE_MTP_CLIENT_FLAGS(Type) \
|
||||
static_assert(Type::Flags(Type::Flag::MAX_FIELD) < static_cast<Type::Flag>(Type##_ClientFlag::MIN_FIELD), \
|
||||
"MTProto flags conflict with client side flags!"); \
|
||||
namespace base {\
|
||||
template<>\
|
||||
struct extended_flags<Type##_ClientFlag> {\
|
||||
using type = Type::Flag;\
|
||||
};\
|
||||
}
|
||||
|
||||
// we use the same flags field for some additional client side flags
|
||||
enum class MTPDmessage_ClientFlag : uint32 {
|
||||
// message has links for "shared links" indexing
|
||||
f_has_text_links = (1U << 30),
|
||||
|
||||
// message is a group / channel create or migrate service message
|
||||
f_is_group_essential = (1U << 29),
|
||||
|
||||
// message's edited media is generated on the client
|
||||
// and should not update media from server
|
||||
f_is_local_update_media = (1U << 28),
|
||||
|
||||
// message was sent from inline bot, need to re-set media when sent
|
||||
f_from_inline_bot = (1U << 27),
|
||||
|
||||
// message has a switch inline keyboard button, need to return to inline
|
||||
f_has_switch_inline_button = (1U << 26),
|
||||
|
||||
// message is generated on the client side and should be unread
|
||||
f_clientside_unread = (1U << 25),
|
||||
|
||||
// message has an admin badge in supergroup
|
||||
f_has_admin_badge = (1U << 24),
|
||||
|
||||
// message is an outgoing message that is being sent
|
||||
f_sending = (1U << 23),
|
||||
|
||||
// message was an outgoing message and failed to be sent
|
||||
f_failed = (1U << 22),
|
||||
|
||||
// message has no media and only a several emoji text
|
||||
f_isolated_emoji = (1U << 21),
|
||||
|
||||
// message is local message existing in the message history
|
||||
f_local_history_entry = (1U << 20),
|
||||
|
||||
// message is an admin log entry
|
||||
f_admin_log_entry = (1U << 19),
|
||||
|
||||
// message is a fake message for some ui
|
||||
f_fake_history_item = (1U << 18),
|
||||
};
|
||||
inline constexpr bool is_flag_type(MTPDmessage_ClientFlag) { return true; }
|
||||
using MTPDmessage_ClientFlags = base::flags<MTPDmessage_ClientFlag>;
|
||||
|
|
|
@ -130,7 +130,6 @@ AdminLog::OwnedItem GenerateForwardedItem(
|
|||
Expects(history->peer->isUser());
|
||||
|
||||
using Flag = MTPDmessage::Flag;
|
||||
using FwdFlag = MTPDmessageFwdHeader::Flag;
|
||||
// #TODO common global incrementable id for fake items, like clientMsgId.
|
||||
static auto id = ServerMaxMsgId + (ServerMaxMsgId / 6);
|
||||
const auto flags = Flag::f_from_id | Flag::f_fwd_from;
|
||||
|
@ -140,7 +139,7 @@ AdminLog::OwnedItem GenerateForwardedItem(
|
|||
peerToMTP(history->peer->id),
|
||||
peerToMTP(history->peer->id),
|
||||
MTP_messageFwdHeader(
|
||||
MTP_flags(FwdFlag::f_from_id),
|
||||
MTP_flags(MTPDmessageFwdHeader::Flag::f_from_id),
|
||||
peerToMTP(history->session().userPeerId()),
|
||||
MTPstring(), // from_name
|
||||
MTP_int(base::unixtime::now()),
|
||||
|
@ -166,9 +165,7 @@ AdminLog::OwnedItem GenerateForwardedItem(
|
|||
MTPVector<MTPRestrictionReason>(),
|
||||
MTPint() // ttl_period
|
||||
).match([&](const MTPDmessage &data) {
|
||||
return history->makeMessage(
|
||||
data,
|
||||
MTPDmessage_ClientFlag::f_fake_history_item);
|
||||
return history->makeMessage(data, MessageFlag::FakeHistoryItem);
|
||||
}, [](auto &&) -> not_null<HistoryMessage*> {
|
||||
Unexpected("Type in GenerateForwardedItem.");
|
||||
});
|
||||
|
|
|
@ -271,22 +271,25 @@ AdminLog::OwnedItem GenerateCommentItem(
|
|||
if (data.comment.isEmpty()) {
|
||||
return nullptr;
|
||||
}
|
||||
using Flag = MTPDmessage::Flag;
|
||||
const auto id = ServerMaxMsgId + (ServerMaxMsgId / 2);
|
||||
const auto flags = Flag::f_entities | Flag::f_from_id | Flag::f_out;
|
||||
const auto clientFlags = MTPDmessage_ClientFlag::f_fake_history_item;
|
||||
const auto replyTo = 0;
|
||||
const auto viaBotId = 0;
|
||||
const auto flags = MessageFlag::HasFromId
|
||||
| MessageFlag::Outgoing
|
||||
| MessageFlag::FakeHistoryItem;
|
||||
const auto replyTo = MsgId();
|
||||
const auto viaBotId = UserId();
|
||||
const auto groupedId = uint64();
|
||||
const auto item = history->makeMessage(
|
||||
id,
|
||||
flags,
|
||||
clientFlags,
|
||||
replyTo,
|
||||
viaBotId,
|
||||
base::unixtime::now(),
|
||||
history->session().userId(),
|
||||
QString(),
|
||||
TextWithEntities{ TextUtilities::Clean(data.comment) });
|
||||
TextWithEntities{ TextUtilities::Clean(data.comment) },
|
||||
MTP_messageMediaEmpty(),
|
||||
MTPReplyMarkup(),
|
||||
groupedId);
|
||||
return AdminLog::OwnedItem(delegate, item);
|
||||
}
|
||||
|
||||
|
@ -294,39 +297,29 @@ AdminLog::OwnedItem GenerateContactItem(
|
|||
not_null<HistoryView::ElementDelegate*> delegate,
|
||||
not_null<History*> history,
|
||||
const Contact &data) {
|
||||
using Flag = MTPDmessage::Flag;
|
||||
const auto id = ServerMaxMsgId + (ServerMaxMsgId / 2) + 1;
|
||||
const auto flags = Flag::f_from_id | Flag::f_media | Flag::f_out;
|
||||
const auto message = MTP_message(
|
||||
MTP_flags(flags),
|
||||
MTP_int(id),
|
||||
peerToMTP(history->session().userPeerId()),
|
||||
peerToMTP(history->peer->id),
|
||||
MTPMessageFwdHeader(),
|
||||
MTPint(), // via_bot_id
|
||||
MTPMessageReplyHeader(),
|
||||
MTP_int(base::unixtime::now()),
|
||||
MTP_string(),
|
||||
const auto replyTo = MsgId();
|
||||
const auto viaBotId = UserId();
|
||||
const auto postAuthor = QString();
|
||||
const auto groupedId = uint64();
|
||||
const auto item = history->makeMessage(
|
||||
(ServerMaxMsgId + (ServerMaxMsgId / 2) + 1),
|
||||
(MessageFlag::HasFromId
|
||||
| MessageFlag::Outgoing
|
||||
| MessageFlag::FakeHistoryItem),
|
||||
replyTo,
|
||||
viaBotId,
|
||||
base::unixtime::now(),
|
||||
history->session().userPeerId(),
|
||||
postAuthor,
|
||||
TextWithEntities(),
|
||||
MTP_messageMediaContact(
|
||||
MTP_string(data.phone),
|
||||
MTP_string(data.firstName),
|
||||
MTP_string(data.lastName),
|
||||
MTP_string(),
|
||||
MTP_int(0)),
|
||||
MTP_string(), // vcard
|
||||
MTP_int(0)), // user_id
|
||||
MTPReplyMarkup(),
|
||||
MTPVector<MTPMessageEntity>(),
|
||||
MTPint(), // views
|
||||
MTPint(), // forwards
|
||||
MTPMessageReplies(),
|
||||
MTPint(), // edit_date
|
||||
MTP_string(),
|
||||
MTP_long(0),
|
||||
//MTPMessageReactions(),
|
||||
MTPVector<MTPRestrictionReason>(),
|
||||
MTPint()); // ttl_period
|
||||
const auto item = history->makeMessage(
|
||||
message.c_message(),
|
||||
MTPDmessage_ClientFlag::f_fake_history_item);
|
||||
groupedId);
|
||||
return AdminLog::OwnedItem(delegate, item);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue