Refresh participants after transfer.

This commit is contained in:
John Preston 2019-06-14 18:04:45 +02:00
parent 3c11eda611
commit d23fd3559a
8 changed files with 87 additions and 8 deletions

View File

@ -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";

View File

@ -3572,7 +3572,9 @@ void ApiWrap::parseRecentChannelParticipants(
availableCount,
list);
}
callbackList(availableCount, list);
if (callbackList) {
callbackList(availableCount, list);
}
}, std::move(callbackNotModified));
}

View File

@ -331,7 +331,7 @@ public:
const MTPchannels_ChannelParticipants &result,
Fn<void(
int availableCount,
const QVector<MTPChannelParticipant> &list)> callbackList,
const QVector<MTPChannelParticipant> &list)> callbackList = nullptr,
Fn<void()> callbackNotModified = nullptr);
void addChatParticipants(
not_null<PeerData*> peer,

View File

@ -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<ChannelData*> channel) {
_peer = channel;
_additional.migrate(channel);
subscribeToCreatorChange(channel);
}
void ParticipantsBoxController::subscribeToCreatorChange(
not_null<ChannelData*> 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(

View File

@ -104,6 +104,7 @@ private:
UserData *applyBanned(const MTPDchannelParticipantBanned &data);
void fillFromChat(not_null<ChatData*> chat);
void fillFromChannel(not_null<ChannelData*> channel);
void subscribeToCreatorChange(not_null<ChannelData*> channel);
not_null<PeerData*> _peer;
Role _role = Role::Members;
@ -226,6 +227,8 @@ private:
void subscribeToMigration();
void migrate(not_null<ChannelData*> channel);
void subscribeToCreatorChange(not_null<ChannelData*> channel);
void fullListRefresh();
not_null<Window::SessionNavigation*> _navigation;
not_null<PeerData*> _peer;

View File

@ -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) {

View File

@ -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)

View File

@ -98,6 +98,8 @@ public:
setup();
}
static QString Url(const LocationCoords &coords);
void onClick(ClickContext context) const override;
QString tooltip() const override {