From 16e189a2ce41a113ef21400404bb59576df2e17e Mon Sep 17 00:00:00 2001 From: John Preston Date: Fri, 14 Oct 2022 17:54:31 +0400 Subject: [PATCH] Update API scheme on layer 148: Usernames. --- Telegram/Resources/tl/api.tl | 3 +- Telegram/SourceFiles/api/api_updates.cpp | 31 ++++++++++--------- .../admin_log/history_admin_log_item.cpp | 9 ++++++ 3 files changed, 27 insertions(+), 16 deletions(-) diff --git a/Telegram/Resources/tl/api.tl b/Telegram/Resources/tl/api.tl index 4cffcf426b..a5d651135b 100644 --- a/Telegram/Resources/tl/api.tl +++ b/Telegram/Resources/tl/api.tl @@ -301,7 +301,7 @@ updateUserTyping#c01e857f user_id:long action:SendMessageAction = Update; updateChatUserTyping#83487af0 chat_id:long from_id:Peer action:SendMessageAction = Update; updateChatParticipants#7761198 participants:ChatParticipants = Update; updateUserStatus#e5bdf8de user_id:long status:UserStatus = Update; -updateUserName#c3f202e0 user_id:long first_name:string last_name:string username:string = Update; +updateUserName#a7848924 user_id:long first_name:string last_name:string usernames:Vector = Update; updateUserPhoto#f227868c user_id:long date:int photo:UserProfilePhoto previous:Bool = Update; updateNewEncryptedMessage#12bcbd9a message:EncryptedMessage qts:int = Update; updateEncryptedChatTyping#1710f156 chat_id:int = Update; @@ -957,6 +957,7 @@ channelAdminLogEventActionParticipantJoinByRequest#afb6144a invite:ExportedChatI channelAdminLogEventActionToggleNoForwards#cb2ac766 new_value:Bool = ChannelAdminLogEventAction; channelAdminLogEventActionSendMessage#278f2868 message:Message = ChannelAdminLogEventAction; channelAdminLogEventActionChangeAvailableReactions#be4e0ef8 prev_value:ChatReactions new_value:ChatReactions = ChannelAdminLogEventAction; +channelAdminLogEventActionChangeUsernames#f04fb3a9 prev_value:Vector new_value:Vector = ChannelAdminLogEventAction; channelAdminLogEvent#1fad68cd id:long date:int user_id:long action:ChannelAdminLogEventAction = ChannelAdminLogEvent; diff --git a/Telegram/SourceFiles/api/api_updates.cpp b/Telegram/SourceFiles/api/api_updates.cpp index 4ba708a4a4..b759af4baf 100644 --- a/Telegram/SourceFiles/api/api_updates.cpp +++ b/Telegram/SourceFiles/api/api_updates.cpp @@ -1872,21 +1872,22 @@ void Updates::feedUpdate(const MTPUpdate &update) { } break; case mtpc_updateUserName: { - auto &d = update.c_updateUserName(); - if (auto user = session().data().userLoaded(d.vuser_id())) { - if (!user->isContact()) { - user->setName( - TextUtilities::SingleLine(qs(d.vfirst_name())), - TextUtilities::SingleLine(qs(d.vlast_name())), - user->nameOrPhone, - TextUtilities::SingleLine(qs(d.vusername()))); - } else { - user->setName( - TextUtilities::SingleLine(user->firstName), - TextUtilities::SingleLine(user->lastName), - user->nameOrPhone, - TextUtilities::SingleLine(qs(d.vusername()))); - } + const auto &d = update.c_updateUserName(); + if (const auto user = session().data().userLoaded(d.vuser_id())) { + const auto contact = user->isContact(); + const auto first = contact + ? user->firstName + : qs(d.vfirst_name()); + const auto last = contact ? user->lastName : qs(d.vlast_name()); + // #TODO usernames + const auto username = d.vusernames().v.isEmpty() + ? QString() + : qs(d.vusernames().v.front().data().vusername()); + user->setName( + TextUtilities::SingleLine(first), + TextUtilities::SingleLine(last), + user->nameOrPhone, + TextUtilities::SingleLine(username)); } } break; diff --git a/Telegram/SourceFiles/history/admin_log/history_admin_log_item.cpp b/Telegram/SourceFiles/history/admin_log/history_admin_log_item.cpp index 9a9cf3e92e..2df3683817 100644 --- a/Telegram/SourceFiles/history/admin_log/history_admin_log_item.cpp +++ b/Telegram/SourceFiles/history/admin_log/history_admin_log_item.cpp @@ -697,6 +697,7 @@ void GenerateItems( using LogNoForwards = MTPDchannelAdminLogEventActionToggleNoForwards; using LogActionSendMessage = MTPDchannelAdminLogEventActionSendMessage; using LogEventActionChangeAvailableReactions = MTPDchannelAdminLogEventActionChangeAvailableReactions; + using LogEventActionChangeUsernames = MTPDchannelAdminLogEventActionChangeUsernames; const auto session = &history->session(); const auto id = event.vid().v; @@ -1513,6 +1514,12 @@ void GenerateItems( addSimpleServiceMessage(text); }; + const auto createChangeUsernames = [&]( + const LogEventActionChangeUsernames &data) { + // #TODO usernames + addSimpleServiceMessage({ "changed usernames" }); + }; + action.match([&](const LogTitle &data) { createChangeTitle(data); }, [&](const LogAbout &data) { @@ -1585,6 +1592,8 @@ void GenerateItems( createSendMessage(data); }, [&](const LogEventActionChangeAvailableReactions &data) { createChangeAvailableReactions(data); + }, [&](const LogEventActionChangeUsernames &data) { + createChangeUsernames(data); }); }