Don't use MTP* for Message flags.

This commit is contained in:
John Preston 2021-07-28 14:55:02 +03:00
parent 22e77bf3af
commit 116a768fde
30 changed files with 638 additions and 841 deletions

View file

@ -40,22 +40,22 @@ namespace {
void InnerFillMessagePostFlags( void InnerFillMessagePostFlags(
const Api::SendOptions &options, const Api::SendOptions &options,
not_null<PeerData*> peer, not_null<PeerData*> peer,
MTPDmessage::Flags &flags) { MessageFlags &flags) {
const auto anonymousPost = peer->amAnonymous(); const auto anonymousPost = peer->amAnonymous();
if (!anonymousPost) { if (!anonymousPost) {
flags |= MTPDmessage::Flag::f_from_id; flags |= MessageFlag::HasFromId;
return; return;
} else if (peer->asMegagroup()) { } else if (peer->asMegagroup()) {
return; return;
} }
flags |= MTPDmessage::Flag::f_post; flags |= MessageFlag::Post;
// Don't display views and author of a new post when it's scheduled. // Don't display views and author of a new post when it's scheduled.
if (options.scheduled) { if (options.scheduled) {
return; return;
} }
flags |= MTPDmessage::Flag::f_views; flags |= MessageFlag::HasViews;
if (peer->asChannel()->addsSignature()) { if (peer->asChannel()->addsSignature()) {
flags |= MTPDmessage::Flag::f_post_author; flags |= MessageFlag::HasPostAuthor;
} }
} }
@ -79,11 +79,10 @@ void SendExistingMedia(
session->data().nextLocalMessageId()); session->data().nextLocalMessageId());
const auto randomId = openssl::RandomValue<uint64>(); const auto randomId = openssl::RandomValue<uint64>();
auto flags = NewMessageFlags(peer) | MTPDmessage::Flag::f_media; auto flags = NewMessageFlags(peer);
auto clientFlags = NewMessageClientFlags();
auto sendFlags = MTPmessages_SendMedia::Flags(0); auto sendFlags = MTPmessages_SendMedia::Flags(0);
if (message.action.replyTo) { if (message.action.replyTo) {
flags |= MTPDmessage::Flag::f_reply_to; flags |= MessageFlag::HasReplyInfo;
sendFlags |= MTPmessages_SendMedia::Flag::f_reply_to_msg_id; sendFlags |= MTPmessages_SendMedia::Flag::f_reply_to_msg_id;
} }
const auto anonymousPost = peer->amAnonymous(); const auto anonymousPost = peer->amAnonymous();
@ -111,19 +110,19 @@ void SendExistingMedia(
const auto captionText = caption.text; const auto captionText = caption.text;
if (message.action.options.scheduled) { if (message.action.options.scheduled) {
flags |= MTPDmessage::Flag::f_from_scheduled; flags |= MessageFlag::IsOrWasScheduled;
sendFlags |= MTPmessages_SendMedia::Flag::f_schedule_date; sendFlags |= MTPmessages_SendMedia::Flag::f_schedule_date;
} else { } else {
clientFlags |= MTPDmessage_ClientFlag::f_local_history_entry; flags |= MessageFlag::LocalHistoryEntry;
} }
session->data().registerMessageRandomId(randomId, newId); session->data().registerMessageRandomId(randomId, newId);
const auto viaBotId = UserId();
history->addNewLocalMessage( history->addNewLocalMessage(
newId.msg, newId.msg,
flags, flags,
clientFlags, viaBotId,
0,
replyTo, replyTo,
HistoryItem::NewMessageDate(message.action.options.scheduled), HistoryItem::NewMessageDate(message.action.options.scheduled),
messageFromId, messageFromId,
@ -253,11 +252,10 @@ bool SendDice(Api::MessageToSend &message) {
const auto randomId = openssl::RandomValue<uint64>(); const auto randomId = openssl::RandomValue<uint64>();
auto &histories = history->owner().histories(); auto &histories = history->owner().histories();
auto flags = NewMessageFlags(peer) | MTPDmessage::Flag::f_media; auto flags = NewMessageFlags(peer);
auto clientFlags = NewMessageClientFlags();
auto sendFlags = MTPmessages_SendMedia::Flags(0); auto sendFlags = MTPmessages_SendMedia::Flags(0);
if (message.action.replyTo) { if (message.action.replyTo) {
flags |= MTPDmessage::Flag::f_reply_to; flags |= MessageFlag::HasReplyInfo;
sendFlags |= MTPmessages_SendMedia::Flag::f_reply_to_msg_id; sendFlags |= MTPmessages_SendMedia::Flag::f_reply_to_msg_id;
} }
const auto replyHeader = NewMessageReplyHeader(message.action); const auto replyHeader = NewMessageReplyHeader(message.action);
@ -272,42 +270,26 @@ bool SendDice(Api::MessageToSend &message) {
const auto replyTo = message.action.replyTo; const auto replyTo = message.action.replyTo;
if (message.action.options.scheduled) { if (message.action.options.scheduled) {
flags |= MTPDmessage::Flag::f_from_scheduled; flags |= MessageFlag::IsOrWasScheduled;
sendFlags |= MTPmessages_SendMedia::Flag::f_schedule_date; sendFlags |= MTPmessages_SendMedia::Flag::f_schedule_date;
} else { } else {
clientFlags |= MTPDmessage_ClientFlag::f_local_history_entry; flags |= MessageFlag::LocalHistoryEntry;
} }
session->data().registerMessageRandomId(randomId, newId); session->data().registerMessageRandomId(randomId, newId);
const auto views = 1; const auto viaBotId = UserId();
const auto forwards = 0; history->addNewLocalMessage(
history->addNewMessage( newId.msg,
MTP_message( flags,
MTP_flags(flags), viaBotId,
MTP_int(newId.msg), message.action.replyTo,
peerToMTP(messageFromId), HistoryItem::NewMessageDate(message.action.options.scheduled),
peerToMTP(history->peer->id), messageFromId,
MTPMessageFwdHeader(), messagePostAuthor,
MTPint(), // via_bot_id TextWithEntities(),
replyHeader, MTP_messageMediaDice(MTP_int(0), MTP_string(emoji)),
MTP_int(HistoryItem::NewMessageDate( MTPReplyMarkup());
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 requestType = Data::Histories::RequestType::Send; const auto requestType = Data::Histories::RequestType::Send;
histories.sendRequest(history, requestType, [=](Fn<void()> finish) { histories.sendRequest(history, requestType, [=](Fn<void()> finish) {
@ -338,14 +320,15 @@ bool SendDice(Api::MessageToSend &message) {
void FillMessagePostFlags( void FillMessagePostFlags(
const Api::SendAction &action, const Api::SendAction &action,
not_null<PeerData*> peer, not_null<PeerData*> peer,
MTPDmessage::Flags &flags) { MessageFlags &flags) {
InnerFillMessagePostFlags(action.options, peer, flags); InnerFillMessagePostFlags(action.options, peer, flags);
} }
void SendConfirmedFile( void SendConfirmedFile(
not_null<Main::Session*> session, not_null<Main::Session*> session,
const std::shared_ptr<FileLoadResult> &file) { 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 channelId = peerToChannel(file->to.peer);
const auto newId = FullMsgId( const auto newId = FullMsgId(
@ -396,29 +379,24 @@ void SendConfirmedFile(
} }
} }
auto flags = (isEditing ? MTPDmessage::Flags() : NewMessageFlags(peer)) auto flags = isEditing ? MessageFlags() : NewMessageFlags(peer);
| MTPDmessage::Flag::f_entities
| MTPDmessage::Flag::f_media;
auto clientFlags = NewMessageClientFlags();
if (file->to.replyTo) { if (file->to.replyTo) {
flags |= MTPDmessage::Flag::f_reply_to; flags |= MessageFlag::HasReplyInfo;
} }
const auto replyHeader = NewMessageReplyHeader(action); const auto replyHeader = NewMessageReplyHeader(action);
const auto anonymousPost = peer->amAnonymous(); const auto anonymousPost = peer->amAnonymous();
const auto silentPost = ShouldSendSilent(peer, file->to.options); const auto silentPost = ShouldSendSilent(peer, file->to.options);
Api::FillMessagePostFlags(action, peer, flags); FillMessagePostFlags(action, peer, flags);
if (silentPost) { if (silentPost) {
flags |= MTPDmessage::Flag::f_silent; flags |= MessageFlag::Silent;
}
if (groupId) {
flags |= MTPDmessage::Flag::f_grouped_id;
} }
if (file->to.options.scheduled) { if (file->to.options.scheduled) {
flags |= MTPDmessage::Flag::f_from_scheduled; flags |= MessageFlag::IsOrWasScheduled;
// Scheduled messages have no the 'edited' badge. // Scheduled messages have no the 'edited' badge.
flags |= MTPDmessage::Flag::f_edit_hide; flags |= MessageFlag::HideEdited;
} else { } else {
clientFlags |= MTPDmessage_ClientFlag::f_local_history_entry; flags |= MessageFlag::LocalHistoryEntry;
} }
const auto messageFromId = anonymousPost ? 0 : session->userPeerId(); const auto messageFromId = anonymousPost ? 0 : session->userPeerId();
@ -426,17 +404,37 @@ void SendConfirmedFile(
? session->user()->name ? session->user()->name
: QString(); : QString();
const auto views = 1; const auto media = [&] {
const auto forwards = 0; if (file->type == SendMediaType::Photo) {
if (file->type == SendMediaType::Photo) { return MTP_messageMediaPhoto(
const auto photoFlags = MTPDmessageMediaPhoto::Flag::f_photo | 0; MTP_flags(MTPDmessageMediaPhoto::Flag::f_photo),
const auto photo = MTP_messageMediaPhoto( file->photo,
MTP_flags(photoFlags), MTPint());
file->photo, } else if (file->type == SendMediaType::File) {
MTPint()); 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( if (itemToEdit) {
MTP_flags(flags), 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), MTP_int(newId.msg),
peerToMTP(messageFromId), peerToMTP(messageFromId),
peerToMTP(file->to.peer), peerToMTP(file->to.peer),
@ -445,105 +443,32 @@ void SendConfirmedFile(
replyHeader, replyHeader,
MTP_int(HistoryItem::NewMessageDate(file->to.options.scheduled)), MTP_int(HistoryItem::NewMessageDate(file->to.options.scheduled)),
MTP_string(caption.text), MTP_string(caption.text),
photo, media,
MTPReplyMarkup(), MTPReplyMarkup(),
localEntities, localEntities,
MTP_int(views), MTPint(), // views
MTP_int(forwards), MTPint(), // forwards
MTPMessageReplies(), MTPMessageReplies(),
MTPint(), // edit_date MTPint(), // edit_date
MTP_string(messagePostAuthor), MTP_string(messagePostAuthor),
MTP_long(groupId), MTP_long(groupId),
//MTPMessageReactions(), //MTPMessageReactions(),
MTPVector<MTPRestrictionReason>(), MTPVector<MTPRestrictionReason>(),
MTPint()); // ttl_period MTPint()).c_message());
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.
} else { } 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) { if (isEditing) {

View file

@ -30,7 +30,7 @@ bool SendDice(Api::MessageToSend &message);
void FillMessagePostFlags( void FillMessagePostFlags(
const SendAction &action, const SendAction &action,
not_null<PeerData*> peer, not_null<PeerData*> peer,
MTPDmessage::Flags &flags); MessageFlags &flags);
void SendConfirmedFile( void SendConfirmedFile(
not_null<Main::Session*> session, not_null<Main::Session*> session,

View file

@ -1055,7 +1055,7 @@ void Updates::applyUpdatesNoPtsCheck(const MTPUpdates &updates) {
//MTPMessageReactions(), //MTPMessageReactions(),
MTPVector<MTPRestrictionReason>(), MTPVector<MTPRestrictionReason>(),
MTP_int(d.vttl_period().value_or_empty())), MTP_int(d.vttl_period().value_or_empty())),
MTPDmessage_ClientFlags(), MessageFlags(),
NewMessageType::Unread); NewMessageType::Unread);
} break; } break;
@ -1086,7 +1086,7 @@ void Updates::applyUpdatesNoPtsCheck(const MTPUpdates &updates) {
//MTPMessageReactions(), //MTPMessageReactions(),
MTPVector<MTPRestrictionReason>(), MTPVector<MTPRestrictionReason>(),
MTP_int(d.vttl_period().value_or_empty())), MTP_int(d.vttl_period().value_or_empty())),
MTPDmessage_ClientFlags(), MessageFlags(),
NewMessageType::Unread); NewMessageType::Unread);
} break; } break;
@ -1115,7 +1115,7 @@ void Updates::applyUpdateNoPtsCheck(const MTPUpdate &update) {
if (needToAdd) { if (needToAdd) {
_session->data().addNewMessage( _session->data().addNewMessage(
d.vmessage(), d.vmessage(),
MTPDmessage_ClientFlags(), MessageFlags(),
NewMessageType::Unread); NewMessageType::Unread);
} }
} break; } break;
@ -1209,7 +1209,7 @@ void Updates::applyUpdateNoPtsCheck(const MTPUpdate &update) {
if (needToAdd) { if (needToAdd) {
_session->data().addNewMessage( _session->data().addNewMessage(
d.vmessage(), d.vmessage(),
MTPDmessage_ClientFlags(), MessageFlags(),
NewMessageType::Unread); NewMessageType::Unread);
} }
} break; } break;

View file

@ -3783,18 +3783,17 @@ void ApiWrap::forwardMessages(
const auto anonymousPost = peer->amAnonymous(); const auto anonymousPost = peer->amAnonymous();
const auto silentPost = ShouldSendSilent(peer, action.options); const auto silentPost = ShouldSendSilent(peer, action.options);
auto flags = MTPDmessage::Flags(0); auto flags = MessageFlags();
auto clientFlags = MTPDmessage_ClientFlags();
auto sendFlags = MTPmessages_ForwardMessages::Flags(0); auto sendFlags = MTPmessages_ForwardMessages::Flags(0);
FillMessagePostFlags(action, peer, flags); FillMessagePostFlags(action, peer, flags);
if (silentPost) { if (silentPost) {
sendFlags |= MTPmessages_ForwardMessages::Flag::f_silent; sendFlags |= MTPmessages_ForwardMessages::Flag::f_silent;
} }
if (action.options.scheduled) { if (action.options.scheduled) {
flags |= MTPDmessage::Flag::f_from_scheduled; flags |= MessageFlag::IsOrWasScheduled;
sendFlags |= MTPmessages_ForwardMessages::Flag::f_schedule_date; sendFlags |= MTPmessages_ForwardMessages::Flag::f_schedule_date;
} else { } else {
clientFlags |= MTPDmessage_ClientFlag::f_local_history_entry; flags |= MessageFlag::LocalHistoryEntry;
} }
auto forwardFrom = items.front()->history()->peer; auto forwardFrom = items.front()->history()->peer;
@ -3861,7 +3860,6 @@ void ApiWrap::forwardMessages(
history->addNewLocalMessage( history->addNewLocalMessage(
newId.msg, newId.msg,
flags, flags,
clientFlags,
HistoryItem::NewMessageDate(action.options.scheduled), HistoryItem::NewMessageDate(action.options.scheduled),
messageFromId, messageFromId,
messagePostAuthor, messagePostAuthor,
@ -3926,61 +3924,44 @@ void ApiWrap::sendSharedContact(
_session->data().nextLocalMessageId()); _session->data().nextLocalMessageId());
const auto anonymousPost = peer->amAnonymous(); const auto anonymousPost = peer->amAnonymous();
auto flags = NewMessageFlags(peer) | MTPDmessage::Flag::f_media; auto flags = NewMessageFlags(peer);
auto clientFlags = NewMessageClientFlags();
if (action.replyTo) { if (action.replyTo) {
flags |= MTPDmessage::Flag::f_reply_to; flags |= MessageFlag::HasReplyInfo;
} }
const auto replyHeader = NewMessageReplyHeader(action); const auto replyHeader = NewMessageReplyHeader(action);
FillMessagePostFlags(action, peer, flags); FillMessagePostFlags(action, peer, flags);
if (action.options.scheduled) { if (action.options.scheduled) {
flags |= MTPDmessage::Flag::f_from_scheduled; flags |= MessageFlag::IsOrWasScheduled;
} else { } else {
clientFlags |= MTPDmessage_ClientFlag::f_local_history_entry; flags |= MessageFlag::LocalHistoryEntry;
} }
const auto messageFromId = anonymousPost ? 0 : _session->userPeerId(); const auto messageFromId = anonymousPost ? 0 : _session->userPeerId();
const auto messagePostAuthor = peer->isBroadcast() const auto messagePostAuthor = peer->isBroadcast()
? _session->user()->name ? _session->user()->name
: QString(); : QString();
const auto vcard = QString(); const auto viaBotId = UserId();
const auto views = 1; const auto item = history->addNewLocalMessage(
const auto forwards = 0; newId.msg,
const auto item = history->addNewMessage( flags,
MTP_message( viaBotId,
MTP_flags(flags), action.replyTo,
MTP_int(newId.msg), HistoryItem::NewMessageDate(action.options.scheduled),
peerToMTP(messageFromId), messageFromId,
peerToMTP(peer->id), messagePostAuthor,
MTPMessageFwdHeader(), TextWithEntities(),
MTPint(), // via_bot_id MTP_messageMediaContact(
replyHeader, MTP_string(phone),
MTP_int(HistoryItem::NewMessageDate(action.options.scheduled)), MTP_string(firstName),
MTP_string(), MTP_string(lastName),
MTP_messageMediaContact( MTP_string(), // vcard
MTP_string(phone), MTP_int(userId.bare)), // #TODO ids
MTP_string(firstName), MTPReplyMarkup());
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 media = MTP_inputMediaContact( const auto media = MTP_inputMediaContact(
MTP_string(phone), MTP_string(phone),
MTP_string(firstName), MTP_string(firstName),
MTP_string(lastName), MTP_string(lastName),
MTP_string(vcard)); MTP_string()); // vcard
sendMedia(item, media, action.options); sendMedia(item, media, action.options);
_session->data().sendHistoryChangeNotifications(); _session->data().sendHistoryChangeNotifications();
@ -4181,11 +4162,10 @@ void ApiWrap::sendMessage(MessageToSend &&message) {
_session->data().registerMessageSentData(randomId, peer->id, sending.text); _session->data().registerMessageSentData(randomId, peer->id, sending.text);
MTPstring msgText(MTP_string(sending.text)); MTPstring msgText(MTP_string(sending.text));
auto flags = NewMessageFlags(peer) | MTPDmessage::Flag::f_entities; auto flags = NewMessageFlags(peer);
auto clientFlags = NewMessageClientFlags();
auto sendFlags = MTPmessages_SendMessage::Flags(0); auto sendFlags = MTPmessages_SendMessage::Flags(0);
if (action.replyTo) { if (action.replyTo) {
flags |= MTPDmessage::Flag::f_reply_to; flags |= MessageFlag::HasReplyInfo;
sendFlags |= MTPmessages_SendMessage::Flag::f_reply_to_msg_id; sendFlags |= MTPmessages_SendMessage::Flag::f_reply_to_msg_id;
} }
const auto replyHeader = NewMessageReplyHeader(action); const auto replyHeader = NewMessageReplyHeader(action);
@ -4198,7 +4178,6 @@ void ApiWrap::sendMessage(MessageToSend &&message) {
MTP_webPagePending( MTP_webPagePending(
MTP_long(page->id), MTP_long(page->id),
MTP_int(page->pendingTill))); MTP_int(page->pendingTill)));
flags |= MTPDmessage::Flag::f_media;
} }
const auto anonymousPost = peer->amAnonymous(); const auto anonymousPost = peer->amAnonymous();
const auto silentPost = ShouldSendSilent(peer, action.options); const auto silentPost = ShouldSendSilent(peer, action.options);
@ -4206,10 +4185,7 @@ void ApiWrap::sendMessage(MessageToSend &&message) {
if (silentPost) { if (silentPost) {
sendFlags |= MTPmessages_SendMessage::Flag::f_silent; sendFlags |= MTPmessages_SendMessage::Flag::f_silent;
} }
auto localEntities = Api::EntitiesToMTP( const auto sentEntities = Api::EntitiesToMTP(
_session,
sending.entities);
auto sentEntities = Api::EntitiesToMTP(
_session, _session,
sending.entities, sending.entities,
Api::ConvertOption::SkipLocal); Api::ConvertOption::SkipLocal);
@ -4227,39 +4203,23 @@ void ApiWrap::sendMessage(MessageToSend &&message) {
? _session->user()->name ? _session->user()->name
: QString(); : QString();
if (action.options.scheduled) { if (action.options.scheduled) {
flags |= MTPDmessage::Flag::f_from_scheduled; flags |= MessageFlag::IsOrWasScheduled;
sendFlags |= MTPmessages_SendMessage::Flag::f_schedule_date; sendFlags |= MTPmessages_SendMessage::Flag::f_schedule_date;
} else { } else {
clientFlags |= MTPDmessage_ClientFlag::f_local_history_entry; flags |= MessageFlag::LocalHistoryEntry;
} }
const auto views = 1; const auto viaBotId = UserId();
const auto forwards = 0; lastMessage = history->addNewLocalMessage(
lastMessage = history->addNewMessage( newId.msg,
MTP_message( flags,
MTP_flags(flags), viaBotId,
MTP_int(newId.msg), action.replyTo,
peerToMTP(messageFromId), HistoryItem::NewMessageDate(action.options.scheduled),
peerToMTP(peer->id), messageFromId,
MTPMessageFwdHeader(), messagePostAuthor,
MTPint(), // via_bot_id sending,
replyHeader, media,
MTP_int( MTPReplyMarkup());
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);
histories.sendRequest(history, requestType, [=](Fn<void()> finish) { histories.sendRequest(history, requestType, [=](Fn<void()> finish) {
history->sendRequestId = request(MTPmessages_SendMessage( history->sendRequestId = request(MTPmessages_SendMessage(
MTP_flags(sendFlags), MTP_flags(sendFlags),
@ -4346,11 +4306,10 @@ void ApiWrap::sendInlineResult(
_session->data().nextLocalMessageId()); _session->data().nextLocalMessageId());
const auto randomId = openssl::RandomValue<uint64>(); const auto randomId = openssl::RandomValue<uint64>();
auto flags = NewMessageFlags(peer) | MTPDmessage::Flag::f_media; auto flags = NewMessageFlags(peer);
auto clientFlags = NewMessageClientFlags();
auto sendFlags = MTPmessages_SendInlineBotResult::Flag::f_clear_draft | 0; auto sendFlags = MTPmessages_SendInlineBotResult::Flag::f_clear_draft | 0;
if (action.replyTo) { if (action.replyTo) {
flags |= MTPDmessage::Flag::f_reply_to; flags |= MessageFlag::HasReplyInfo;
sendFlags |= MTPmessages_SendInlineBotResult::Flag::f_reply_to_msg_id; sendFlags |= MTPmessages_SendInlineBotResult::Flag::f_reply_to_msg_id;
} }
const auto anonymousPost = peer->amAnonymous(); const auto anonymousPost = peer->amAnonymous();
@ -4360,13 +4319,13 @@ void ApiWrap::sendInlineResult(
sendFlags |= MTPmessages_SendInlineBotResult::Flag::f_silent; sendFlags |= MTPmessages_SendInlineBotResult::Flag::f_silent;
} }
if (bot) { if (bot) {
flags |= MTPDmessage::Flag::f_via_bot_id; flags |= MessageFlag::HasViaBot;
} }
if (action.options.scheduled) { if (action.options.scheduled) {
flags |= MTPDmessage::Flag::f_from_scheduled; flags |= MessageFlag::IsOrWasScheduled;
sendFlags |= MTPmessages_SendInlineBotResult::Flag::f_schedule_date; sendFlags |= MTPmessages_SendInlineBotResult::Flag::f_schedule_date;
} else { } else {
clientFlags |= MTPDmessage_ClientFlag::f_local_history_entry; flags |= MessageFlag::LocalHistoryEntry;
} }
const auto messageFromId = anonymousPost ? 0 : _session->userPeerId(); const auto messageFromId = anonymousPost ? 0 : _session->userPeerId();
@ -4379,10 +4338,9 @@ void ApiWrap::sendInlineResult(
data->addToHistory( data->addToHistory(
history, history,
flags, flags,
clientFlags,
newId.msg, newId.msg,
messageFromId, messageFromId,
MTP_int(HistoryItem::NewMessageDate(action.options.scheduled)), HistoryItem::NewMessageDate(action.options.scheduled),
bot ? peerToUser(bot->id) : 0, bot ? peerToUser(bot->id) : 0,
action.replyTo, action.replyTo,
messagePostAuthor); messagePostAuthor);

View file

@ -286,24 +286,25 @@ AdminLog::OwnedItem GenerateTextItem(
bool out) { bool out) {
Expects(history->peer->isUser()); Expects(history->peer->isUser());
using Flag = MTPDmessage::Flag;
static auto id = ServerMaxMsgId + (ServerMaxMsgId / 3); static auto id = ServerMaxMsgId + (ServerMaxMsgId / 3);
const auto flags = Flag::f_entities const auto flags = MessageFlag::FakeHistoryItem
| Flag::f_from_id | MessageFlag::HasFromId
| (out ? Flag::f_out : Flag(0)); | (out ? MessageFlag::Outgoing : MessageFlag(0));
const auto clientFlags = MTPDmessage_ClientFlag::f_fake_history_item; const auto replyTo = MsgId();
const auto replyTo = 0; const auto viaBotId = UserId();
const auto viaBotId = UserId(0); const auto groupedId = uint64();
const auto item = history->makeMessage( const auto item = history->makeMessage(
++id, ++id,
flags, flags,
clientFlags,
replyTo, replyTo,
viaBotId, viaBotId,
base::unixtime::now(), base::unixtime::now(),
out ? history->session().userId() : peerToUser(history->peer->id), out ? history->session().userId() : peerToUser(history->peer->id),
QString(), QString(),
TextWithEntities{ TextUtilities::Clean(text) }); TextWithEntities{ TextUtilities::Clean(text) },
MTP_messageMediaEmpty(),
MTPReplyMarkup(),
groupedId);
return AdminLog::OwnedItem(delegate, item); return AdminLog::OwnedItem(delegate, item);
} }

View file

@ -398,7 +398,7 @@ void BoxController::receivedCalls(const QVector<MTPMessage> &result) {
if (const auto peer = session().data().peerLoaded(peerId)) { if (const auto peer = session().data().peerLoaded(peerId)) {
const auto item = session().data().addNewMessage( const auto item = session().data().addNewMessage(
message, message,
MTPDmessage_ClientFlags(), MessageFlags(),
NewMessageType::Existing); NewMessageType::Existing);
insertRow(item, InsertWay::Append); insertRow(item, InsertWay::Append);
} else { } else {

View file

@ -30,7 +30,7 @@ constexpr auto kMessagesPerPage = 50;
const QString &text) { const QString &text) {
return history->makeServiceMessage( return history->makeServiceMessage(
history->session().data().nextNonHistoryEntryId(), history->session().data().nextNonHistoryEntryId(),
MTPDmessage_ClientFlag::f_fake_history_item, MessageFlag::FakeHistoryItem,
date, date,
HistoryService::PreparedText{ text }); HistoryService::PreparedText{ text });
} }
@ -538,7 +538,7 @@ bool RepliesList::processMessagesIsEmpty(const MTPmessages_Messages &result) {
const auto maxId = IdFromMessage(list.front()); const auto maxId = IdFromMessage(list.front());
const auto wasSize = int(_list.size()); const auto wasSize = int(_list.size());
const auto toFront = (wasSize > 0) && (maxId > _list.front()); const auto toFront = (wasSize > 0) && (maxId > _list.front());
const auto clientFlags = MTPDmessage_ClientFlags(); const auto localFlags = MessageFlags();
const auto type = NewMessageType::Existing; const auto type = NewMessageType::Existing;
auto refreshed = std::vector<MsgId>(); auto refreshed = std::vector<MsgId>();
if (toFront) { if (toFront) {
@ -546,7 +546,7 @@ bool RepliesList::processMessagesIsEmpty(const MTPmessages_Messages &result) {
} }
auto skipped = 0; auto skipped = 0;
for (const auto &message : list) { 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 (item->replyToTop() == _rootId) {
if (toFront) { if (toFront) {
refreshed.push_back(item->id); refreshed.push_back(item->id);

View file

@ -158,6 +158,7 @@ void ScheduledMessages::sendNowSimpleMessage(
not_null<HistoryItem*> local) { not_null<HistoryItem*> local) {
Expects(local->isSending()); Expects(local->isSending());
Expects(local->isScheduled()); Expects(local->isScheduled());
if (HasScheduledDate(local)) { if (HasScheduledDate(local)) {
LOG(("Error: trying to put to history a new local message, " LOG(("Error: trying to put to history a new local message, "
"that has scheduled date.")); "that has scheduled date."));
@ -175,17 +176,19 @@ void ScheduledMessages::sendNowSimpleMessage(
auto action = Api::SendAction(history); auto action = Api::SendAction(history);
action.replyTo = local->replyToId(); action.replyTo = local->replyToId();
const auto replyHeader = NewMessageReplyHeader(action); const auto replyHeader = NewMessageReplyHeader(action);
auto flags = NewMessageFlags(history->peer) const auto localFlags = NewMessageFlags(history->peer)
| MTPDmessage::Flag::f_entities | MessageFlag::LocalHistoryEntry;
const auto flags = MTPDmessage::Flag::f_entities
| MTPDmessage::Flag::f_from_id | MTPDmessage::Flag::f_from_id
| (local->replyToId() | (local->replyToId()
? MTPDmessage::Flag::f_reply_to ? MTPDmessage::Flag::f_reply_to
: MTPDmessage::Flag(0)) : MTPDmessage::Flag(0))
| (update.vttl_period() | (update.vttl_period()
? MTPDmessage::Flag::f_ttl_period ? MTPDmessage::Flag::f_ttl_period
: MTPDmessage::Flag(0))
| ((localFlags & MessageFlag::Outgoing)
? MTPDmessage::Flag::f_out
: MTPDmessage::Flag(0)); : MTPDmessage::Flag(0));
auto clientFlags = NewMessageClientFlags()
| MTPDmessage_ClientFlag::f_local_history_entry;
const auto views = 1; const auto views = 1;
const auto forwards = 0; const auto forwards = 0;
history->addNewMessage( history->addNewMessage(
@ -213,7 +216,7 @@ void ScheduledMessages::sendNowSimpleMessage(
//MTPMessageReactions(), //MTPMessageReactions(),
MTPVector<MTPRestrictionReason>(), MTPVector<MTPRestrictionReason>(),
MTP_int(update.vttl_period().value_or_empty())), MTP_int(update.vttl_period().value_or_empty())),
clientFlags, localFlags,
NewMessageType::Unread); NewMessageType::Unread);
local->destroy(); local->destroy();
@ -459,7 +462,7 @@ HistoryItem *ScheduledMessages::append(
const auto item = _session->data().addNewMessage( const auto item = _session->data().addNewMessage(
PrepareMessage(message, history->nextNonHistoryEntryId()), PrepareMessage(message, history->nextNonHistoryEntryId()),
MTPDmessage_ClientFlags(), MessageFlags(), // localFlags
NewMessageType::Existing); NewMessageType::Existing);
if (!item || item->history() != history) { if (!item || item->history() != history) {
LOG(("API Error: Bad data received in scheduled messages.")); LOG(("API Error: Bad data received in scheduled messages."));

View file

@ -161,7 +161,7 @@ SearchResult ParseSearchResult(
for (const auto &message : *messages) { for (const auto &message : *messages) {
const auto item = peer->owner().addNewMessage( const auto item = peer->owner().addNewMessage(
message, message,
MTPDmessage_ClientFlags(), MessageFlags(),
addType); addType);
if (item) { if (item) {
const auto itemId = item->id; const auto itemId = item->id;

View file

@ -1964,7 +1964,7 @@ void Session::processMessages(
for (const auto &[position, index] : indices) { for (const auto &[position, index] : indices) {
addNewMessage( addNewMessage(
data[index], data[index],
MTPDmessage_ClientFlags(), MessageFlags(),
type); type);
} }
} }
@ -2281,7 +2281,7 @@ void Session::unmuteByFinished() {
HistoryItem *Session::addNewMessage( HistoryItem *Session::addNewMessage(
const MTPMessage &data, const MTPMessage &data,
MTPDmessage_ClientFlags clientFlags, MessageFlags localFlags,
NewMessageType type) { NewMessageType type) {
const auto peerId = PeerFromMessage(data); const auto peerId = PeerFromMessage(data);
if (!peerId) { if (!peerId) {
@ -2290,7 +2290,7 @@ HistoryItem *Session::addNewMessage(
const auto result = history(peerId)->addNewMessage( const auto result = history(peerId)->addNewMessage(
data, data,
clientFlags, localFlags,
type); type);
if (result && type == NewMessageType::Unread) { if (result && type == NewMessageType::Unread) {
CheckForSwitchInlineButton(result); CheckForSwitchInlineButton(result);
@ -4062,8 +4062,8 @@ void Session::insertCheckedServiceNotification(
const auto flags = MTPDmessage::Flag::f_entities const auto flags = MTPDmessage::Flag::f_entities
| MTPDmessage::Flag::f_from_id | MTPDmessage::Flag::f_from_id
| MTPDmessage::Flag::f_media; | MTPDmessage::Flag::f_media;
const auto clientFlags = MTPDmessage_ClientFlag::f_clientside_unread const auto localFlags = MessageFlag::ClientSideUnread
| MTPDmessage_ClientFlag::f_local_history_entry; | MessageFlag::LocalHistoryEntry;
auto sending = TextWithEntities(), left = message; auto sending = TextWithEntities(), left = message;
while (TextUtilities::CutPart(sending, left, MaxMessageSize)) { while (TextUtilities::CutPart(sending, left, MaxMessageSize)) {
addNewMessage( addNewMessage(
@ -4089,7 +4089,7 @@ void Session::insertCheckedServiceNotification(
//MTPMessageReactions(), //MTPMessageReactions(),
MTPVector<MTPRestrictionReason>(), MTPVector<MTPRestrictionReason>(),
MTPint()), // ttl_period MTPint()), // ttl_period
clientFlags, localFlags,
NewMessageType::Unread); NewMessageType::Unread);
} }
sendHistoryChangeNotifications(); sendHistoryChangeNotifications();

View file

@ -400,7 +400,7 @@ public:
HistoryItem *addNewMessage( HistoryItem *addNewMessage(
const MTPMessage &data, const MTPMessage &data,
MTPDmessage_ClientFlags flags, MessageFlags localFlags,
NewMessageType type); NewMessageType type);
struct SendActionAnimationUpdate { struct SendActionAnimationUpdate {

View file

@ -364,3 +364,61 @@ struct StickerSetIdentifier {
return !empty(); 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>;

View file

@ -2047,7 +2047,7 @@ bool InnerWidget::searchReceived(
if (lastDate) { if (lastDate) {
const auto item = session().data().addNewMessage( const auto item = session().data().addNewMessage(
message, message,
MTPDmessage_ClientFlags(), MessageFlags(),
NewMessageType::Existing); NewMessageType::Existing);
const auto history = item->history(); const auto history = item->history();
if (!uniquePeers || !hasHistoryInResults(history)) { if (!uniquePeers || !hasHistoryInResults(history)) {

View file

@ -520,10 +520,9 @@ void GenerateItems(
message.links.push_back(fromLink); message.links.push_back(fromLink);
addPart(history->makeServiceMessage( addPart(history->makeServiceMessage(
history->nextNonHistoryEntryId(), history->nextNonHistoryEntryId(),
MTPDmessage_ClientFlag::f_admin_log_entry, MessageFlag::AdminLogEntry,
date, date,
message, message,
MTPDmessage::Flags(0),
peerToUser(from->id), peerToUser(from->id),
photo)); photo));
}; };
@ -540,6 +539,29 @@ void GenerateItems(
addSimpleServiceMessage(text); 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 createChangeAbout = [&](const MTPDchannelAdminLogEventActionChangeAbout &action) {
auto newValue = qs(action.vnew_value()); auto newValue = qs(action.vnew_value());
auto oldValue = qs(action.vprev_value()); auto oldValue = qs(action.vprev_value());
@ -553,21 +575,8 @@ void GenerateItems(
)(tr::now, lt_from, fromLinkText); )(tr::now, lt_from, fromLinkText);
addSimpleServiceMessage(text); 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 newDescription = PrepareText(newValue, QString());
auto body = history->makeMessage( auto body = makeSimpleTextMessage(PrepareText(newValue, QString()));
history->nextNonHistoryEntryId(),
bodyFlags,
bodyClientFlags,
bodyReplyTo,
bodyViaBotId,
date,
peerToUser(from->id),
QString(),
newDescription);
if (!oldValue.isEmpty()) { if (!oldValue.isEmpty()) {
auto oldDescription = PrepareText(oldValue, QString()); auto oldDescription = PrepareText(oldValue, QString());
body->addLogEntryOriginal(id, tr::lng_admin_log_previous_description(tr::now), oldDescription); body->addLogEntryOriginal(id, tr::lng_admin_log_previous_description(tr::now), oldDescription);
@ -588,25 +597,20 @@ void GenerateItems(
)(tr::now, lt_from, fromLinkText); )(tr::now, lt_from, fromLinkText);
addSimpleServiceMessage(text); addSimpleServiceMessage(text);
auto bodyFlags = Flag::f_entities | Flag::f_from_id; auto bodyFlags = MessageFlag::Outgoing | MessageFlag::AdminLogEntry;
auto bodyClientFlags = MTPDmessage_ClientFlag::f_admin_log_entry; auto bodyReplyTo = MsgId();
auto bodyReplyTo = 0; auto bodyViaBotId = UserId();
auto bodyViaBotId = 0; auto bodyGroupedId = uint64();
auto newLink = newValue.isEmpty() auto newLink = newValue.isEmpty()
? TextWithEntities() ? TextWithEntities()
: PrepareText( : PrepareText(
history->session().createInternalLinkFull(newValue), history->session().createInternalLinkFull(newValue),
QString()); QString());
auto body = history->makeMessage( auto body = makeSimpleTextMessage(newValue.isEmpty()
history->nextNonHistoryEntryId(), ? TextWithEntities()
bodyFlags, : PrepareText(
bodyClientFlags, history->session().createInternalLinkFull(newValue),
bodyReplyTo, QString()));
bodyViaBotId,
date,
peerToUser(from->id),
QString(),
newLink);
if (!oldValue.isEmpty()) { if (!oldValue.isEmpty()) {
auto oldLink = PrepareText( auto oldLink = PrepareText(
history->session().createInternalLinkFull(oldValue), history->session().createInternalLinkFull(oldValue),
@ -668,7 +672,7 @@ void GenerateItems(
action.vmessage(), action.vmessage(),
history->nextNonHistoryEntryId(), history->nextNonHistoryEntryId(),
date), date),
MTPDmessage_ClientFlag::f_admin_log_entry, MessageFlag::AdminLogEntry,
detachExistingItem), detachExistingItem),
ExtractSentDate(action.vmessage())); ExtractSentDate(action.vmessage()));
}, [&](const auto &) { }, [&](const auto &) {
@ -697,7 +701,7 @@ void GenerateItems(
action.vnew_message(), action.vnew_message(),
history->nextNonHistoryEntryId(), history->nextNonHistoryEntryId(),
date), date),
MTPDmessage_ClientFlag::f_admin_log_entry, MessageFlag::AdminLogEntry,
detachExistingItem); detachExistingItem);
if (oldValue.text.isEmpty()) { if (oldValue.text.isEmpty()) {
oldValue = PrepareText(QString(), tr::lng_admin_log_empty_text(tr::now)); oldValue = PrepareText(QString(), tr::lng_admin_log_empty_text(tr::now));
@ -723,7 +727,7 @@ void GenerateItems(
action.vmessage(), action.vmessage(),
history->nextNonHistoryEntryId(), history->nextNonHistoryEntryId(),
date), date),
MTPDmessage_ClientFlag::f_admin_log_entry, MessageFlag::AdminLogEntry,
detachExistingItem), detachExistingItem),
ExtractSentDate(action.vmessage())); ExtractSentDate(action.vmessage()));
}; };
@ -743,39 +747,13 @@ void GenerateItems(
}; };
auto createParticipantInvite = [&](const MTPDchannelAdminLogEventActionParticipantInvite &action) { auto createParticipantInvite = [&](const MTPDchannelAdminLogEventActionParticipantInvite &action) {
auto bodyFlags = Flag::f_entities | Flag::f_from_id; addSimpleTextMessage(
auto bodyClientFlags = MTPDmessage_ClientFlag::f_admin_log_entry; GenerateParticipantChangeText(channel, action.vparticipant()));
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));
}; };
auto createParticipantToggleBan = [&](const MTPDchannelAdminLogEventActionParticipantToggleBan &action) { auto createParticipantToggleBan = [&](const MTPDchannelAdminLogEventActionParticipantToggleBan &action) {
auto bodyFlags = Flag::f_entities | Flag::f_from_id; addSimpleTextMessage(
auto bodyClientFlags = MTPDmessage_ClientFlag::f_admin_log_entry; GenerateParticipantChangeText(channel, action.vnew_participant(), &action.vprev_participant()));
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));
}; };
auto createParticipantToggleAdmin = [&](const MTPDchannelAdminLogEventActionParticipantToggleAdmin &action) { auto createParticipantToggleAdmin = [&](const MTPDchannelAdminLogEventActionParticipantToggleAdmin &action) {
@ -785,21 +763,8 @@ void GenerateItems(
// the "User > Creator" part and skip the "Creator > Admin" part. // the "User > Creator" part and skip the "Creator > Admin" part.
return; return;
} }
auto bodyFlags = Flag::f_entities | Flag::f_from_id; addSimpleTextMessage(
auto bodyClientFlags = MTPDmessage_ClientFlag::f_admin_log_entry; GenerateParticipantChangeText(channel, action.vnew_participant(), &action.vprev_participant()));
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));
}; };
auto createChangeStickerSet = [&](const MTPDchannelAdminLogEventActionChangeStickerSet &action) { auto createChangeStickerSet = [&](const MTPDchannelAdminLogEventActionChangeStickerSet &action) {
@ -825,10 +790,9 @@ void GenerateItems(
message.links.push_back(setLink); message.links.push_back(setLink);
addPart(history->makeServiceMessage( addPart(history->makeServiceMessage(
history->nextNonHistoryEntryId(), history->nextNonHistoryEntryId(),
MTPDmessage_ClientFlag::f_admin_log_entry, MessageFlag::AdminLogEntry,
date, date,
message, message,
MTPDmessage::Flags(0),
peerToUser(from->id))); peerToUser(from->id)));
} }
}; };
@ -842,24 +806,11 @@ void GenerateItems(
}; };
auto createDefaultBannedRights = [&](const MTPDchannelAdminLogEventActionDefaultBannedRights &action) { auto createDefaultBannedRights = [&](const MTPDchannelAdminLogEventActionDefaultBannedRights &action) {
auto bodyFlags = Flag::f_entities | Flag::f_from_id; addSimpleTextMessage(
auto bodyClientFlags = MTPDmessage_ClientFlag::f_admin_log_entry; GenerateDefaultBannedRightsChangeText(
auto bodyReplyTo = 0; channel,
auto bodyViaBotId = 0; ChatRestrictionsInfo(action.vnew_banned_rights()),
auto bodyText = GenerateDefaultBannedRightsChangeText( ChatRestrictionsInfo(action.vprev_banned_rights())));
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));
}; };
auto createStopPoll = [&](const MTPDchannelAdminLogEventActionStopPoll &action) { auto createStopPoll = [&](const MTPDchannelAdminLogEventActionStopPoll &action) {
@ -873,7 +824,7 @@ void GenerateItems(
action.vmessage(), action.vmessage(),
history->nextNonHistoryEntryId(), history->nextNonHistoryEntryId(),
date), date),
MTPDmessage_ClientFlag::f_admin_log_entry, MessageFlag::AdminLogEntry,
detachExistingItem), detachExistingItem),
ExtractSentDate(action.vmessage())); ExtractSentDate(action.vmessage()));
}; };
@ -906,10 +857,9 @@ void GenerateItems(
message.links.push_back(chatLink); message.links.push_back(chatLink);
addPart(history->makeServiceMessage( addPart(history->makeServiceMessage(
history->nextNonHistoryEntryId(), history->nextNonHistoryEntryId(),
MTPDmessage_ClientFlag::f_admin_log_entry, MessageFlag::AdminLogEntry,
date, date,
message, message,
MTPDmessage::Flags(0),
peerToUser(from->id))); peerToUser(from->id)));
} }
}; };
@ -977,10 +927,9 @@ void GenerateItems(
message.links.push_back(link); message.links.push_back(link);
addPart(history->makeServiceMessage( addPart(history->makeServiceMessage(
history->nextNonHistoryEntryId(), history->nextNonHistoryEntryId(),
MTPDmessage_ClientFlag::f_admin_log_entry, MessageFlag::AdminLogEntry,
date, date,
message, message,
MTPDmessage::Flags(0),
peerToUser(from->id))); peerToUser(from->id)));
}; };
@ -1025,10 +974,9 @@ void GenerateItems(
} }
addPart(history->makeServiceMessage( addPart(history->makeServiceMessage(
history->nextNonHistoryEntryId(), history->nextNonHistoryEntryId(),
MTPDmessage_ClientFlag::f_admin_log_entry, MessageFlag::AdminLogEntry,
date, date,
message, message,
MTPDmessage::Flags(0),
peerToUser(from->id), peerToUser(from->id),
nullptr)); nullptr));
}; };
@ -1070,21 +1018,8 @@ void GenerateItems(
}; };
auto createExportedInviteEdit = [&](const MTPDchannelAdminLogEventActionExportedInviteEdit &data) { auto createExportedInviteEdit = [&](const MTPDchannelAdminLogEventActionExportedInviteEdit &data) {
auto bodyFlags = Flag::f_entities | Flag::f_from_id; addSimpleTextMessage(
auto bodyClientFlags = MTPDmessage_ClientFlag::f_admin_log_entry; GenerateInviteLinkChangeText(data.vnew_invite(), data.vprev_invite()));
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));
}; };
auto createParticipantVolume = [&](const MTPDchannelAdminLogEventActionParticipantVolume &data) { auto createParticipantVolume = [&](const MTPDchannelAdminLogEventActionParticipantVolume &data) {

View file

@ -349,7 +349,7 @@ void History::setForwardDraft(MessageIdsList &&items) {
HistoryItem *History::createItem( HistoryItem *History::createItem(
const MTPMessage &message, const MTPMessage &message,
MTPDmessage_ClientFlags clientFlags, MessageFlags localFlags,
bool detachExistingItem) { bool detachExistingItem) {
const auto messageId = IdFromMessage(message); const auto messageId = IdFromMessage(message);
if (!messageId) { if (!messageId) {
@ -362,17 +362,17 @@ HistoryItem *History::createItem(
} }
return result; return result;
} }
return HistoryItem::Create(this, message, clientFlags); return HistoryItem::Create(this, message, localFlags);
} }
std::vector<not_null<HistoryItem*>> History::createItems( std::vector<not_null<HistoryItem*>> History::createItems(
const QVector<MTPMessage> &data) { const QVector<MTPMessage> &data) {
auto result = std::vector<not_null<HistoryItem*>>(); auto result = std::vector<not_null<HistoryItem*>>();
result.reserve(data.size()); result.reserve(data.size());
const auto clientFlags = MTPDmessage_ClientFlags(); const auto localFlags = MessageFlags();
for (auto i = data.cend(), e = data.cbegin(); i != e;) { for (auto i = data.cend(), e = data.cbegin(); i != e;) {
const auto detachExistingItem = true; const auto detachExistingItem = true;
const auto item = createItem(*--i, clientFlags, detachExistingItem); const auto item = createItem(*--i, localFlags, detachExistingItem);
if (item) { if (item) {
result.emplace_back(item); result.emplace_back(item);
} }
@ -382,10 +382,10 @@ std::vector<not_null<HistoryItem*>> History::createItems(
HistoryItem *History::addNewMessage( HistoryItem *History::addNewMessage(
const MTPMessage &msg, const MTPMessage &msg,
MTPDmessage_ClientFlags clientFlags, MessageFlags localFlags,
NewMessageType type) { NewMessageType type) {
const auto detachExistingItem = (type == NewMessageType::Unread); const auto detachExistingItem = (type == NewMessageType::Unread);
const auto item = createItem(msg, clientFlags, detachExistingItem); const auto item = createItem(msg, localFlags, detachExistingItem);
if (!item) { if (!item) {
return nullptr; return nullptr;
} }
@ -515,8 +515,35 @@ void History::checkForLoadedAtTop(not_null<HistoryItem*> added) {
not_null<HistoryItem*> History::addNewLocalMessage( not_null<HistoryItem*> History::addNewLocalMessage(
MsgId id, MsgId id,
MTPDmessage::Flags flags, MessageFlags flags,
MTPDmessage_ClientFlags clientFlags, 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, TimeId date,
PeerId from, PeerId from,
const QString &postAuthor, const QString &postAuthor,
@ -525,7 +552,6 @@ not_null<HistoryItem*> History::addNewLocalMessage(
makeMessage( makeMessage(
id, id,
flags, flags,
clientFlags,
date, date,
from, from,
postAuthor, postAuthor,
@ -535,8 +561,7 @@ not_null<HistoryItem*> History::addNewLocalMessage(
not_null<HistoryItem*> History::addNewLocalMessage( not_null<HistoryItem*> History::addNewLocalMessage(
MsgId id, MsgId id,
MTPDmessage::Flags flags, MessageFlags flags,
MTPDmessage_ClientFlags clientFlags,
UserId viaBotId, UserId viaBotId,
MsgId replyTo, MsgId replyTo,
TimeId date, TimeId date,
@ -549,7 +574,6 @@ not_null<HistoryItem*> History::addNewLocalMessage(
makeMessage( makeMessage(
id, id,
flags, flags,
clientFlags,
replyTo, replyTo,
viaBotId, viaBotId,
date, date,
@ -563,8 +587,7 @@ not_null<HistoryItem*> History::addNewLocalMessage(
not_null<HistoryItem*> History::addNewLocalMessage( not_null<HistoryItem*> History::addNewLocalMessage(
MsgId id, MsgId id,
MTPDmessage::Flags flags, MessageFlags flags,
MTPDmessage_ClientFlags clientFlags,
UserId viaBotId, UserId viaBotId,
MsgId replyTo, MsgId replyTo,
TimeId date, TimeId date,
@ -577,7 +600,6 @@ not_null<HistoryItem*> History::addNewLocalMessage(
makeMessage( makeMessage(
id, id,
flags, flags,
clientFlags,
replyTo, replyTo,
viaBotId, viaBotId,
date, date,
@ -591,8 +613,7 @@ not_null<HistoryItem*> History::addNewLocalMessage(
not_null<HistoryItem*> History::addNewLocalMessage( not_null<HistoryItem*> History::addNewLocalMessage(
MsgId id, MsgId id,
MTPDmessage::Flags flags, MessageFlags flags,
MTPDmessage_ClientFlags clientFlags,
UserId viaBotId, UserId viaBotId,
MsgId replyTo, MsgId replyTo,
TimeId date, TimeId date,
@ -604,7 +625,6 @@ not_null<HistoryItem*> History::addNewLocalMessage(
makeMessage( makeMessage(
id, id,
flags, flags,
clientFlags,
replyTo, replyTo,
viaBotId, viaBotId,
date, date,
@ -696,10 +716,10 @@ void History::addUnreadMentionsSlice(const MTPmessages_Messages &result) {
auto added = false; auto added = false;
if (messages) { if (messages) {
const auto clientFlags = MTPDmessage_ClientFlags(); const auto localFlags = MessageFlags();
const auto type = NewMessageType::Existing; const auto type = NewMessageType::Existing;
for (const auto &message : *messages) { for (const auto &message : *messages) {
if (const auto item = addNewMessage(message, clientFlags, type)) { if (const auto item = addNewMessage(message, localFlags, type)) {
if (item->isUnreadMention()) { if (item->isUnreadMention()) {
_unreadMentions.insert(item->id); _unreadMentions.insert(item->id);
added = true; added = true;
@ -2352,7 +2372,7 @@ void History::setFakeChatListMessageFrom(const MTPmessages_Messages &data) {
} }
const auto item = owner().addNewMessage( const auto item = owner().addNewMessage(
*other, *other,
MTPDmessage_ClientFlags(), MessageFlags(),
NewMessageType::Existing); NewMessageType::Existing);
if (!item || item->isGroupMigrate()) { if (!item || item->isGroupMigrate()) {
// Not better than the last one. // Not better than the last one.
@ -2785,9 +2805,8 @@ HistoryService *History::insertJoinedMessage() {
return nullptr; return nullptr;
} }
const auto flags = MTPDmessage::Flags();
const auto inviteDate = peer->asChannel()->inviteDate; const auto inviteDate = peer->asChannel()->inviteDate;
_joinedMessage = GenerateJoinedMessage(this, inviteDate, inviter, flags); _joinedMessage = GenerateJoinedMessage(this, inviteDate, inviter);
insertLocalMessage(_joinedMessage); insertLocalMessage(_joinedMessage);
return _joinedMessage; return _joinedMessage;
} }

View file

@ -118,23 +118,33 @@ public:
HistoryItem *addNewMessage( HistoryItem *addNewMessage(
const MTPMessage &msg, const MTPMessage &msg,
MTPDmessage_ClientFlags clientFlags, MessageFlags localFlags,
NewMessageType type); NewMessageType type);
HistoryItem *addToHistory( HistoryItem *addToHistory(
const MTPMessage &msg, const MTPMessage &msg,
MTPDmessage_ClientFlags clientFlags); MessageFlags localFlags);
not_null<HistoryItem*> addNewLocalMessage( not_null<HistoryItem*> addNewLocalMessage(
MsgId id, MsgId id,
MTPDmessage::Flags flags, MessageFlags flags,
MTPDmessage_ClientFlags clientFlags, 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, TimeId date,
PeerId from, PeerId from,
const QString &postAuthor, const QString &postAuthor,
not_null<HistoryMessage*> forwardOriginal); not_null<HistoryMessage*> forwardOriginal);
not_null<HistoryItem*> addNewLocalMessage( not_null<HistoryItem*> addNewLocalMessage(
MsgId id, MsgId id,
MTPDmessage::Flags flags, MessageFlags flags,
MTPDmessage_ClientFlags clientFlags,
UserId viaBotId, UserId viaBotId,
MsgId replyTo, MsgId replyTo,
TimeId date, TimeId date,
@ -145,8 +155,7 @@ public:
const MTPReplyMarkup &markup); const MTPReplyMarkup &markup);
not_null<HistoryItem*> addNewLocalMessage( not_null<HistoryItem*> addNewLocalMessage(
MsgId id, MsgId id,
MTPDmessage::Flags flags, MessageFlags flags,
MTPDmessage_ClientFlags clientFlags,
UserId viaBotId, UserId viaBotId,
MsgId replyTo, MsgId replyTo,
TimeId date, TimeId date,
@ -157,8 +166,7 @@ public:
const MTPReplyMarkup &markup); const MTPReplyMarkup &markup);
not_null<HistoryItem*> addNewLocalMessage( not_null<HistoryItem*> addNewLocalMessage(
MsgId id, MsgId id,
MTPDmessage::Flags flags, MessageFlags flags,
MTPDmessage_ClientFlags clientFlags,
UserId viaBotId, UserId viaBotId,
MsgId replyTo, MsgId replyTo,
TimeId date, TimeId date,
@ -170,7 +178,7 @@ public:
// Used only internally and for channel admin log. // Used only internally and for channel admin log.
HistoryItem *createItem( HistoryItem *createItem(
const MTPMessage &message, const MTPMessage &message,
MTPDmessage_ClientFlags clientFlags, MessageFlags localFlags,
bool detachExistingItem); bool detachExistingItem);
std::vector<not_null<HistoryItem*>> createItems( std::vector<not_null<HistoryItem*>> createItems(
const QVector<MTPMessage> &data); const QVector<MTPMessage> &data);

View file

@ -59,8 +59,7 @@ enum class MediaCheckResult {
not_null<HistoryItem*> CreateUnsupportedMessage( not_null<HistoryItem*> CreateUnsupportedMessage(
not_null<History*> history, not_null<History*> history,
MsgId msgId, MsgId msgId,
MTPDmessage::Flags flags, MessageFlags flags,
MTPDmessage_ClientFlags clientFlags,
MsgId replyTo, MsgId replyTo,
UserId viaBotId, UserId viaBotId,
TimeId date, TimeId date,
@ -72,18 +71,21 @@ not_null<HistoryItem*> CreateUnsupportedMessage(
TextUtilities::ParseEntities(text, Ui::ItemTextNoMonoOptions().flags); TextUtilities::ParseEntities(text, Ui::ItemTextNoMonoOptions().flags);
text.entities.push_front( text.entities.push_front(
EntityInText(EntityType::Italic, 0, text.text.size())); EntityInText(EntityType::Italic, 0, text.text.size()));
flags &= ~MTPDmessage::Flag::f_post_author; flags &= ~MessageFlag::HasPostAuthor;
flags |= MTPDmessage::Flag::f_legacy; flags |= MessageFlag::Legacy;
const auto groupedId = uint64();
return history->makeMessage( return history->makeMessage(
msgId, msgId,
flags, flags,
clientFlags,
replyTo, replyTo,
viaBotId, viaBotId,
date, date,
from, from,
QString(), QString(),
text); text,
MTP_messageMediaEmpty(),
MTPReplyMarkup(),
groupedId);
} }
MediaCheckResult CheckMessageMedia(const MTPMessageMedia &media) { MediaCheckResult CheckMessageMedia(const MTPMessageMedia &media) {
@ -170,15 +172,13 @@ void HistoryItem::HistoryItem::Destroyer::operator()(HistoryItem *value) {
HistoryItem::HistoryItem( HistoryItem::HistoryItem(
not_null<History*> history, not_null<History*> history,
MsgId id, MsgId id,
MTPDmessage::Flags flags, MessageFlags flags,
MTPDmessage_ClientFlags clientFlags,
TimeId date, TimeId date,
PeerId from) PeerId from)
: id(id) : id(id)
, _history(history) , _history(history)
, _from(from ? history->owner().peer(from) : history->peer) , _from(from ? history->owner().peer(from) : history->peer)
, _flags(flags) , _flags(flags)
, _clientFlags(clientFlags)
, _date(date) { , _date(date) {
if (isHistoryEntry() && IsClientMsgId(id)) { if (isHistoryEntry() && IsClientMsgId(id)) {
_history->registerLocalMessage(this); _history->registerLocalMessage(this);
@ -318,11 +318,11 @@ bool HistoryItem::hasUnreadMediaFlag() const {
return false; return false;
} }
} }
return _flags & MTPDmessage::Flag::f_media_unread; return _flags & MessageFlag::MediaIsUnread;
} }
bool HistoryItem::isUnreadMention() const { bool HistoryItem::isUnreadMention() const {
return mentionsMe() && (_flags & MTPDmessage::Flag::f_media_unread); return mentionsMe() && (_flags & MessageFlag::MediaIsUnread);
} }
bool HistoryItem::mentionsMe() const { bool HistoryItem::mentionsMe() const {
@ -330,7 +330,7 @@ bool HistoryItem::mentionsMe() const {
&& !Core::App().settings().notifyAboutPinned()) { && !Core::App().settings().notifyAboutPinned()) {
return false; return false;
} }
return _flags & MTPDmessage::Flag::f_mentioned; return _flags & MessageFlag::MentionsMe;
} }
bool HistoryItem::isUnreadMedia() const { bool HistoryItem::isUnreadMedia() const {
@ -347,7 +347,7 @@ bool HistoryItem::isUnreadMedia() const {
} }
void HistoryItem::markMediaRead() { void HistoryItem::markMediaRead() {
_flags &= ~MTPDmessage::Flag::f_media_unread; _flags &= ~MessageFlag::MediaIsUnread;
if (mentionsMe()) { if (mentionsMe()) {
history()->updateChatListEntry(); history()->updateChatListEntry();
@ -358,7 +358,7 @@ void HistoryItem::markMediaRead() {
void HistoryItem::setIsPinned(bool pinned) { void HistoryItem::setIsPinned(bool pinned) {
const auto changed = (isPinned() != pinned); const auto changed = (isPinned() != pinned);
if (pinned) { if (pinned) {
_flags |= MTPDmessage::Flag::f_pinned; _flags |= MessageFlag::Pinned;
history()->session().storage().add(Storage::SharedMediaAddExisting( history()->session().storage().add(Storage::SharedMediaAddExisting(
history()->peer->id, history()->peer->id,
Storage::SharedMediaType::Pinned, Storage::SharedMediaType::Pinned,
@ -366,7 +366,7 @@ void HistoryItem::setIsPinned(bool pinned) {
{ id, id })); { id, id }));
history()->peer->setHasPinnedMessages(true); history()->peer->setHasPinnedMessages(true);
} else { } else {
_flags &= ~MTPDmessage::Flag::f_pinned; _flags &= ~MessageFlag::Pinned;
history()->session().storage().remove(Storage::SharedMediaRemoveOne( history()->session().storage().remove(Storage::SharedMediaRemoveOne(
history()->peer->id, history()->peer->id,
Storage::SharedMediaType::Pinned, Storage::SharedMediaType::Pinned,
@ -387,7 +387,7 @@ bool HistoryItem::definesReplyKeyboard() const {
// optimization: don't create markup component for the case // optimization: don't create markup component for the case
// MTPDreplyKeyboardHide with flags = 0, assume it has f_zero flag // 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 { ReplyMarkupFlags HistoryItem::replyKeyboardFlags() const {
@ -441,22 +441,22 @@ UserData *HistoryItem::getMessageBot() const {
bool HistoryItem::isHistoryEntry() const { bool HistoryItem::isHistoryEntry() const {
return IsServerMsgId(id) return IsServerMsgId(id)
|| (_clientFlags & MTPDmessage_ClientFlag::f_local_history_entry); || (_flags & MessageFlag::LocalHistoryEntry);
} }
bool HistoryItem::isAdminLogEntry() const { bool HistoryItem::isAdminLogEntry() const {
return (_clientFlags & MTPDmessage_ClientFlag::f_admin_log_entry); return (_flags & MessageFlag::AdminLogEntry);
} }
bool HistoryItem::isFromScheduled() const { bool HistoryItem::isFromScheduled() const {
return isHistoryEntry() return isHistoryEntry()
&& (_flags & MTPDmessage::Flag::f_from_scheduled); && (_flags & MessageFlag::IsOrWasScheduled);
} }
bool HistoryItem::isScheduled() const { bool HistoryItem::isScheduled() const {
return !isHistoryEntry() return !isHistoryEntry()
&& !isAdminLogEntry() && !isAdminLogEntry()
&& (_flags & MTPDmessage::Flag::f_from_scheduled); && (_flags & MessageFlag::IsOrWasScheduled);
} }
void HistoryItem::destroy() { void HistoryItem::destroy() {
@ -560,11 +560,11 @@ void HistoryItem::indexAsNewItem() {
} }
void HistoryItem::setRealId(MsgId newId) { void HistoryItem::setRealId(MsgId newId) {
Expects(_clientFlags & MTPDmessage_ClientFlag::f_sending); Expects(_flags & MessageFlag::BeingSent);
Expects(IsClientMsgId(id)); Expects(IsClientMsgId(id));
const auto oldId = std::exchange(id, newId); const auto oldId = std::exchange(id, newId);
_clientFlags &= ~MTPDmessage_ClientFlag::f_sending; _flags &= ~MessageFlag::BeingSent;
if (IsServerMsgId(id)) { if (IsServerMsgId(id)) {
_history->unregisterLocalMessage(this); _history->unregisterLocalMessage(this);
} }
@ -846,11 +846,10 @@ void HistoryItem::applyTTL(TimeId destroyAt) {
} }
void HistoryItem::sendFailed() { void HistoryItem::sendFailed() {
Expects(_clientFlags & MTPDmessage_ClientFlag::f_sending); Expects(_flags & MessageFlag::BeingSent);
Expects(!(_clientFlags & MTPDmessage_ClientFlag::f_failed)); Expects(!(_flags & MessageFlag::SendingFailed));
_clientFlags = (_clientFlags | MTPDmessage_ClientFlag::f_failed) _flags = (_flags | MessageFlag::SendingFailed) & ~MessageFlag::BeingSent;
& ~MTPDmessage_ClientFlag::f_sending;
history()->session().changes().historyUpdated( history()->session().changes().historyUpdated(
history(), history(),
Data::HistoryUpdate::Flag::LocalMessages); Data::HistoryUpdate::Flag::LocalMessages);
@ -895,7 +894,7 @@ bool HistoryItem::unread() const {
} }
return true; return true;
} }
return (_clientFlags & MTPDmessage_ClientFlag::f_clientside_unread); return (_flags & MessageFlag::ClientSideUnread);
} }
bool HistoryItem::showNotification() const { bool HistoryItem::showNotification() const {
@ -909,7 +908,7 @@ bool HistoryItem::showNotification() const {
} }
void HistoryItem::markClientSideAsRead() { void HistoryItem::markClientSideAsRead() {
_clientFlags &= ~MTPDmessage_ClientFlag::f_clientside_unread; _flags &= ~MessageFlag::ClientSideUnread;
} }
MessageGroupId HistoryItem::groupId() const { 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<HistoryItem*> HistoryItem::Create(
not_null<History*> history, not_null<History*> history,
const MTPMessage &message, const MTPMessage &message,
MTPDmessage_ClientFlags clientFlags) { MessageFlags localFlags) {
return message.match([&](const MTPDmessage &data) -> HistoryItem* { return message.match([&](const MTPDmessage &data) -> HistoryItem* {
const auto media = data.vmedia(); const auto media = data.vmedia();
const auto checked = media const auto checked = media
@ -1057,8 +1089,7 @@ not_null<HistoryItem*> HistoryItem::Create(
return CreateUnsupportedMessage( return CreateUnsupportedMessage(
history, history,
data.vid().v, data.vid().v,
data.vflags().v, FlagsFromMTP(data.vflags().v) | localFlags,
clientFlags,
MsgId(0), // No need to pass reply_to data here. MsgId(0), // No need to pass reply_to data here.
data.vvia_bot_id().value_or_empty(), data.vvia_bot_id().value_or_empty(),
data.vdate().v, data.vdate().v,
@ -1069,27 +1100,26 @@ not_null<HistoryItem*> HistoryItem::Create(
}; };
return history->makeServiceMessage( return history->makeServiceMessage(
data.vid().v, data.vid().v,
clientFlags, FlagsFromMTP(data.vflags().v) | localFlags,
data.vdate().v, data.vdate().v,
text, text,
data.vflags().v,
data.vfrom_id() ? peerFromMTP(*data.vfrom_id()) : PeerId(0)); data.vfrom_id() ? peerFromMTP(*data.vfrom_id()) : PeerId(0));
} else if (checked == MediaCheckResult::HasTimeToLive) { } 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* { }, [&](const MTPDmessageService &data) -> HistoryItem* {
if (data.vaction().type() == mtpc_messageActionPhoneCall) { 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 MTPDmessageEmpty &data) -> HistoryItem* {
const auto text = HistoryService::PreparedText{ const auto text = HistoryService::PreparedText{
tr::lng_message_empty(tr::now) tr::lng_message_empty(tr::now)
}; };
return history->makeServiceMessage( return history->makeServiceMessage(
data.vid().v, data.vid().v,
clientFlags, localFlags,
TimeId(0), TimeId(0),
text); text);
}); });

View file

@ -69,12 +69,15 @@ enum class ReplyMarkupFlag : uint32 {
inline constexpr bool is_flag_type(ReplyMarkupFlag) { return true; } inline constexpr bool is_flag_type(ReplyMarkupFlag) { return true; }
using ReplyMarkupFlags = base::flags<ReplyMarkupFlag>; using ReplyMarkupFlags = base::flags<ReplyMarkupFlag>;
[[nodiscard]] MessageFlags FlagsFromMTP(MTPDmessage::Flags flags);
[[nodiscard]] MessageFlags FlagsFromMTP(MTPDmessageService::Flags flags);
class HistoryItem : public RuntimeComposer<HistoryItem> { class HistoryItem : public RuntimeComposer<HistoryItem> {
public: public:
static not_null<HistoryItem*> Create( static not_null<HistoryItem*> Create(
not_null<History*> history, not_null<History*> history,
const MTPMessage &message, const MTPMessage &message,
MTPDmessage_ClientFlags clientFlags); MessageFlags localFlags);
struct Destroyer { struct Destroyer {
void operator()(HistoryItem *value); void operator()(HistoryItem *value);
@ -125,10 +128,10 @@ public:
void destroy(); void destroy();
[[nodiscard]] bool out() const { [[nodiscard]] bool out() const {
return _flags & MTPDmessage::Flag::f_out; return _flags & MessageFlag::Outgoing;
} }
[[nodiscard]] bool isPinned() const { [[nodiscard]] bool isPinned() const {
return _flags & MTPDmessage::Flag::f_pinned; return _flags & MessageFlag::Pinned;
} }
[[nodiscard]] bool unread() const; [[nodiscard]] bool unread() const;
[[nodiscard]] bool showNotification() const; [[nodiscard]] bool showNotification() const;
@ -164,44 +167,44 @@ public:
[[nodiscard]] ReplyMarkupFlags replyKeyboardFlags() const; [[nodiscard]] ReplyMarkupFlags replyKeyboardFlags() const;
[[nodiscard]] bool hasSwitchInlineButton() const { [[nodiscard]] bool hasSwitchInlineButton() const {
return _clientFlags & MTPDmessage_ClientFlag::f_has_switch_inline_button; return _flags & MessageFlag::HasSwitchInlineButton;
} }
[[nodiscard]] bool hasTextLinks() const { [[nodiscard]] bool hasTextLinks() const {
return _clientFlags & MTPDmessage_ClientFlag::f_has_text_links; return _flags & MessageFlag::HasTextLinks;
} }
[[nodiscard]] bool isGroupEssential() const { [[nodiscard]] bool isGroupEssential() const {
return _clientFlags & MTPDmessage_ClientFlag::f_is_group_essential; return _flags & MessageFlag::IsGroupEssential;
} }
[[nodiscard]] bool isLocalUpdateMedia() const { [[nodiscard]] bool isLocalUpdateMedia() const {
return _clientFlags & MTPDmessage_ClientFlag::f_is_local_update_media; return _flags & MessageFlag::IsLocalUpdateMedia;
} }
void setIsLocalUpdateMedia(bool flag) { void setIsLocalUpdateMedia(bool flag) {
if (flag) { if (flag) {
_clientFlags |= MTPDmessage_ClientFlag::f_is_local_update_media; _flags |= MessageFlag::IsLocalUpdateMedia;
} else { } else {
_clientFlags &= ~MTPDmessage_ClientFlag::f_is_local_update_media; _flags &= ~MessageFlag::IsLocalUpdateMedia;
} }
} }
[[nodiscard]] bool isGroupMigrate() const { [[nodiscard]] bool isGroupMigrate() const {
return isGroupEssential() && isEmpty(); return isGroupEssential() && isEmpty();
} }
[[nodiscard]] bool isIsolatedEmoji() const { [[nodiscard]] bool isIsolatedEmoji() const {
return _clientFlags & MTPDmessage_ClientFlag::f_isolated_emoji; return _flags & MessageFlag::IsolatedEmoji;
} }
[[nodiscard]] bool hasViews() const { [[nodiscard]] bool hasViews() const {
return _flags & MTPDmessage::Flag::f_views; return _flags & MessageFlag::HasViews;
} }
[[nodiscard]] bool isPost() const { [[nodiscard]] bool isPost() const {
return _flags & MTPDmessage::Flag::f_post; return _flags & MessageFlag::Post;
} }
[[nodiscard]] bool isSilent() const { [[nodiscard]] bool isSilent() const {
return _flags & MTPDmessage::Flag::f_silent; return _flags & MessageFlag::Silent;
} }
[[nodiscard]] bool isSending() const { [[nodiscard]] bool isSending() const {
return _clientFlags & MTPDmessage_ClientFlag::f_sending; return _flags & MessageFlag::BeingSent;
} }
[[nodiscard]] bool hasFailed() const { [[nodiscard]] bool hasFailed() const {
return _clientFlags & MTPDmessage_ClientFlag::f_failed; return _flags & MessageFlag::SendingFailed;
} }
void sendFailed(); void sendFailed();
[[nodiscard]] virtual int viewsCount() const { [[nodiscard]] virtual int viewsCount() const {
@ -422,8 +425,7 @@ protected:
HistoryItem( HistoryItem(
not_null<History*> history, not_null<History*> history,
MsgId id, MsgId id,
MTPDmessage::Flags flags, MessageFlags flags,
MTPDmessage_ClientFlags clientFlags,
TimeId date, TimeId date,
PeerId from); PeerId from);
@ -436,8 +438,7 @@ protected:
const not_null<History*> _history; const not_null<History*> _history;
not_null<PeerData*> _from; not_null<PeerData*> _from;
MTPDmessage::Flags _flags = 0; MessageFlags _flags = 0;
MTPDmessage_ClientFlags _clientFlags = 0;
void invalidateChatListEntry(); void invalidateChatListEntry();

View file

@ -56,39 +56,29 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
namespace { namespace {
[[nodiscard]] MTPDmessage::Flags NewForwardedFlags( [[nodiscard]] MessageFlags NewForwardedFlags(
not_null<PeerData*> peer, not_null<PeerData*> peer,
PeerId from, PeerId from,
not_null<HistoryMessage*> fwd) { not_null<HistoryMessage*> fwd) {
auto result = NewMessageFlags(peer) | MTPDmessage::Flag::f_fwd_from; auto result = NewMessageFlags(peer);
if (from) { if (from) {
result |= MTPDmessage::Flag::f_from_id; result |= MessageFlag::HasFromId;
} }
if (fwd->Has<HistoryMessageVia>()) { if (fwd->Has<HistoryMessageVia>()) {
result |= MTPDmessage::Flag::f_via_bot_id; result |= MessageFlag::HasViaBot;
} }
if (const auto media = fwd->media()) { 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()) if ((!peer->isChannel() || peer->isMegagroup())
&& media->forwardedBecomesUnread()) { && media->forwardedBecomesUnread()) {
result |= MTPDmessage::Flag::f_media_unread; result |= MessageFlag::MediaIsUnread;
} }
} }
if (fwd->hasViews()) { if (fwd->hasViews()) {
result |= MTPDmessage::Flag::f_views; result |= MessageFlag::HasViews;
} }
return result; return result;
} }
[[nodiscard]] MTPDmessage_ClientFlags NewForwardedClientFlags() {
return NewMessageClientFlags();
}
[[nodiscard]] bool CopyMarkupToForward(not_null<const HistoryItem*> item) { [[nodiscard]] bool CopyMarkupToForward(not_null<const HistoryItem*> item) {
auto mediaOriginal = item->media(); auto mediaOriginal = item->media();
if (mediaOriginal && mediaOriginal->game()) { if (mediaOriginal && mediaOriginal->game()) {
@ -369,15 +359,9 @@ Fn<void(ChannelData*, MsgId)> HistoryDependentItemCallback(
}; };
} }
MTPDmessage::Flags NewMessageFlags(not_null<PeerData*> peer) { MessageFlags NewMessageFlags(not_null<PeerData*> peer) {
MTPDmessage::Flags result = 0; return MessageFlag::BeingSent
if (!peer->isSelf()) { | (peer->isSelf() ? MessageFlag() : MessageFlag::Outgoing);
result |= MTPDmessage::Flag::f_out;
//if (p->isChat() || (p->isUser() && !p->asUser()->isBot())) {
// result |= MTPDmessage::Flag::f_unread;
//}
}
return result;
} }
bool ShouldSendSilent( bool ShouldSendSilent(
@ -415,10 +399,6 @@ MTPMessageReplyHeader NewMessageReplyHeader(const Api::SendAction &action) {
return MTPMessageReplyHeader(); return MTPMessageReplyHeader();
} }
MTPDmessage_ClientFlags NewMessageClientFlags() {
return MTPDmessage_ClientFlag::f_sending;
}
QString GetErrorTextForSending( QString GetErrorTextForSending(
not_null<PeerData*> peer, not_null<PeerData*> peer,
const HistoryItemsList &items, const HistoryItemsList &items,
@ -475,12 +455,11 @@ void HistoryMessage::FillForwardedInfo(
HistoryMessage::HistoryMessage( HistoryMessage::HistoryMessage(
not_null<History*> history, not_null<History*> history,
const MTPDmessage &data, const MTPDmessage &data,
MTPDmessage_ClientFlags clientFlags) MessageFlags localFlags)
: HistoryItem( : HistoryItem(
history, history,
data.vid().v, data.vid().v,
data.vflags().v, FlagsFromMTP(data.vflags().v) | localFlags,
clientFlags,
data.vdate().v, data.vdate().v,
data.vfrom_id() ? peerFromMTP(*data.vfrom_id()) : PeerId(0)) { data.vfrom_id() ? peerFromMTP(*data.vfrom_id()) : PeerId(0)) {
auto config = CreateConfig(); auto config = CreateConfig();
@ -532,12 +511,11 @@ HistoryMessage::HistoryMessage(
HistoryMessage::HistoryMessage( HistoryMessage::HistoryMessage(
not_null<History*> history, not_null<History*> history,
const MTPDmessageService &data, const MTPDmessageService &data,
MTPDmessage_ClientFlags clientFlags) MessageFlags localFlags)
: HistoryItem( : HistoryItem(
history, history,
data.vid().v, data.vid().v,
mtpCastFlags(data.vflags().v), FlagsFromMTP(data.vflags().v) | localFlags,
clientFlags,
data.vdate().v, data.vdate().v,
data.vfrom_id() ? peerFromMTP(*data.vfrom_id()) : PeerId(0)) { data.vfrom_id() ? peerFromMTP(*data.vfrom_id()) : PeerId(0)) {
auto config = CreateConfig(); auto config = CreateConfig();
@ -570,8 +548,7 @@ HistoryMessage::HistoryMessage(
HistoryMessage::HistoryMessage( HistoryMessage::HistoryMessage(
not_null<History*> history, not_null<History*> history,
MsgId id, MsgId id,
MTPDmessage::Flags flags, MessageFlags flags,
MTPDmessage_ClientFlags clientFlags,
TimeId date, TimeId date,
PeerId from, PeerId from,
const QString &postAuthor, const QString &postAuthor,
@ -580,7 +557,6 @@ HistoryMessage::HistoryMessage(
history, history,
id, id,
NewForwardedFlags(history->peer, from, original) | flags, NewForwardedFlags(history->peer, from, original) | flags,
NewForwardedClientFlags() | clientFlags,
date, date,
from) { from) {
const auto peer = history->peer; const auto peer = history->peer;
@ -615,7 +591,7 @@ HistoryMessage::HistoryMessage(
config.savedFromMsgId = original->id; config.savedFromMsgId = original->id;
//} //}
} }
if (flags & MTPDmessage::Flag::f_post_author) { if (flags & MessageFlag::HasPostAuthor) {
config.author = postAuthor; config.author = postAuthor;
} }
if (const auto fwdViaBot = original->viaBot()) { if (const auto fwdViaBot = original->viaBot()) {
@ -654,36 +630,34 @@ HistoryMessage::HistoryMessage(
HistoryMessage::HistoryMessage( HistoryMessage::HistoryMessage(
not_null<History*> history, not_null<History*> history,
MsgId id, MsgId id,
MTPDmessage::Flags flags, MessageFlags flags,
MTPDmessage_ClientFlags clientFlags,
MsgId replyTo, MsgId replyTo,
UserId viaBotId, UserId viaBotId,
TimeId date, TimeId date,
PeerId from, PeerId from,
const QString &postAuthor, const QString &postAuthor,
const TextWithEntities &textWithEntities) const TextWithEntities &textWithEntities,
const MTPMessageMedia &media,
const MTPReplyMarkup &markup,
uint64 groupedId)
: HistoryItem( : HistoryItem(
history, history,
id, id,
flags & ~MTPDmessage::Flag::f_reply_markup, flags,
clientFlags,
date, date,
(flags & MTPDmessage::Flag::f_from_id) ? from : 0) { (flags & MessageFlag::HasFromId) ? from : 0) {
createComponentsHelper( createComponentsHelper(flags, replyTo, viaBotId, postAuthor, markup);
flags & ~MTPDmessage::Flag::f_reply_markup, setMedia(media);
replyTo,
viaBotId,
postAuthor,
MTPReplyMarkup());
setText(textWithEntities); setText(textWithEntities);
if (groupedId) {
setGroupId(MessageGroupId::FromRaw(history->peer->id, groupedId));
}
} }
HistoryMessage::HistoryMessage( HistoryMessage::HistoryMessage(
not_null<History*> history, not_null<History*> history,
MsgId id, MsgId id,
MTPDmessage::Flags flags, MessageFlags flags,
MTPDmessage_ClientFlags clientFlags,
MsgId replyTo, MsgId replyTo,
UserId viaBotId, UserId viaBotId,
TimeId date, TimeId date,
@ -696,9 +670,8 @@ HistoryMessage::HistoryMessage(
history, history,
id, id,
flags, flags,
clientFlags,
date, date,
(flags & MTPDmessage::Flag::f_from_id) ? from : 0) { (flags & MessageFlag::HasFromId) ? from : 0) {
createComponentsHelper(flags, replyTo, viaBotId, postAuthor, markup); createComponentsHelper(flags, replyTo, viaBotId, postAuthor, markup);
_media = std::make_unique<Data::MediaFile>(this, document); _media = std::make_unique<Data::MediaFile>(this, document);
@ -708,8 +681,7 @@ HistoryMessage::HistoryMessage(
HistoryMessage::HistoryMessage( HistoryMessage::HistoryMessage(
not_null<History*> history, not_null<History*> history,
MsgId id, MsgId id,
MTPDmessage::Flags flags, MessageFlags flags,
MTPDmessage_ClientFlags clientFlags,
MsgId replyTo, MsgId replyTo,
UserId viaBotId, UserId viaBotId,
TimeId date, TimeId date,
@ -722,9 +694,8 @@ HistoryMessage::HistoryMessage(
history, history,
id, id,
flags, flags,
clientFlags,
date, date,
(flags & MTPDmessage::Flag::f_from_id) ? from : 0) { (flags & MessageFlag::HasFromId) ? from : 0) {
createComponentsHelper(flags, replyTo, viaBotId, postAuthor, markup); createComponentsHelper(flags, replyTo, viaBotId, postAuthor, markup);
_media = std::make_unique<Data::MediaPhoto>(this, photo); _media = std::make_unique<Data::MediaPhoto>(this, photo);
@ -734,8 +705,7 @@ HistoryMessage::HistoryMessage(
HistoryMessage::HistoryMessage( HistoryMessage::HistoryMessage(
not_null<History*> history, not_null<History*> history,
MsgId id, MsgId id,
MTPDmessage::Flags flags, MessageFlags flags,
MTPDmessage_ClientFlags clientFlags,
MsgId replyTo, MsgId replyTo,
UserId viaBotId, UserId viaBotId,
TimeId date, TimeId date,
@ -747,9 +717,8 @@ HistoryMessage::HistoryMessage(
history, history,
id, id,
flags, flags,
clientFlags,
date, date,
(flags & MTPDmessage::Flag::f_from_id) ? from : 0) { (flags & MessageFlag::HasFromId) ? from : 0) {
createComponentsHelper(flags, replyTo, viaBotId, postAuthor, markup); createComponentsHelper(flags, replyTo, viaBotId, postAuthor, markup);
_media = std::make_unique<Data::MediaGame>(this, game); _media = std::make_unique<Data::MediaGame>(this, game);
@ -757,22 +726,22 @@ HistoryMessage::HistoryMessage(
} }
void HistoryMessage::createComponentsHelper( void HistoryMessage::createComponentsHelper(
MTPDmessage::Flags flags, MessageFlags flags,
MsgId replyTo, MsgId replyTo,
UserId viaBotId, UserId viaBotId,
const QString &postAuthor, const QString &postAuthor,
const MTPReplyMarkup &markup) { const MTPReplyMarkup &markup) {
auto config = CreateConfig(); auto config = CreateConfig();
if (flags & MTPDmessage::Flag::f_via_bot_id) config.viaBotId = viaBotId; if (flags & MessageFlag::HasViaBot) config.viaBotId = viaBotId;
if (flags & MTPDmessage::Flag::f_reply_to) { if (flags & MessageFlag::HasReplyInfo) {
config.replyTo = replyTo; config.replyTo = replyTo;
const auto replyToTop = LookupReplyToTop(history(), replyTo); const auto replyToTop = LookupReplyToTop(history(), replyTo);
config.replyToTop = replyToTop ? replyToTop : replyTo; config.replyToTop = replyToTop ? replyToTop : replyTo;
} }
if (flags & MTPDmessage::Flag::f_reply_markup) config.mtpMarkup = &markup; if (flags & MessageFlag::HasReplyMarkup) config.mtpMarkup = &markup;
if (flags & MTPDmessage::Flag::f_post_author) config.author = postAuthor; if (flags & MessageFlag::HasPostAuthor) config.author = postAuthor;
if (flags & MTPDmessage::Flag::f_views) config.viewsCount = 1; if (flags & MessageFlag::HasViews) config.viewsCount = 1;
createComponents(config); createComponents(config);
} }
@ -1133,7 +1102,7 @@ void HistoryMessage::createComponents(const CreateConfig &config) {
markup->create(*config.inlineMarkup); markup->create(*config.inlineMarkup);
} }
if (markup->flags & ReplyMarkupFlag::HasSwitchInlineButton) { if (markup->flags & ReplyMarkupFlag::HasSwitchInlineButton) {
_clientFlags |= MTPDmessage_ClientFlag::f_has_switch_inline_button; _flags |= MessageFlag::HasSwitchInlineButton;
} }
} }
const auto from = displayFrom(); const auto from = displayFrom();
@ -1341,7 +1310,6 @@ std::unique_ptr<Data::Media> HistoryMessage::CreateMedia(
}, [](const MTPDmessageMediaUnsupported &) -> Result { }, [](const MTPDmessageMediaUnsupported &) -> Result {
return nullptr; return nullptr;
}); });
return nullptr;
} }
void HistoryMessage::replaceBuyWithReceiptInMarkup() { void HistoryMessage::replaceBuyWithReceiptInMarkup() {
@ -1372,11 +1340,14 @@ void HistoryMessage::applyEdition(const MTPDmessage &message) {
// } // }
//} //}
const auto copyFlags = MTPDmessage::Flag::f_edit_hide; if (message.is_edit_hide()) {
_flags = (_flags & ~copyFlags) | (message.vflags().v & copyFlags); _flags |= MessageFlag::HideEdited;
} else {
_flags &= ~MessageFlag::HideEdited;
}
if (const auto editDate = message.vedit_date()) { if (const auto editDate = message.vedit_date()) {
_flags |= MTPDmessage::Flag::f_edit_date; //_flags |= MTPDmessage::Flag::f_edit_date;
if (!Has<HistoryMessageEdited>()) { if (!Has<HistoryMessageEdited>()) {
AddComponents(HistoryMessageEdited::Bit()); AddComponents(HistoryMessageEdited::Bit());
} }
@ -1434,11 +1405,11 @@ void HistoryMessage::updateSentContent(
const MTPMessageMedia *media) { const MTPMessageMedia *media) {
const auto isolated = isolatedEmoji(); const auto isolated = isolatedEmoji();
setText(textWithEntities); setText(textWithEntities);
if (_clientFlags & MTPDmessage_ClientFlag::f_from_inline_bot) { if (_flags & MessageFlag::FromInlineBot) {
if (!media || !_media || !_media->updateInlineResultMedia(*media)) { if (!media || !_media || !_media->updateInlineResultMedia(*media)) {
refreshSentMedia(media); refreshSentMedia(media);
} }
_clientFlags &= ~MTPDmessage_ClientFlag::f_from_inline_bot; _flags &= ~MessageFlag::FromInlineBot;
} else if (media || _media || !isolated || isolated != isolatedEmoji()) { } else if (media || _media || !isolated || isolated != isolatedEmoji()) {
if (!media || !_media || !_media->updateSentMedia(*media)) { if (!media || !_media || !_media->updateSentMedia(*media)) {
refreshSentMedia(media); refreshSentMedia(media);
@ -1548,7 +1519,7 @@ void HistoryMessage::setText(const TextWithEntities &textWithEntities) {
if (type == EntityType::Url if (type == EntityType::Url
|| type == EntityType::CustomUrl || type == EntityType::CustomUrl
|| type == EntityType::Email) { || type == EntityType::Email) {
_clientFlags |= MTPDmessage_ClientFlag::f_has_text_links; _flags |= MessageFlag::HasTextLinks;
break; break;
} }
} }
@ -1599,16 +1570,16 @@ void HistoryMessage::setEmptyText() {
} }
void HistoryMessage::clearIsolatedEmoji() { void HistoryMessage::clearIsolatedEmoji() {
if (!(_clientFlags & MTPDmessage_ClientFlag::f_isolated_emoji)) { if (!(_flags & MessageFlag::IsolatedEmoji)) {
return; return;
} }
history()->session().emojiStickersPack().remove(this); history()->session().emojiStickersPack().remove(this);
_clientFlags &= ~MTPDmessage_ClientFlag::f_isolated_emoji; _flags &= ~MessageFlag::IsolatedEmoji;
} }
void HistoryMessage::checkIsolatedEmoji() { void HistoryMessage::checkIsolatedEmoji() {
if (history()->session().emojiStickersPack().add(this)) { 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); Data::MessageUpdate::Flag::ReplyMarkup);
}; };
if (!markup) { if (!markup) {
if (_flags & MTPDmessage::Flag::f_reply_markup) { if (_flags & MessageFlag::HasReplyMarkup) {
_flags &= ~MTPDmessage::Flag::f_reply_markup; _flags &= ~MessageFlag::HasReplyMarkup;
if (Has<HistoryMessageReplyMarkup>()) { if (Has<HistoryMessageReplyMarkup>()) {
RemoveComponents(HistoryMessageReplyMarkup::Bit()); RemoveComponents(HistoryMessageReplyMarkup::Bit());
} }
@ -1632,22 +1603,23 @@ void HistoryMessage::setReplyMarkup(const MTPReplyMarkup *markup) {
// optimization: don't create markup component for the case // optimization: don't create markup component for the case
// MTPDreplyKeyboardHide with flags = 0, assume it has f_zero flag // 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; bool changed = false;
if (Has<HistoryMessageReplyMarkup>()) { if (Has<HistoryMessageReplyMarkup>()) {
RemoveComponents(HistoryMessageReplyMarkup::Bit()); RemoveComponents(HistoryMessageReplyMarkup::Bit());
changed = true; changed = true;
} }
if (!(_flags & MTPDmessage::Flag::f_reply_markup)) { if (!(_flags & MessageFlag::HasReplyMarkup)) {
_flags |= MTPDmessage::Flag::f_reply_markup; _flags |= MessageFlag::HasReplyMarkup;
changed = true; changed = true;
} }
if (changed) { if (changed) {
requestUpdate(); requestUpdate();
} }
} else { } else {
if (!(_flags & MTPDmessage::Flag::f_reply_markup)) { if (!(_flags & MessageFlag::HasReplyMarkup)) {
_flags |= MTPDmessage::Flag::f_reply_markup; _flags |= MessageFlag::HasReplyMarkup;
} }
if (!Has<HistoryMessageReplyMarkup>()) { if (!Has<HistoryMessageReplyMarkup>()) {
AddComponents(HistoryMessageReplyMarkup::Bit()); AddComponents(HistoryMessageReplyMarkup::Bit());

View file

@ -24,11 +24,10 @@ struct HistoryMessageViews;
[[nodiscard]] Fn<void(ChannelData*, MsgId)> HistoryDependentItemCallback( [[nodiscard]] Fn<void(ChannelData*, MsgId)> HistoryDependentItemCallback(
not_null<HistoryItem*> item); not_null<HistoryItem*> item);
[[nodiscard]] MTPDmessage::Flags NewMessageFlags(not_null<PeerData*> peer); [[nodiscard]] MessageFlags NewMessageFlags(not_null<PeerData*> peer);
[[nodiscard]] bool ShouldSendSilent( [[nodiscard]] bool ShouldSendSilent(
not_null<PeerData*> peer, not_null<PeerData*> peer,
const Api::SendOptions &options); const Api::SendOptions &options);
[[nodiscard]] MTPDmessage_ClientFlags NewMessageClientFlags();
[[nodiscard]] MsgId LookupReplyToTop( [[nodiscard]] MsgId LookupReplyToTop(
not_null<History*> history, not_null<History*> history,
MsgId replyToId); MsgId replyToId);
@ -50,16 +49,15 @@ public:
HistoryMessage( HistoryMessage(
not_null<History*> history, not_null<History*> history,
const MTPDmessage &data, const MTPDmessage &data,
MTPDmessage_ClientFlags clientFlags); MessageFlags localFlags);
HistoryMessage( HistoryMessage(
not_null<History*> history, not_null<History*> history,
const MTPDmessageService &data, const MTPDmessageService &data,
MTPDmessage_ClientFlags clientFlags); MessageFlags localFlags);
HistoryMessage( HistoryMessage(
not_null<History*> history, not_null<History*> history,
MsgId id, MsgId id,
MTPDmessage::Flags flags, MessageFlags flags,
MTPDmessage_ClientFlags clientFlags,
TimeId date, TimeId date,
PeerId from, PeerId from,
const QString &postAuthor, const QString &postAuthor,
@ -67,19 +65,20 @@ public:
HistoryMessage( HistoryMessage(
not_null<History*> history, not_null<History*> history,
MsgId id, MsgId id,
MTPDmessage::Flags flags, MessageFlags flags,
MTPDmessage_ClientFlags clientFlags,
MsgId replyTo, MsgId replyTo,
UserId viaBotId, UserId viaBotId,
TimeId date, TimeId date,
PeerId from, PeerId from,
const QString &postAuthor, const QString &postAuthor,
const TextWithEntities &textWithEntities); // local message const TextWithEntities &textWithEntities,
const MTPMessageMedia &media,
const MTPReplyMarkup &markup,
uint64 groupedId); // local message
HistoryMessage( HistoryMessage(
not_null<History*> history, not_null<History*> history,
MsgId id, MsgId id,
MTPDmessage::Flags flags, MessageFlags flags,
MTPDmessage_ClientFlags clientFlags,
MsgId replyTo, MsgId replyTo,
UserId viaBotId, UserId viaBotId,
TimeId date, TimeId date,
@ -91,8 +90,7 @@ public:
HistoryMessage( HistoryMessage(
not_null<History*> history, not_null<History*> history,
MsgId id, MsgId id,
MTPDmessage::Flags flags, MessageFlags flags,
MTPDmessage_ClientFlags clientFlags,
MsgId replyTo, MsgId replyTo,
UserId viaBotId, UserId viaBotId,
TimeId date, TimeId date,
@ -104,8 +102,7 @@ public:
HistoryMessage( HistoryMessage(
not_null<History*> history, not_null<History*> history,
MsgId id, MsgId id,
MTPDmessage::Flags flags, MessageFlags flags,
MTPDmessage_ClientFlags clientFlags,
MsgId replyTo, MsgId replyTo,
UserId viaBotId, UserId viaBotId,
TimeId date, TimeId date,
@ -129,7 +126,7 @@ public:
[[nodiscard]] bool uploading() const; [[nodiscard]] bool uploading() const;
[[nodiscard]] bool hideEditedBadge() const { [[nodiscard]] bool hideEditedBadge() const {
return (_flags & MTPDmessage::Flag::f_edit_hide); return (_flags & MessageFlag::HideEdited);
} }
void setViewsCount(int count) override; void setViewsCount(int count) override;
@ -146,7 +143,18 @@ public:
[[nodiscard]] QString notificationHeader() const override; [[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 MTPDmessage &message) override;
void applyEdition(const MTPDmessageService &message) override; void applyEdition(const MTPDmessageService &message) override;
void updateSentContent( void updateSentContent(
const TextWithEntities &textWithEntities, const TextWithEntities &textWithEntities,
@ -213,7 +221,7 @@ private:
void setEmptyText(); void setEmptyText();
[[nodiscard]] bool isTooOldForEdit(TimeId now) const; [[nodiscard]] bool isTooOldForEdit(TimeId now) const;
[[nodiscard]] bool isLegacyMessage() const { [[nodiscard]] bool isLegacyMessage() const {
return _flags & MTPDmessage::Flag::f_legacy; return _flags & MessageFlag::Legacy;
} }
[[nodiscard]] bool checkCommentsLinkedChat(ChannelId id) const; [[nodiscard]] bool checkCommentsLinkedChat(ChannelId id) const;
@ -228,7 +236,12 @@ private:
void setReplyMarkup(const MTPReplyMarkup *markup); void setReplyMarkup(const MTPReplyMarkup *markup);
struct CreateConfig; 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 createComponents(const CreateConfig &config);
void setupForwardedComponent(const CreateConfig &config); void setupForwardedComponent(const CreateConfig &config);
void changeReplyToTopCounter( void changeReplyToTopCounter(

View file

@ -518,13 +518,13 @@ void HistoryService::applyAction(const MTPMessageAction &action) {
}, [](const MTPDphotoEmpty &) { }, [](const MTPDphotoEmpty &) {
}); });
}, [&](const MTPDmessageActionChatCreate &) { }, [&](const MTPDmessageActionChatCreate &) {
_clientFlags |= MTPDmessage_ClientFlag::f_is_group_essential; _flags |= MessageFlag::IsGroupEssential;
}, [&](const MTPDmessageActionChannelCreate &) { }, [&](const MTPDmessageActionChannelCreate &) {
_clientFlags |= MTPDmessage_ClientFlag::f_is_group_essential; _flags |= MessageFlag::IsGroupEssential;
}, [&](const MTPDmessageActionChatMigrateTo &) { }, [&](const MTPDmessageActionChatMigrateTo &) {
_clientFlags |= MTPDmessage_ClientFlag::f_is_group_essential; _flags |= MessageFlag::IsGroupEssential;
}, [&](const MTPDmessageActionChannelMigrateFrom &) { }, [&](const MTPDmessageActionChannelMigrateFrom &) {
_clientFlags |= MTPDmessage_ClientFlag::f_is_group_essential; _flags |= MessageFlag::IsGroupEssential;
}, [](const auto &) { }, [](const auto &) {
}); });
} }
@ -836,12 +836,11 @@ HistoryService::PreparedText HistoryService::prepareCallScheduledText(
HistoryService::HistoryService( HistoryService::HistoryService(
not_null<History*> history, not_null<History*> history,
const MTPDmessage &data, const MTPDmessage &data,
MTPDmessage_ClientFlags clientFlags) MessageFlags localFlags)
: HistoryItem( : HistoryItem(
history, history,
data.vid().v, data.vid().v,
data.vflags().v, FlagsFromMTP(data.vflags().v) | localFlags,
clientFlags,
data.vdate().v, data.vdate().v,
data.vfrom_id() ? peerFromMTP(*data.vfrom_id()) : PeerId(0)) { data.vfrom_id() ? peerFromMTP(*data.vfrom_id()) : PeerId(0)) {
createFromMtp(data); createFromMtp(data);
@ -851,12 +850,11 @@ HistoryService::HistoryService(
HistoryService::HistoryService( HistoryService::HistoryService(
not_null<History*> history, not_null<History*> history,
const MTPDmessageService &data, const MTPDmessageService &data,
MTPDmessage_ClientFlags clientFlags) MessageFlags localFlags)
: HistoryItem( : HistoryItem(
history, history,
data.vid().v, data.vid().v,
mtpCastFlags(data.vflags().v), FlagsFromMTP(data.vflags().v) | localFlags,
clientFlags,
data.vdate().v, data.vdate().v,
data.vfrom_id() ? peerFromMTP(*data.vfrom_id()) : PeerId(0)) { data.vfrom_id() ? peerFromMTP(*data.vfrom_id()) : PeerId(0)) {
createFromMtp(data); createFromMtp(data);
@ -866,13 +864,12 @@ HistoryService::HistoryService(
HistoryService::HistoryService( HistoryService::HistoryService(
not_null<History*> history, not_null<History*> history,
MsgId id, MsgId id,
MTPDmessage_ClientFlags clientFlags, MessageFlags flags,
TimeId date, TimeId date,
const PreparedText &message, const PreparedText &message,
MTPDmessage::Flags flags,
PeerId from, PeerId from,
PhotoData *photo) PhotoData *photo)
: HistoryItem(history, id, flags, clientFlags, date, from) { : HistoryItem(history, id, flags, date, from) {
setServiceText(message); setServiceText(message);
if (photo) { if (photo) {
_media = std::make_unique<Data::MediaPhoto>( _media = std::make_unique<Data::MediaPhoto>(
@ -1227,14 +1224,12 @@ HistoryService::PreparedText GenerateJoinedText(
not_null<HistoryService*> GenerateJoinedMessage( not_null<HistoryService*> GenerateJoinedMessage(
not_null<History*> history, not_null<History*> history,
TimeId inviteDate, TimeId inviteDate,
not_null<UserData*> inviter, not_null<UserData*> inviter) {
MTPDmessage::Flags flags) {
return history->makeServiceMessage( return history->makeServiceMessage(
history->owner().nextLocalMessageId(), history->owner().nextLocalMessageId(),
MTPDmessage_ClientFlag::f_local_history_entry, MessageFlag::LocalHistoryEntry,
inviteDate, inviteDate,
GenerateJoinedText(history, inviter), GenerateJoinedText(history, inviter));
flags);
} }
std::optional<bool> PeerHasThisCall( std::optional<bool> PeerHasThisCall(

View file

@ -70,18 +70,17 @@ public:
HistoryService( HistoryService(
not_null<History*> history, not_null<History*> history,
const MTPDmessage &data, const MTPDmessage &data,
MTPDmessage_ClientFlags clientFlags); MessageFlags localFlags);
HistoryService( HistoryService(
not_null<History*> history, not_null<History*> history,
const MTPDmessageService &data, const MTPDmessageService &data,
MTPDmessage_ClientFlags clientFlags); MessageFlags localFlags);
HistoryService( HistoryService(
not_null<History*> history, not_null<History*> history,
MsgId id, MsgId id,
MTPDmessage_ClientFlags clientFlags, MessageFlags flags,
TimeId date, TimeId date,
const PreparedText &message, const PreparedText &message,
MTPDmessage::Flags flags = 0,
PeerId from = 0, PeerId from = 0,
PhotoData *photo = nullptr); PhotoData *photo = nullptr);
@ -174,8 +173,7 @@ private:
[[nodiscard]] not_null<HistoryService*> GenerateJoinedMessage( [[nodiscard]] not_null<HistoryService*> GenerateJoinedMessage(
not_null<History*> history, not_null<History*> history,
TimeId inviteDate, TimeId inviteDate,
not_null<UserData*> inviter, not_null<UserData*> inviter);
MTPDmessage::Flags flags);
[[nodiscard]] std::optional<bool> PeerHasThisCall( [[nodiscard]] std::optional<bool> PeerHasThisCall(
not_null<PeerData*> peer, not_null<PeerData*> peer,
uint64 id); uint64 id);

View file

@ -385,7 +385,7 @@ private:
// This should be called only from previousInBlocksChanged() or when // This should be called only from previousInBlocksChanged() or when
// DateBadge or UnreadBar bit is changed in the Composer mask // DateBadge or UnreadBar bit is changed in the Composer mask
// then the result should be cached in a client side flag // then the result should be cached in a client side flag
// MTPDmessage_ClientFlag::f_attach_to_previous. // HistoryView::Element::Flag::AttachedToPrevious.
void recountAttachToPreviousInBlocks(); void recountAttachToPreviousInBlocks();
QSize countOptimalSize() final override; QSize countOptimalSize() final override;

View file

@ -364,29 +364,27 @@ bool Result::hasThumbDisplay() const {
void Result::addToHistory( void Result::addToHistory(
History *history, History *history,
MTPDmessage::Flags flags, MessageFlags flags,
MTPDmessage_ClientFlags clientFlags,
MsgId msgId, MsgId msgId,
PeerId fromId, PeerId fromId,
MTPint mtpDate, TimeId date,
UserId viaBotId, UserId viaBotId,
MsgId replyToId, MsgId replyToId,
const QString &postAuthor) const { const QString &postAuthor) const {
clientFlags |= MTPDmessage_ClientFlag::f_from_inline_bot; flags |= MessageFlag::FromInlineBot;
auto markup = MTPReplyMarkup(); auto markup = MTPReplyMarkup();
if (_mtpKeyboard) { if (_mtpKeyboard) {
flags |= MTPDmessage::Flag::f_reply_markup; flags |= MessageFlag::HasReplyMarkup;
markup = *_mtpKeyboard; markup = *_mtpKeyboard;
} }
sendData->addToHistory( sendData->addToHistory(
this, this,
history, history,
flags, flags,
clientFlags,
msgId, msgId,
fromId, fromId,
mtpDate, date,
viaBotId, viaBotId,
replyToId, replyToId,
postAuthor, postAuthor,

View file

@ -62,11 +62,10 @@ public:
void addToHistory( void addToHistory(
History *history, History *history,
MTPDmessage::Flags flags, MessageFlags flags,
MTPDmessage_ClientFlags clientFlags,
MsgId msgId, MsgId msgId,
PeerId fromId, PeerId fromId,
MTPint mtpDate, TimeId date,
UserId viaBotId, UserId viaBotId,
MsgId replyToId, MsgId replyToId,
const QString &postAuthor) const; const QString &postAuthor) const;

View file

@ -31,52 +31,29 @@ QString SendData::getLayoutDescription(const Result *owner) const {
void SendDataCommon::addToHistory( void SendDataCommon::addToHistory(
const Result *owner, const Result *owner,
not_null<History*> history, not_null<History*> history,
MTPDmessage::Flags flags, MessageFlags flags,
MTPDmessage_ClientFlags clientFlags,
MsgId msgId, MsgId msgId,
PeerId fromId, PeerId fromId,
MTPint mtpDate, TimeId date,
UserId viaBotId, UserId viaBotId,
MsgId replyToId, MsgId replyToId,
const QString &postAuthor, const QString &postAuthor,
const MTPReplyMarkup &markup) const { const MTPReplyMarkup &markup) const {
auto fields = getSentMessageFields(); 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) { if (replyToId) {
flags |= MTPDmessage::Flag::f_reply_to; flags |= MessageFlag::HasReplyInfo;
} }
const auto views = 1; history->addNewLocalMessage(
const auto forwards = 0; msgId,
history->addNewMessage( flags,
MTP_message( viaBotId,
MTP_flags(flags), replyToId,
MTP_int(msgId), date,
peerToMTP(fromId), fromId,
peerToMTP(history->peer->id), postAuthor,
MTPMessageFwdHeader(), std::move(fields.text),
MTP_int(viaBotId.bare), // #TODO ids std::move(fields.media),
replyHeader, markup);
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);
} }
QString SendDataCommon::getErrorOnSend( QString SendDataCommon::getErrorOnSend(
@ -88,54 +65,44 @@ QString SendDataCommon::getErrorOnSend(
return error.value_or(QString()); return error.value_or(QString());
} }
SendDataCommon::SentMTPMessageFields SendText::getSentMessageFields() const { SendDataCommon::SentMessageFields SendText::getSentMessageFields() const {
SentMTPMessageFields result; return { .text = { _message, _entities } };
result.text = MTP_string(_message);
result.entities = Api::EntitiesToMTP(&session(), _entities);
return result;
} }
SendDataCommon::SentMTPMessageFields SendGeo::getSentMessageFields() const { SendDataCommon::SentMessageFields SendGeo::getSentMessageFields() const {
SentMTPMessageFields result;
if (_period) { if (_period) {
using Flag = MTPDmessageMediaGeoLive::Flag; using Flag = MTPDmessageMediaGeoLive::Flag;
result.media = MTP_messageMediaGeoLive( return { .media = MTP_messageMediaGeoLive(
MTP_flags((_heading ? Flag::f_heading : Flag(0)) 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(), _location.toMTP(),
MTP_int(_heading.value_or(0)), MTP_int(_heading.value_or(0)),
MTP_int(*_period), MTP_int(*_period),
MTP_int(_proximityNotificationRadius.value_or(0))); MTP_int(_proximityNotificationRadius.value_or(0))) };
} else {
result.media = MTP_messageMediaGeo(_location.toMTP());
} }
return result; return { .media = MTP_messageMediaGeo(_location.toMTP()) };
} }
SendDataCommon::SentMTPMessageFields SendVenue::getSentMessageFields() const { SendDataCommon::SentMessageFields SendVenue::getSentMessageFields() const {
SentMTPMessageFields result; const auto venueType = QString();
auto venueType = QString(); return { .media = MTP_messageMediaVenue(
result.media = MTP_messageMediaVenue(
_location.toMTP(), _location.toMTP(),
MTP_string(_title), MTP_string(_title),
MTP_string(_address), MTP_string(_address),
MTP_string(_provider), MTP_string(_provider),
MTP_string(_venueId), MTP_string(_venueId),
MTP_string(venueType)); MTP_string(QString())) }; // venue_type
return result;
} }
SendDataCommon::SentMTPMessageFields SendContact::getSentMessageFields() const { SendDataCommon::SentMessageFields SendContact::getSentMessageFields() const {
SentMTPMessageFields result; return { .media = MTP_messageMediaContact(
const auto userId = 0;
const auto vcard = QString();
result.media = MTP_messageMediaContact(
MTP_string(_phoneNumber), MTP_string(_phoneNumber),
MTP_string(_firstName), MTP_string(_firstName),
MTP_string(_lastName), MTP_string(_lastName),
MTP_string(vcard), MTP_string(), // vcard
MTP_int(userId)); MTP_int(0)) }; // user_id
return result;
} }
QString SendContact::getLayoutDescription(const Result *owner) const { QString SendContact::getLayoutDescription(const Result *owner) const {
@ -149,11 +116,10 @@ QString SendContact::getLayoutDescription(const Result *owner) const {
void SendPhoto::addToHistory( void SendPhoto::addToHistory(
const Result *owner, const Result *owner,
not_null<History*> history, not_null<History*> history,
MTPDmessage::Flags flags, MessageFlags flags,
MTPDmessage_ClientFlags clientFlags,
MsgId msgId, MsgId msgId,
PeerId fromId, PeerId fromId,
MTPint mtpDate, TimeId date,
UserId viaBotId, UserId viaBotId,
MsgId replyToId, MsgId replyToId,
const QString &postAuthor, const QString &postAuthor,
@ -161,10 +127,9 @@ void SendPhoto::addToHistory(
history->addNewLocalMessage( history->addNewLocalMessage(
msgId, msgId,
flags, flags,
clientFlags,
viaBotId, viaBotId,
replyToId, replyToId,
mtpDate.v, date,
fromId, fromId,
postAuthor, postAuthor,
_photo, _photo,
@ -184,11 +149,10 @@ QString SendPhoto::getErrorOnSend(
void SendFile::addToHistory( void SendFile::addToHistory(
const Result *owner, const Result *owner,
not_null<History*> history, not_null<History*> history,
MTPDmessage::Flags flags, MessageFlags flags,
MTPDmessage_ClientFlags clientFlags,
MsgId msgId, MsgId msgId,
PeerId fromId, PeerId fromId,
MTPint mtpDate, TimeId date,
UserId viaBotId, UserId viaBotId,
MsgId replyToId, MsgId replyToId,
const QString &postAuthor, const QString &postAuthor,
@ -196,10 +160,9 @@ void SendFile::addToHistory(
history->addNewLocalMessage( history->addNewLocalMessage(
msgId, msgId,
flags, flags,
clientFlags,
viaBotId, viaBotId,
replyToId, replyToId,
mtpDate.v, date,
fromId, fromId,
postAuthor, postAuthor,
_document, _document,
@ -233,11 +196,10 @@ QString SendFile::getErrorOnSend(
void SendGame::addToHistory( void SendGame::addToHistory(
const Result *owner, const Result *owner,
not_null<History*> history, not_null<History*> history,
MTPDmessage::Flags flags, MessageFlags flags,
MTPDmessage_ClientFlags clientFlags,
MsgId msgId, MsgId msgId,
PeerId fromId, PeerId fromId,
MTPint mtpDate, TimeId date,
UserId viaBotId, UserId viaBotId,
MsgId replyToId, MsgId replyToId,
const QString &postAuthor, const QString &postAuthor,
@ -245,10 +207,9 @@ void SendGame::addToHistory(
history->addNewLocalMessage( history->addNewLocalMessage(
msgId, msgId,
flags, flags,
clientFlags,
viaBotId, viaBotId,
replyToId, replyToId,
mtpDate.v, date,
fromId, fromId,
postAuthor, postAuthor,
_game, _game,
@ -264,10 +225,8 @@ QString SendGame::getErrorOnSend(
return error.value_or(QString()); return error.value_or(QString());
} }
auto SendInvoice::getSentMessageFields() const -> SentMTPMessageFields { SendDataCommon::SentMessageFields SendInvoice::getSentMessageFields() const {
SentMTPMessageFields result; return { .media = _media };
result.media = _media;
return result;
} }
QString SendInvoice::getLayoutDescription(const Result *owner) const { QString SendInvoice::getLayoutDescription(const Result *owner) const {

View file

@ -41,11 +41,10 @@ public:
virtual void addToHistory( virtual void addToHistory(
const Result *owner, const Result *owner,
not_null<History*> history, not_null<History*> history,
MTPDmessage::Flags flags, MessageFlags flags,
MTPDmessage_ClientFlags clientFlags,
MsgId msgId, MsgId msgId,
PeerId fromId, PeerId fromId,
MTPint mtpDate, TimeId date,
UserId viaBotId, UserId viaBotId,
MsgId replyToId, MsgId replyToId,
const QString &postAuthor, const QString &postAuthor,
@ -75,21 +74,19 @@ class SendDataCommon : public SendData {
public: public:
using SendData::SendData; using SendData::SendData;
struct SentMTPMessageFields { struct SentMessageFields {
MTPString text = MTP_string(); TextWithEntities text;
MTPVector<MTPMessageEntity> entities = MTP_vector<MTPMessageEntity>();
MTPMessageMedia media = MTP_messageMediaEmpty(); MTPMessageMedia media = MTP_messageMediaEmpty();
}; };
virtual SentMTPMessageFields getSentMessageFields() const = 0; virtual SentMessageFields getSentMessageFields() const = 0;
void addToHistory( void addToHistory(
const Result *owner, const Result *owner,
not_null<History*> history, not_null<History*> history,
MTPDmessage::Flags flags, MessageFlags flags,
MTPDmessage_ClientFlags clientFlags,
MsgId msgId, MsgId msgId,
PeerId fromId, PeerId fromId,
MTPint mtpDate, TimeId date,
UserId viaBotId, UserId viaBotId,
MsgId replyToId, MsgId replyToId,
const QString &postAuthor, const QString &postAuthor,
@ -118,7 +115,7 @@ public:
return !_message.isEmpty(); return !_message.isEmpty();
} }
SentMTPMessageFields getSentMessageFields() const override; SentMessageFields getSentMessageFields() const override;
private: private:
QString _message; QString _message;
@ -152,7 +149,7 @@ public:
return true; return true;
} }
SentMTPMessageFields getSentMessageFields() const override; SentMessageFields getSentMessageFields() const override;
bool hasLocationCoords() const override { bool hasLocationCoords() const override {
return true; return true;
@ -191,7 +188,7 @@ public:
return true; return true;
} }
SentMTPMessageFields getSentMessageFields() const override; SentMessageFields getSentMessageFields() const override;
bool hasLocationCoords() const override { bool hasLocationCoords() const override {
return true; return true;
@ -224,7 +221,7 @@ public:
return (!_firstName.isEmpty() || !_lastName.isEmpty()) && !_phoneNumber.isEmpty(); return (!_firstName.isEmpty() || !_lastName.isEmpty()) && !_phoneNumber.isEmpty();
} }
SentMTPMessageFields getSentMessageFields() const override; SentMessageFields getSentMessageFields() const override;
QString getLayoutDescription(const Result *owner) const override; QString getLayoutDescription(const Result *owner) const override;
@ -254,11 +251,10 @@ public:
void addToHistory( void addToHistory(
const Result *owner, const Result *owner,
not_null<History*> history, not_null<History*> history,
MTPDmessage::Flags flags, MessageFlags flags,
MTPDmessage_ClientFlags clientFlags,
MsgId msgId, MsgId msgId,
PeerId fromId, PeerId fromId,
MTPint mtpDate, TimeId date,
UserId viaBotId, UserId viaBotId,
MsgId replyToId, MsgId replyToId,
const QString &postAuthor, const QString &postAuthor,
@ -296,11 +292,10 @@ public:
void addToHistory( void addToHistory(
const Result *owner, const Result *owner,
not_null<History*> history, not_null<History*> history,
MTPDmessage::Flags flags, MessageFlags flags,
MTPDmessage_ClientFlags clientFlags,
MsgId msgId, MsgId msgId,
PeerId fromId, PeerId fromId,
MTPint mtpDate, TimeId date,
UserId viaBotId, UserId viaBotId,
MsgId replyToId, MsgId replyToId,
const QString &postAuthor, const QString &postAuthor,
@ -332,11 +327,10 @@ public:
void addToHistory( void addToHistory(
const Result *owner, const Result *owner,
not_null<History*> history, not_null<History*> history,
MTPDmessage::Flags flags, MessageFlags flags,
MTPDmessage_ClientFlags clientFlags,
MsgId msgId, MsgId msgId,
PeerId fromId, PeerId fromId,
MTPint mtpDate, TimeId date,
UserId viaBotId, UserId viaBotId,
MsgId replyToId, MsgId replyToId,
const QString &postAuthor, const QString &postAuthor,
@ -364,7 +358,7 @@ public:
return true; return true;
} }
SentMTPMessageFields getSentMessageFields() const override; SentMessageFields getSentMessageFields() const override;
QString getLayoutDescription(const Result *owner) const override; QString getLayoutDescription(const Result *owner) const override;

View file

@ -7,8 +7,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/ */
#pragma once #pragma once
#include "base/flags.h"
inline MTPbool MTP_bool(bool v) { inline MTPbool MTP_bool(bool v) {
return v ? MTP_boolTrue() : MTP_boolFalse(); return v ? MTP_boolTrue() : MTP_boolFalse();
} }
@ -19,60 +17,3 @@ inline bool mtpIsTrue(const MTPBool &v) {
inline bool mtpIsFalse(const MTPBool &v) { inline bool mtpIsFalse(const MTPBool &v) {
return !mtpIsTrue(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>;

View file

@ -130,7 +130,6 @@ AdminLog::OwnedItem GenerateForwardedItem(
Expects(history->peer->isUser()); Expects(history->peer->isUser());
using Flag = MTPDmessage::Flag; using Flag = MTPDmessage::Flag;
using FwdFlag = MTPDmessageFwdHeader::Flag;
// #TODO common global incrementable id for fake items, like clientMsgId. // #TODO common global incrementable id for fake items, like clientMsgId.
static auto id = ServerMaxMsgId + (ServerMaxMsgId / 6); static auto id = ServerMaxMsgId + (ServerMaxMsgId / 6);
const auto flags = Flag::f_from_id | Flag::f_fwd_from; 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),
peerToMTP(history->peer->id), peerToMTP(history->peer->id),
MTP_messageFwdHeader( MTP_messageFwdHeader(
MTP_flags(FwdFlag::f_from_id), MTP_flags(MTPDmessageFwdHeader::Flag::f_from_id),
peerToMTP(history->session().userPeerId()), peerToMTP(history->session().userPeerId()),
MTPstring(), // from_name MTPstring(), // from_name
MTP_int(base::unixtime::now()), MTP_int(base::unixtime::now()),
@ -166,9 +165,7 @@ AdminLog::OwnedItem GenerateForwardedItem(
MTPVector<MTPRestrictionReason>(), MTPVector<MTPRestrictionReason>(),
MTPint() // ttl_period MTPint() // ttl_period
).match([&](const MTPDmessage &data) { ).match([&](const MTPDmessage &data) {
return history->makeMessage( return history->makeMessage(data, MessageFlag::FakeHistoryItem);
data,
MTPDmessage_ClientFlag::f_fake_history_item);
}, [](auto &&) -> not_null<HistoryMessage*> { }, [](auto &&) -> not_null<HistoryMessage*> {
Unexpected("Type in GenerateForwardedItem."); Unexpected("Type in GenerateForwardedItem.");
}); });

View file

@ -271,22 +271,25 @@ AdminLog::OwnedItem GenerateCommentItem(
if (data.comment.isEmpty()) { if (data.comment.isEmpty()) {
return nullptr; return nullptr;
} }
using Flag = MTPDmessage::Flag;
const auto id = ServerMaxMsgId + (ServerMaxMsgId / 2); const auto id = ServerMaxMsgId + (ServerMaxMsgId / 2);
const auto flags = Flag::f_entities | Flag::f_from_id | Flag::f_out; const auto flags = MessageFlag::HasFromId
const auto clientFlags = MTPDmessage_ClientFlag::f_fake_history_item; | MessageFlag::Outgoing
const auto replyTo = 0; | MessageFlag::FakeHistoryItem;
const auto viaBotId = 0; const auto replyTo = MsgId();
const auto viaBotId = UserId();
const auto groupedId = uint64();
const auto item = history->makeMessage( const auto item = history->makeMessage(
id, id,
flags, flags,
clientFlags,
replyTo, replyTo,
viaBotId, viaBotId,
base::unixtime::now(), base::unixtime::now(),
history->session().userId(), history->session().userId(),
QString(), QString(),
TextWithEntities{ TextUtilities::Clean(data.comment) }); TextWithEntities{ TextUtilities::Clean(data.comment) },
MTP_messageMediaEmpty(),
MTPReplyMarkup(),
groupedId);
return AdminLog::OwnedItem(delegate, item); return AdminLog::OwnedItem(delegate, item);
} }
@ -294,39 +297,29 @@ AdminLog::OwnedItem GenerateContactItem(
not_null<HistoryView::ElementDelegate*> delegate, not_null<HistoryView::ElementDelegate*> delegate,
not_null<History*> history, not_null<History*> history,
const Contact &data) { const Contact &data) {
using Flag = MTPDmessage::Flag; const auto replyTo = MsgId();
const auto id = ServerMaxMsgId + (ServerMaxMsgId / 2) + 1; const auto viaBotId = UserId();
const auto flags = Flag::f_from_id | Flag::f_media | Flag::f_out; const auto postAuthor = QString();
const auto message = MTP_message( const auto groupedId = uint64();
MTP_flags(flags), const auto item = history->makeMessage(
MTP_int(id), (ServerMaxMsgId + (ServerMaxMsgId / 2) + 1),
peerToMTP(history->session().userPeerId()), (MessageFlag::HasFromId
peerToMTP(history->peer->id), | MessageFlag::Outgoing
MTPMessageFwdHeader(), | MessageFlag::FakeHistoryItem),
MTPint(), // via_bot_id replyTo,
MTPMessageReplyHeader(), viaBotId,
MTP_int(base::unixtime::now()), base::unixtime::now(),
MTP_string(), history->session().userPeerId(),
postAuthor,
TextWithEntities(),
MTP_messageMediaContact( MTP_messageMediaContact(
MTP_string(data.phone), MTP_string(data.phone),
MTP_string(data.firstName), MTP_string(data.firstName),
MTP_string(data.lastName), MTP_string(data.lastName),
MTP_string(), MTP_string(), // vcard
MTP_int(0)), MTP_int(0)), // user_id
MTPReplyMarkup(), MTPReplyMarkup(),
MTPVector<MTPMessageEntity>(), groupedId);
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);
return AdminLog::OwnedItem(delegate, item); return AdminLog::OwnedItem(delegate, item);
} }