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"
|
2020-06-17 09:36:25 +00:00
|
|
|
#include "mtproto/mtproto_config.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"
|
2020-06-12 12:12:34 +00:00
|
|
|
#include "data/data_changes.h"
|
2016-12-13 17:07:56 +00:00
|
|
|
#include "mainwidget.h"
|
2016-10-23 21:03:10 +00:00
|
|
|
#include "apiwrap.h"
|
2019-07-24 11:45:24 +00:00
|
|
|
#include "main/main_session.h"
|
2017-04-13 08:27:10 +00:00
|
|
|
#include "lang/lang_keys.h"
|
2020-06-17 09:36:25 +00:00
|
|
|
#include "facades.h" // Ui::showPeerProfile
|
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
|
|
|
|
2020-06-12 12:12:34 +00:00
|
|
|
using UpdateFlag = Data::PeerUpdate::Flag;
|
2016-10-23 21:03:10 +00:00
|
|
|
|
2019-01-04 11:09:48 +00:00
|
|
|
} // namespace
|
|
|
|
|
2020-05-28 14:32:10 +00:00
|
|
|
GroupMembersWidget::Member::Member(not_null<UserData*> user) : Item(user) {
|
2019-01-04 11:09:48 +00:00
|
|
|
}
|
|
|
|
|
2020-05-28 14:32:10 +00:00
|
|
|
not_null<UserData*> GroupMembersWidget::Member::user() const {
|
|
|
|
return static_cast<UserData*>(peer.get());
|
2019-01-04 11:09:48 +00:00
|
|
|
}
|
|
|
|
|
2017-09-25 16:06:53 +00:00
|
|
|
GroupMembersWidget::GroupMembersWidget(
|
|
|
|
QWidget *parent,
|
2020-06-12 12:12:34 +00:00
|
|
|
not_null<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()));
|
|
|
|
|
2020-06-12 12:12:34 +00:00
|
|
|
peer->session().changes().peerUpdates(
|
|
|
|
UpdateFlag::Admins
|
|
|
|
| UpdateFlag::Members
|
|
|
|
| UpdateFlag::OnlineStatus
|
|
|
|
) | rpl::start_with_next([=](const Data::PeerUpdate &update) {
|
2016-10-23 21:03:10 +00:00
|
|
|
notifyPeerUpdated(update);
|
2020-06-12 12:12:34 +00:00
|
|
|
}, lifetime());
|
2016-10-23 21:03:10 +00:00
|
|
|
|
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) {
|
2020-06-08 15:17:33 +00:00
|
|
|
const 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
|
|
|
}();
|
2020-06-08 15:17:33 +00:00
|
|
|
|
|
|
|
const auto peer = this->peer();
|
|
|
|
const auto callback = [=] {
|
2017-01-11 05:30:51 +00:00
|
|
|
Ui::hideLayer();
|
2017-12-26 16:12:10 +00:00
|
|
|
if (const auto chat = peer->asChat()) {
|
2020-06-08 15:17:33 +00:00
|
|
|
chat->session().api().kickParticipant(chat, user);
|
2020-06-18 18:04:16 +00:00
|
|
|
Ui::showPeerHistory(chat, ShowAtTheEndMsgId);
|
2017-12-26 16:12:10 +00:00
|
|
|
} else if (const auto channel = peer->asChannel()) {
|
2020-06-08 15:17:33 +00:00
|
|
|
channel->session().api().kickParticipant(
|
2017-12-26 16:12:10 +00:00
|
|
|
channel,
|
|
|
|
user,
|
|
|
|
currentRestrictedRights);
|
2017-01-11 05:30:51 +00:00
|
|
|
}
|
2020-06-08 15:17:33 +00:00
|
|
|
};
|
|
|
|
Ui::show(Box<ConfirmBox>(
|
|
|
|
text,
|
|
|
|
tr::lng_box_remove(tr::now),
|
|
|
|
crl::guard(&peer->session(), callback)));
|
2017-01-11 05:30:51 +00:00
|
|
|
}
|
|
|
|
|
2020-06-12 12:12:34 +00:00
|
|
|
void GroupMembersWidget::notifyPeerUpdated(const Data::PeerUpdate &update) {
|
2016-10-23 21:03:10 +00:00
|
|
|
if (update.peer != peer()) {
|
2020-06-12 12:12:34 +00:00
|
|
|
if (update.flags & UpdateFlag::OnlineStatus) {
|
2016-10-23 21:03:10 +00:00
|
|
|
if (auto user = update.peer->asUser()) {
|
|
|
|
refreshUserOnline(user);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-06-12 12:12:34 +00:00
|
|
|
if (update.flags & UpdateFlag::Members) {
|
2016-10-23 21:03:10 +00:00
|
|
|
refreshMembers();
|
|
|
|
contentSizeUpdated();
|
2019-01-10 12:38:57 +00:00
|
|
|
}
|
2020-06-12 12:12:34 +00:00
|
|
|
if (update.flags & UpdateFlag::Admins) {
|
2019-01-10 12:38:57 +00:00
|
|
|
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()) {
|
2020-06-08 15:17:33 +00:00
|
|
|
// peer()->session().api().requestLastParticipants(megagroup, false);
|
2017-11-28 18:30:01 +00:00
|
|
|
// }
|
|
|
|
//}
|
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()) {
|
2020-06-08 15:17:33 +00:00
|
|
|
chat->session().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;
|
2020-03-13 19:14:23 +00:00
|
|
|
if (megagroup->lastParticipantsRequestNeeded()) {
|
2020-06-08 15:17:33 +00:00
|
|
|
megagroup->session().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);
|
2020-03-23 09:38:50 +00:00
|
|
|
const auto isAdmin = (item->peer->isSelf() && chat->hasAdminRights())
|
|
|
|
|| chat->admins.contains(user);
|
2019-01-13 08:03:34 +00:00
|
|
|
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)
|
2020-06-17 09:36:25 +00:00
|
|
|
&& (megagroup->membersCount()
|
|
|
|
<= megagroup->session().serverConfig().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
|