From d23fd3559a539d6e16781d2e05a98005312b752d Mon Sep 17 00:00:00 2001 From: John Preston Date: Fri, 14 Jun 2019 18:04:45 +0200 Subject: [PATCH] Refresh participants after transfer. --- Telegram/Resources/langs/lang.strings | 2 +- Telegram/SourceFiles/apiwrap.cpp | 4 +- Telegram/SourceFiles/apiwrap.h | 2 +- .../boxes/peers/edit_participants_box.cpp | 51 +++++++++++++++++++ .../boxes/peers/edit_participants_box.h | 3 ++ .../admin_log/history_admin_log_item.cpp | 23 +++++++-- .../history/history_location_manager.cpp | 8 ++- .../history/history_location_manager.h | 2 + 8 files changed, 87 insertions(+), 8 deletions(-) diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index 25dfa4691..c9ae3ad7c 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -1755,7 +1755,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_admin_log_removed_linked_chat" = "{from} removed the discussion group"; "lng_admin_log_changed_linked_channel" = "{from} changed the linked channel to «{chat}»"; "lng_admin_log_removed_linked_channel" = "{from} removed the linked channel"; -"lng_admin_log_changed_location_chat" = "{from} changed the group location"; +"lng_admin_log_changed_location_chat" = "{from} changed the group location to {address}"; "lng_admin_log_removed_location_chat" = "{from} removed the group location"; "lng_admin_log_user_with_username" = "{name} ({mention})"; "lng_admin_log_restricted_forever" = "indefinitely"; diff --git a/Telegram/SourceFiles/apiwrap.cpp b/Telegram/SourceFiles/apiwrap.cpp index 8552963c8..0bccdc082 100644 --- a/Telegram/SourceFiles/apiwrap.cpp +++ b/Telegram/SourceFiles/apiwrap.cpp @@ -3572,7 +3572,9 @@ void ApiWrap::parseRecentChannelParticipants( availableCount, list); } - callbackList(availableCount, list); + if (callbackList) { + callbackList(availableCount, list); + } }, std::move(callbackNotModified)); } diff --git a/Telegram/SourceFiles/apiwrap.h b/Telegram/SourceFiles/apiwrap.h index 3feeccf07..61d323aec 100644 --- a/Telegram/SourceFiles/apiwrap.h +++ b/Telegram/SourceFiles/apiwrap.h @@ -331,7 +331,7 @@ public: const MTPchannels_ChannelParticipants &result, Fn &list)> callbackList, + const QVector &list)> callbackList = nullptr, Fn callbackNotModified = nullptr); void addChatParticipants( not_null peer, diff --git a/Telegram/SourceFiles/boxes/peers/edit_participants_box.cpp b/Telegram/SourceFiles/boxes/peers/edit_participants_box.cpp index 508dc5ba2..74bd2a8a7 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_participants_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_participants_box.cpp @@ -718,6 +718,9 @@ ParticipantsBoxController::ParticipantsBoxController( if (_role == Role::Profile) { setupListChangeViewers(); } + if (const auto channel = _peer->asChannel()) { + subscribeToCreatorChange(channel); + } } void ParticipantsBoxController::setupListChangeViewers() { @@ -1782,6 +1785,54 @@ void ParticipantsBoxController::subscribeToMigration() { void ParticipantsBoxController::migrate(not_null channel) { _peer = channel; _additional.migrate(channel); + subscribeToCreatorChange(channel); +} + +void ParticipantsBoxController::subscribeToCreatorChange( + not_null channel) { + const auto isCreator = channel->amCreator(); + channel->flagsValue( + ) | rpl::filter([](const ChannelData::Flags::Change &change) { + return (change.diff & MTPDchannel::Flag::f_creator); + }) | rpl::filter([=] { + return (isCreator != channel->amCreator()); + }) | rpl::start_with_next([=] { + if (channel->isBroadcast()) { + fullListRefresh(); + return; + } + const auto weak = base::make_weak(this); + const auto api = &channel->session().api(); + api->request(MTPchannels_GetParticipants( + channel->inputChannel, + MTP_channelParticipantsRecent(), + MTP_int(0), + MTP_int(Global::ChatSizeMax()), + MTP_int(0) + )).done([=](const MTPchannels_ChannelParticipants &result) { + channel->mgInfo->creator = channel->amCreator() + ? channel->session().user().get() + : nullptr; + channel->mgInfo->lastAdmins.clear(); + channel->mgInfo->lastRestricted.clear(); + channel->mgInfo->lastParticipants.clear(); + api->parseRecentChannelParticipants(channel, result); + if (weak) { + fullListRefresh(); + } + }).send(); + }, lifetime()); +} + +void ParticipantsBoxController::fullListRefresh() { + _additional = ParticipantsAdditionalData(_peer, _role); + + while (const auto count = delegate()->peerListFullRowsCount()) { + delegate()->peerListRemoveRow( + delegate()->peerListRowAt(count - 1)); + } + loadMoreRows(); + delegate()->peerListRefreshRows(); } ParticipantsBoxSearchController::ParticipantsBoxSearchController( diff --git a/Telegram/SourceFiles/boxes/peers/edit_participants_box.h b/Telegram/SourceFiles/boxes/peers/edit_participants_box.h index a58cae39b..716a87fbb 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_participants_box.h +++ b/Telegram/SourceFiles/boxes/peers/edit_participants_box.h @@ -104,6 +104,7 @@ private: UserData *applyBanned(const MTPDchannelParticipantBanned &data); void fillFromChat(not_null chat); void fillFromChannel(not_null channel); + void subscribeToCreatorChange(not_null channel); not_null _peer; Role _role = Role::Members; @@ -226,6 +227,8 @@ private: void subscribeToMigration(); void migrate(not_null channel); + void subscribeToCreatorChange(not_null channel); + void fullListRefresh(); not_null _navigation; not_null _peer; 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 a25f0341b..44af5c437 100644 --- a/Telegram/SourceFiles/history/admin_log/history_admin_log_item.cpp +++ b/Telegram/SourceFiles/history/admin_log/history_admin_log_item.cpp @@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "history/admin_log/history_admin_log_inner.h" #include "history/view/history_view_element.h" +#include "history/history_location_manager.h" #include "history/history_service.h" #include "history/history_message.h" #include "history/history.h" @@ -604,9 +605,25 @@ void GenerateItems( }; auto createChangeLocation = [&](const MTPDchannelAdminLogEventActionChangeLocation &action) { - const auto now = (action.vnew_value.type() != mtpc_channelLocationEmpty); - auto text = (now ? lng_admin_log_changed_location_chat : lng_admin_log_removed_location_chat)(lt_from, fromLinkText); - addSimpleServiceMessage(text); + action.vnew_value.match([&](const MTPDchannelLocation &data) { + const auto address = qs(data.vaddress); + const auto link = data.vgeo_point.match([&](const MTPDgeoPoint &data) { + return textcmdLink( + LocationClickHandler::Url(LocationCoords(data)), + address); + }, [&](const MTPDgeoPointEmpty &) { + return address; + }); + const auto text = lng_admin_log_changed_location_chat( + lt_from, + fromLinkText, + lt_address, + link); + addSimpleServiceMessage(text); + }, [&](const MTPDchannelLocationEmpty &) { + const auto text = lng_admin_log_removed_location_chat(lt_from, fromLinkText); + addSimpleServiceMessage(text); + }); }; action.match([&](const MTPDchannelAdminLogEventActionChangeTitle &data) { diff --git a/Telegram/SourceFiles/history/history_location_manager.cpp b/Telegram/SourceFiles/history/history_location_manager.cpp index 919da6e8b..7fc45011d 100644 --- a/Telegram/SourceFiles/history/history_location_manager.cpp +++ b/Telegram/SourceFiles/history/history_location_manager.cpp @@ -52,8 +52,12 @@ void LocationClickHandler::onClick(ClickContext context) const { } void LocationClickHandler::setup() { - auto latlon = _coords.latAsString() + ',' + _coords.lonAsString(); - _text = qsl("https://maps.google.com/maps?q=") + latlon + qsl("&ll=") + latlon + qsl("&z=16"); + _text = Url(_coords); +} + +QString LocationClickHandler::Url(const LocationCoords &coords) { + const auto latlon = coords.latAsString() + ',' + coords.lonAsString(); + return qsl("https://maps.google.com/maps?q=") + latlon + qsl("&ll=") + latlon + qsl("&z=16"); } LocationData::LocationData(const LocationCoords &coords) diff --git a/Telegram/SourceFiles/history/history_location_manager.h b/Telegram/SourceFiles/history/history_location_manager.h index e1a5a8110..30eb82741 100644 --- a/Telegram/SourceFiles/history/history_location_manager.h +++ b/Telegram/SourceFiles/history/history_location_manager.h @@ -98,6 +98,8 @@ public: setup(); } + static QString Url(const LocationCoords &coords); + void onClick(ClickContext context) const override; QString tooltip() const override {