2016-10-23 21:03:10 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 10:23:14 +00:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2016-10-23 21:03:10 +00:00
|
|
|
|
2018-01-03 10:23:14 +00:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2016-10-23 21:03:10 +00:00
|
|
|
*/
|
|
|
|
#include "profile/profile_block_group_members.h"
|
|
|
|
|
|
|
|
#include "styles/style_profile.h"
|
|
|
|
#include "ui/widgets/labels.h"
|
2017-04-06 14:38:10 +00:00
|
|
|
#include "boxes/confirm_box.h"
|
2019-01-07 12:55:49 +00:00
|
|
|
#include "boxes/peers/edit_participant_box.h"
|
2019-01-10 06:26:08 +00:00
|
|
|
#include "boxes/peers/edit_participants_box.h"
|
2019-07-10 17:28:33 +00:00
|
|
|
#include "base/unixtime.h"
|
2017-01-11 05:30:51 +00:00
|
|
|
#include "ui/widgets/popup_menu.h"
|
2017-12-17 08:13:26 +00:00
|
|
|
#include "data/data_peer_values.h"
|
2019-01-04 11:09:48 +00:00
|
|
|
#include "data/data_channel.h"
|
|
|
|
#include "data/data_chat.h"
|
|
|
|
#include "data/data_user.h"
|
2016-12-13 17:07:56 +00:00
|
|
|
#include "mainwidget.h"
|
2016-10-23 21:03:10 +00:00
|
|
|
#include "apiwrap.h"
|
|
|
|
#include "observer_peer.h"
|
2017-02-23 09:32:28 +00:00
|
|
|
#include "auth_session.h"
|
2017-04-13 08:27:10 +00:00
|
|
|
#include "lang/lang_keys.h"
|
2016-10-23 21:03:10 +00:00
|
|
|
|
|
|
|
namespace Profile {
|
2019-01-04 11:09:48 +00:00
|
|
|
namespace {
|
2016-10-23 21:03:10 +00:00
|
|
|
|
|
|
|
using UpdateFlag = Notify::PeerUpdate::Flag;
|
|
|
|
|
2019-01-04 11:09:48 +00:00
|
|
|
} // namespace
|
|
|
|
|
|
|
|
GroupMembersWidget::Member::Member(UserData *user) : Item(user) {
|
|
|
|
}
|
|
|
|
|
|
|
|
UserData *GroupMembersWidget::Member::user() const {
|
|
|
|
return static_cast<UserData*>(peer);
|
|
|
|
}
|
|
|
|
|
2017-09-25 16:06:53 +00:00
|
|
|
GroupMembersWidget::GroupMembersWidget(
|
|
|
|
QWidget *parent,
|
|
|
|
PeerData *peer,
|
2017-09-26 17:57:01 +00:00
|
|
|
const style::PeerListItem &st)
|
2019-06-19 15:09:03 +00:00
|
|
|
: PeerListWidget(parent, peer, QString(), st, tr::lng_profile_kick(tr::now)) {
|
2016-10-23 21:03:10 +00:00
|
|
|
_updateOnlineTimer.setSingleShot(true);
|
|
|
|
connect(&_updateOnlineTimer, SIGNAL(timeout()), this, SLOT(onUpdateOnlineDisplay()));
|
|
|
|
|
|
|
|
auto observeEvents = UpdateFlag::AdminsChanged
|
|
|
|
| UpdateFlag::MembersChanged
|
|
|
|
| UpdateFlag::UserOnlineChanged;
|
|
|
|
subscribe(Notify::PeerUpdated(), Notify::PeerUpdatedHandler(observeEvents, [this](const Notify::PeerUpdate &update) {
|
|
|
|
notifyPeerUpdated(update);
|
|
|
|
}));
|
|
|
|
|
2018-04-07 08:47:08 +00:00
|
|
|
setRemovedCallback([=](PeerData *selectedPeer) {
|
2017-01-11 05:30:51 +00:00
|
|
|
removePeer(selectedPeer);
|
2016-10-23 21:03:10 +00:00
|
|
|
});
|
2018-04-07 08:47:08 +00:00
|
|
|
setSelectedCallback([=](PeerData *selectedPeer) {
|
2016-10-23 21:03:10 +00:00
|
|
|
Ui::showPeerProfile(selectedPeer);
|
|
|
|
});
|
2018-04-07 08:47:08 +00:00
|
|
|
setUpdateItemCallback([=](Item *item) {
|
2016-10-23 21:03:10 +00:00
|
|
|
updateItemStatusText(item);
|
|
|
|
});
|
2018-04-07 08:47:08 +00:00
|
|
|
setPreloadMoreCallback([=] {
|
2016-10-23 21:03:10 +00:00
|
|
|
preloadMore();
|
|
|
|
});
|
|
|
|
|
|
|
|
refreshMembers();
|
|
|
|
}
|
|
|
|
|
2017-01-11 05:30:51 +00:00
|
|
|
void GroupMembersWidget::removePeer(PeerData *selectedPeer) {
|
|
|
|
auto user = selectedPeer->asUser();
|
2017-08-17 09:06:26 +00:00
|
|
|
Assert(user != nullptr);
|
2017-12-26 16:12:10 +00:00
|
|
|
|
2019-06-19 16:39:25 +00:00
|
|
|
auto text = tr::lng_profile_sure_kick(tr::now, lt_user, user->firstName);
|
2019-01-03 14:39:19 +00:00
|
|
|
auto currentRestrictedRights = [&]() -> MTPChatBannedRights {
|
2017-12-01 18:38:44 +00:00
|
|
|
if (auto channel = peer()->asMegagroup()) {
|
|
|
|
auto it = channel->mgInfo->lastRestricted.find(user);
|
|
|
|
if (it != channel->mgInfo->lastRestricted.cend()) {
|
|
|
|
return it->second.rights;
|
|
|
|
}
|
2017-07-05 21:11:49 +00:00
|
|
|
}
|
2019-01-03 14:39:19 +00:00
|
|
|
return MTP_chatBannedRights(MTP_flags(0), MTP_int(0));
|
2017-12-01 18:38:44 +00:00
|
|
|
}();
|
2019-06-19 15:09:03 +00:00
|
|
|
Ui::show(Box<ConfirmBox>(text, tr::lng_box_remove(tr::now), [user, currentRestrictedRights, peer = peer()] {
|
2017-01-11 05:30:51 +00:00
|
|
|
Ui::hideLayer();
|
2017-12-26 16:12:10 +00:00
|
|
|
if (const auto chat = peer->asChat()) {
|
|
|
|
Auth().api().kickParticipant(chat, user);
|
|
|
|
Ui::showPeerHistory(chat->id, ShowAtTheEndMsgId);
|
|
|
|
} else if (const auto channel = peer->asChannel()) {
|
|
|
|
Auth().api().kickParticipant(
|
|
|
|
channel,
|
|
|
|
user,
|
|
|
|
currentRestrictedRights);
|
2017-01-11 05:30:51 +00:00
|
|
|
}
|
2017-07-13 16:25:28 +00:00
|
|
|
}));
|
2017-01-11 05:30:51 +00:00
|
|
|
}
|
|
|
|
|
2016-10-23 21:03:10 +00:00
|
|
|
void GroupMembersWidget::notifyPeerUpdated(const Notify::PeerUpdate &update) {
|
|
|
|
if (update.peer != peer()) {
|
|
|
|
if (update.flags & UpdateFlag::UserOnlineChanged) {
|
|
|
|
if (auto user = update.peer->asUser()) {
|
|
|
|
refreshUserOnline(user);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (update.flags & UpdateFlag::MembersChanged) {
|
|
|
|
refreshMembers();
|
|
|
|
contentSizeUpdated();
|
2019-01-10 12:38:57 +00:00
|
|
|
}
|
|
|
|
if (update.flags & UpdateFlag::AdminsChanged) {
|
|
|
|
if (const auto chat = peer()->asChat()) {
|
|
|
|
for (const auto item : items()) {
|
2016-10-23 21:03:10 +00:00
|
|
|
setItemFlags(getMember(item), chat);
|
|
|
|
}
|
2019-01-10 12:38:57 +00:00
|
|
|
} else if (const auto megagroup = peer()->asMegagroup()) {
|
|
|
|
for (const auto item : items()) {
|
2016-10-23 21:03:10 +00:00
|
|
|
setItemFlags(getMember(item), megagroup);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this->update();
|
|
|
|
}
|
|
|
|
|
|
|
|
void GroupMembersWidget::refreshUserOnline(UserData *user) {
|
|
|
|
auto it = _membersByUser.find(user);
|
|
|
|
if (it == _membersByUser.cend()) return;
|
|
|
|
|
2019-07-10 17:28:33 +00:00
|
|
|
_now = base::unixtime::now();
|
2016-10-23 21:03:10 +00:00
|
|
|
|
|
|
|
auto member = getMember(it.value());
|
2019-07-18 08:51:11 +00:00
|
|
|
member->statusHasOnlineColor = !user->isBot()
|
|
|
|
&& Data::OnlineTextActive(user->onlineTill, _now);
|
2016-10-23 21:03:10 +00:00
|
|
|
member->onlineTill = user->onlineTill;
|
2017-12-17 08:13:26 +00:00
|
|
|
member->onlineForSort = user->isSelf()
|
|
|
|
? std::numeric_limits<TimeId>::max()
|
|
|
|
: Data::SortByOnlineValue(user, _now);
|
2016-10-23 21:03:10 +00:00
|
|
|
member->statusText = QString();
|
|
|
|
|
|
|
|
sortMembers();
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
void GroupMembersWidget::preloadMore() {
|
2017-11-28 18:30:01 +00:00
|
|
|
//
|
|
|
|
// This can cause a ddos, because lastParticipants may never reach members count.
|
|
|
|
//
|
|
|
|
//if (auto megagroup = peer()->asMegagroup()) {
|
|
|
|
// auto &megagroupInfo = megagroup->mgInfo;
|
|
|
|
// if (!megagroupInfo->lastParticipants.isEmpty() && megagroupInfo->lastParticipants.size() < megagroup->membersCount()) {
|
|
|
|
// Auth().api().requestLastParticipants(megagroup, false);
|
|
|
|
// }
|
|
|
|
//}
|
2016-10-23 21:03:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GroupMembersWidget::updateItemStatusText(Item *item) {
|
|
|
|
auto member = getMember(item);
|
|
|
|
auto user = member->user();
|
|
|
|
if (member->statusText.isEmpty() || (member->onlineTextTill <= _now)) {
|
2019-07-18 08:51:11 +00:00
|
|
|
if (user->isBot()) {
|
2017-07-03 10:31:37 +00:00
|
|
|
auto seesAllMessages = (user->botInfo->readsAllHistory || (member->adminState != Item::AdminState::None));
|
2019-06-19 15:09:03 +00:00
|
|
|
member->statusText = seesAllMessages
|
|
|
|
? tr::lng_status_bot_reads_all(tr::now)
|
|
|
|
: tr::lng_status_bot_not_reads_all(tr::now);
|
2016-10-23 21:03:10 +00:00
|
|
|
member->onlineTextTill = _now + 86400;
|
|
|
|
} else {
|
2017-12-17 08:13:26 +00:00
|
|
|
member->statusHasOnlineColor = Data::OnlineTextActive(member->onlineTill, _now);
|
|
|
|
member->statusText = Data::OnlineText(member->onlineTill, _now);
|
|
|
|
const auto changeInMs = Data::OnlineChangeTimeout(
|
|
|
|
member->onlineTill,
|
|
|
|
_now);
|
|
|
|
member->onlineTextTill = _now + TimeId(changeInMs / 1000);
|
2016-10-23 21:03:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (_updateOnlineAt <= _now || _updateOnlineAt > member->onlineTextTill) {
|
|
|
|
_updateOnlineAt = member->onlineTextTill;
|
|
|
|
_updateOnlineTimer.start((_updateOnlineAt - _now + 1) * 1000);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GroupMembersWidget::refreshMembers() {
|
2019-07-10 17:28:33 +00:00
|
|
|
_now = base::unixtime::now();
|
2019-01-13 08:03:34 +00:00
|
|
|
if (const auto chat = peer()->asChat()) {
|
2016-10-23 21:03:10 +00:00
|
|
|
checkSelfAdmin(chat);
|
|
|
|
if (chat->noParticipantInfo()) {
|
2017-08-04 14:54:32 +00:00
|
|
|
Auth().api().requestFullPeer(chat);
|
2016-10-23 21:03:10 +00:00
|
|
|
}
|
|
|
|
fillChatMembers(chat);
|
2019-01-13 08:03:34 +00:00
|
|
|
} else if (const auto megagroup = peer()->asMegagroup()) {
|
2017-06-09 16:12:02 +00:00
|
|
|
auto &megagroupInfo = megagroup->mgInfo;
|
2017-12-01 18:38:44 +00:00
|
|
|
if (megagroupInfo->lastParticipants.empty() || megagroup->lastParticipantsCountOutdated()) {
|
2017-08-04 14:54:32 +00:00
|
|
|
Auth().api().requestLastParticipants(megagroup);
|
2016-10-23 21:03:10 +00:00
|
|
|
}
|
|
|
|
fillMegagroupMembers(megagroup);
|
|
|
|
}
|
|
|
|
sortMembers();
|
|
|
|
|
|
|
|
refreshVisibility();
|
|
|
|
}
|
|
|
|
|
2019-01-13 08:03:34 +00:00
|
|
|
void GroupMembersWidget::checkSelfAdmin(not_null<ChatData*> chat) {
|
|
|
|
if (chat->participants.empty()) {
|
|
|
|
return;
|
|
|
|
}
|
2016-10-23 21:03:10 +00:00
|
|
|
|
2019-01-13 08:03:34 +00:00
|
|
|
const auto self = chat->session().user();
|
2019-01-03 14:39:19 +00:00
|
|
|
//if (chat->amAdmin() && !chat->admins.contains(self)) {
|
|
|
|
// chat->admins.insert(self);
|
|
|
|
//} else if (!chat->amAdmin() && chat->admins.contains(self)) {
|
|
|
|
// chat->admins.remove(self);
|
|
|
|
//}
|
2016-10-23 21:03:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GroupMembersWidget::sortMembers() {
|
|
|
|
if (!_sortByOnline || !itemsCount()) return;
|
|
|
|
|
|
|
|
sortItems([this](Item *a, Item *b) {
|
|
|
|
return getMember(a)->onlineForSort > getMember(b)->onlineForSort;
|
|
|
|
});
|
|
|
|
|
|
|
|
updateOnlineCount();
|
|
|
|
}
|
|
|
|
|
|
|
|
void GroupMembersWidget::updateOnlineCount() {
|
|
|
|
bool onlyMe = true;
|
|
|
|
int newOnlineCount = 0;
|
|
|
|
for_const (auto item, items()) {
|
|
|
|
auto member = getMember(item);
|
|
|
|
auto user = member->user();
|
2019-07-18 08:51:11 +00:00
|
|
|
auto isOnline = !user->isBot() && Data::OnlineTextActive(member->onlineTill, _now);
|
2016-10-23 21:03:10 +00:00
|
|
|
if (member->statusHasOnlineColor != isOnline) {
|
|
|
|
member->statusHasOnlineColor = isOnline;
|
|
|
|
member->statusText = QString();
|
|
|
|
}
|
|
|
|
if (member->statusHasOnlineColor) {
|
|
|
|
++newOnlineCount;
|
|
|
|
if (!user->isSelf()) {
|
|
|
|
onlyMe = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (newOnlineCount == 1 && onlyMe) {
|
|
|
|
newOnlineCount = 0;
|
|
|
|
}
|
|
|
|
if (_onlineCount != newOnlineCount) {
|
|
|
|
_onlineCount = newOnlineCount;
|
|
|
|
emit onlineCountUpdated(_onlineCount);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-13 08:03:34 +00:00
|
|
|
auto GroupMembersWidget::addUser(
|
|
|
|
not_null<ChatData*> chat,
|
|
|
|
not_null<UserData*> user)
|
|
|
|
-> not_null<Member*> {
|
|
|
|
const auto member = computeMember(user);
|
2016-10-23 21:03:10 +00:00
|
|
|
setItemFlags(member, chat);
|
|
|
|
addItem(member);
|
|
|
|
return member;
|
|
|
|
}
|
|
|
|
|
2019-01-13 08:03:34 +00:00
|
|
|
void GroupMembersWidget::fillChatMembers(not_null<ChatData*> chat) {
|
|
|
|
if (chat->participants.empty()) {
|
|
|
|
return;
|
|
|
|
}
|
2016-10-23 21:03:10 +00:00
|
|
|
|
|
|
|
clearItems();
|
2019-01-13 08:03:34 +00:00
|
|
|
if (!chat->amIn()) {
|
|
|
|
return;
|
|
|
|
}
|
2016-10-23 21:03:10 +00:00
|
|
|
|
|
|
|
_sortByOnline = true;
|
|
|
|
|
|
|
|
reserveItemsForSize(chat->participants.size());
|
2019-01-13 08:03:34 +00:00
|
|
|
addUser(chat, chat->session().user())->onlineForSort
|
2017-12-17 08:13:26 +00:00
|
|
|
= std::numeric_limits<TimeId>::max();
|
2019-01-13 08:03:34 +00:00
|
|
|
for (const auto user : chat->participants) {
|
2016-10-23 21:03:10 +00:00
|
|
|
if (!user->isSelf()) {
|
|
|
|
addUser(chat, user);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-13 08:03:34 +00:00
|
|
|
void GroupMembersWidget::setItemFlags(
|
|
|
|
not_null<Item*> item,
|
|
|
|
not_null<ChatData*> chat) {
|
2017-07-03 10:31:37 +00:00
|
|
|
using AdminState = Item::AdminState;
|
2019-01-13 08:03:34 +00:00
|
|
|
const auto user = getMember(item)->user();
|
|
|
|
const auto isCreator = (peerFromUser(chat->creator) == item->peer->id);
|
|
|
|
const auto isAdmin = chat->hasAdminRights();
|
|
|
|
const auto adminState = isCreator
|
|
|
|
? AdminState::Creator
|
|
|
|
: isAdmin
|
|
|
|
? AdminState::Admin
|
|
|
|
: AdminState::None;
|
2017-07-03 10:31:37 +00:00
|
|
|
item->adminState = adminState;
|
2019-01-13 08:03:34 +00:00
|
|
|
if (item->peer->id == chat->session().userPeerId()) {
|
2016-10-23 21:03:10 +00:00
|
|
|
item->hasRemoveLink = false;
|
2019-01-13 08:03:34 +00:00
|
|
|
} else if (chat->amCreator()
|
|
|
|
|| ((chat->adminRights() & ChatAdminRight::f_ban_users)
|
|
|
|
&& (adminState == AdminState::None))) {
|
2016-10-23 21:03:10 +00:00
|
|
|
item->hasRemoveLink = true;
|
2019-01-13 08:03:34 +00:00
|
|
|
} else if (chat->invitedByMe.contains(user)
|
|
|
|
&& (adminState == AdminState::None)) {
|
2017-07-01 05:45:42 +00:00
|
|
|
item->hasRemoveLink = true;
|
2016-10-23 21:03:10 +00:00
|
|
|
} else {
|
2017-07-01 05:45:42 +00:00
|
|
|
item->hasRemoveLink = false;
|
2016-10-23 21:03:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-13 08:03:34 +00:00
|
|
|
auto GroupMembersWidget::addUser(
|
|
|
|
not_null<ChannelData*> megagroup,
|
|
|
|
not_null<UserData*> user)
|
|
|
|
-> not_null<Member*> {
|
|
|
|
const auto member = computeMember(user);
|
2016-10-23 21:03:10 +00:00
|
|
|
setItemFlags(member, megagroup);
|
|
|
|
addItem(member);
|
|
|
|
return member;
|
|
|
|
}
|
|
|
|
|
2019-01-13 08:03:34 +00:00
|
|
|
void GroupMembersWidget::fillMegagroupMembers(
|
|
|
|
not_null<ChannelData*> megagroup) {
|
|
|
|
Expects(megagroup->mgInfo != nullptr);
|
2016-10-23 21:03:10 +00:00
|
|
|
|
2019-01-13 08:03:34 +00:00
|
|
|
if (megagroup->mgInfo->lastParticipants.empty()) {
|
|
|
|
return;
|
|
|
|
} else if (!megagroup->canViewMembers()) {
|
2016-10-23 21:03:10 +00:00
|
|
|
clearItems();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-01-13 08:03:34 +00:00
|
|
|
_sortByOnline = (megagroup->membersCount() > 0)
|
|
|
|
&& (megagroup->membersCount() <= Global::ChatSizeMax());
|
2016-10-23 21:03:10 +00:00
|
|
|
|
|
|
|
auto &membersList = megagroup->mgInfo->lastParticipants;
|
|
|
|
if (_sortByOnline) {
|
|
|
|
clearItems();
|
|
|
|
reserveItemsForSize(membersList.size());
|
|
|
|
if (megagroup->amIn()) {
|
2019-01-13 08:03:34 +00:00
|
|
|
addUser(megagroup, megagroup->session().user())->onlineForSort
|
2017-12-17 08:13:26 +00:00
|
|
|
= std::numeric_limits<TimeId>::max();
|
2016-10-23 21:03:10 +00:00
|
|
|
}
|
|
|
|
} else if (membersList.size() >= itemsCount()) {
|
|
|
|
if (addUsersToEnd(megagroup)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!_sortByOnline) {
|
|
|
|
clearItems();
|
|
|
|
reserveItemsForSize(membersList.size());
|
|
|
|
}
|
2019-01-13 08:03:34 +00:00
|
|
|
for (const auto user : membersList) {
|
2016-10-23 21:03:10 +00:00
|
|
|
if (!_sortByOnline || !user->isSelf()) {
|
|
|
|
addUser(megagroup, user);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-13 08:03:34 +00:00
|
|
|
bool GroupMembersWidget::addUsersToEnd(not_null<ChannelData*> megagroup) {
|
2016-10-23 21:03:10 +00:00
|
|
|
auto &membersList = megagroup->mgInfo->lastParticipants;
|
|
|
|
auto &itemsList = items();
|
|
|
|
for (int i = 0, count = itemsList.size(); i < count; ++i) {
|
|
|
|
if (itemsList[i]->peer != membersList.at(i)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
reserveItemsForSize(membersList.size());
|
|
|
|
for (int i = itemsCount(), count = membersList.size(); i < count; ++i) {
|
|
|
|
addUser(megagroup, membersList.at(i));
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-01-13 08:03:34 +00:00
|
|
|
void GroupMembersWidget::setItemFlags(
|
|
|
|
not_null<Item*> item,
|
|
|
|
not_null<ChannelData*> megagroup) {
|
2017-07-03 10:31:37 +00:00
|
|
|
using AdminState = Item::AdminState;
|
|
|
|
auto amCreator = item->peer->isSelf() && megagroup->amCreator();
|
|
|
|
auto amAdmin = item->peer->isSelf() && megagroup->hasAdminRights();
|
2017-12-01 18:38:44 +00:00
|
|
|
auto adminIt = megagroup->mgInfo->lastAdmins.find(getMember(item)->user());
|
2017-06-09 16:12:02 +00:00
|
|
|
auto isAdmin = (adminIt != megagroup->mgInfo->lastAdmins.cend());
|
|
|
|
auto isCreator = megagroup->mgInfo->creator == item->peer;
|
2017-12-01 18:38:44 +00:00
|
|
|
auto adminCanEdit = isAdmin && adminIt->second.canEdit;
|
2019-01-13 08:03:34 +00:00
|
|
|
auto adminState = (amCreator || isCreator)
|
|
|
|
? AdminState::Creator
|
|
|
|
: (amAdmin || isAdmin)
|
|
|
|
? AdminState::Admin
|
|
|
|
: AdminState::None;
|
2017-07-03 10:31:37 +00:00
|
|
|
if (item->adminState != adminState) {
|
|
|
|
item->adminState = adminState;
|
2017-06-17 19:51:23 +00:00
|
|
|
auto user = item->peer->asUser();
|
2017-08-17 09:06:26 +00:00
|
|
|
Assert(user != nullptr);
|
2019-07-18 08:51:11 +00:00
|
|
|
if (user->isBot()) {
|
2017-06-17 19:51:23 +00:00
|
|
|
// Update "has access to messages" status.
|
|
|
|
item->statusText = QString();
|
|
|
|
updateItemStatusText(item);
|
|
|
|
}
|
|
|
|
}
|
2016-10-23 21:03:10 +00:00
|
|
|
if (item->peer->isSelf()) {
|
|
|
|
item->hasRemoveLink = false;
|
2017-07-04 16:17:44 +00:00
|
|
|
} else if (megagroup->amCreator() || (megagroup->canBanMembers() && ((adminState == AdminState::None) || adminCanEdit))) {
|
2016-10-23 21:03:10 +00:00
|
|
|
item->hasRemoveLink = true;
|
|
|
|
} else {
|
|
|
|
item->hasRemoveLink = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-13 08:03:34 +00:00
|
|
|
auto GroupMembersWidget::computeMember(not_null<UserData*> user)
|
|
|
|
-> not_null<Member*> {
|
2016-10-23 21:03:10 +00:00
|
|
|
auto it = _membersByUser.constFind(user);
|
|
|
|
if (it == _membersByUser.cend()) {
|
|
|
|
auto member = new Member(user);
|
|
|
|
it = _membersByUser.insert(user, member);
|
2019-07-18 08:51:11 +00:00
|
|
|
member->statusHasOnlineColor = !user->isBot()
|
2017-12-17 08:13:26 +00:00
|
|
|
&& Data::OnlineTextActive(user->onlineTill, _now);
|
2016-10-23 21:03:10 +00:00
|
|
|
member->onlineTill = user->onlineTill;
|
2017-12-17 08:13:26 +00:00
|
|
|
member->onlineForSort = Data::SortByOnlineValue(user, _now);
|
2016-10-23 21:03:10 +00:00
|
|
|
}
|
|
|
|
return it.value();
|
|
|
|
}
|
|
|
|
|
|
|
|
void GroupMembersWidget::onUpdateOnlineDisplay() {
|
|
|
|
if (_sortByOnline) {
|
2019-07-10 17:28:33 +00:00
|
|
|
_now = base::unixtime::now();
|
2016-10-23 21:03:10 +00:00
|
|
|
|
|
|
|
bool changed = false;
|
|
|
|
for_const (auto item, items()) {
|
|
|
|
if (!item->statusHasOnlineColor) {
|
|
|
|
if (!item->peer->isSelf()) {
|
|
|
|
continue;
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
auto member = getMember(item);
|
2019-07-18 08:51:11 +00:00
|
|
|
bool isOnline = !member->user()->isBot()
|
2017-12-17 08:13:26 +00:00
|
|
|
&& Data::OnlineTextActive(member->onlineTill, _now);
|
2016-10-23 21:03:10 +00:00
|
|
|
if (!isOnline) {
|
|
|
|
changed = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (changed) {
|
|
|
|
updateOnlineCount();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
GroupMembersWidget::~GroupMembersWidget() {
|
|
|
|
auto members = base::take(_membersByUser);
|
|
|
|
for_const (auto member, members) {
|
|
|
|
delete member;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Profile
|