From cf02a4cc3173871a6dbb2bb1725ded2f4a5c0e42 Mon Sep 17 00:00:00 2001 From: John Preston Date: Wed, 12 Jul 2017 22:14:20 +0300 Subject: [PATCH] API scheme updated to layer 70. --- Telegram/Resources/langs/lang.strings | 2 + Telegram/Resources/scheme.tl | 42 ++++---- Telegram/SourceFiles/apiwrap.cpp | 4 +- Telegram/SourceFiles/history/history.cpp | 77 +++++++++------ Telegram/SourceFiles/history/history.h | 16 +-- .../history/history_admin_log_item.cpp | 18 ++-- Telegram/SourceFiles/history/history_item.h | 25 +++-- .../history/history_media_types.cpp | 65 ++++++++++--- .../SourceFiles/history/history_message.cpp | 95 ++++++++++-------- .../SourceFiles/history/history_message.h | 37 +++---- .../SourceFiles/history/history_service.cpp | 12 +++ .../SourceFiles/history/history_widget.cpp | 97 ++++++++++++------- .../inline_bots/inline_bot_result.cpp | 4 +- .../inline_bots/inline_bot_result.h | 2 +- .../inline_bots/inline_bot_send_data.cpp | 16 +-- .../inline_bots/inline_bot_send_data.h | 10 +- Telegram/SourceFiles/mainwidget.cpp | 22 +++-- Telegram/SourceFiles/mediaview.cpp | 4 +- Telegram/SourceFiles/mtproto/core_types.cpp | 4 +- 19 files changed, 343 insertions(+), 209 deletions(-) diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index 09c817c31..24f2743b8 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -758,6 +758,8 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org "lng_action_game_you_scored_no_game#other" = "You scored {count}"; "lng_action_payment_done" = "You have just successfully transferred {amount} to {user}"; "lng_action_payment_done_for" = "You have just successfully transferred {amount} to {user} for {invoice}"; +"lng_action_took_screenshot" = "{from} took a screenshot!"; +"lng_action_you_took_screenshot" = "You took a screenshot!"; "lng_profile_migrate_reached#one" = "{count} member limit reached"; "lng_profile_migrate_reached#other" = "{count} members limit reached"; diff --git a/Telegram/Resources/scheme.tl b/Telegram/Resources/scheme.tl index f962c152f..bdc97c3ca 100644 --- a/Telegram/Resources/scheme.tl +++ b/Telegram/Resources/scheme.tl @@ -155,17 +155,16 @@ inputFile#f52ff27f id:long parts:int name:string md5_checksum:string = InputFile inputFileBig#fa4f0bb5 id:long parts:int name:string = InputFile; inputMediaEmpty#9664f57f = InputMedia; -inputMediaUploadedPhoto#630c9af1 flags:# file:InputFile caption:string stickers:flags.0?Vector = InputMedia; -inputMediaPhoto#e9bfb4f3 id:InputPhoto caption:string = InputMedia; +inputMediaUploadedPhoto#2f37e231 flags:# file:InputFile caption:string stickers:flags.0?Vector ttl_seconds:flags.1?int = InputMedia; +inputMediaPhoto#81fa373a flags:# id:InputPhoto caption:string ttl_seconds:flags.0?int = InputMedia; inputMediaGeoPoint#f9c44144 geo_point:InputGeoPoint = InputMedia; inputMediaContact#a6e45987 phone_number:string first_name:string last_name:string = InputMedia; -inputMediaUploadedDocument#d070f1e9 flags:# file:InputFile mime_type:string attributes:Vector caption:string stickers:flags.0?Vector = InputMedia; -inputMediaUploadedThumbDocument#50d88cae flags:# file:InputFile thumb:InputFile mime_type:string attributes:Vector caption:string stickers:flags.0?Vector = InputMedia; -inputMediaDocument#1a77f29c id:InputDocument caption:string = InputMedia; +inputMediaUploadedDocument#e39621fd flags:# file:InputFile thumb:flags.2?InputFile mime_type:string attributes:Vector caption:string stickers:flags.0?Vector ttl_seconds:flags.1?int = InputMedia; +inputMediaDocument#5acb668e flags:# id:InputDocument caption:string ttl_seconds:flags.0?int = InputMedia; inputMediaVenue#2827a81a geo_point:InputGeoPoint title:string address:string provider:string venue_id:string = InputMedia; inputMediaGifExternal#4843b0fd url:string q:string = InputMedia; -inputMediaPhotoExternal#b55f4f18 url:string caption:string = InputMedia; -inputMediaDocumentExternal#e5e9607c url:string caption:string = InputMedia; +inputMediaPhotoExternal#922aec1 flags:# url:string caption:string ttl_seconds:flags.0?int = InputMedia; +inputMediaDocumentExternal#b6f74335 flags:# url:string caption:string ttl_seconds:flags.0?int = InputMedia; inputMediaGame#d33f43f3 id:InputGame = InputMedia; inputMediaInvoice#92153685 flags:# title:string description:string photo:flags.0?InputWebDocument invoice:Invoice payload:bytes provider:string start_param:string = InputMedia; @@ -219,7 +218,7 @@ userStatusLastMonth#77ebc742 = UserStatus; chatEmpty#9ba2d800 id:int = Chat; chat#d91cdd54 flags:# creator:flags.0?true kicked:flags.1?true left:flags.2?true admins_enabled:flags.3?true admin:flags.4?true deactivated:flags.5?true id:int title:string photo:ChatPhoto participants_count:int date:int version:int migrated_to:flags.6?InputChannel = Chat; chatForbidden#7328bdb id:int title:string = Chat; -channel#cb44b1c flags:# creator:flags.0?true left:flags.2?true broadcast:flags.5?true verified:flags.7?true megagroup:flags.8?true restricted:flags.9?true democracy:flags.10?true signatures:flags.11?true min:flags.12?true id:int access_hash:flags.13?long title:string username:flags.6?string photo:ChatPhoto date:int version:int restriction_reason:flags.9?string admin_rights:flags.14?ChannelAdminRights banned_rights:flags.15?ChannelBannedRights = Chat; +channel#cb44b1c flags:# creator:flags.0?true left:flags.2?true editor:flags.3?true broadcast:flags.5?true verified:flags.7?true megagroup:flags.8?true restricted:flags.9?true democracy:flags.10?true signatures:flags.11?true min:flags.12?true id:int access_hash:flags.13?long title:string username:flags.6?string photo:ChatPhoto date:int version:int restriction_reason:flags.9?string admin_rights:flags.14?ChannelAdminRights banned_rights:flags.15?ChannelBannedRights = Chat; channelForbidden#289da732 flags:# broadcast:flags.5?true megagroup:flags.8?true id:int access_hash:long title:string until_date:flags.16?int = Chat; chatFull#2e02a614 id:int participants:ChatParticipants chat_photo:Photo notify_settings:PeerNotifySettings exported_invite:ExportedChatInvite bot_info:Vector = ChatFull; @@ -236,15 +235,15 @@ chatPhotoEmpty#37c1011c = ChatPhoto; chatPhoto#6153276a photo_small:FileLocation photo_big:FileLocation = ChatPhoto; messageEmpty#83e5de54 id:int = Message; -message#c09be45f flags:# out:flags.1?true mentioned:flags.4?true media_unread:flags.5?true silent:flags.13?true post:flags.14?true id:int from_id:flags.8?int to_id:Peer fwd_from:flags.2?MessageFwdHeader via_bot_id:flags.11?int reply_to_msg_id:flags.3?int date:int message:string media:flags.9?MessageMedia reply_markup:flags.6?ReplyMarkup entities:flags.7?Vector views:flags.10?int edit_date:flags.15?int = Message; +message#90dddc11 flags:# out:flags.1?true mentioned:flags.4?true media_unread:flags.5?true silent:flags.13?true post:flags.14?true id:int from_id:flags.8?int to_id:Peer fwd_from:flags.2?MessageFwdHeader via_bot_id:flags.11?int reply_to_msg_id:flags.3?int date:int message:string media:flags.9?MessageMedia reply_markup:flags.6?ReplyMarkup entities:flags.7?Vector views:flags.10?int edit_date:flags.15?int post_author:flags.16?string = Message; messageService#9e19a1f6 flags:# out:flags.1?true mentioned:flags.4?true media_unread:flags.5?true silent:flags.13?true post:flags.14?true id:int from_id:flags.8?int to_id:Peer reply_to_msg_id:flags.3?int date:int action:MessageAction = Message; messageMediaEmpty#3ded6320 = MessageMedia; -messageMediaPhoto#3d8ce53d photo:Photo caption:string = MessageMedia; +messageMediaPhoto#b5223b0f flags:# photo:flags.0?Photo caption:flags.1?string ttl_seconds:flags.2?int = MessageMedia; messageMediaGeo#56e0d474 geo:GeoPoint = MessageMedia; messageMediaContact#5e7d2f39 phone_number:string first_name:string last_name:string user_id:int = MessageMedia; messageMediaUnsupported#9f84f49e = MessageMedia; -messageMediaDocument#f3e02ea8 document:Document caption:string = MessageMedia; +messageMediaDocument#7c4414d3 flags:# document:flags.0?Document caption:flags.1?string ttl_seconds:flags.2?int = MessageMedia; messageMediaWebPage#a32dd600 webpage:WebPage = MessageMedia; messageMediaVenue#7912b71f geo:GeoPoint title:string address:string provider:string venue_id:string = MessageMedia; messageMediaGame#fdb19008 game:Game = MessageMedia; @@ -267,6 +266,7 @@ messageActionGameScore#92a72876 game_id:long score:int = MessageAction; messageActionPaymentSentMe#8f31b327 flags:# currency:string total_amount:long payload:bytes info:flags.0?PaymentRequestedInfo shipping_option_id:flags.1?string charge:PaymentCharge = MessageAction; messageActionPaymentSent#40699cd0 currency:string total_amount:long = MessageAction; messageActionPhoneCall#80e11a7f flags:# call_id:long reason:flags.0?PhoneCallDiscardReason duration:flags.1?int = MessageAction; +messageActionScreenshotTaken#4792929b = MessageAction; dialog#66ffba14 flags:# pinned:flags.2?true peer:Peer top_message:int read_inbox_max_id:int read_outbox_max_id:int unread_count:int notify_settings:PeerNotifySettings pts:flags.0?int draft:flags.1?DraftMessage = Dialog; @@ -329,7 +329,7 @@ contacts.link#3ace484c my_link:ContactLink foreign_link:ContactLink user:User = contacts.contactsNotModified#b74ba9d2 = contacts.Contacts; contacts.contacts#6f8b8cb2 contacts:Vector users:Vector = contacts.Contacts; -contacts.importedContacts#ad524315 imported:Vector retry_contacts:Vector users:Vector = contacts.ImportedContacts; +contacts.importedContacts#77d01c3b imported:Vector popular_invites:Vector retry_contacts:Vector users:Vector = contacts.ImportedContacts; contacts.blocked#1c138d15 blocked:Vector users:Vector = contacts.Blocked; contacts.blockedSlice#900802a1 count:int blocked:Vector users:Vector = contacts.Blocked; @@ -447,7 +447,7 @@ photos.photosSlice#15051f54 count:int photos:Vector users:Vector = photos.photo#20212ca8 photo:Photo users:Vector = photos.Photo; upload.file#96a18d5 type:storage.FileType mtime:int bytes:bytes = upload.File; -upload.fileCdnRedirect#1508485a dc_id:int file_token:bytes encryption_key:bytes encryption_iv:bytes = upload.File; +upload.fileCdnRedirect#ea52fe5a dc_id:int file_token:bytes encryption_key:bytes encryption_iv:bytes cdn_file_hashes:Vector = upload.File; dcOption#5d8c6cc flags:# ipv6:flags.0?true media_only:flags.1?true tcpo_only:flags.2?true cdn:flags.3?true static:flags.4?true id:int ip_address:string port:int = DcOption; @@ -699,7 +699,7 @@ messages.botResults#ccd3563d flags:# gallery:flags.0?true query_id:long next_off exportedMessageLink#1f486803 link:string = ExportedMessageLink; -messageFwdHeader#c786ddcb flags:# from_id:flags.0?int date:int channel_id:flags.1?int channel_post:flags.2?int = MessageFwdHeader; +messageFwdHeader#fadff4ac flags:# from_id:flags.0?int date:int channel_id:flags.1?int channel_post:flags.2?int post_author:flags.3?string = MessageFwdHeader; auth.codeTypeSms#72a3158c = auth.CodeType; auth.codeTypeCall#741cd3e3 = auth.CodeType; @@ -905,6 +905,10 @@ channels.adminLogResults#ed8af74d events:Vector chats:Vect channelAdminLogEventsFilter#ea107ae4 flags:# join:flags.0?true leave:flags.1?true invite:flags.2?true ban:flags.3?true unban:flags.4?true kick:flags.5?true unkick:flags.6?true promote:flags.7?true demote:flags.8?true info:flags.9?true settings:flags.10?true pinned:flags.11?true edit:flags.12?true delete:flags.13?true = ChannelAdminLogEventsFilter; +popularContact#5ce14175 client_id:long importers:int = PopularContact; + +cdnFileHash#77eec38f offset:int limit:int hash:bytes = CdnFileHash; + ---functions--- invokeAfterMsg#cb9f372d {X:Type} msg_id:long query:!X = X; @@ -1063,6 +1067,7 @@ messages.getPinnedDialogs#e254d64e = messages.PeerDialogs; messages.setBotShippingResults#e5f672fa flags:# query_id:long error:flags.0?string shipping_options:flags.1?Vector = Bool; messages.setBotPrecheckoutResults#9c2dd95 flags:# success:flags.1?true query_id:long error:flags.0?string = Bool; messages.uploadMedia#519bc2b1 peer:InputPeer media:InputMedia = MessageMedia; +messages.sendScreenshotNotification#c97df020 peer:InputPeer reply_to_msg_id:int random_id:long = Updates; updates.getState#edd4882a = updates.State; updates.getDifference#25939651 flags:# pts:int pts_total_limit:flags.0?int date:int qts:int = updates.Difference; @@ -1078,7 +1083,8 @@ upload.getFile#e3a6cfb5 location:InputFileLocation offset:int limit:int = upload upload.saveBigFilePart#de7b673d file_id:long file_part:int file_total_parts:int bytes:bytes = Bool; upload.getWebFile#24e6818d location:InputWebFileLocation offset:int limit:int = upload.WebFile; upload.getCdnFile#2000bcc3 file_token:bytes offset:int limit:int = upload.CdnFile; -upload.reuploadCdnFile#2e7a2020 file_token:bytes request_token:bytes = Bool; +upload.reuploadCdnFile#1af91c09 file_token:bytes request_token:bytes = Vector; +upload.getCdnFileHashes#f715c87b file_token:bytes offset:int = Vector; help.getConfig#c4f9186b = Config; help.getNearestDc#1fb33026 = NearestDc; @@ -1131,8 +1137,8 @@ payments.getSavedInfo#227d824b = payments.SavedInfo; payments.clearSavedInfo#d83d70c1 flags:# credentials:flags.0?true info:flags.1?true = Bool; stickers.createStickerSet#9bd86e6a flags:# masks:flags.0?true user_id:InputUser title:string short_name:string stickers:Vector = messages.StickerSet; -stickers.removeStickerFromSet#4255934 sticker:InputDocument = Bool; -stickers.changeStickerPosition#4ed705ca sticker:InputDocument position:int = Bool; +stickers.removeStickerFromSet#f7760f51 sticker:InputDocument = messages.StickerSet; +stickers.changeStickerPosition#ffb6d4ca sticker:InputDocument position:int = messages.StickerSet; stickers.addStickerToSet#8653febe stickerset:InputStickerSet sticker:InputStickerSetItem = messages.StickerSet; phone.getCallConfig#55451fa9 = DataJSON; @@ -1149,4 +1155,4 @@ langpack.getStrings#2e1ee318 lang_code:string keys:Vector = Vector; -// LAYER 68 +// LAYER 70 diff --git a/Telegram/SourceFiles/apiwrap.cpp b/Telegram/SourceFiles/apiwrap.cpp index 2f378d475..82aeb1a93 100644 --- a/Telegram/SourceFiles/apiwrap.cpp +++ b/Telegram/SourceFiles/apiwrap.cpp @@ -1536,13 +1536,13 @@ void ApiWrap::applyUpdatesNoPtsCheck(const MTPUpdates &updates) { case mtpc_updateShortMessage: { auto &d = updates.c_updateShortMessage(); auto flags = mtpCastFlags(d.vflags.v) | MTPDmessage::Flag::f_from_id; - App::histories().addNewMessage(MTP_message(MTP_flags(flags), d.vid, d.is_out() ? MTP_int(AuthSession::CurrentUserId()) : d.vuser_id, MTP_peerUser(d.is_out() ? d.vuser_id : MTP_int(AuthSession::CurrentUserId())), d.vfwd_from, d.vvia_bot_id, d.vreply_to_msg_id, d.vdate, d.vmessage, MTP_messageMediaEmpty(), MTPnullMarkup, d.has_entities() ? d.ventities : MTPnullEntities, MTPint(), MTPint()), NewMessageUnread); + App::histories().addNewMessage(MTP_message(MTP_flags(flags), d.vid, d.is_out() ? MTP_int(AuthSession::CurrentUserId()) : d.vuser_id, MTP_peerUser(d.is_out() ? d.vuser_id : MTP_int(AuthSession::CurrentUserId())), d.vfwd_from, d.vvia_bot_id, d.vreply_to_msg_id, d.vdate, d.vmessage, MTP_messageMediaEmpty(), MTPnullMarkup, d.has_entities() ? d.ventities : MTPnullEntities, MTPint(), MTPint(), MTPstring()), NewMessageUnread); } break; case mtpc_updateShortChatMessage: { auto &d = updates.c_updateShortChatMessage(); auto flags = mtpCastFlags(d.vflags.v) | MTPDmessage::Flag::f_from_id; - App::histories().addNewMessage(MTP_message(MTP_flags(flags), d.vid, d.vfrom_id, MTP_peerChat(d.vchat_id), d.vfwd_from, d.vvia_bot_id, d.vreply_to_msg_id, d.vdate, d.vmessage, MTP_messageMediaEmpty(), MTPnullMarkup, d.has_entities() ? d.ventities : MTPnullEntities, MTPint(), MTPint()), NewMessageUnread); + App::histories().addNewMessage(MTP_message(MTP_flags(flags), d.vid, d.vfrom_id, MTP_peerChat(d.vchat_id), d.vfwd_from, d.vvia_bot_id, d.vreply_to_msg_id, d.vdate, d.vmessage, MTP_messageMediaEmpty(), MTPnullMarkup, d.has_entities() ? d.ventities : MTPnullEntities, MTPint(), MTPint(), MTPstring()), NewMessageUnread); } break; case mtpc_updateShortSentMessage: { diff --git a/Telegram/SourceFiles/history/history.cpp b/Telegram/SourceFiles/history/history.cpp index 9ee000659..1b3212b28 100644 --- a/Telegram/SourceFiles/history/history.cpp +++ b/Telegram/SourceFiles/history/history.cpp @@ -60,7 +60,8 @@ HistoryItem *createUnsupportedMessage(History *history, MsgId msgId, MTPDmessage auto text = TextWithEntities { lng_message_unsupported(lt_link, qsl("https://desktop.telegram.org")) }; TextUtilities::ParseEntities(text, _historyTextNoMonoOptions.flags); text.entities.push_front(EntityInText(EntityInTextItalic, 0, text.text.size())); - return HistoryMessage::create(history, msgId, flags, replyTo, viaBotId, date, from, text); + flags &= ~MTPDmessage::Flag::f_post_author; + return HistoryMessage::create(history, msgId, flags, replyTo, viaBotId, date, from, QString(), text); } } // namespace @@ -798,6 +799,7 @@ HistoryItem *History::createItem(const MTPMessage &msg, bool applyServiceAction, Good, Unsupported, Empty, + HasTTL, }; auto badMedia = MediaCheckResult::Good; if (m.has_media()) switch (m.vmedia.type()) { @@ -817,20 +819,34 @@ HistoryItem *History::createItem(const MTPMessage &msg, bool applyServiceAction, default: badMedia = MediaCheckResult::Unsupported; break; } break; - case mtpc_messageMediaPhoto: - switch (m.vmedia.c_messageMediaPhoto().vphoto.type()) { - case mtpc_photo: break; - case mtpc_photoEmpty: badMedia = MediaCheckResult::Empty; break; - default: badMedia = MediaCheckResult::Unsupported; break; + case mtpc_messageMediaPhoto: { + auto &photo = m.vmedia.c_messageMediaPhoto(); + if (photo.has_ttl_seconds()) { + badMedia = MediaCheckResult::HasTTL; + } else if (!photo.has_photo()) { + badMedia = MediaCheckResult::Empty; + } else { + switch (photo.vphoto.type()) { + case mtpc_photo: break; + case mtpc_photoEmpty: badMedia = MediaCheckResult::Empty; break; + default: badMedia = MediaCheckResult::Unsupported; break; + } } - break; - case mtpc_messageMediaDocument: - switch (m.vmedia.c_messageMediaDocument().vdocument.type()) { - case mtpc_document: break; - case mtpc_documentEmpty: badMedia = MediaCheckResult::Empty; break; - default: badMedia = MediaCheckResult::Unsupported; break; + } break; + case mtpc_messageMediaDocument: { + auto &document = m.vmedia.c_messageMediaDocument(); + if (document.has_ttl_seconds()) { + badMedia = MediaCheckResult::HasTTL; + } else if (!document.has_document()) { + badMedia = MediaCheckResult::Empty; + } else { + switch (document.vdocument.type()) { + case mtpc_document: break; + case mtpc_documentEmpty: badMedia = MediaCheckResult::Empty; break; + default: badMedia = MediaCheckResult::Unsupported; break; + } } - break; + } break; case mtpc_messageMediaWebPage: switch (m.vmedia.c_messageMediaWebPage().vwebpage.type()) { case mtpc_webPage: @@ -856,6 +872,9 @@ HistoryItem *History::createItem(const MTPMessage &msg, bool applyServiceAction, } else if (badMedia == MediaCheckResult::Empty) { auto message = HistoryService::PreparedText { lang(lng_message_empty) }; result = HistoryService::create(this, m.vid.v, date(m.vdate), message, m.vflags.v, m.has_from_id() ? m.vfrom_id.v : 0); + } else if (badMedia == MediaCheckResult::HasTTL) { + auto message = HistoryService::PreparedText { qsl("Self-destruct media, see mobile") }; + result = HistoryService::create(this, m.vid.v, date(m.vdate), message, m.vflags.v, m.has_from_id() ? m.vfrom_id.v : 0); } else { result = HistoryMessage::create(this, m); } @@ -1025,20 +1044,20 @@ HistoryItem *History::createItem(const MTPMessage &msg, bool applyServiceAction, return result; } -HistoryItem *History::createItemForwarded(MsgId id, MTPDmessage::Flags flags, QDateTime date, int32 from, HistoryMessage *msg) { - return HistoryMessage::create(this, id, flags, date, from, msg); +HistoryItem *History::createItemForwarded(MsgId id, MTPDmessage::Flags flags, QDateTime date, UserId from, const QString &postAuthor, HistoryMessage *msg) { + return HistoryMessage::create(this, id, flags, date, from, postAuthor, msg); } -HistoryItem *History::createItemDocument(MsgId id, MTPDmessage::Flags flags, int32 viaBotId, MsgId replyTo, QDateTime date, int32 from, DocumentData *doc, const QString &caption, const MTPReplyMarkup &markup) { - return HistoryMessage::create(this, id, flags, replyTo, viaBotId, date, from, doc, caption, markup); +HistoryItem *History::createItemDocument(MsgId id, MTPDmessage::Flags flags, UserId viaBotId, MsgId replyTo, QDateTime date, UserId from, const QString &postAuthor, DocumentData *doc, const QString &caption, const MTPReplyMarkup &markup) { + return HistoryMessage::create(this, id, flags, replyTo, viaBotId, date, from, postAuthor, doc, caption, markup); } -HistoryItem *History::createItemPhoto(MsgId id, MTPDmessage::Flags flags, int32 viaBotId, MsgId replyTo, QDateTime date, int32 from, PhotoData *photo, const QString &caption, const MTPReplyMarkup &markup) { - return HistoryMessage::create(this, id, flags, replyTo, viaBotId, date, from, photo, caption, markup); +HistoryItem *History::createItemPhoto(MsgId id, MTPDmessage::Flags flags, UserId viaBotId, MsgId replyTo, QDateTime date, UserId from, const QString &postAuthor, PhotoData *photo, const QString &caption, const MTPReplyMarkup &markup) { + return HistoryMessage::create(this, id, flags, replyTo, viaBotId, date, from, postAuthor, photo, caption, markup); } -HistoryItem *History::createItemGame(MsgId id, MTPDmessage::Flags flags, int32 viaBotId, MsgId replyTo, QDateTime date, int32 from, GameData *game, const MTPReplyMarkup &markup) { - return HistoryMessage::create(this, id, flags, replyTo, viaBotId, date, from, game, markup); +HistoryItem *History::createItemGame(MsgId id, MTPDmessage::Flags flags, UserId viaBotId, MsgId replyTo, QDateTime date, UserId from, const QString &postAuthor, GameData *game, const MTPReplyMarkup &markup) { + return HistoryMessage::create(this, id, flags, replyTo, viaBotId, date, from, postAuthor, game, markup); } HistoryItem *History::addNewService(MsgId msgId, QDateTime date, const QString &text, MTPDmessage::Flags flags, bool newMsg) { @@ -1078,20 +1097,20 @@ HistoryItem *History::addToHistory(const MTPMessage &msg) { return createItem(msg, false, false); } -HistoryItem *History::addNewForwarded(MsgId id, MTPDmessage::Flags flags, QDateTime date, int32 from, HistoryMessage *item) { - return addNewItem(createItemForwarded(id, flags, date, from, item), true); +HistoryItem *History::addNewForwarded(MsgId id, MTPDmessage::Flags flags, QDateTime date, UserId from, const QString &postAuthor, HistoryMessage *item) { + return addNewItem(createItemForwarded(id, flags, date, from, postAuthor, item), true); } -HistoryItem *History::addNewDocument(MsgId id, MTPDmessage::Flags flags, int32 viaBotId, MsgId replyTo, QDateTime date, int32 from, DocumentData *doc, const QString &caption, const MTPReplyMarkup &markup) { - return addNewItem(createItemDocument(id, flags, viaBotId, replyTo, date, from, doc, caption, markup), true); +HistoryItem *History::addNewDocument(MsgId id, MTPDmessage::Flags flags, UserId viaBotId, MsgId replyTo, QDateTime date, UserId from, const QString &postAuthor, DocumentData *doc, const QString &caption, const MTPReplyMarkup &markup) { + return addNewItem(createItemDocument(id, flags, viaBotId, replyTo, date, from, postAuthor, doc, caption, markup), true); } -HistoryItem *History::addNewPhoto(MsgId id, MTPDmessage::Flags flags, int32 viaBotId, MsgId replyTo, QDateTime date, int32 from, PhotoData *photo, const QString &caption, const MTPReplyMarkup &markup) { - return addNewItem(createItemPhoto(id, flags, viaBotId, replyTo, date, from, photo, caption, markup), true); +HistoryItem *History::addNewPhoto(MsgId id, MTPDmessage::Flags flags, UserId viaBotId, MsgId replyTo, QDateTime date, UserId from, const QString &postAuthor, PhotoData *photo, const QString &caption, const MTPReplyMarkup &markup) { + return addNewItem(createItemPhoto(id, flags, viaBotId, replyTo, date, from, postAuthor, photo, caption, markup), true); } -HistoryItem *History::addNewGame(MsgId id, MTPDmessage::Flags flags, int32 viaBotId, MsgId replyTo, QDateTime date, int32 from, GameData *game, const MTPReplyMarkup &markup) { - return addNewItem(createItemGame(id, flags, viaBotId, replyTo, date, from, game, markup), true); +HistoryItem *History::addNewGame(MsgId id, MTPDmessage::Flags flags, UserId viaBotId, MsgId replyTo, QDateTime date, UserId from, const QString &postAuthor, GameData *game, const MTPReplyMarkup &markup) { + return addNewItem(createItemGame(id, flags, viaBotId, replyTo, date, from, postAuthor, game, markup), true); } bool History::addToOverview(MediaOverviewType type, MsgId msgId, AddToOverviewMethod method) { diff --git a/Telegram/SourceFiles/history/history.h b/Telegram/SourceFiles/history/history.h index adaf38932..25907c353 100644 --- a/Telegram/SourceFiles/history/history.h +++ b/Telegram/SourceFiles/history/history.h @@ -212,10 +212,10 @@ public: HistoryItem *addNewService(MsgId msgId, QDateTime date, const QString &text, MTPDmessage::Flags flags = 0, bool newMsg = true); HistoryItem *addNewMessage(const MTPMessage &msg, NewMessageType type); HistoryItem *addToHistory(const MTPMessage &msg); - HistoryItem *addNewForwarded(MsgId id, MTPDmessage::Flags flags, QDateTime date, int32 from, HistoryMessage *item); - HistoryItem *addNewDocument(MsgId id, MTPDmessage::Flags flags, int32 viaBotId, MsgId replyTo, QDateTime date, int32 from, DocumentData *doc, const QString &caption, const MTPReplyMarkup &markup); - HistoryItem *addNewPhoto(MsgId id, MTPDmessage::Flags flags, int32 viaBotId, MsgId replyTo, QDateTime date, int32 from, PhotoData *photo, const QString &caption, const MTPReplyMarkup &markup); - HistoryItem *addNewGame(MsgId id, MTPDmessage::Flags flags, int32 viaBotId, MsgId replyTo, QDateTime date, int32 from, GameData *game, const MTPReplyMarkup &markup); + HistoryItem *addNewForwarded(MsgId id, MTPDmessage::Flags flags, QDateTime date, UserId from, const QString &postAuthor, HistoryMessage *item); + HistoryItem *addNewDocument(MsgId id, MTPDmessage::Flags flags, UserId viaBotId, MsgId replyTo, QDateTime date, UserId from, const QString &postAuthor, DocumentData *doc, const QString &caption, const MTPReplyMarkup &markup); + HistoryItem *addNewPhoto(MsgId id, MTPDmessage::Flags flags, UserId viaBotId, MsgId replyTo, QDateTime date, UserId from, const QString &postAuthor, PhotoData *photo, const QString &caption, const MTPReplyMarkup &markup); + HistoryItem *addNewGame(MsgId id, MTPDmessage::Flags flags, UserId viaBotId, MsgId replyTo, QDateTime date, UserId from, const QString &postAuthor, GameData *game, const MTPReplyMarkup &markup); // Used only internally and for channel admin log. HistoryItem *createItem(const MTPMessage &msg, bool applyServiceAction, bool detachExistingItem); @@ -483,10 +483,10 @@ protected: void clearBlocks(bool leaveItems); - HistoryItem *createItemForwarded(MsgId id, MTPDmessage::Flags flags, QDateTime date, int32 from, HistoryMessage *msg); - HistoryItem *createItemDocument(MsgId id, MTPDmessage::Flags flags, int32 viaBotId, MsgId replyTo, QDateTime date, int32 from, DocumentData *doc, const QString &caption, const MTPReplyMarkup &markup); - HistoryItem *createItemPhoto(MsgId id, MTPDmessage::Flags flags, int32 viaBotId, MsgId replyTo, QDateTime date, int32 from, PhotoData *photo, const QString &caption, const MTPReplyMarkup &markup); - HistoryItem *createItemGame(MsgId id, MTPDmessage::Flags flags, int32 viaBotId, MsgId replyTo, QDateTime date, int32 from, GameData *game, const MTPReplyMarkup &markup); + HistoryItem *createItemForwarded(MsgId id, MTPDmessage::Flags flags, QDateTime date, UserId from, const QString &postAuthor, HistoryMessage *msg); + HistoryItem *createItemDocument(MsgId id, MTPDmessage::Flags flags, UserId viaBotId, MsgId replyTo, QDateTime date, UserId from, const QString &postAuthor, DocumentData *doc, const QString &caption, const MTPReplyMarkup &markup); + HistoryItem *createItemPhoto(MsgId id, MTPDmessage::Flags flags, UserId viaBotId, MsgId replyTo, QDateTime date, UserId from, const QString &postAuthor, PhotoData *photo, const QString &caption, const MTPReplyMarkup &markup); + HistoryItem *createItemGame(MsgId id, MTPDmessage::Flags flags, UserId viaBotId, MsgId replyTo, QDateTime date, UserId from, const QString &postAuthor, GameData *game, const MTPReplyMarkup &markup); HistoryItem *addNewItem(HistoryItem *adding, bool newMsg); HistoryItem *addNewInTheMiddle(HistoryItem *newItem, int32 blockIndex, int32 itemIndex); diff --git a/Telegram/SourceFiles/history/history_admin_log_item.cpp b/Telegram/SourceFiles/history/history_admin_log_item.cpp index b3cb04b73..6f41549a7 100644 --- a/Telegram/SourceFiles/history/history_admin_log_item.cpp +++ b/Telegram/SourceFiles/history/history_admin_log_item.cpp @@ -53,7 +53,7 @@ MTPMessage PrepareLogMessage(const MTPMessage &message, MsgId newId, int32 newDa case mtpc_message: { auto &data = message.c_message(); auto flags = data.vflags.v & ~(MTPDmessage::Flag::f_out | MTPDmessage::Flag::f_post | MTPDmessage::Flag::f_reply_to_msg_id | MTPDmessage::Flag::f_edit_date); - return MTP_message(MTP_flags(flags), MTP_int(newId), data.vfrom_id, data.vto_id, data.vfwd_from, data.vvia_bot_id, data.vreply_to_msg_id, MTP_int(newDate), data.vmessage, data.vmedia, data.vreply_markup, data.ventities, data.vviews, data.vedit_date); + return MTP_message(MTP_flags(flags), MTP_int(newId), data.vfrom_id, data.vto_id, data.vfwd_from, data.vvia_bot_id, data.vreply_to_msg_id, MTP_int(newDate), data.vmessage, data.vmedia, data.vreply_markup, data.ventities, data.vviews, data.vedit_date, MTP_string("")); } break; } Unexpected("Type in PrepareLogMessage()"); @@ -75,9 +75,11 @@ TextWithEntities ExtractEditedText(const MTPMessage &message) { auto &data = message.c_message(); auto mediaType = data.has_media() ? data.vmedia.type() : mtpc_messageMediaEmpty; if (mediaType == mtpc_messageMediaDocument) { - return PrepareText(qs(data.vmedia.c_messageMediaDocument().vcaption), QString()); + auto &document = data.vmedia.c_messageMediaDocument(); + return PrepareText(document.has_caption() ? qs(document.vcaption) : QString(), QString()); } else if (mediaType == mtpc_messageMediaPhoto) { - return PrepareText(qs(data.vmedia.c_messageMediaPhoto().vcaption), QString()); + auto &photo = data.vmedia.c_messageMediaPhoto(); + return PrepareText(photo.has_caption() ? qs(photo.vcaption) : QString(), QString()); } auto text = TextUtilities::Clean(qs(data.vmessage)); auto entities = data.has_entities() ? TextUtilities::EntitiesFromMTP(data.ventities.v) : EntitiesInText(); @@ -277,7 +279,7 @@ void GenerateItems(gsl::not_null history, LocalIdManager &idManager, c auto bodyReplyTo = 0; auto bodyViaBotId = 0; auto newDescription = PrepareText(newValue, QString()); - auto body = HistoryMessage::create(history, idManager.next(), bodyFlags, bodyReplyTo, bodyViaBotId, ::date(date), peerToUser(from->id), newDescription); + auto body = HistoryMessage::create(history, idManager.next(), bodyFlags, bodyReplyTo, bodyViaBotId, ::date(date), peerToUser(from->id), QString(), newDescription); if (!oldValue.isEmpty()) { auto oldDescription = PrepareText(oldValue, QString()); body->addLogEntryOriginal(id, lang(lng_admin_log_previous_description), oldDescription); @@ -298,7 +300,7 @@ void GenerateItems(gsl::not_null history, LocalIdManager &idManager, c auto bodyReplyTo = 0; auto bodyViaBotId = 0; auto newLink = newValue.isEmpty() ? TextWithEntities() : PrepareText(Messenger::Instance().createInternalLinkFull(newValue), QString()); - auto body = HistoryMessage::create(history, idManager.next(), bodyFlags, bodyReplyTo, bodyViaBotId, ::date(date), peerToUser(from->id), newLink); + auto body = HistoryMessage::create(history, idManager.next(), bodyFlags, bodyReplyTo, bodyViaBotId, ::date(date), peerToUser(from->id), QString(), newLink); if (!oldValue.isEmpty()) { auto oldLink = PrepareText(Messenger::Instance().createInternalLinkFull(oldValue), QString()); body->addLogEntryOriginal(id, lang(lng_admin_log_previous_link), oldLink); @@ -391,7 +393,7 @@ void GenerateItems(gsl::not_null history, LocalIdManager &idManager, c auto bodyReplyTo = 0; auto bodyViaBotId = 0; auto bodyText = GenerateParticipantChangeText(channel, action.vparticipant); - addPart(HistoryMessage::create(history, idManager.next(), bodyFlags, bodyReplyTo, bodyViaBotId, ::date(date), peerToUser(from->id), bodyText)); + addPart(HistoryMessage::create(history, idManager.next(), bodyFlags, bodyReplyTo, bodyViaBotId, ::date(date), peerToUser(from->id), QString(), bodyText)); }; auto createParticipantToggleBan = [&](const MTPDchannelAdminLogEventActionParticipantToggleBan &action) { @@ -399,7 +401,7 @@ void GenerateItems(gsl::not_null history, LocalIdManager &idManager, c auto bodyReplyTo = 0; auto bodyViaBotId = 0; auto bodyText = GenerateParticipantChangeText(channel, action.vnew_participant, &action.vprev_participant); - addPart(HistoryMessage::create(history, idManager.next(), bodyFlags, bodyReplyTo, bodyViaBotId, ::date(date), peerToUser(from->id), bodyText)); + addPart(HistoryMessage::create(history, idManager.next(), bodyFlags, bodyReplyTo, bodyViaBotId, ::date(date), peerToUser(from->id), QString(), bodyText)); }; auto createParticipantToggleAdmin = [&](const MTPDchannelAdminLogEventActionParticipantToggleAdmin &action) { @@ -407,7 +409,7 @@ void GenerateItems(gsl::not_null history, LocalIdManager &idManager, c auto bodyReplyTo = 0; auto bodyViaBotId = 0; auto bodyText = GenerateParticipantChangeText(channel, action.vnew_participant, &action.vprev_participant); - addPart(HistoryMessage::create(history, idManager.next(), bodyFlags, bodyReplyTo, bodyViaBotId, ::date(date), peerToUser(from->id), bodyText)); + addPart(HistoryMessage::create(history, idManager.next(), bodyFlags, bodyReplyTo, bodyViaBotId, ::date(date), peerToUser(from->id), QString(), bodyText)); }; switch (action.type()) { diff --git a/Telegram/SourceFiles/history/history_item.h b/Telegram/SourceFiles/history/history_item.h index 2e3dc2455..c0337d689 100644 --- a/Telegram/SourceFiles/history/history_item.h +++ b/Telegram/SourceFiles/history/history_item.h @@ -119,9 +119,10 @@ struct HistoryMessageViews : public RuntimeComponent { }; struct HistoryMessageSigned : public RuntimeComponent { - void create(UserData *from, const QString &date); + void create(const QString &author, const QString &date); int maxWidth() const; + QString _author; Text _signature; }; @@ -137,8 +138,8 @@ struct HistoryMessageForwarded : public RuntimeComponent()) { + return forwarded->_originalPeer; + } + return history()->peer; + } PeerData *fromOriginal() const { if (auto forwarded = Get()) { - return forwarded->_fromOriginal; + if (auto user = forwarded->_originalPeer->asUser()) { + return user; + } } return from(); } - PeerData *authorOriginal() const { + QString authorOriginal() const { if (auto forwarded = Get()) { - return forwarded->_authorOriginal; + return forwarded->_originalAuthor; + } else if (auto msgsigned = Get()) { + return msgsigned->_author; } - return author(); + return QString(); } MsgId idOriginal() const { if (auto forwarded = Get()) { diff --git a/Telegram/SourceFiles/history/history_media_types.cpp b/Telegram/SourceFiles/history/history_media_types.cpp index 366723fea..1806d9ff9 100644 --- a/Telegram/SourceFiles/history/history_media_types.cpp +++ b/Telegram/SourceFiles/history/history_media_types.cpp @@ -76,12 +76,17 @@ inline void initTextOptions() { bool needReSetInlineResultDocument(const MTPMessageMedia &media, DocumentData *existing) { if (media.type() == mtpc_messageMediaDocument) { - if (auto document = App::feedDocument(media.c_messageMediaDocument().vdocument)) { - if (document == existing) { - return false; - } else { - document->collectLocalData(existing); + auto &mediaDocument = media.c_messageMediaDocument(); + if (mediaDocument.has_document() && !mediaDocument.has_ttl_seconds()) { + if (auto document = App::feedDocument(mediaDocument.vdocument)) { + if (document == existing) { + return false; + } else { + document->collectLocalData(existing); + } } + } else { + LOG(("API Error: Got MTPMessageMediaDocument without document or with ttl_seconds in needReSetInlineResultDocument()")); } } return true; @@ -528,7 +533,12 @@ HistoryTextState HistoryPhoto::getState(QPoint point, HistoryStateRequest reques void HistoryPhoto::updateSentMedia(const MTPMessageMedia &media) { if (media.type() == mtpc_messageMediaPhoto) { - auto &photo = media.c_messageMediaPhoto().vphoto; + auto &mediaPhoto = media.c_messageMediaPhoto(); + if (!mediaPhoto.has_photo() || mediaPhoto.has_ttl_seconds()) { + LOG(("Api Error: Got MTPMessageMediaPhoto without photo or with ttl_seconds in updateSentMedia()")); + return; + } + auto &photo = mediaPhoto.vphoto; App::feedPhoto(photo, _data); if (photo.type() == mtpc_photo) { @@ -576,12 +586,17 @@ void HistoryPhoto::updateSentMedia(const MTPMessageMedia &media) { bool HistoryPhoto::needReSetInlineResultMedia(const MTPMessageMedia &media) { if (media.type() == mtpc_messageMediaPhoto) { - if (auto existing = App::feedPhoto(media.c_messageMediaPhoto().vphoto)) { - if (existing == _data) { - return false; - } else { - // collect data + auto &photo = media.c_messageMediaPhoto(); + if (photo.has_photo() && !photo.has_ttl_seconds()) { + if (auto existing = App::feedPhoto(photo.vphoto)) { + if (existing == _data) { + return false; + } else { + // collect data + } } + } else { + LOG(("API Error: Got MTPMessageMediaPhoto without photo or with ttl_seconds in needReSetInlineResultMedia()")); } } return false; @@ -973,7 +988,12 @@ void HistoryVideo::detachFromParent() { void HistoryVideo::updateSentMedia(const MTPMessageMedia &media) { if (media.type() == mtpc_messageMediaDocument) { - App::feedDocument(media.c_messageMediaDocument().vdocument, _data); + auto &mediaDocument = media.c_messageMediaDocument(); + if (!mediaDocument.has_document() || mediaDocument.has_ttl_seconds()) { + LOG(("Api Error: Got MTPMessageMediaDocument without document or with ttl_seconds in HistoryVideo::updateSentMedia()")); + return; + } + App::feedDocument(mediaDocument.vdocument, _data); } } @@ -1748,7 +1768,12 @@ void HistoryDocument::detachFromParent() { void HistoryDocument::updateSentMedia(const MTPMessageMedia &media) { if (media.type() == mtpc_messageMediaDocument) { - App::feedDocument(media.c_messageMediaDocument().vdocument, _data); + auto &mediaDocument = media.c_messageMediaDocument(); + if (!mediaDocument.has_document() || mediaDocument.has_ttl_seconds()) { + LOG(("Api Error: Got MTPMessageMediaDocument without document or with ttl_seconds in HistoryDocument::updateSentMedia()")); + return; + } + App::feedDocument(mediaDocument.vdocument, _data); if (!_data->data().isEmpty()) { if (_data->voice()) { Local::writeAudio(_data->mediaKey(), _data->data()); @@ -2489,7 +2514,12 @@ void HistoryGif::detachFromParent() { void HistoryGif::updateSentMedia(const MTPMessageMedia &media) { if (media.type() == mtpc_messageMediaDocument) { - App::feedDocument(media.c_messageMediaDocument().vdocument, _data); + auto &mediaDocument = media.c_messageMediaDocument(); + if (!mediaDocument.has_document() || mediaDocument.has_ttl_seconds()) { + LOG(("Api Error: Got MTPMessageMediaDocument without document or with ttl_seconds in HistoryGif::updateSentMedia()")); + return; + } + App::feedDocument(mediaDocument.vdocument, _data); } } @@ -2836,7 +2866,12 @@ void HistorySticker::detachFromParent() { void HistorySticker::updateSentMedia(const MTPMessageMedia &media) { if (media.type() == mtpc_messageMediaDocument) { - App::feedDocument(media.c_messageMediaDocument().vdocument, _data); + auto &mediaDocument = media.c_messageMediaDocument(); + if (!mediaDocument.has_document() || mediaDocument.has_ttl_seconds()) { + LOG(("Api Error: Got MTPMessageMediaDocument without document or with ttl_seconds in HistorySticker::updateSentMedia()")); + return; + } + App::feedDocument(mediaDocument.vdocument, _data); if (!_data->data().isEmpty()) { Local::writeStickerImage(_data->mediaKey(), _data->data()); } diff --git a/Telegram/SourceFiles/history/history_message.cpp b/Telegram/SourceFiles/history/history_message.cpp index 6d69d3f1c..28c8fa9ee 100644 --- a/Telegram/SourceFiles/history/history_message.cpp +++ b/Telegram/SourceFiles/history/history_message.cpp @@ -77,7 +77,7 @@ style::color fromNameFgSelected(int index) { return colors[index]; } -MTPDmessage::Flags NewForwardedFlags(gsl::not_null peer, int32 from, gsl::not_null fwd) { +MTPDmessage::Flags NewForwardedFlags(gsl::not_null peer, UserId from, gsl::not_null fwd) { auto result = NewMessageFlags(peer) | MTPDmessage::Flag::f_fwd_from; if (from) { result |= MTPDmessage::Flag::f_from_id; @@ -321,7 +321,7 @@ QString GetErrorTextForForward(gsl::not_null peer, const SelectedItem return QString(); } -void HistoryMessageVia::create(int32 userId) { +void HistoryMessageVia::create(UserId userId) { _bot = App::user(peerFromUser(userId)); _maxWidth = st::msgServiceNameFont->width(lng_inline_bot_via(lt_inline_bot, '@' + _bot->username)); _lnk = MakeShared([bot = _bot] { @@ -344,14 +344,15 @@ void HistoryMessageVia::resize(int32 availw) const { } } -void HistoryMessageSigned::create(UserData *from, const QString &date) { +void HistoryMessageSigned::create(const QString &author, const QString &date) { auto time = qsl(", ") + date; - auto name = App::peerName(from); + auto name = author; auto timew = st::msgDateFont->width(time); auto namew = st::msgDateFont->width(name); if (timew + namew > st::maxSignatureSize) { - name = st::msgDateFont->elided(from->firstName, st::maxSignatureSize - timew); + name = st::msgDateFont->elided(author, st::maxSignatureSize - timew); } + _author = author; _signature.setText(st::msgDateTextStyle, name + time, _textNameOptions); } @@ -370,19 +371,19 @@ int HistoryMessageEdited::maxWidth() const { void HistoryMessageForwarded::create(const HistoryMessageVia *via) const { QString text; - if (_authorOriginal != _fromOriginal) { - text = lng_forwarded_signed(lt_channel, App::peerName(_authorOriginal), lt_user, App::peerName(_fromOriginal)); + if (!_originalAuthor.isEmpty()) { + text = lng_forwarded_signed(lt_channel, App::peerName(_originalPeer), lt_user, _originalAuthor); } else { - text = App::peerName(_authorOriginal); + text = App::peerName(_originalPeer); } if (via) { - if (_authorOriginal->isChannel()) { + if (_originalPeer->isChannel()) { text = lng_forwarded_channel_via(lt_channel, textcmdLink(1, text), lt_inline_bot, textcmdLink(2, '@' + via->_bot->username)); } else { text = lng_forwarded_via(lt_user, textcmdLink(1, text), lt_inline_bot, textcmdLink(2, '@' + via->_bot->username)); } } else { - if (_authorOriginal->isChannel()) { + if (_originalPeer->isChannel()) { text = lng_forwarded_channel(lt_channel, textcmdLink(1, text)); } else { text = lng_forwarded(lt_user, textcmdLink(1, text)); @@ -390,7 +391,7 @@ void HistoryMessageForwarded::create(const HistoryMessageVia *via) const { } TextParseOptions opts = { TextParseRichText, 0, 0, Qt::LayoutDirectionAuto }; _text.setText(st::fwdTextStyle, text, opts); - _text.setLink(1, (_originalId && _authorOriginal->isChannel()) ? goToMessageClickHandler(_authorOriginal, _originalId) : _authorOriginal->openLink()); + _text.setLink(1, (_originalId && _originalPeer->isChannel()) ? goToMessageClickHandler(_originalPeer, _originalId) : _originalPeer->openLink()); if (via) { _text.setLink(2, via->_lnk); } @@ -609,9 +610,9 @@ HistoryMessage::HistoryMessage(gsl::not_null history, const MTPDmessag auto &f = msg.vfwd_from.c_messageFwdHeader(); config.originalDate = ::date(f.vdate); if (f.has_from_id() || f.has_channel_id()) { - config.authorIdOriginal = f.has_channel_id() ? peerFromChannel(f.vchannel_id) : peerFromUser(f.vfrom_id); - config.fromIdOriginal = f.has_from_id() ? peerFromUser(f.vfrom_id) : peerFromChannel(f.vchannel_id); + config.peerIdOriginal = f.has_channel_id() ? peerFromChannel(f.vchannel_id) : peerFromUser(f.vfrom_id); if (f.has_channel_post()) config.originalId = f.vchannel_post.v; + if (f.has_post_author()) config.authorOriginal = qs(f.vpost_author); } } if (msg.has_reply_to_msg_id()) config.replyTo = msg.vreply_to_msg_id.v; @@ -619,6 +620,7 @@ HistoryMessage::HistoryMessage(gsl::not_null history, const MTPDmessag if (msg.has_views()) config.viewsCount = msg.vviews.v; if (msg.has_reply_markup()) config.mtpMarkup = &msg.vreply_markup; if (msg.has_edit_date()) config.editDate = ::date(msg.vedit_date); + if (msg.has_post_author()) config.author = qs(msg.vpost_author); createComponents(config); @@ -648,19 +650,23 @@ HistoryMessage::HistoryMessage(gsl::not_null history, const MTPDmessag setText(TextWithEntities {}); } -HistoryMessage::HistoryMessage(gsl::not_null history, MsgId id, MTPDmessage::Flags flags, QDateTime date, int32 from, gsl::not_null fwd) +HistoryMessage::HistoryMessage(gsl::not_null history, MsgId id, MTPDmessage::Flags flags, QDateTime date, UserId from, const QString &postAuthor, gsl::not_null fwd) : HistoryItem(history, id, NewForwardedFlags(history->peer, from, fwd) | flags, date, from) { CreateConfig config; if (fwd->Has() || !fwd->history()->peer->isSelf()) { // Server doesn't add "fwd_from" to non-forwarded messages from chat with yourself. config.originalDate = fwd->dateOriginal(); - config.authorIdOriginal = fwd->authorOriginal()->id; - config.fromIdOriginal = fwd->fromOriginal()->id; - if (fwd->authorOriginal()->isChannel()) { + auto peerOriginal = fwd->peerOriginal(); + config.peerIdOriginal = peerOriginal->id; + config.authorOriginal = fwd->authorOriginal(); + if (peerOriginal->isChannel()) { config.originalId = fwd->idOriginal(); } } + if (flags & MTPDmessage::Flag::f_post_author) { + config.author = postAuthor; + } auto fwdViaBot = fwd->viaBot(); if (fwdViaBot) config.viaBotId = peerToUser(fwdViaBot->id); int fwdViewsCount = fwd->viewsCount(); @@ -695,43 +701,44 @@ HistoryMessage::HistoryMessage(gsl::not_null history, MsgId id, MTPDme setText(fwd->originalText()); } -HistoryMessage::HistoryMessage(gsl::not_null history, MsgId id, MTPDmessage::Flags flags, MsgId replyTo, int32 viaBotId, QDateTime date, int32 from, const TextWithEntities &textWithEntities) +HistoryMessage::HistoryMessage(gsl::not_null history, MsgId id, MTPDmessage::Flags flags, MsgId replyTo, UserId viaBotId, QDateTime date, UserId from, const QString &postAuthor, const TextWithEntities &textWithEntities) : HistoryItem(history, id, flags, date, (flags & MTPDmessage::Flag::f_from_id) ? from : 0) { - createComponentsHelper(flags, replyTo, viaBotId, MTPnullMarkup); + createComponentsHelper(flags, replyTo, viaBotId, postAuthor, MTPnullMarkup); setText(textWithEntities); } -HistoryMessage::HistoryMessage(gsl::not_null history, MsgId msgId, MTPDmessage::Flags flags, MsgId replyTo, int32 viaBotId, QDateTime date, int32 from, DocumentData *doc, const QString &caption, const MTPReplyMarkup &markup) +HistoryMessage::HistoryMessage(gsl::not_null history, MsgId msgId, MTPDmessage::Flags flags, MsgId replyTo, UserId viaBotId, QDateTime date, UserId from, const QString &postAuthor, DocumentData *doc, const QString &caption, const MTPReplyMarkup &markup) : HistoryItem(history, msgId, flags, date, (flags & MTPDmessage::Flag::f_from_id) ? from : 0) { - createComponentsHelper(flags, replyTo, viaBotId, markup); + createComponentsHelper(flags, replyTo, viaBotId, postAuthor, markup); initMediaFromDocument(doc, caption); setText(TextWithEntities()); } -HistoryMessage::HistoryMessage(gsl::not_null history, MsgId msgId, MTPDmessage::Flags flags, MsgId replyTo, int32 viaBotId, QDateTime date, int32 from, PhotoData *photo, const QString &caption, const MTPReplyMarkup &markup) +HistoryMessage::HistoryMessage(gsl::not_null history, MsgId msgId, MTPDmessage::Flags flags, MsgId replyTo, UserId viaBotId, QDateTime date, UserId from, const QString &postAuthor, PhotoData *photo, const QString &caption, const MTPReplyMarkup &markup) : HistoryItem(history, msgId, flags, date, (flags & MTPDmessage::Flag::f_from_id) ? from : 0) { - createComponentsHelper(flags, replyTo, viaBotId, markup); + createComponentsHelper(flags, replyTo, viaBotId, postAuthor, markup); _media = std::make_unique(this, photo, caption); setText(TextWithEntities()); } -HistoryMessage::HistoryMessage(gsl::not_null history, MsgId msgId, MTPDmessage::Flags flags, MsgId replyTo, int32 viaBotId, QDateTime date, int32 from, GameData *game, const MTPReplyMarkup &markup) +HistoryMessage::HistoryMessage(gsl::not_null history, MsgId msgId, MTPDmessage::Flags flags, MsgId replyTo, UserId viaBotId, QDateTime date, UserId from, const QString &postAuthor, GameData *game, const MTPReplyMarkup &markup) : HistoryItem(history, msgId, flags, date, (flags & MTPDmessage::Flag::f_from_id) ? from : 0) { - createComponentsHelper(flags, replyTo, viaBotId, markup); + createComponentsHelper(flags, replyTo, viaBotId, postAuthor, markup); _media = std::make_unique(this, game); setText(TextWithEntities()); } -void HistoryMessage::createComponentsHelper(MTPDmessage::Flags flags, MsgId replyTo, int32 viaBotId, const MTPReplyMarkup &markup) { +void HistoryMessage::createComponentsHelper(MTPDmessage::Flags flags, MsgId replyTo, UserId viaBotId, const QString &postAuthor, const MTPReplyMarkup &markup) { CreateConfig config; if (flags & MTPDmessage::Flag::f_via_bot_id) config.viaBotId = viaBotId; if (flags & MTPDmessage::Flag::f_reply_to_msg_id) config.replyTo = replyTo; if (flags & MTPDmessage::Flag::f_reply_markup) config.mtpMarkup = &markup; + if (flags & MTPDmessage::Flag::f_post_author) config.author = postAuthor; if (isPost()) config.viewsCount = 1; createComponents(config); @@ -823,7 +830,7 @@ void HistoryMessage::createComponents(const CreateConfig &config) { if (config.viewsCount >= 0) { mask |= HistoryMessageViews::Bit(); } - if (isPost() && _from->isUser()) { + if (!config.author.isEmpty()) { mask |= HistoryMessageSigned::Bit(); } auto hasViaBot = (config.viaBotId != 0); @@ -836,7 +843,7 @@ void HistoryMessage::createComponents(const CreateConfig &config) { if (displayEditedBadge(hasViaBot || hasInlineMarkup())) { mask |= HistoryMessageEdited::Bit(); } - if (config.authorIdOriginal && config.fromIdOriginal) { + if (config.peerIdOriginal) { mask |= HistoryMessageForwarded::Bit(); } if (config.mtpMarkup) { @@ -866,16 +873,16 @@ void HistoryMessage::createComponents(const CreateConfig &config) { if (auto edited = Get()) { edited->create(config.editDate, date.toString(cTimeFormat())); if (auto msgsigned = Get()) { - msgsigned->create(_from->asUser(), edited->_edited.originalText()); + msgsigned->create(config.author, edited->_edited.originalText()); } } else if (auto msgsigned = Get()) { - msgsigned->create(_from->asUser(), date.toString(cTimeFormat())); + msgsigned->create(config.author, date.toString(cTimeFormat())); } if (auto forwarded = Get()) { forwarded->_originalDate = config.originalDate; - forwarded->_authorOriginal = App::peer(config.authorIdOriginal); - forwarded->_fromOriginal = App::peer(config.fromIdOriginal); + forwarded->_originalPeer = App::peer(config.peerIdOriginal); forwarded->_originalId = config.originalId; + forwarded->_originalAuthor = config.authorOriginal; } if (auto markup = Get()) { if (config.mtpMarkup) { @@ -944,14 +951,22 @@ void HistoryMessage::initMedia(const MTPMessageMedia *media) { } break; case mtpc_messageMediaPhoto: { auto &photo = media->c_messageMediaPhoto(); - if (photo.vphoto.type() == mtpc_photo) { - _media = std::make_unique(this, App::feedPhoto(photo.vphoto.c_photo()), qs(photo.vcaption)); + if (photo.has_ttl_seconds()) { + LOG(("App Error: Unexpected MTPMessageMediaPhoto with ttl_seconds in HistoryMessage.")); + } else if (photo.has_photo() && photo.vphoto.type() == mtpc_photo) { + _media = std::make_unique(this, App::feedPhoto(photo.vphoto.c_photo()), photo.has_caption() ? qs(photo.vcaption) : QString()); + } else { + LOG(("API Error: Got MTPMessageMediaPhoto without photo and without ttl_seconds.")); } } break; case mtpc_messageMediaDocument: { - auto &document = media->c_messageMediaDocument().vdocument; - if (document.type() == mtpc_document) { - return initMediaFromDocument(App::feedDocument(document), qs(media->c_messageMediaDocument().vcaption)); + auto &document = media->c_messageMediaDocument(); + if (document.has_ttl_seconds()) { + LOG(("App Error: Unexpected MTPMessageMediaDocument with ttl_seconds in HistoryMessage.")); + } else if (document.has_document() && document.vdocument.type() == mtpc_document) { + return initMediaFromDocument(App::feedDocument(document.vdocument.c_document()), document.has_caption() ? qs(document.vcaption) : QString()); + } else { + LOG(("API Error: Got MTPMessageMediaDocument without document and without ttl_seconds.")); } } break; case mtpc_messageMediaWebPage: { @@ -1177,12 +1192,12 @@ void HistoryMessage::applyEdition(const MTPDmessage &message) { auto edited = Get(); edited->create(::date(message.vedit_date), date.toString(cTimeFormat())); if (auto msgsigned = Get()) { - msgsigned->create(_from->asUser(), edited->_edited.originalText()); + msgsigned->create(msgsigned->_author, edited->_edited.originalText()); } } else if (Has()) { RemoveComponents(HistoryMessageEdited::Bit()); if (auto msgsigned = Get()) { - msgsigned->create(_from->asUser(), date.toString(cTimeFormat())); + msgsigned->create(msgsigned->_author, date.toString(cTimeFormat())); } } initTime(); @@ -1221,7 +1236,7 @@ bool HistoryMessage::displayForwardedFrom() const { || !_media || !_media->isDisplayed() || !_media->hideForwardedFrom() - || forwarded->_authorOriginal->isChannel(); + || forwarded->_originalPeer->isChannel(); } return false; } diff --git a/Telegram/SourceFiles/history/history_message.h b/Telegram/SourceFiles/history/history_message.h index edcd380fc..ea9f6280a 100644 --- a/Telegram/SourceFiles/history/history_message.h +++ b/Telegram/SourceFiles/history/history_message.h @@ -34,20 +34,20 @@ public: static gsl::not_null create(gsl::not_null history, const MTPDmessageService &msg) { return _create(history, msg); } - static gsl::not_null create(gsl::not_null history, MsgId msgId, MTPDmessage::Flags flags, QDateTime date, int32 from, gsl::not_null fwd) { - return _create(history, msgId, flags, date, from, fwd); + static gsl::not_null create(gsl::not_null history, MsgId msgId, MTPDmessage::Flags flags, QDateTime date, UserId from, const QString &postAuthor, gsl::not_null fwd) { + return _create(history, msgId, flags, date, from, postAuthor, fwd); } - static gsl::not_null create(gsl::not_null history, MsgId msgId, MTPDmessage::Flags flags, MsgId replyTo, int32 viaBotId, QDateTime date, int32 from, const TextWithEntities &textWithEntities) { - return _create(history, msgId, flags, replyTo, viaBotId, date, from, textWithEntities); + static gsl::not_null create(gsl::not_null history, MsgId msgId, MTPDmessage::Flags flags, MsgId replyTo, UserId viaBotId, QDateTime date, UserId from, const QString &postAuthor, const TextWithEntities &textWithEntities) { + return _create(history, msgId, flags, replyTo, viaBotId, date, from, postAuthor, textWithEntities); } - static gsl::not_null create(gsl::not_null history, MsgId msgId, MTPDmessage::Flags flags, MsgId replyTo, int32 viaBotId, QDateTime date, int32 from, DocumentData *doc, const QString &caption, const MTPReplyMarkup &markup) { - return _create(history, msgId, flags, replyTo, viaBotId, date, from, doc, caption, markup); + static gsl::not_null create(gsl::not_null history, MsgId msgId, MTPDmessage::Flags flags, MsgId replyTo, UserId viaBotId, QDateTime date, UserId from, const QString &postAuthor, DocumentData *doc, const QString &caption, const MTPReplyMarkup &markup) { + return _create(history, msgId, flags, replyTo, viaBotId, date, from, postAuthor, doc, caption, markup); } - static gsl::not_null create(gsl::not_null history, MsgId msgId, MTPDmessage::Flags flags, MsgId replyTo, int32 viaBotId, QDateTime date, int32 from, PhotoData *photo, const QString &caption, const MTPReplyMarkup &markup) { - return _create(history, msgId, flags, replyTo, viaBotId, date, from, photo, caption, markup); + static gsl::not_null create(gsl::not_null history, MsgId msgId, MTPDmessage::Flags flags, MsgId replyTo, UserId viaBotId, QDateTime date, UserId from, const QString &postAuthor, PhotoData *photo, const QString &caption, const MTPReplyMarkup &markup) { + return _create(history, msgId, flags, replyTo, viaBotId, date, from, postAuthor, photo, caption, markup); } - static gsl::not_null create(gsl::not_null history, MsgId msgId, MTPDmessage::Flags flags, MsgId replyTo, int32 viaBotId, QDateTime date, int32 from, GameData *game, const MTPReplyMarkup &markup) { - return _create(history, msgId, flags, replyTo, viaBotId, date, from, game, markup); + static gsl::not_null create(gsl::not_null history, MsgId msgId, MTPDmessage::Flags flags, MsgId replyTo, UserId viaBotId, QDateTime date, UserId from, const QString &postAuthor, GameData *game, const MTPReplyMarkup &markup) { + return _create(history, msgId, flags, replyTo, viaBotId, date, from, postAuthor, game, markup); } void initTime(); @@ -148,11 +148,11 @@ public: private: HistoryMessage(gsl::not_null history, const MTPDmessage &msg); HistoryMessage(gsl::not_null history, const MTPDmessageService &msg); - HistoryMessage(gsl::not_null history, MsgId msgId, MTPDmessage::Flags flags, QDateTime date, int32 from, gsl::not_null fwd); // local forwarded - HistoryMessage(gsl::not_null history, MsgId msgId, MTPDmessage::Flags flags, MsgId replyTo, int32 viaBotId, QDateTime date, int32 from, const TextWithEntities &textWithEntities); // local message - HistoryMessage(gsl::not_null history, MsgId msgId, MTPDmessage::Flags flags, MsgId replyTo, int32 viaBotId, QDateTime date, int32 from, DocumentData *doc, const QString &caption, const MTPReplyMarkup &markup); // local document - HistoryMessage(gsl::not_null history, MsgId msgId, MTPDmessage::Flags flags, MsgId replyTo, int32 viaBotId, QDateTime date, int32 from, PhotoData *photo, const QString &caption, const MTPReplyMarkup &markup); // local photo - HistoryMessage(gsl::not_null history, MsgId msgId, MTPDmessage::Flags flags, MsgId replyTo, int32 viaBotId, QDateTime date, int32 from, GameData *game, const MTPReplyMarkup &markup); // local game + HistoryMessage(gsl::not_null history, MsgId msgId, MTPDmessage::Flags flags, QDateTime date, UserId from, const QString &postAuthor, gsl::not_null fwd); // local forwarded + HistoryMessage(gsl::not_null history, MsgId msgId, MTPDmessage::Flags flags, MsgId replyTo, UserId viaBotId, QDateTime date, UserId from, const QString &postAuthor, const TextWithEntities &textWithEntities); // local message + HistoryMessage(gsl::not_null history, MsgId msgId, MTPDmessage::Flags flags, MsgId replyTo, UserId viaBotId, QDateTime date, UserId from, const QString &postAuthor, DocumentData *doc, const QString &caption, const MTPReplyMarkup &markup); // local document + HistoryMessage(gsl::not_null history, MsgId msgId, MTPDmessage::Flags flags, MsgId replyTo, UserId viaBotId, QDateTime date, UserId from, const QString &postAuthor, PhotoData *photo, const QString &caption, const MTPReplyMarkup &markup); // local photo + HistoryMessage(gsl::not_null history, MsgId msgId, MTPDmessage::Flags flags, MsgId replyTo, UserId viaBotId, QDateTime date, UserId from, const QString &postAuthor, GameData *game, const MTPReplyMarkup &markup); // local game friend class HistoryItemInstantiated; void setEmptyText(); @@ -192,9 +192,10 @@ private: MsgId replyTo = 0; UserId viaBotId = 0; int viewsCount = -1; - PeerId authorIdOriginal = 0; - PeerId fromIdOriginal = 0; + QString author; + PeerId peerIdOriginal = 0; MsgId originalId = 0; + QString authorOriginal; QDateTime originalDate; QDateTime editDate; @@ -204,7 +205,7 @@ private: // For messages created from existing messages (forwarded). const HistoryMessageReplyMarkup *inlineMarkup = nullptr; }; - void createComponentsHelper(MTPDmessage::Flags flags, MsgId replyTo, int32 viaBotId, const MTPReplyMarkup &markup); + void createComponentsHelper(MTPDmessage::Flags flags, MsgId replyTo, UserId viaBotId, const QString &postAuthor, const MTPReplyMarkup &markup); void createComponents(const CreateConfig &config); class KeyboardStyle : public ReplyKeyboard::Style { diff --git a/Telegram/SourceFiles/history/history_service.cpp b/Telegram/SourceFiles/history/history_service.cpp index 7b1903b09..cb4128a63 100644 --- a/Telegram/SourceFiles/history/history_service.cpp +++ b/Telegram/SourceFiles/history/history_service.cpp @@ -151,6 +151,17 @@ void HistoryService::setMessageByAction(const MTPmessageAction &action) { return result; }; + auto prepareScreenshotTaken = [this] { + auto result = PreparedText {}; + if (out()) { + result.text = lang(lng_action_you_took_screenshot); + } else { + result.links.push_back(fromLink()); + result.text = lng_action_took_screenshot(lt_from, fromLinkText()); + } + return result; + }; + auto messageText = PreparedText {}; switch (action.type()) { @@ -169,6 +180,7 @@ void HistoryService::setMessageByAction(const MTPmessageAction &action) { case mtpc_messageActionGameScore: messageText = prepareGameScoreText(); break; case mtpc_messageActionPhoneCall: Unexpected("PhoneCall type in HistoryService."); case mtpc_messageActionPaymentSent: messageText = preparePaymentSentText(); break; + case mtpc_messageActionScreenshotTaken: messageText = prepareScreenshotTaken(); break; default: messageText.text = lang(lng_message_empty); break; } diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index 949781dda..7e896e936 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -3121,20 +3121,22 @@ void HistoryWidget::shareContact(const PeerId &peer, const QString &phone, const } bool channelPost = p->isChannel() && !p->isMegagroup(); - bool showFromName = !channelPost || p->asChannel()->addsSignature(); bool silentPost = channelPost && _silent->checked(); if (channelPost) { flags |= MTPDmessage::Flag::f_views; flags |= MTPDmessage::Flag::f_post; } - if (showFromName) { + if (!channelPost) { flags |= MTPDmessage::Flag::f_from_id; + } else if (p->asChannel()->addsSignature()) { + flags |= MTPDmessage::Flag::f_post_author; } if (silentPost) { sendFlags |= MTPmessages_SendMedia::Flag::f_silent; } - auto messageFromId = showFromName ? AuthSession::CurrentUserId() : 0; - history->addNewMessage(MTP_message(MTP_flags(flags), MTP_int(newId.msg), MTP_int(messageFromId), peerToMTP(peer), MTPnullFwdHeader, MTPint(), MTP_int(replyToId()), MTP_int(unixtime()), MTP_string(""), MTP_messageMediaContact(MTP_string(phone), MTP_string(fname), MTP_string(lname), MTP_int(userId)), MTPnullMarkup, MTPnullEntities, MTP_int(1), MTPint()), NewMessageUnread); + auto messageFromId = channelPost ? 0 : AuthSession::CurrentUserId(); + auto messagePostAuthor = channelPost ? (AuthSession::CurrentUser()->firstName + ' ' + AuthSession::CurrentUser()->lastName) : QString(); + history->addNewMessage(MTP_message(MTP_flags(flags), MTP_int(newId.msg), MTP_int(messageFromId), peerToMTP(peer), MTPnullFwdHeader, MTPint(), MTP_int(replyToId()), MTP_int(unixtime()), MTP_string(""), MTP_messageMediaContact(MTP_string(phone), MTP_string(fname), MTP_string(lname), MTP_int(userId)), MTPnullMarkup, MTPnullEntities, MTP_int(1), MTPint(), MTP_string(messagePostAuthor)), NewMessageUnread); history->sendRequestId = MTP::send(MTPmessages_SendMedia(MTP_flags(sendFlags), p->input, MTP_int(replyTo), MTP_inputMediaContact(MTP_string(phone), MTP_string(fname), MTP_string(lname)), MTP_long(randomId), MTPnullMarkup), App::main()->rpcDone(&MainWidget::sentUpdatesReceived), App::main()->rpcFail(&MainWidget::sendMessageFail), 0, 0, history->sendRequestId); App::historyRegRandom(randomId, newId); @@ -3551,13 +3553,15 @@ bool HistoryWidget::botCallbackFail(BotCallbackInfo info, const RPCError &error, bool HistoryWidget::insertBotCommand(const QString &cmd) { if (!canWriteMessage()) return false; - bool insertingInlineBot = !cmd.isEmpty() && (cmd.at(0) == '@'); - QString toInsert = cmd; + auto insertingInlineBot = !cmd.isEmpty() && (cmd.at(0) == '@'); + auto toInsert = cmd; if (!toInsert.isEmpty() && !insertingInlineBot) { - PeerData *bot = _peer->isUser() ? _peer : (App::hoveredLinkItem() ? App::hoveredLinkItem()->fromOriginal() : 0); - if (!bot->isUser() || !bot->asUser()->botInfo) bot = 0; - QString username = bot ? bot->asUser()->username : QString(); - int32 botStatus = _peer->isChat() ? _peer->asChat()->botStatus : (_peer->isMegagroup() ? _peer->asChannel()->mgInfo->botStatus : -1); + auto bot = _peer->isUser() ? _peer : (App::hoveredLinkItem() ? App::hoveredLinkItem()->fromOriginal() : nullptr); + if (bot && (!bot->isUser() || !bot->asUser()->botInfo)) { + bot = nullptr; + } + auto username = bot ? bot->asUser()->username : QString(); + auto botStatus = _peer->isChat() ? _peer->asChat()->botStatus : (_peer->isMegagroup() ? _peer->asChannel()->mgInfo->botStatus : -1); if (toInsert.indexOf('@') < 0 && !username.isEmpty() && (botStatus == 0 || botStatus == 2)) { toInsert += '@' + username; } @@ -4562,28 +4566,45 @@ void HistoryWidget::sendFileConfirmed(const FileLoadResultPtr &file) { auto flags = NewMessageFlags(h->peer) | MTPDmessage::Flag::f_media; // unread, out if (file->to.replyTo) flags |= MTPDmessage::Flag::f_reply_to_msg_id; bool channelPost = h->peer->isChannel() && !h->peer->isMegagroup(); - bool showFromName = !channelPost || h->peer->asChannel()->addsSignature(); bool silentPost = channelPost && file->to.silent; if (channelPost) { flags |= MTPDmessage::Flag::f_views; flags |= MTPDmessage::Flag::f_post; } - if (showFromName) { + if (!channelPost) { flags |= MTPDmessage::Flag::f_from_id; + } else if (h->peer->asChannel()->addsSignature()) { + flags |= MTPDmessage::Flag::f_post_author; } if (silentPost) { flags |= MTPDmessage::Flag::f_silent; } - auto messageFromId = showFromName ? AuthSession::CurrentUserId() : 0; + auto messageFromId = channelPost ? 0 : AuthSession::CurrentUserId(); + auto messagePostAuthor = channelPost ? (AuthSession::CurrentUser()->firstName + ' ' + AuthSession::CurrentUser()->lastName) : QString(); if (file->type == SendMediaType::Photo) { - h->addNewMessage(MTP_message(MTP_flags(flags), MTP_int(newId.msg), MTP_int(messageFromId), peerToMTP(file->to.peer), MTPnullFwdHeader, MTPint(), MTP_int(file->to.replyTo), MTP_int(unixtime()), MTP_string(""), MTP_messageMediaPhoto(file->photo, MTP_string(file->caption)), MTPnullMarkup, MTPnullEntities, MTP_int(1), MTPint()), NewMessageUnread); + auto photoFlags = qFlags(MTPDmessageMediaPhoto::Flag::f_photo); + if (!file->caption.isEmpty()) { + photoFlags |= MTPDmessageMediaPhoto::Flag::f_caption; + } + auto photo = MTP_messageMediaPhoto(MTP_flags(photoFlags), file->photo, MTP_string(file->caption), MTPint()); + h->addNewMessage(MTP_message(MTP_flags(flags), MTP_int(newId.msg), MTP_int(messageFromId), peerToMTP(file->to.peer), MTPnullFwdHeader, MTPint(), MTP_int(file->to.replyTo), MTP_int(unixtime()), MTP_string(""), photo, MTPnullMarkup, MTPnullEntities, MTP_int(1), MTPint(), MTP_string(messagePostAuthor)), NewMessageUnread); } else if (file->type == SendMediaType::File) { - h->addNewMessage(MTP_message(MTP_flags(flags), MTP_int(newId.msg), MTP_int(messageFromId), peerToMTP(file->to.peer), MTPnullFwdHeader, MTPint(), MTP_int(file->to.replyTo), MTP_int(unixtime()), MTP_string(""), MTP_messageMediaDocument(file->document, MTP_string(file->caption)), MTPnullMarkup, MTPnullEntities, MTP_int(1), MTPint()), NewMessageUnread); + auto documentFlags = qFlags(MTPDmessageMediaDocument::Flag::f_document); + if (!file->caption.isEmpty()) { + documentFlags |= MTPDmessageMediaDocument::Flag::f_caption; + } + auto document = MTP_messageMediaDocument(MTP_flags(documentFlags), file->document, MTP_string(file->caption), MTPint()); + h->addNewMessage(MTP_message(MTP_flags(flags), MTP_int(newId.msg), MTP_int(messageFromId), peerToMTP(file->to.peer), MTPnullFwdHeader, MTPint(), MTP_int(file->to.replyTo), MTP_int(unixtime()), MTP_string(""), document, MTPnullMarkup, MTPnullEntities, MTP_int(1), MTPint(), MTP_string(messagePostAuthor)), NewMessageUnread); } else if (file->type == SendMediaType::Audio) { if (!h->peer->isChannel()) { flags |= MTPDmessage::Flag::f_media_unread; } - h->addNewMessage(MTP_message(MTP_flags(flags), MTP_int(newId.msg), MTP_int(messageFromId), peerToMTP(file->to.peer), MTPnullFwdHeader, MTPint(), MTP_int(file->to.replyTo), MTP_int(unixtime()), MTP_string(""), MTP_messageMediaDocument(file->document, MTP_string(file->caption)), MTPnullMarkup, MTPnullEntities, MTP_int(1), MTPint()), NewMessageUnread); + auto documentFlags = qFlags(MTPDmessageMediaDocument::Flag::f_document); + if (!file->caption.isEmpty()) { + documentFlags |= MTPDmessageMediaDocument::Flag::f_caption; + } + auto document = MTP_messageMediaDocument(MTP_flags(documentFlags), file->document, MTP_string(file->caption), MTPint()); + h->addNewMessage(MTP_message(MTP_flags(flags), MTP_int(newId.msg), MTP_int(messageFromId), peerToMTP(file->to.peer), MTPnullFwdHeader, MTPint(), MTP_int(file->to.replyTo), MTP_int(unixtime()), MTP_string(""), document, MTPnullMarkup, MTPnullEntities, MTP_int(1), MTPint(), MTP_string(messagePostAuthor)), NewMessageUnread); } if (_peer && file->to.peer == _peer->id) { @@ -4612,7 +4633,7 @@ void HistoryWidget::onPhotoUploaded(const FullMsgId &newId, bool silent, const M sendFlags |= MTPmessages_SendMedia::Flag::f_silent; } auto caption = item->getMedia() ? item->getMedia()->getCaption() : TextWithEntities(); - auto media = MTP_inputMediaUploadedPhoto(MTP_flags(0), file, MTP_string(caption.text), MTPVector()); + auto media = MTP_inputMediaUploadedPhoto(MTP_flags(0), file, MTP_string(caption.text), MTPVector(), MTP_int(0)); hist->sendRequestId = MTP::send(MTPmessages_SendMedia(MTP_flags(sendFlags), item->history()->peer->input, MTP_int(replyTo), media, MTP_long(randomId), MTPnullMarkup), App::main()->rpcDone(&MainWidget::sentUpdatesReceived), App::main()->rpcFail(&MainWidget::sendMessageFail), 0, 0, hist->sendRequestId); } } @@ -4636,7 +4657,7 @@ void HistoryWidget::onDocumentUploaded(const FullMsgId &newId, bool silent, cons sendFlags |= MTPmessages_SendMedia::Flag::f_silent; } auto caption = item->getMedia() ? item->getMedia()->getCaption() : TextWithEntities(); - auto media = MTP_inputMediaUploadedDocument(MTP_flags(0), file, MTP_string(document->mime), composeDocumentAttributes(document), MTP_string(caption.text), MTPVector()); + auto media = MTP_inputMediaUploadedDocument(MTP_flags(0), file, MTPInputFile(), MTP_string(document->mime), composeDocumentAttributes(document), MTP_string(caption.text), MTPVector(), MTP_int(0)); hist->sendRequestId = MTP::send(MTPmessages_SendMedia(MTP_flags(sendFlags), item->history()->peer->input, MTP_int(replyTo), media, MTP_long(randomId), MTPnullMarkup), App::main()->rpcDone(&MainWidget::sentUpdatesReceived), App::main()->rpcFail(&MainWidget::sendMessageFail), 0, 0, hist->sendRequestId); } } @@ -4661,7 +4682,7 @@ void HistoryWidget::onThumbDocumentUploaded(const FullMsgId &newId, bool silent, sendFlags |= MTPmessages_SendMedia::Flag::f_silent; } auto caption = media ? media->getCaption() : TextWithEntities(); - auto media = MTP_inputMediaUploadedThumbDocument(MTP_flags(0), file, thumb, MTP_string(document->mime), composeDocumentAttributes(document), MTP_string(caption.text), MTPVector()); + auto media = MTP_inputMediaUploadedDocument(MTP_flags(MTPDinputMediaUploadedDocument::Flag::f_thumb), file, thumb, MTP_string(document->mime), composeDocumentAttributes(document), MTP_string(caption.text), MTPVector(), MTP_int(0)); hist->sendRequestId = MTP::send(MTPmessages_SendMedia(MTP_flags(sendFlags), item->history()->peer->input, MTP_int(replyTo), media, MTP_long(randomId), MTPnullMarkup), App::main()->rpcDone(&MainWidget::sentUpdatesReceived), App::main()->rpcFail(&MainWidget::sendMessageFail), 0, 0, hist->sendRequestId); } } @@ -5383,14 +5404,15 @@ void HistoryWidget::onInlineResultSend(InlineBots::Result *result, UserData *bot sendFlags |= MTPmessages_SendInlineBotResult::Flag::f_reply_to_msg_id; } bool channelPost = _peer->isChannel() && !_peer->isMegagroup(); - bool showFromName = !channelPost || _peer->asChannel()->addsSignature(); bool silentPost = channelPost && _silent->checked(); if (channelPost) { flags |= MTPDmessage::Flag::f_views; flags |= MTPDmessage::Flag::f_post; } - if (showFromName) { + if (!channelPost) { flags |= MTPDmessage::Flag::f_from_id; + } else if (_peer->asChannel()->addsSignature()) { + flags |= MTPDmessage::Flag::f_post_author; } if (silentPost) { sendFlags |= MTPmessages_SendInlineBotResult::Flag::f_silent; @@ -5399,12 +5421,13 @@ void HistoryWidget::onInlineResultSend(InlineBots::Result *result, UserData *bot flags |= MTPDmessage::Flag::f_via_bot_id; } - auto messageFromId = showFromName ? AuthSession::CurrentUserId() : 0; + auto messageFromId = channelPost ? 0 : AuthSession::CurrentUserId(); + auto messagePostAuthor = channelPost ? (AuthSession::CurrentUser()->firstName + ' ' + AuthSession::CurrentUser()->lastName) : QString(); MTPint messageDate = MTP_int(unixtime()); UserId messageViaBotId = bot ? peerToUser(bot->id) : 0; MsgId messageId = newId.msg; - result->addToHistory(_history, flags, messageId, messageFromId, messageDate, messageViaBotId, replyToId()); + result->addToHistory(_history, flags, messageId, messageFromId, messageDate, messageViaBotId, replyToId(), messagePostAuthor); _history->sendRequestId = MTP::send(MTPmessages_SendInlineBotResult(MTP_flags(sendFlags), _peer->input, MTP_int(replyToId()), MTP_long(randomId), MTP_long(result->getQueryId()), MTP_string(result->getId())), App::main()->rpcDone(&MainWidget::sentUpdatesReceived), App::main()->rpcFail(&MainWidget::sendMessageFail), 0, 0, _history->sendRequestId); App::main()->finishForwarding(_history, _silent->checked()); @@ -5556,22 +5579,24 @@ bool HistoryWidget::sendExistingDocument(DocumentData *doc, const QString &capti sendFlags |= MTPmessages_SendMedia::Flag::f_reply_to_msg_id; } bool channelPost = _peer->isChannel() && !_peer->isMegagroup(); - bool showFromName = !channelPost || _peer->asChannel()->addsSignature(); bool silentPost = channelPost && _silent->checked(); if (channelPost) { flags |= MTPDmessage::Flag::f_views; flags |= MTPDmessage::Flag::f_post; } - if (showFromName) { + if (!channelPost) { flags |= MTPDmessage::Flag::f_from_id; + } else if (_peer->asChannel()->addsSignature()) { + flags |= MTPDmessage::Flag::f_post_author; } if (silentPost) { sendFlags |= MTPmessages_SendMedia::Flag::f_silent; } - auto messageFromId = showFromName ? AuthSession::CurrentUserId() : 0; - _history->addNewDocument(newId.msg, flags, 0, replyToId(), date(MTP_int(unixtime())), messageFromId, doc, caption, MTPnullMarkup); + auto messageFromId = channelPost ? 0 : AuthSession::CurrentUserId(); + auto messagePostAuthor = channelPost ? (AuthSession::CurrentUser()->firstName + ' ' + AuthSession::CurrentUser()->lastName) : QString(); + _history->addNewDocument(newId.msg, flags, 0, replyToId(), date(MTP_int(unixtime())), messageFromId, messagePostAuthor, doc, caption, MTPnullMarkup); - _history->sendRequestId = MTP::send(MTPmessages_SendMedia(MTP_flags(sendFlags), _peer->input, MTP_int(replyToId()), MTP_inputMediaDocument(mtpInput, MTP_string(caption)), MTP_long(randomId), MTPnullMarkup), App::main()->rpcDone(&MainWidget::sentUpdatesReceived), App::main()->rpcFail(&MainWidget::sendMessageFail), 0, 0, _history->sendRequestId); + _history->sendRequestId = MTP::send(MTPmessages_SendMedia(MTP_flags(sendFlags), _peer->input, MTP_int(replyToId()), MTP_inputMediaDocument(MTP_flags(0), mtpInput, MTP_string(caption), MTPint()), MTP_long(randomId), MTPnullMarkup), App::main()->rpcDone(&MainWidget::sentUpdatesReceived), App::main()->rpcFail(&MainWidget::sendMessageFail), 0, 0, _history->sendRequestId); App::main()->finishForwarding(_history, _silent->checked()); cancelReplyAfterMediaSend(lastKeyboardUsed); @@ -5612,22 +5637,24 @@ void HistoryWidget::sendExistingPhoto(PhotoData *photo, const QString &caption) sendFlags |= MTPmessages_SendMedia::Flag::f_reply_to_msg_id; } bool channelPost = _peer->isChannel() && !_peer->isMegagroup(); - bool showFromName = !channelPost || _peer->asChannel()->addsSignature(); bool silentPost = channelPost && _silent->checked(); if (channelPost) { flags |= MTPDmessage::Flag::f_views; flags |= MTPDmessage::Flag::f_post; } - if (showFromName) { + if (!channelPost) { flags |= MTPDmessage::Flag::f_from_id; + } else if (_peer->asChannel()->addsSignature()) { + flags |= MTPDmessage::Flag::f_post_author; } if (silentPost) { sendFlags |= MTPmessages_SendMedia::Flag::f_silent; } - auto messageFromId = showFromName ? AuthSession::CurrentUserId() : 0; - _history->addNewPhoto(newId.msg, flags, 0, replyToId(), date(MTP_int(unixtime())), messageFromId, photo, caption, MTPnullMarkup); + auto messageFromId = channelPost ? 0 : AuthSession::CurrentUserId(); + auto messagePostAuthor = channelPost ? (AuthSession::CurrentUser()->firstName + ' ' + AuthSession::CurrentUser()->lastName) : QString(); + _history->addNewPhoto(newId.msg, flags, 0, replyToId(), date(MTP_int(unixtime())), messageFromId, messagePostAuthor, photo, caption, MTPnullMarkup); - _history->sendRequestId = MTP::send(MTPmessages_SendMedia(MTP_flags(sendFlags), _peer->input, MTP_int(replyToId()), MTP_inputMediaPhoto(MTP_inputPhoto(MTP_long(photo->id), MTP_long(photo->access)), MTP_string(caption)), MTP_long(randomId), MTPnullMarkup), App::main()->rpcDone(&MainWidget::sentUpdatesReceived), App::main()->rpcFail(&MainWidget::sendMessageFail), 0, 0, _history->sendRequestId); + _history->sendRequestId = MTP::send(MTPmessages_SendMedia(MTP_flags(sendFlags), _peer->input, MTP_int(replyToId()), MTP_inputMediaPhoto(MTP_flags(0), MTP_inputPhoto(MTP_long(photo->id), MTP_long(photo->access)), MTP_string(caption), MTPint()), MTP_long(randomId), MTPnullMarkup), App::main()->rpcDone(&MainWidget::sentUpdatesReceived), App::main()->rpcFail(&MainWidget::sendMessageFail), 0, 0, _history->sendRequestId); App::main()->finishForwarding(_history, _silent->checked()); cancelReplyAfterMediaSend(lastKeyboardUsed); @@ -6387,7 +6414,7 @@ void HistoryWidget::updateForwardingTexts() { QVector fromUsers; fromUsers.reserve(_toForward.size()); for (auto i = _toForward.cbegin(), e = _toForward.cend(); i != e; ++i) { - auto from = i.value()->authorOriginal(); + auto from = i.value()->peerOriginal(); if (!fromUsersMap.contains(from)) { fromUsersMap.insert(from, true); fromUsers.push_back(from); @@ -6417,7 +6444,7 @@ void HistoryWidget::checkForwardingInfo() { if (!_toForward.isEmpty()) { auto version = 0; for_const (auto item, _toForward) { - version += item->authorOriginal()->nameVersion; + version += item->peerOriginal()->nameVersion; } if (version != _toForwardNameVersion) { updateForwardingTexts(); diff --git a/Telegram/SourceFiles/inline_bots/inline_bot_result.cpp b/Telegram/SourceFiles/inline_bots/inline_bot_result.cpp index 0689f68c3..a123e1cac 100644 --- a/Telegram/SourceFiles/inline_bots/inline_bot_result.cpp +++ b/Telegram/SourceFiles/inline_bots/inline_bot_result.cpp @@ -279,7 +279,7 @@ bool Result::hasThumbDisplay() const { return false; }; -void Result::addToHistory(History *history, MTPDmessage::Flags flags, MsgId msgId, UserId fromId, MTPint mtpDate, UserId viaBotId, MsgId replyToId) const { +void Result::addToHistory(History *history, MTPDmessage::Flags flags, MsgId msgId, UserId fromId, MTPint mtpDate, UserId viaBotId, MsgId replyToId, const QString &postAuthor) const { flags |= MTPDmessage_ClientFlag::f_from_inline_bot; MTPReplyMarkup markup = MTPnullMarkup; @@ -287,7 +287,7 @@ void Result::addToHistory(History *history, MTPDmessage::Flags flags, MsgId msgI flags |= MTPDmessage::Flag::f_reply_markup; markup = *_mtpKeyboard; } - sendData->addToHistory(this, history, flags, msgId, fromId, mtpDate, viaBotId, replyToId, markup); + sendData->addToHistory(this, history, flags, msgId, fromId, mtpDate, viaBotId, replyToId, postAuthor, markup); } QString Result::getErrorOnSend(History *history) const { diff --git a/Telegram/SourceFiles/inline_bots/inline_bot_result.h b/Telegram/SourceFiles/inline_bots/inline_bot_result.h index 6db867ed2..b6be5f2e7 100644 --- a/Telegram/SourceFiles/inline_bots/inline_bot_result.h +++ b/Telegram/SourceFiles/inline_bots/inline_bot_result.h @@ -67,7 +67,7 @@ public: bool hasThumbDisplay() const; - void addToHistory(History *history, MTPDmessage::Flags flags, MsgId msgId, UserId fromId, MTPint mtpDate, UserId viaBotId, MsgId replyToId) const; + void addToHistory(History *history, MTPDmessage::Flags flags, MsgId msgId, UserId fromId, MTPint mtpDate, UserId viaBotId, MsgId replyToId, const QString &postAuthor) const; QString getErrorOnSend(History *history) const; // interface for Layout:: usage diff --git a/Telegram/SourceFiles/inline_bots/inline_bot_send_data.cpp b/Telegram/SourceFiles/inline_bots/inline_bot_send_data.cpp index f6fedcca1..0db4ddda5 100644 --- a/Telegram/SourceFiles/inline_bots/inline_bot_send_data.cpp +++ b/Telegram/SourceFiles/inline_bots/inline_bot_send_data.cpp @@ -37,12 +37,12 @@ QString SendData::getLayoutDescription(const Result *owner) const { void SendDataCommon::addToHistory(const Result *owner, History *history, MTPDmessage::Flags flags, MsgId msgId, UserId fromId, MTPint mtpDate, -UserId viaBotId, MsgId replyToId, const MTPReplyMarkup &markup) const { +UserId viaBotId, MsgId replyToId, const QString &postAuthor, const MTPReplyMarkup &markup) const { auto fields = getSentMessageFields(); if (!fields.entities.v.isEmpty()) { flags |= MTPDmessage::Flag::f_entities; } - history->addNewMessage(MTP_message(MTP_flags(flags), MTP_int(msgId), MTP_int(fromId), peerToMTP(history->peer->id), MTPnullFwdHeader, MTP_int(viaBotId), MTP_int(replyToId), mtpDate, fields.text, fields.media, markup, fields.entities, MTP_int(1), MTPint()), NewMessageUnread); + history->addNewMessage(MTP_message(MTP_flags(flags), MTP_int(msgId), MTP_int(fromId), peerToMTP(history->peer->id), MTPnullFwdHeader, MTP_int(viaBotId), MTP_int(replyToId), mtpDate, fields.text, fields.media, markup, fields.entities, MTP_int(1), MTPint(), MTP_string(postAuthor)), NewMessageUnread); } QString SendDataCommon::getErrorOnSend(const Result *owner, History *history) const { @@ -89,8 +89,8 @@ QString SendContact::getLayoutDescription(const Result *owner) const { void SendPhoto::addToHistory(const Result *owner, History *history, MTPDmessage::Flags flags, MsgId msgId, UserId fromId, MTPint mtpDate, -UserId viaBotId, MsgId replyToId, const MTPReplyMarkup &markup) const { - history->addNewPhoto(msgId, flags, viaBotId, replyToId, date(mtpDate), fromId, _photo, _caption, markup); +UserId viaBotId, MsgId replyToId, const QString &postAuthor, const MTPReplyMarkup &markup) const { + history->addNewPhoto(msgId, flags, viaBotId, replyToId, date(mtpDate), fromId, postAuthor, _photo, _caption, markup); } QString SendPhoto::getErrorOnSend(const Result *owner, History *history) const { @@ -104,8 +104,8 @@ QString SendPhoto::getErrorOnSend(const Result *owner, History *history) const { void SendFile::addToHistory(const Result *owner, History *history, MTPDmessage::Flags flags, MsgId msgId, UserId fromId, MTPint mtpDate, -UserId viaBotId, MsgId replyToId, const MTPReplyMarkup &markup) const { - history->addNewDocument(msgId, flags, viaBotId, replyToId, date(mtpDate), fromId, _document, _caption, markup); +UserId viaBotId, MsgId replyToId, const QString &postAuthor, const MTPReplyMarkup &markup) const { + history->addNewDocument(msgId, flags, viaBotId, replyToId, date(mtpDate), fromId, postAuthor, _document, _caption, markup); } QString SendFile::getErrorOnSend(const Result *owner, History *history) const { @@ -123,8 +123,8 @@ QString SendFile::getErrorOnSend(const Result *owner, History *history) const { void SendGame::addToHistory(const Result *owner, History *history, MTPDmessage::Flags flags, MsgId msgId, UserId fromId, MTPint mtpDate, - UserId viaBotId, MsgId replyToId, const MTPReplyMarkup &markup) const { - history->addNewGame(msgId, flags, viaBotId, replyToId, date(mtpDate), fromId, _game, markup); + UserId viaBotId, MsgId replyToId, const QString &postAuthor, const MTPReplyMarkup &markup) const { + history->addNewGame(msgId, flags, viaBotId, replyToId, date(mtpDate), fromId, postAuthor, _game, markup); } QString SendGame::getErrorOnSend(const Result *owner, History *history) const { diff --git a/Telegram/SourceFiles/inline_bots/inline_bot_send_data.h b/Telegram/SourceFiles/inline_bots/inline_bot_send_data.h index 6906a615d..1275c7c33 100644 --- a/Telegram/SourceFiles/inline_bots/inline_bot_send_data.h +++ b/Telegram/SourceFiles/inline_bots/inline_bot_send_data.h @@ -45,7 +45,7 @@ public: virtual void addToHistory(const Result *owner, History *history, MTPDmessage::Flags flags, MsgId msgId, UserId fromId, MTPint mtpDate, - UserId viaBotId, MsgId replyToId, const MTPReplyMarkup &markup) const = 0; + UserId viaBotId, MsgId replyToId, const QString &postAuthor, const MTPReplyMarkup &markup) const = 0; virtual QString getErrorOnSend(const Result *owner, History *history) const = 0; virtual bool hasLocationCoords() const { @@ -73,7 +73,7 @@ public: void addToHistory(const Result *owner, History *history, MTPDmessage::Flags flags, MsgId msgId, UserId fromId, MTPint mtpDate, - UserId viaBotId, MsgId replyToId, const MTPReplyMarkup &markup) const override; + UserId viaBotId, MsgId replyToId, const QString &postAuthor, const MTPReplyMarkup &markup) const override; QString getErrorOnSend(const Result *owner, History *history) const override; @@ -194,7 +194,7 @@ public: void addToHistory(const Result *owner, History *history, MTPDmessage::Flags flags, MsgId msgId, UserId fromId, MTPint mtpDate, - UserId viaBotId, MsgId replyToId, const MTPReplyMarkup &markup) const override; + UserId viaBotId, MsgId replyToId, const QString &postAuthor, const MTPReplyMarkup &markup) const override; QString getErrorOnSend(const Result *owner, History *history) const override; @@ -218,7 +218,7 @@ public: void addToHistory(const Result *owner, History *history, MTPDmessage::Flags flags, MsgId msgId, UserId fromId, MTPint mtpDate, - UserId viaBotId, MsgId replyToId, const MTPReplyMarkup &markup) const override; + UserId viaBotId, MsgId replyToId, const QString &postAuthor, const MTPReplyMarkup &markup) const override; QString getErrorOnSend(const Result *owner, History *history) const override; @@ -241,7 +241,7 @@ public: void addToHistory(const Result *owner, History *history, MTPDmessage::Flags flags, MsgId msgId, UserId fromId, MTPint mtpDate, - UserId viaBotId, MsgId replyToId, const MTPReplyMarkup &markup) const override; + UserId viaBotId, MsgId replyToId, const QString &postAuthor, const MTPReplyMarkup &markup) const override; QString getErrorOnSend(const Result *owner, History *history) const override; diff --git a/Telegram/SourceFiles/mainwidget.cpp b/Telegram/SourceFiles/mainwidget.cpp index e87274c37..35d75570f 100644 --- a/Telegram/SourceFiles/mainwidget.cpp +++ b/Telegram/SourceFiles/mainwidget.cpp @@ -610,14 +610,15 @@ void MainWidget::finishForwarding(History *history, bool silent) { auto flags = MTPDmessage::Flags(0); auto sendFlags = MTPmessages_ForwardMessages::Flags(0); bool channelPost = history->peer->isChannel() && !history->peer->isMegagroup(); - bool showFromName = !channelPost || history->peer->asChannel()->addsSignature(); bool silentPost = channelPost && silent; if (channelPost) { flags |= MTPDmessage::Flag::f_views; flags |= MTPDmessage::Flag::f_post; } - if (showFromName) { + if (!channelPost) { flags |= MTPDmessage::Flag::f_from_id; + } else if (history->peer->asChannel()->addsSignature()) { + flags |= MTPDmessage::Flag::f_post_author; } if (silentPost) { sendFlags |= MTPmessages_ForwardMessages::Flag::f_silent; @@ -632,8 +633,9 @@ void MainWidget::finishForwarding(History *history, bool silent) { if (genClientSideMessage) { if (auto message = i.value()->toHistoryMessage()) { auto newId = FullMsgId(peerToChannel(history->peer->id), clientMsgId()); - auto messageFromId = showFromName ? AuthSession::CurrentUserId() : 0; - history->addNewForwarded(newId.msg, flags, date(MTP_int(unixtime())), messageFromId, message); + auto messageFromId = channelPost ? 0 : AuthSession::CurrentUserId(); + auto messagePostAuthor = channelPost ? (AuthSession::CurrentUser()->firstName + ' ' + AuthSession::CurrentUser()->lastName) : QString(); + history->addNewForwarded(newId.msg, flags, date(MTP_int(unixtime())), messageFromId, messagePostAuthor, message); App::historyRegRandom(randomId, newId); } } @@ -1445,14 +1447,15 @@ void MainWidget::sendMessage(const MessageToSend &message) { flags |= MTPDmessage::Flag::f_media; } bool channelPost = history->peer->isChannel() && !history->peer->isMegagroup(); - bool showFromName = !channelPost || history->peer->asChannel()->addsSignature(); bool silentPost = channelPost && message.silent; if (channelPost) { flags |= MTPDmessage::Flag::f_views; flags |= MTPDmessage::Flag::f_post; } - if (showFromName) { + if (!channelPost) { flags |= MTPDmessage::Flag::f_from_id; + } else if (history->peer->asChannel()->addsSignature()) { + flags |= MTPDmessage::Flag::f_post_author; } if (silentPost) { sendFlags |= MTPmessages_SendMessage::Flag::f_silent; @@ -1466,8 +1469,9 @@ void MainWidget::sendMessage(const MessageToSend &message) { sendFlags |= MTPmessages_SendMessage::Flag::f_clear_draft; history->clearCloudDraft(); } - auto messageFromId = showFromName ? AuthSession::CurrentUserId() : 0; - lastMessage = history->addNewMessage(MTP_message(MTP_flags(flags), MTP_int(newId.msg), MTP_int(messageFromId), peerToMTP(history->peer->id), MTPnullFwdHeader, MTPint(), MTP_int(replyTo), MTP_int(unixtime()), msgText, media, MTPnullMarkup, localEntities, MTP_int(1), MTPint()), NewMessageUnread); + auto messageFromId = channelPost ? 0 : AuthSession::CurrentUserId(); + auto messagePostAuthor = channelPost ? (AuthSession::CurrentUser()->firstName + ' ' + AuthSession::CurrentUser()->lastName) : QString(); + lastMessage = history->addNewMessage(MTP_message(MTP_flags(flags), MTP_int(newId.msg), MTP_int(messageFromId), peerToMTP(history->peer->id), MTPnullFwdHeader, MTPint(), MTP_int(replyTo), MTP_int(unixtime()), msgText, media, MTPnullMarkup, localEntities, MTP_int(1), MTPint(), MTP_string(messagePostAuthor)), NewMessageUnread); history->sendRequestId = MTP::send(MTPmessages_SendMessage(MTP_flags(sendFlags), history->peer->input, MTP_int(replyTo), msgText, MTP_long(randomId), MTPnullMarkup, sentEntities), rpcDone(&MainWidget::sentUpdatesReceived, randomId), rpcFail(&MainWidget::sendMessageFail), 0, 0, history->sendRequestId); } @@ -2028,7 +2032,7 @@ void MainWidget::insertCheckedServiceNotification(const TextWithEntities &messag HistoryItem *item = nullptr; while (TextUtilities::CutPart(sending, left, MaxMessageSize)) { auto localEntities = TextUtilities::EntitiesToMTP(sending.entities); - item = App::histories().addNewMessage(MTP_message(MTP_flags(flags), MTP_int(clientMsgId()), MTP_int(ServiceUserId), MTP_peerUser(MTP_int(AuthSession::CurrentUserId())), MTPnullFwdHeader, MTPint(), MTPint(), MTP_int(date), MTP_string(sending.text), media, MTPnullMarkup, localEntities, MTPint(), MTPint()), NewMessageUnread); + item = App::histories().addNewMessage(MTP_message(MTP_flags(flags), MTP_int(clientMsgId()), MTP_int(ServiceUserId), MTP_peerUser(MTP_int(AuthSession::CurrentUserId())), MTPnullFwdHeader, MTPint(), MTPint(), MTP_int(date), MTP_string(sending.text), media, MTPnullMarkup, localEntities, MTPint(), MTPint(), MTPstring()), NewMessageUnread); } if (item) { _history->peerMessagesUpdated(item->history()->peer->id); diff --git a/Telegram/SourceFiles/mediaview.cpp b/Telegram/SourceFiles/mediaview.cpp index a4ccaa6f2..81444ffde 100644 --- a/Telegram/SourceFiles/mediaview.cpp +++ b/Telegram/SourceFiles/mediaview.cpp @@ -1212,7 +1212,7 @@ void MediaView::displayPhoto(PhotoData *photo, HistoryItem *item) { _y = (height() - _h) / 2; _width = _w; if (_msgid && item) { - _from = item->authorOriginal(); + _from = item->peerOriginal(); } else { _from = _user; } @@ -1366,7 +1366,7 @@ void MediaView::displayDocument(DocumentData *doc, HistoryItem *item) { // empty _x = (width() - _w) / 2; _y = (height() - _h) / 2; if (_msgid && item) { - _from = item->authorOriginal(); + _from = item->peerOriginal(); } else { _from = _user; } diff --git a/Telegram/SourceFiles/mtproto/core_types.cpp b/Telegram/SourceFiles/mtproto/core_types.cpp index 717da8d67..86ddccd07 100644 --- a/Telegram/SourceFiles/mtproto/core_types.cpp +++ b/Telegram/SourceFiles/mtproto/core_types.cpp @@ -157,9 +157,9 @@ void mtpTextSerializeCore(MTPStringLogger &to, const mtpPrime *&from, const mtpP } } -const MTPReplyMarkup MTPnullMarkup = MTP_replyKeyboardMarkup(MTP_flags(MTPDreplyKeyboardMarkup::Flags(0)), MTP_vector(0)); +const MTPReplyMarkup MTPnullMarkup = MTP_replyKeyboardMarkup(MTP_flags(0), MTP_vector(0)); const MTPVector MTPnullEntities = MTP_vector(0); -const MTPMessageFwdHeader MTPnullFwdHeader = MTP_messageFwdHeader(MTP_flags(MTPDmessageFwdHeader::Flags(0)), MTPint(), MTPint(), MTPint(), MTPint()); +const MTPMessageFwdHeader MTPnullFwdHeader = MTP_messageFwdHeader(MTP_flags(0), MTPint(), MTPint(), MTPint(), MTPint(), MTPstring()); QString stickerSetTitle(const MTPDstickerSet &s) { QString title = qs(s.vtitle);