2019-01-04 11:09:48 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
|
|
|
the official desktop application for the Telegram messaging service.
|
|
|
|
|
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|
|
|
*/
|
|
|
|
#include "data/data_channel.h"
|
|
|
|
|
|
|
|
#include "data/data_peer_values.h"
|
2020-06-12 12:12:34 +00:00
|
|
|
#include "data/data_changes.h"
|
2019-01-04 11:09:48 +00:00
|
|
|
#include "data/data_channel_admins.h"
|
|
|
|
#include "data/data_user.h"
|
2019-01-14 06:34:51 +00:00
|
|
|
#include "data/data_chat.h"
|
2019-01-04 11:09:48 +00:00
|
|
|
#include "data/data_session.h"
|
2019-04-15 11:54:03 +00:00
|
|
|
#include "data/data_folder.h"
|
2022-09-20 09:35:47 +00:00
|
|
|
#include "data/data_forum.h"
|
2019-06-21 12:27:46 +00:00
|
|
|
#include "data/data_location.h"
|
2020-02-21 07:58:50 +00:00
|
|
|
#include "data/data_histories.h"
|
2020-11-20 19:25:35 +00:00
|
|
|
#include "data/data_group_call.h"
|
2021-12-07 11:11:27 +00:00
|
|
|
#include "data/data_message_reactions.h"
|
2022-05-14 20:50:02 +00:00
|
|
|
#include "data/data_peer_bot_command.h"
|
2021-11-09 13:50:33 +00:00
|
|
|
#include "main/main_session.h"
|
|
|
|
#include "main/session/send_as_peers.h"
|
2019-07-16 11:46:50 +00:00
|
|
|
#include "base/unixtime.h"
|
2019-04-23 09:40:14 +00:00
|
|
|
#include "history/history.h"
|
2019-07-24 11:45:24 +00:00
|
|
|
#include "main/main_session.h"
|
2020-07-01 14:19:25 +00:00
|
|
|
#include "api/api_chat_invite.h"
|
2021-01-14 13:13:43 +00:00
|
|
|
#include "api/api_invite_links.h"
|
2019-01-13 08:03:34 +00:00
|
|
|
#include "apiwrap.h"
|
2019-01-04 11:09:48 +00:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2020-06-12 12:12:34 +00:00
|
|
|
using UpdateFlag = Data::PeerUpdate::Flag;
|
2019-01-04 11:09:48 +00:00
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2022-09-20 09:35:47 +00:00
|
|
|
MegagroupInfo::MegagroupInfo() = default;
|
|
|
|
|
|
|
|
MegagroupInfo::~MegagroupInfo() = default;
|
|
|
|
|
2019-01-14 06:34:51 +00:00
|
|
|
ChatData *MegagroupInfo::getMigrateFromChat() const {
|
|
|
|
return _migratedFrom;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MegagroupInfo::setMigrateFromChat(ChatData *chat) {
|
|
|
|
_migratedFrom = chat;
|
|
|
|
}
|
|
|
|
|
2019-06-21 12:27:46 +00:00
|
|
|
const ChannelLocation *MegagroupInfo::getLocation() const {
|
|
|
|
return _location.address.isEmpty() ? nullptr : &_location;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MegagroupInfo::setLocation(const ChannelLocation &location) {
|
|
|
|
_location = location;
|
|
|
|
}
|
|
|
|
|
2022-05-14 21:27:21 +00:00
|
|
|
Data::ChatBotCommands::Changed MegagroupInfo::setBotCommands(
|
|
|
|
const std::vector<Data::BotCommands> &list) {
|
|
|
|
return _botCommands.update(list);
|
2021-07-05 17:59:06 +00:00
|
|
|
}
|
|
|
|
|
2022-09-20 09:35:47 +00:00
|
|
|
void MegagroupInfo::setIsForum(bool is) {
|
|
|
|
if (is == (_forum != nullptr)) {
|
|
|
|
return;
|
|
|
|
} else if (is) {
|
|
|
|
_forum = std::make_unique<Data::Forum>();
|
|
|
|
} else {
|
|
|
|
_forum = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Data::Forum *MegagroupInfo::forum() const {
|
|
|
|
return _forum.get();
|
|
|
|
}
|
|
|
|
|
2019-01-04 11:09:48 +00:00
|
|
|
ChannelData::ChannelData(not_null<Data::Session*> owner, PeerId id)
|
|
|
|
: PeerData(owner, id)
|
2021-04-01 21:04:10 +00:00
|
|
|
, inputChannel(
|
2021-08-25 08:15:05 +00:00
|
|
|
MTP_inputChannel(MTP_long(peerToChannel(id).bare), MTP_long(0)))
|
2020-06-11 09:41:03 +00:00
|
|
|
, _ptsWaiter(&owner->session().updates()) {
|
2020-12-01 13:22:07 +00:00
|
|
|
_flags.changes(
|
|
|
|
) | rpl::start_with_next([=](const Flags::Change &change) {
|
|
|
|
if (change.diff
|
2021-07-08 13:11:09 +00:00
|
|
|
& (Flag::Left | Flag::Forbidden)) {
|
2020-12-01 13:22:07 +00:00
|
|
|
if (const auto chat = getMigrateFromChat()) {
|
|
|
|
session().changes().peerUpdated(chat, UpdateFlag::Migration);
|
|
|
|
session().changes().peerUpdated(this, UpdateFlag::Migration);
|
2019-01-04 11:09:48 +00:00
|
|
|
}
|
|
|
|
}
|
2021-07-08 13:11:09 +00:00
|
|
|
if (change.diff & Flag::Megagroup) {
|
|
|
|
if (change.value & Flag::Megagroup) {
|
2020-12-01 13:22:07 +00:00
|
|
|
if (!mgInfo) {
|
|
|
|
mgInfo = std::make_unique<MegagroupInfo>();
|
|
|
|
}
|
|
|
|
} else if (mgInfo) {
|
|
|
|
mgInfo = nullptr;
|
|
|
|
}
|
|
|
|
}
|
2022-09-20 09:35:47 +00:00
|
|
|
if (change.diff & Flag::Forum) {
|
|
|
|
Assert(mgInfo != nullptr);
|
|
|
|
mgInfo->setIsForum(change.value & Flag::Forum);
|
|
|
|
}
|
2021-07-08 13:11:09 +00:00
|
|
|
if (change.diff & Flag::CallNotEmpty) {
|
2020-12-01 13:22:07 +00:00
|
|
|
if (const auto history = this->owner().historyLoaded(this)) {
|
|
|
|
history->updateChatListEntry();
|
|
|
|
}
|
2019-01-14 06:34:51 +00:00
|
|
|
}
|
|
|
|
}, _lifetime);
|
2019-01-04 11:09:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ChannelData::setPhoto(const MTPChatPhoto &photo) {
|
2019-03-22 14:19:43 +00:00
|
|
|
photo.match([&](const MTPDchatPhoto & data) {
|
2022-05-16 11:38:35 +00:00
|
|
|
updateUserpic(
|
|
|
|
data.vphoto_id().v,
|
|
|
|
data.vdc_id().v,
|
|
|
|
data.is_has_video());
|
2019-03-22 14:19:43 +00:00
|
|
|
}, [&](const MTPDchatPhotoEmpty &) {
|
2019-01-04 11:09:48 +00:00
|
|
|
clearUserpic();
|
2019-03-22 14:19:43 +00:00
|
|
|
});
|
2019-01-04 11:09:48 +00:00
|
|
|
}
|
|
|
|
|
2022-08-09 11:12:19 +00:00
|
|
|
void ChannelData::setName(
|
|
|
|
const QString &newName,
|
|
|
|
const QString &newUsername) {
|
|
|
|
updateNameDelayed(newName.isEmpty() ? name() : newName, {}, newUsername);
|
2019-01-04 11:09:48 +00:00
|
|
|
}
|
|
|
|
|
2020-02-07 16:07:21 +00:00
|
|
|
void ChannelData::setAccessHash(uint64 accessHash) {
|
|
|
|
access = accessHash;
|
2022-08-09 11:12:19 +00:00
|
|
|
input = MTP_inputPeerChannel(
|
|
|
|
MTP_long(peerToChannel(id).bare),
|
|
|
|
MTP_long(accessHash));
|
|
|
|
inputChannel = MTP_inputChannel(
|
|
|
|
MTP_long(peerToChannel(id).bare),
|
|
|
|
MTP_long(accessHash));
|
2020-02-07 16:07:21 +00:00
|
|
|
}
|
|
|
|
|
2019-01-04 11:09:48 +00:00
|
|
|
void ChannelData::setInviteLink(const QString &newInviteLink) {
|
2021-01-14 13:13:43 +00:00
|
|
|
_inviteLink = newInviteLink;
|
2019-01-04 11:09:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ChannelData::canHaveInviteLink() const {
|
2020-12-14 12:52:18 +00:00
|
|
|
return amCreator()
|
2021-07-08 10:34:06 +00:00
|
|
|
|| (adminRights() & AdminRight::InviteUsers);
|
2019-01-04 11:09:48 +00:00
|
|
|
}
|
|
|
|
|
2019-06-21 12:27:46 +00:00
|
|
|
void ChannelData::setLocation(const MTPChannelLocation &data) {
|
|
|
|
if (!mgInfo) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const auto was = mgInfo->getLocation();
|
|
|
|
const auto wasValue = was ? *was : ChannelLocation();
|
|
|
|
data.match([&](const MTPDchannelLocation &data) {
|
2019-07-05 13:38:38 +00:00
|
|
|
data.vgeo_point().match([&](const MTPDgeoPoint &point) {
|
2019-06-21 12:27:46 +00:00
|
|
|
mgInfo->setLocation({
|
2019-07-05 13:38:38 +00:00
|
|
|
qs(data.vaddress()),
|
2019-06-21 12:27:46 +00:00
|
|
|
Data::LocationPoint(point)
|
|
|
|
});
|
|
|
|
}, [&](const MTPDgeoPointEmpty &) {
|
|
|
|
mgInfo->setLocation(ChannelLocation());
|
|
|
|
});
|
|
|
|
}, [&](const MTPDchannelLocationEmpty &) {
|
|
|
|
mgInfo->setLocation(ChannelLocation());
|
|
|
|
});
|
|
|
|
const auto now = mgInfo->getLocation();
|
|
|
|
const auto nowValue = now ? *now : ChannelLocation();
|
|
|
|
if (was != now || (was && wasValue != nowValue)) {
|
2020-06-12 12:12:34 +00:00
|
|
|
session().changes().peerUpdated(
|
2019-06-21 12:27:46 +00:00
|
|
|
this,
|
2020-06-12 12:12:34 +00:00
|
|
|
UpdateFlag::ChannelLocation);
|
2019-06-21 12:27:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const ChannelLocation *ChannelData::getLocation() const {
|
|
|
|
return mgInfo ? mgInfo->getLocation() : nullptr;
|
|
|
|
}
|
|
|
|
|
2019-05-23 21:38:49 +00:00
|
|
|
void ChannelData::setLinkedChat(ChannelData *linked) {
|
|
|
|
if (_linkedChat != linked) {
|
|
|
|
_linkedChat = linked;
|
2020-09-03 07:19:02 +00:00
|
|
|
if (const auto history = owner().historyLoaded(this)) {
|
|
|
|
history->forceFullResize();
|
|
|
|
}
|
2020-06-12 12:12:34 +00:00
|
|
|
session().changes().peerUpdated(this, UpdateFlag::ChannelLinkedChat);
|
2019-05-23 21:38:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ChannelData *ChannelData::linkedChat() const {
|
2020-09-10 11:56:46 +00:00
|
|
|
return _linkedChat.value_or(nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ChannelData::linkedChatKnown() const {
|
|
|
|
return _linkedChat.has_value();
|
2019-05-23 21:38:49 +00:00
|
|
|
}
|
|
|
|
|
2019-01-04 11:09:48 +00:00
|
|
|
void ChannelData::setMembersCount(int newMembersCount) {
|
|
|
|
if (_membersCount != newMembersCount) {
|
|
|
|
if (isMegagroup() && !mgInfo->lastParticipants.empty()) {
|
|
|
|
mgInfo->lastParticipantsStatus |= MegagroupInfo::LastParticipantsCountOutdated;
|
|
|
|
mgInfo->lastParticipantsCount = membersCount();
|
|
|
|
}
|
|
|
|
_membersCount = newMembersCount;
|
2020-06-12 12:12:34 +00:00
|
|
|
session().changes().peerUpdated(this, UpdateFlag::Members);
|
2019-01-04 11:09:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ChannelData::setAdminsCount(int newAdminsCount) {
|
|
|
|
if (_adminsCount != newAdminsCount) {
|
|
|
|
_adminsCount = newAdminsCount;
|
2020-06-12 12:12:34 +00:00
|
|
|
session().changes().peerUpdated(this, UpdateFlag::Admins);
|
2019-01-04 11:09:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ChannelData::setRestrictedCount(int newRestrictedCount) {
|
|
|
|
if (_restrictedCount != newRestrictedCount) {
|
|
|
|
_restrictedCount = newRestrictedCount;
|
2020-06-12 12:12:34 +00:00
|
|
|
session().changes().peerUpdated(this, UpdateFlag::BannedUsers);
|
2019-01-04 11:09:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ChannelData::setKickedCount(int newKickedCount) {
|
|
|
|
if (_kickedCount != newKickedCount) {
|
|
|
|
_kickedCount = newKickedCount;
|
2020-06-12 12:12:34 +00:00
|
|
|
session().changes().peerUpdated(this, UpdateFlag::BannedUsers);
|
2019-01-04 11:09:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-27 05:57:37 +00:00
|
|
|
void ChannelData::setPendingRequestsCount(
|
|
|
|
int count,
|
|
|
|
const QVector<MTPlong> &recentRequesters) {
|
|
|
|
setPendingRequestsCount(count, ranges::views::all(
|
|
|
|
recentRequesters
|
|
|
|
) | ranges::views::transform([&](const MTPlong &value) {
|
|
|
|
return UserId(value);
|
|
|
|
}) | ranges::to_vector);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ChannelData::setPendingRequestsCount(
|
|
|
|
int count,
|
|
|
|
std::vector<UserId> recentRequesters) {
|
|
|
|
if (_pendingRequestsCount != count
|
|
|
|
|| _recentRequesters != recentRequesters) {
|
2021-10-12 08:39:07 +00:00
|
|
|
_pendingRequestsCount = count;
|
2021-10-27 05:57:37 +00:00
|
|
|
_recentRequesters = std::move(recentRequesters);
|
2021-10-12 08:39:07 +00:00
|
|
|
session().changes().peerUpdated(this, UpdateFlag::PendingRequests);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-08 10:34:06 +00:00
|
|
|
ChatRestrictionsInfo ChannelData::KickedRestrictedRights(
|
2021-03-19 15:10:44 +00:00
|
|
|
not_null<PeerData*> participant) {
|
2021-07-08 10:34:06 +00:00
|
|
|
using Flag = ChatRestriction;
|
|
|
|
const auto flags = Flag::ViewMessages
|
|
|
|
| Flag::SendMessages
|
|
|
|
| Flag::SendMedia
|
|
|
|
| Flag::EmbedLinks
|
|
|
|
| Flag::SendStickers
|
|
|
|
| Flag::SendGifs
|
|
|
|
| Flag::SendGames
|
|
|
|
| Flag::SendInline;
|
|
|
|
return ChatRestrictionsInfo(
|
|
|
|
(participant->isUser() ? flags : Flag::ViewMessages),
|
|
|
|
std::numeric_limits<int32>::max());
|
2019-01-04 11:09:48 +00:00
|
|
|
}
|
|
|
|
|
2019-01-10 06:26:08 +00:00
|
|
|
void ChannelData::applyEditAdmin(
|
|
|
|
not_null<UserData*> user,
|
2021-07-08 10:34:06 +00:00
|
|
|
ChatAdminRightsInfo oldRights,
|
|
|
|
ChatAdminRightsInfo newRights,
|
2019-07-19 13:34:09 +00:00
|
|
|
const QString &rank) {
|
2019-01-04 11:09:48 +00:00
|
|
|
if (mgInfo) {
|
|
|
|
// If rights are empty - still add participant? TODO check
|
|
|
|
if (!base::contains(mgInfo->lastParticipants, user)) {
|
|
|
|
mgInfo->lastParticipants.push_front(user);
|
|
|
|
setMembersCount(membersCount() + 1);
|
2019-07-18 08:51:11 +00:00
|
|
|
if (user->isBot() && !mgInfo->bots.contains(user)) {
|
2019-01-04 11:09:48 +00:00
|
|
|
mgInfo->bots.insert(user);
|
|
|
|
if (mgInfo->botStatus != 0 && mgInfo->botStatus < 2) {
|
|
|
|
mgInfo->botStatus = 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// If rights are empty - still remove restrictions? TODO check
|
|
|
|
if (mgInfo->lastRestricted.contains(user)) {
|
|
|
|
mgInfo->lastRestricted.remove(user);
|
|
|
|
if (restrictedCount() > 0) {
|
|
|
|
setRestrictedCount(restrictedCount() - 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
auto userId = peerToUser(user->id);
|
|
|
|
auto it = mgInfo->lastAdmins.find(user);
|
2021-07-08 10:34:06 +00:00
|
|
|
if (newRights.flags) {
|
2019-01-04 11:09:48 +00:00
|
|
|
auto lastAdmin = MegagroupInfo::Admin { newRights };
|
|
|
|
lastAdmin.canEdit = true;
|
|
|
|
if (it == mgInfo->lastAdmins.cend()) {
|
|
|
|
mgInfo->lastAdmins.emplace(user, lastAdmin);
|
|
|
|
setAdminsCount(adminsCount() + 1);
|
|
|
|
} else {
|
|
|
|
it->second = lastAdmin;
|
|
|
|
}
|
2019-07-19 13:34:09 +00:00
|
|
|
Data::ChannelAdminChanges(this).add(userId, rank);
|
2019-01-04 11:09:48 +00:00
|
|
|
} else {
|
|
|
|
if (it != mgInfo->lastAdmins.cend()) {
|
|
|
|
mgInfo->lastAdmins.erase(it);
|
|
|
|
if (adminsCount() > 0) {
|
|
|
|
setAdminsCount(adminsCount() - 1);
|
|
|
|
}
|
|
|
|
}
|
2019-07-19 13:34:09 +00:00
|
|
|
Data::ChannelAdminChanges(this).remove(userId);
|
2019-01-04 11:09:48 +00:00
|
|
|
}
|
|
|
|
}
|
2021-07-08 10:34:06 +00:00
|
|
|
if (oldRights.flags && !newRights.flags) {
|
2019-01-04 11:09:48 +00:00
|
|
|
// We removed an admin.
|
|
|
|
if (adminsCount() > 1) {
|
|
|
|
setAdminsCount(adminsCount() - 1);
|
|
|
|
}
|
2019-07-18 08:51:11 +00:00
|
|
|
if (!isMegagroup() && user->isBot() && membersCount() > 1) {
|
2019-01-04 11:09:48 +00:00
|
|
|
// Removing bot admin removes it from channel.
|
|
|
|
setMembersCount(membersCount() - 1);
|
|
|
|
}
|
2021-07-08 10:34:06 +00:00
|
|
|
} else if (!oldRights.flags && newRights.flags) {
|
2019-01-04 11:09:48 +00:00
|
|
|
// We added an admin.
|
|
|
|
setAdminsCount(adminsCount() + 1);
|
|
|
|
updateFullForced();
|
|
|
|
}
|
2020-06-12 12:12:34 +00:00
|
|
|
session().changes().peerUpdated(this, UpdateFlag::Admins);
|
2019-01-04 11:09:48 +00:00
|
|
|
}
|
|
|
|
|
2021-03-19 14:01:21 +00:00
|
|
|
void ChannelData::applyEditBanned(
|
|
|
|
not_null<PeerData*> participant,
|
2021-07-08 10:34:06 +00:00
|
|
|
ChatRestrictionsInfo oldRights,
|
|
|
|
ChatRestrictionsInfo newRights) {
|
2020-06-12 12:12:34 +00:00
|
|
|
auto flags = UpdateFlag::BannedUsers | UpdateFlag::None;
|
2021-07-08 10:34:06 +00:00
|
|
|
auto isKicked = newRights.flags & ChatRestriction::ViewMessages;
|
|
|
|
auto isRestricted = !isKicked && newRights.flags;
|
2021-03-19 14:01:21 +00:00
|
|
|
const auto user = participant->asUser();
|
|
|
|
if (mgInfo && user) {
|
2019-01-04 11:09:48 +00:00
|
|
|
// If rights are empty - still remove admin? TODO check
|
|
|
|
if (mgInfo->lastAdmins.contains(user)) {
|
|
|
|
mgInfo->lastAdmins.remove(user);
|
|
|
|
if (adminsCount() > 1) {
|
|
|
|
setAdminsCount(adminsCount() - 1);
|
|
|
|
} else {
|
2020-06-12 12:12:34 +00:00
|
|
|
flags |= UpdateFlag::Admins;
|
2019-01-04 11:09:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
auto it = mgInfo->lastRestricted.find(user);
|
|
|
|
if (isRestricted) {
|
|
|
|
if (it == mgInfo->lastRestricted.cend()) {
|
2021-03-19 14:01:21 +00:00
|
|
|
mgInfo->lastRestricted.emplace(
|
|
|
|
user,
|
|
|
|
MegagroupInfo::Restricted { newRights });
|
2019-01-04 11:09:48 +00:00
|
|
|
setRestrictedCount(restrictedCount() + 1);
|
|
|
|
} else {
|
|
|
|
it->second.rights = newRights;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (it != mgInfo->lastRestricted.cend()) {
|
|
|
|
mgInfo->lastRestricted.erase(it);
|
|
|
|
if (restrictedCount() > 0) {
|
|
|
|
setRestrictedCount(restrictedCount() - 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (isKicked) {
|
2021-03-19 14:01:21 +00:00
|
|
|
auto i = ranges::find(
|
|
|
|
mgInfo->lastParticipants,
|
|
|
|
not_null{ user });
|
2019-01-04 11:09:48 +00:00
|
|
|
if (i != mgInfo->lastParticipants.end()) {
|
|
|
|
mgInfo->lastParticipants.erase(i);
|
|
|
|
}
|
|
|
|
if (membersCount() > 1) {
|
|
|
|
setMembersCount(membersCount() - 1);
|
|
|
|
} else {
|
|
|
|
mgInfo->lastParticipantsStatus |= MegagroupInfo::LastParticipantsCountOutdated;
|
|
|
|
mgInfo->lastParticipantsCount = 0;
|
|
|
|
}
|
|
|
|
setKickedCount(kickedCount() + 1);
|
|
|
|
if (mgInfo->bots.contains(user)) {
|
|
|
|
mgInfo->bots.remove(user);
|
|
|
|
if (mgInfo->bots.empty() && mgInfo->botStatus > 0) {
|
|
|
|
mgInfo->botStatus = -1;
|
|
|
|
}
|
|
|
|
}
|
2020-06-12 12:12:34 +00:00
|
|
|
flags |= UpdateFlag::Members;
|
2019-01-04 11:09:48 +00:00
|
|
|
owner().removeMegagroupParticipant(this, user);
|
|
|
|
}
|
|
|
|
}
|
2019-07-19 13:34:09 +00:00
|
|
|
Data::ChannelAdminChanges(this).remove(peerToUser(user->id));
|
2021-03-19 14:01:21 +00:00
|
|
|
} else if (!mgInfo) {
|
2019-01-04 11:09:48 +00:00
|
|
|
if (isKicked) {
|
2021-03-19 14:01:21 +00:00
|
|
|
if (user && membersCount() > 1) {
|
2019-01-04 11:09:48 +00:00
|
|
|
setMembersCount(membersCount() - 1);
|
2020-06-12 12:12:34 +00:00
|
|
|
flags |= UpdateFlag::Members;
|
2019-01-04 11:09:48 +00:00
|
|
|
}
|
|
|
|
setKickedCount(kickedCount() + 1);
|
|
|
|
}
|
|
|
|
}
|
2020-06-12 12:12:34 +00:00
|
|
|
session().changes().peerUpdated(this, flags);
|
2019-01-04 11:09:48 +00:00
|
|
|
}
|
|
|
|
|
2019-04-09 13:18:47 +00:00
|
|
|
void ChannelData::markForbidden() {
|
|
|
|
owner().processChat(MTP_channelForbidden(
|
|
|
|
MTP_flags(isMegagroup()
|
|
|
|
? MTPDchannelForbidden::Flag::f_megagroup
|
|
|
|
: MTPDchannelForbidden::Flag::f_broadcast),
|
2021-08-25 08:15:05 +00:00
|
|
|
MTP_long(peerToChannel(id).bare),
|
2019-04-09 13:18:47 +00:00
|
|
|
MTP_long(access),
|
2022-08-09 11:12:19 +00:00
|
|
|
MTP_string(name()),
|
2019-04-09 13:18:47 +00:00
|
|
|
MTPint()));
|
|
|
|
}
|
|
|
|
|
2019-01-04 11:09:48 +00:00
|
|
|
bool ChannelData::isGroupAdmin(not_null<UserData*> user) const {
|
|
|
|
if (auto info = mgInfo.get()) {
|
|
|
|
return info->admins.contains(peerToUser(user->id));
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-03-13 19:14:23 +00:00
|
|
|
bool ChannelData::lastParticipantsRequestNeeded() const {
|
|
|
|
if (!mgInfo) {
|
|
|
|
return false;
|
|
|
|
} else if (mgInfo->lastParticipantsCount == membersCount()) {
|
|
|
|
mgInfo->lastParticipantsStatus
|
|
|
|
&= ~MegagroupInfo::LastParticipantsCountOutdated;
|
|
|
|
}
|
|
|
|
return mgInfo->lastParticipants.empty()
|
|
|
|
|| !(mgInfo->lastParticipantsStatus
|
|
|
|
& MegagroupInfo::LastParticipantsOnceReceived)
|
|
|
|
|| (mgInfo->lastParticipantsStatus
|
|
|
|
& MegagroupInfo::LastParticipantsCountOutdated);
|
|
|
|
}
|
|
|
|
|
2019-12-09 13:57:33 +00:00
|
|
|
auto ChannelData::unavailableReasons() const
|
|
|
|
-> const std::vector<Data::UnavailableReason> & {
|
|
|
|
return _unavailableReasons;
|
2019-01-04 11:09:48 +00:00
|
|
|
}
|
|
|
|
|
2020-06-12 12:12:34 +00:00
|
|
|
void ChannelData::setUnavailableReasons(
|
|
|
|
std::vector<Data::UnavailableReason> &&reasons) {
|
2019-12-09 13:57:33 +00:00
|
|
|
if (_unavailableReasons != reasons) {
|
|
|
|
_unavailableReasons = std::move(reasons);
|
2020-06-12 12:12:34 +00:00
|
|
|
session().changes().peerUpdated(this, UpdateFlag::UnavailableReason);
|
2019-01-04 11:09:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ChannelData::setAvailableMinId(MsgId availableMinId) {
|
|
|
|
if (_availableMinId != availableMinId) {
|
|
|
|
_availableMinId = availableMinId;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ChannelData::canBanMembers() const {
|
2019-01-10 06:26:08 +00:00
|
|
|
return amCreator()
|
2021-07-08 10:34:06 +00:00
|
|
|
|| (adminRights() & AdminRight::BanUsers);
|
2019-01-04 11:09:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ChannelData::canEditMessages() const {
|
2019-01-10 06:26:08 +00:00
|
|
|
return amCreator()
|
2021-07-08 10:34:06 +00:00
|
|
|
|| (adminRights() & AdminRight::EditMessages);
|
2019-01-04 11:09:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ChannelData::canDeleteMessages() const {
|
2019-01-10 06:26:08 +00:00
|
|
|
return amCreator()
|
2021-07-08 10:34:06 +00:00
|
|
|
|| (adminRights() & AdminRight::DeleteMessages);
|
2019-01-04 11:09:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ChannelData::anyoneCanAddMembers() const {
|
2021-07-08 10:34:06 +00:00
|
|
|
return !(defaultRestrictions() & Restriction::InviteUsers);
|
2019-01-04 11:09:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ChannelData::hiddenPreHistory() const {
|
2021-07-08 13:11:09 +00:00
|
|
|
return (flags() & Flag::PreHistoryHidden);
|
2019-01-04 11:09:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ChannelData::canAddMembers() const {
|
2019-01-30 10:49:36 +00:00
|
|
|
return isMegagroup()
|
2021-07-08 10:34:06 +00:00
|
|
|
? !amRestricted(ChatRestriction::InviteUsers)
|
|
|
|
: ((adminRights() & AdminRight::InviteUsers) || amCreator());
|
2019-01-04 11:09:48 +00:00
|
|
|
}
|
|
|
|
|
2019-01-10 06:26:08 +00:00
|
|
|
bool ChannelData::canSendPolls() const {
|
2021-07-08 10:34:06 +00:00
|
|
|
return canWrite() && !amRestricted(ChatRestriction::SendPolls);
|
2019-01-10 06:26:08 +00:00
|
|
|
}
|
|
|
|
|
2019-01-04 11:09:48 +00:00
|
|
|
bool ChannelData::canAddAdmins() const {
|
2019-01-05 10:50:04 +00:00
|
|
|
return amCreator()
|
2021-07-08 10:34:06 +00:00
|
|
|
|| (adminRights() & AdminRight::AddAdmins);
|
2019-01-04 11:09:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ChannelData::canPublish() const {
|
2019-01-05 10:50:04 +00:00
|
|
|
return amCreator()
|
2021-07-08 10:34:06 +00:00
|
|
|
|| (adminRights() & AdminRight::PostMessages);
|
2019-01-04 11:09:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ChannelData::canWrite() const {
|
|
|
|
// Duplicated in Data::CanWriteValue().
|
2022-04-21 14:29:49 +00:00
|
|
|
const auto allowed = amIn()
|
|
|
|
|| ((flags() & Flag::HasLink) && !(flags() & Flag::JoinToWrite));
|
2020-09-11 11:14:24 +00:00
|
|
|
return allowed && (canPublish()
|
2019-01-04 11:09:48 +00:00
|
|
|
|| (!isBroadcast()
|
2021-07-08 10:34:06 +00:00
|
|
|
&& !amRestricted(Restriction::SendMessages)));
|
2019-01-04 11:09:48 +00:00
|
|
|
}
|
|
|
|
|
2021-11-05 14:03:17 +00:00
|
|
|
bool ChannelData::allowsForwarding() const {
|
|
|
|
return !(flags() & Flag::NoForwards);
|
|
|
|
}
|
|
|
|
|
2019-01-04 11:09:48 +00:00
|
|
|
bool ChannelData::canViewMembers() const {
|
2021-07-08 13:11:09 +00:00
|
|
|
return flags() & Flag::CanViewParticipants;
|
2019-01-04 11:09:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ChannelData::canViewAdmins() const {
|
|
|
|
return (isMegagroup() || hasAdminRights() || amCreator());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ChannelData::canViewBanned() const {
|
|
|
|
return (hasAdminRights() || amCreator());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ChannelData::canEditInformation() const {
|
2019-01-28 10:09:46 +00:00
|
|
|
return isMegagroup()
|
2021-07-08 10:34:06 +00:00
|
|
|
? !amRestricted(Restriction::ChangeInfo)
|
|
|
|
: ((adminRights() & AdminRight::ChangeInfo) || amCreator());
|
2019-01-04 11:09:48 +00:00
|
|
|
}
|
|
|
|
|
2019-01-07 12:55:49 +00:00
|
|
|
bool ChannelData::canEditPermissions() const {
|
2019-01-14 06:34:51 +00:00
|
|
|
return isMegagroup()
|
2021-02-12 15:07:41 +00:00
|
|
|
&& !isGigagroup()
|
2021-07-08 10:34:06 +00:00
|
|
|
&& ((adminRights() & AdminRight::BanUsers) || amCreator());
|
2019-01-07 12:55:49 +00:00
|
|
|
}
|
|
|
|
|
2019-01-04 11:09:48 +00:00
|
|
|
bool ChannelData::canEditSignatures() const {
|
2019-03-20 09:22:58 +00:00
|
|
|
return isChannel() && canEditInformation();
|
2019-01-04 11:09:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ChannelData::canEditPreHistoryHidden() const {
|
2019-03-20 09:22:58 +00:00
|
|
|
return isMegagroup()
|
2021-07-08 10:34:06 +00:00
|
|
|
&& ((adminRights() & AdminRight::BanUsers) || amCreator())
|
2019-01-08 13:57:22 +00:00
|
|
|
&& (!isPublic() || canEditUsername());
|
2019-01-04 11:09:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ChannelData::canEditUsername() const {
|
|
|
|
return amCreator()
|
2021-07-08 13:11:09 +00:00
|
|
|
&& (flags() & Flag::CanSetUsername);
|
2019-01-04 11:09:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ChannelData::canEditStickers() const {
|
2021-07-08 13:11:09 +00:00
|
|
|
return (flags() & Flag::CanSetStickers);
|
2019-01-04 11:09:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ChannelData::canDelete() const {
|
|
|
|
constexpr auto kDeleteChannelMembersLimit = 1000;
|
|
|
|
return amCreator()
|
|
|
|
&& (membersCount() <= kDeleteChannelMembersLimit);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ChannelData::canEditLastAdmin(not_null<UserData*> user) const {
|
2021-03-19 15:10:44 +00:00
|
|
|
// Duplicated in ParticipantsAdditionalData::canEditAdmin :(
|
2019-01-04 11:09:48 +00:00
|
|
|
if (mgInfo) {
|
|
|
|
auto i = mgInfo->lastAdmins.find(user);
|
|
|
|
if (i != mgInfo->lastAdmins.cend()) {
|
|
|
|
return i->second.canEdit;
|
|
|
|
}
|
|
|
|
return (user != mgInfo->creator);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ChannelData::canEditAdmin(not_null<UserData*> user) const {
|
2021-03-19 15:10:44 +00:00
|
|
|
// Duplicated in ParticipantsAdditionalData::canEditAdmin :(
|
2019-01-04 11:09:48 +00:00
|
|
|
if (user->isSelf()) {
|
|
|
|
return false;
|
|
|
|
} else if (amCreator()) {
|
|
|
|
return true;
|
|
|
|
} else if (!canEditLastAdmin(user)) {
|
|
|
|
return false;
|
|
|
|
}
|
2021-07-08 10:34:06 +00:00
|
|
|
return adminRights() & AdminRight::AddAdmins;
|
2019-01-04 11:09:48 +00:00
|
|
|
}
|
|
|
|
|
2021-03-19 15:10:44 +00:00
|
|
|
bool ChannelData::canRestrictParticipant(
|
|
|
|
not_null<PeerData*> participant) const {
|
|
|
|
// Duplicated in ParticipantsAdditionalData::canRestrictParticipant :(
|
|
|
|
if (participant->isSelf()) {
|
2019-01-04 11:09:48 +00:00
|
|
|
return false;
|
|
|
|
} else if (amCreator()) {
|
|
|
|
return true;
|
2021-03-19 15:10:44 +00:00
|
|
|
} else if (const auto user = participant->asUser()) {
|
|
|
|
if (!canEditLastAdmin(user)) {
|
|
|
|
return false;
|
|
|
|
}
|
2019-01-04 11:09:48 +00:00
|
|
|
}
|
2021-07-08 10:34:06 +00:00
|
|
|
return adminRights() & AdminRight::BanUsers;
|
2019-01-04 11:09:48 +00:00
|
|
|
}
|
|
|
|
|
2021-07-08 10:34:06 +00:00
|
|
|
void ChannelData::setAdminRights(ChatAdminRights rights) {
|
|
|
|
if (rights == adminRights()) {
|
2019-01-04 11:09:48 +00:00
|
|
|
return;
|
|
|
|
}
|
2021-07-08 10:34:06 +00:00
|
|
|
_adminRights.set(rights);
|
2021-10-12 08:39:07 +00:00
|
|
|
if (!canHaveInviteLink()) {
|
2021-10-27 05:57:37 +00:00
|
|
|
setPendingRequestsCount(0, std::vector<UserId>{});
|
2021-10-12 08:39:07 +00:00
|
|
|
}
|
2019-01-04 11:09:48 +00:00
|
|
|
if (isMegagroup()) {
|
|
|
|
const auto self = session().user();
|
|
|
|
if (hasAdminRights()) {
|
|
|
|
if (!amCreator()) {
|
2021-07-08 10:34:06 +00:00
|
|
|
auto me = MegagroupInfo::Admin{
|
|
|
|
ChatAdminRightsInfo{ rights } };
|
2019-01-04 11:09:48 +00:00
|
|
|
me.canEdit = false;
|
|
|
|
mgInfo->lastAdmins.emplace(self, me);
|
|
|
|
}
|
|
|
|
mgInfo->lastRestricted.remove(self);
|
|
|
|
} else {
|
|
|
|
mgInfo->lastAdmins.remove(self);
|
|
|
|
}
|
|
|
|
}
|
2020-06-12 12:12:34 +00:00
|
|
|
session().changes().peerUpdated(
|
|
|
|
this,
|
|
|
|
UpdateFlag::Rights | UpdateFlag::Admins | UpdateFlag::BannedUsers);
|
2019-01-04 11:09:48 +00:00
|
|
|
}
|
|
|
|
|
2021-07-08 10:34:06 +00:00
|
|
|
void ChannelData::setRestrictions(ChatRestrictionsInfo rights) {
|
|
|
|
if (rights.flags == restrictions() && rights.until == _restrictedUntil) {
|
2019-01-04 11:09:48 +00:00
|
|
|
return;
|
|
|
|
}
|
2021-07-08 10:34:06 +00:00
|
|
|
_restrictedUntil = rights.until;
|
|
|
|
_restrictions.set(rights.flags);
|
2019-01-04 11:09:48 +00:00
|
|
|
if (isMegagroup()) {
|
|
|
|
const auto self = session().user();
|
|
|
|
if (hasRestrictions()) {
|
|
|
|
if (!amCreator()) {
|
|
|
|
auto me = MegagroupInfo::Restricted { rights };
|
|
|
|
mgInfo->lastRestricted.emplace(self, me);
|
|
|
|
}
|
|
|
|
mgInfo->lastAdmins.remove(self);
|
2019-07-19 13:34:09 +00:00
|
|
|
Data::ChannelAdminChanges(this).remove(session().userId());
|
2019-01-04 11:09:48 +00:00
|
|
|
} else {
|
|
|
|
mgInfo->lastRestricted.remove(self);
|
|
|
|
}
|
|
|
|
}
|
2020-06-12 12:12:34 +00:00
|
|
|
session().changes().peerUpdated(
|
|
|
|
this,
|
|
|
|
UpdateFlag::Rights | UpdateFlag::Admins | UpdateFlag::BannedUsers);
|
2019-01-05 10:50:04 +00:00
|
|
|
}
|
|
|
|
|
2021-07-08 10:34:06 +00:00
|
|
|
void ChannelData::setDefaultRestrictions(ChatRestrictions rights) {
|
|
|
|
if (rights == defaultRestrictions()) {
|
2019-01-05 10:50:04 +00:00
|
|
|
return;
|
|
|
|
}
|
2021-07-08 10:34:06 +00:00
|
|
|
_defaultRestrictions.set(rights);
|
2020-06-12 12:12:34 +00:00
|
|
|
session().changes().peerUpdated(this, UpdateFlag::Rights);
|
2019-01-04 11:09:48 +00:00
|
|
|
}
|
2019-01-13 08:03:34 +00:00
|
|
|
|
2019-01-14 06:34:51 +00:00
|
|
|
ChatData *ChannelData::getMigrateFromChat() const {
|
|
|
|
if (const auto info = mgInfo.get()) {
|
|
|
|
return info->getMigrateFromChat();
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ChannelData::setMigrateFromChat(ChatData *chat) {
|
|
|
|
Expects(mgInfo != nullptr);
|
|
|
|
|
|
|
|
const auto info = mgInfo.get();
|
|
|
|
if (chat != info->getMigrateFromChat()) {
|
|
|
|
info->setMigrateFromChat(chat);
|
|
|
|
if (amIn()) {
|
2020-06-12 12:12:34 +00:00
|
|
|
session().changes().peerUpdated(this, UpdateFlag::Migration);
|
2019-01-14 06:34:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-16 11:46:50 +00:00
|
|
|
int ChannelData::slowmodeSeconds() const {
|
|
|
|
return _slowmodeSeconds;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ChannelData::setSlowmodeSeconds(int seconds) {
|
|
|
|
if (_slowmodeSeconds == seconds) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_slowmodeSeconds = seconds;
|
2020-06-12 12:12:34 +00:00
|
|
|
session().changes().peerUpdated(this, UpdateFlag::Slowmode);
|
2019-07-16 11:46:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TimeId ChannelData::slowmodeLastMessage() const {
|
|
|
|
return (hasAdminRights() || amCreator()) ? 0 : _slowmodeLastMessage;
|
|
|
|
}
|
|
|
|
|
2019-07-16 13:59:50 +00:00
|
|
|
void ChannelData::growSlowmodeLastMessage(TimeId when) {
|
2019-08-20 09:42:13 +00:00
|
|
|
const auto now = base::unixtime::now();
|
|
|
|
accumulate_min(when, now);
|
|
|
|
if (_slowmodeLastMessage > now) {
|
|
|
|
_slowmodeLastMessage = when;
|
|
|
|
} else if (_slowmodeLastMessage >= when) {
|
2019-07-16 11:46:50 +00:00
|
|
|
return;
|
2019-08-20 09:42:13 +00:00
|
|
|
} else {
|
|
|
|
_slowmodeLastMessage = when;
|
2019-07-16 11:46:50 +00:00
|
|
|
}
|
2020-06-12 12:12:34 +00:00
|
|
|
session().changes().peerUpdated(this, UpdateFlag::Slowmode);
|
2019-07-16 11:46:50 +00:00
|
|
|
}
|
|
|
|
|
2020-07-01 14:19:25 +00:00
|
|
|
void ChannelData::setInvitePeek(const QString &hash, TimeId expires) {
|
|
|
|
if (!_invitePeek) {
|
|
|
|
_invitePeek = std::make_unique<InvitePeek>();
|
|
|
|
}
|
|
|
|
_invitePeek->hash = hash;
|
|
|
|
_invitePeek->expires = expires;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ChannelData::clearInvitePeek() {
|
|
|
|
_invitePeek = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
TimeId ChannelData::invitePeekExpires() const {
|
|
|
|
return _invitePeek ? _invitePeek->expires : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString ChannelData::invitePeekHash() const {
|
|
|
|
return _invitePeek ? _invitePeek->hash : QString();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ChannelData::privateErrorReceived() {
|
|
|
|
if (const auto expires = invitePeekExpires()) {
|
|
|
|
const auto hash = invitePeekHash();
|
2021-09-08 10:53:54 +00:00
|
|
|
for (const auto &window : session().windows()) {
|
2020-07-01 14:19:25 +00:00
|
|
|
clearInvitePeek();
|
|
|
|
Api::CheckChatInvite(window, hash, this);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_invitePeek->expires = base::unixtime::now();
|
|
|
|
} else {
|
|
|
|
markForbidden();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-14 12:52:18 +00:00
|
|
|
void ChannelData::migrateCall(std::unique_ptr<Data::GroupCall> call) {
|
|
|
|
Expects(_call == nullptr);
|
|
|
|
Expects(call != nullptr);
|
|
|
|
|
|
|
|
_call = std::move(call);
|
|
|
|
_call->setPeer(this);
|
|
|
|
session().changes().peerUpdated(this, UpdateFlag::GroupCall);
|
2021-07-08 13:11:09 +00:00
|
|
|
addFlags(Flag::CallActive);
|
2020-12-14 12:52:18 +00:00
|
|
|
}
|
|
|
|
|
2021-04-12 11:36:19 +00:00
|
|
|
void ChannelData::setGroupCall(
|
|
|
|
const MTPInputGroupCall &call,
|
2022-02-25 11:14:15 +00:00
|
|
|
TimeId scheduleDate,
|
|
|
|
bool rtmp) {
|
2020-11-20 19:25:35 +00:00
|
|
|
call.match([&](const MTPDinputGroupCall &data) {
|
|
|
|
if (_call && _call->id() == data.vid().v) {
|
|
|
|
return;
|
|
|
|
} else if (!_call && !data.vid().v) {
|
|
|
|
return;
|
|
|
|
} else if (!data.vid().v) {
|
2020-12-14 12:52:18 +00:00
|
|
|
clearGroupCall();
|
2020-11-20 19:25:35 +00:00
|
|
|
return;
|
|
|
|
}
|
2020-12-01 13:22:07 +00:00
|
|
|
const auto hasCall = (_call != nullptr);
|
|
|
|
if (hasCall) {
|
2020-11-24 14:40:10 +00:00
|
|
|
owner().unregisterGroupCall(_call.get());
|
|
|
|
}
|
2020-11-20 19:25:35 +00:00
|
|
|
_call = std::make_unique<Data::GroupCall>(
|
|
|
|
this,
|
|
|
|
data.vid().v,
|
2021-04-12 11:36:19 +00:00
|
|
|
data.vaccess_hash().v,
|
2022-02-25 11:14:15 +00:00
|
|
|
scheduleDate,
|
|
|
|
rtmp);
|
2020-11-24 14:40:10 +00:00
|
|
|
owner().registerGroupCall(_call.get());
|
2020-11-20 19:25:35 +00:00
|
|
|
session().changes().peerUpdated(this, UpdateFlag::GroupCall);
|
2021-07-08 13:11:09 +00:00
|
|
|
addFlags(Flag::CallActive);
|
2020-11-20 19:25:35 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-12-14 12:52:18 +00:00
|
|
|
void ChannelData::clearGroupCall() {
|
2020-11-20 19:25:35 +00:00
|
|
|
if (!_call) {
|
|
|
|
return;
|
|
|
|
}
|
2020-11-24 14:40:10 +00:00
|
|
|
owner().unregisterGroupCall(_call.get());
|
2020-11-20 19:25:35 +00:00
|
|
|
_call = nullptr;
|
|
|
|
session().changes().peerUpdated(this, UpdateFlag::GroupCall);
|
2021-07-08 13:11:09 +00:00
|
|
|
removeFlags(Flag::CallActive | Flag::CallNotEmpty);
|
2020-11-20 19:25:35 +00:00
|
|
|
}
|
|
|
|
|
2021-03-05 08:14:34 +00:00
|
|
|
void ChannelData::setGroupCallDefaultJoinAs(PeerId peerId) {
|
|
|
|
_callDefaultJoinAs = peerId;
|
|
|
|
}
|
|
|
|
|
|
|
|
PeerId ChannelData::groupCallDefaultJoinAs() const {
|
|
|
|
return _callDefaultJoinAs;
|
|
|
|
}
|
|
|
|
|
2022-08-22 09:15:34 +00:00
|
|
|
void ChannelData::setAllowedReactions(Data::AllowedReactions value) {
|
|
|
|
if (_allowedReactions != value) {
|
|
|
|
const auto enabled = [](const Data::AllowedReactions &allowed) {
|
|
|
|
return (allowed.type != Data::AllowedReactionsType::Some)
|
|
|
|
|| !allowed.some.empty();
|
|
|
|
};
|
|
|
|
const auto was = enabled(_allowedReactions);
|
|
|
|
_allowedReactions = std::move(value);
|
|
|
|
const auto now = enabled(_allowedReactions);
|
|
|
|
if (was != now) {
|
|
|
|
owner().reactions().updateAllInHistory(this, now);
|
2021-12-28 22:06:01 +00:00
|
|
|
}
|
2021-12-13 11:26:19 +00:00
|
|
|
session().changes().peerUpdated(this, UpdateFlag::Reactions);
|
|
|
|
}
|
2021-12-07 11:11:27 +00:00
|
|
|
}
|
|
|
|
|
2022-08-22 09:15:34 +00:00
|
|
|
const Data::AllowedReactions &ChannelData::allowedReactions() const {
|
2021-12-07 11:11:27 +00:00
|
|
|
return _allowedReactions;
|
|
|
|
}
|
|
|
|
|
2019-01-13 08:03:34 +00:00
|
|
|
namespace Data {
|
|
|
|
|
2019-01-14 06:34:51 +00:00
|
|
|
void ApplyMigration(
|
|
|
|
not_null<ChatData*> chat,
|
|
|
|
not_null<ChannelData*> channel) {
|
|
|
|
Expects(channel->isMegagroup());
|
|
|
|
|
|
|
|
chat->setMigrateToChannel(channel);
|
|
|
|
channel->setMigrateFromChat(chat);
|
|
|
|
}
|
|
|
|
|
2019-01-13 08:03:34 +00:00
|
|
|
void ApplyChannelUpdate(
|
|
|
|
not_null<ChannelData*> channel,
|
|
|
|
const MTPDupdateChatDefaultBannedRights &update) {
|
2021-11-21 19:48:08 +00:00
|
|
|
channel->setDefaultRestrictions(ChatRestrictionsInfo(
|
|
|
|
update.vdefault_banned_rights()).flags);
|
2019-01-13 08:03:34 +00:00
|
|
|
}
|
|
|
|
|
2019-04-23 09:40:14 +00:00
|
|
|
void ApplyChannelUpdate(
|
|
|
|
not_null<ChannelData*> channel,
|
|
|
|
const MTPDchannelFull &update) {
|
2020-06-12 12:12:34 +00:00
|
|
|
const auto session = &channel->session();
|
|
|
|
|
2021-02-19 13:53:20 +00:00
|
|
|
if (channel->isMegagroup()) {
|
|
|
|
const auto suggestions = update.vpending_suggestions().value_or_empty();
|
|
|
|
channel->owner().setSuggestToGigagroup(
|
|
|
|
channel,
|
|
|
|
ranges::contains(
|
|
|
|
suggestions,
|
|
|
|
"convert_to_gigagroup"_q,
|
|
|
|
&MTPstring::v));
|
|
|
|
}
|
|
|
|
|
2019-07-05 13:38:38 +00:00
|
|
|
channel->setAvailableMinId(update.vavailable_min_id().value_or_empty());
|
2019-04-23 09:40:14 +00:00
|
|
|
auto canViewAdmins = channel->canViewAdmins();
|
|
|
|
auto canViewMembers = channel->canViewMembers();
|
|
|
|
auto canEditStickers = channel->canEditStickers();
|
|
|
|
|
2020-11-20 19:25:35 +00:00
|
|
|
if (const auto call = update.vcall()) {
|
2020-12-14 12:52:18 +00:00
|
|
|
channel->setGroupCall(*call);
|
2020-11-20 19:25:35 +00:00
|
|
|
} else {
|
2020-12-14 12:52:18 +00:00
|
|
|
channel->clearGroupCall();
|
2020-11-20 19:25:35 +00:00
|
|
|
}
|
2021-03-05 08:14:34 +00:00
|
|
|
if (const auto as = update.vgroupcall_default_join_as()) {
|
|
|
|
channel->setGroupCallDefaultJoinAs(peerFromMTP(*as));
|
|
|
|
} else {
|
|
|
|
channel->setGroupCallDefaultJoinAs(0);
|
|
|
|
}
|
2020-11-20 19:25:35 +00:00
|
|
|
|
2021-02-15 10:31:04 +00:00
|
|
|
channel->setMessagesTTL(update.vttl_period().value_or_empty());
|
2021-07-08 13:11:09 +00:00
|
|
|
using Flag = ChannelDataFlag;
|
|
|
|
const auto mask = Flag::CanSetUsername
|
|
|
|
| Flag::CanViewParticipants
|
|
|
|
| Flag::CanSetStickers
|
|
|
|
| Flag::PreHistoryHidden
|
|
|
|
| Flag::Location;
|
|
|
|
channel->setFlags((channel->flags() & ~mask)
|
|
|
|
| (update.is_can_set_username() ? Flag::CanSetUsername : Flag())
|
|
|
|
| (update.is_can_view_participants() ? Flag::CanViewParticipants : Flag())
|
|
|
|
| (update.is_can_set_stickers() ? Flag::CanSetStickers : Flag())
|
|
|
|
| (update.is_hidden_prehistory() ? Flag::PreHistoryHidden : Flag())
|
|
|
|
| (update.vlocation() ? Flag::Location : Flag()));
|
2019-07-05 13:38:38 +00:00
|
|
|
channel->setUserpicPhoto(update.vchat_photo());
|
|
|
|
if (const auto migratedFrom = update.vmigrated_from_chat_id()) {
|
2021-07-08 13:11:09 +00:00
|
|
|
channel->addFlags(Flag::Megagroup);
|
2019-07-05 13:38:38 +00:00
|
|
|
const auto chat = channel->owner().chat(migratedFrom->v);
|
2019-04-23 09:40:14 +00:00
|
|
|
Data::ApplyMigration(chat, channel);
|
|
|
|
}
|
2019-07-05 13:38:38 +00:00
|
|
|
channel->setAbout(qs(update.vabout()));
|
|
|
|
channel->setMembersCount(update.vparticipants_count().value_or_empty());
|
|
|
|
channel->setAdminsCount(update.vadmins_count().value_or_empty());
|
|
|
|
channel->setRestrictedCount(update.vbanned_count().value_or_empty());
|
|
|
|
channel->setKickedCount(update.vkicked_count().value_or_empty());
|
2019-07-16 11:46:50 +00:00
|
|
|
channel->setSlowmodeSeconds(update.vslowmode_seconds().value_or_empty());
|
|
|
|
if (const auto next = update.vslowmode_next_send_date()) {
|
2019-08-20 09:42:13 +00:00
|
|
|
channel->growSlowmodeLastMessage(
|
|
|
|
next->v - channel->slowmodeSeconds());
|
2019-07-16 11:46:50 +00:00
|
|
|
}
|
2020-12-29 12:39:10 +00:00
|
|
|
if (const auto invite = update.vexported_invite()) {
|
2021-02-05 13:22:02 +00:00
|
|
|
channel->session().api().inviteLinks().setMyPermanent(
|
2021-01-14 13:13:43 +00:00
|
|
|
channel,
|
|
|
|
*invite);
|
2020-12-29 12:39:10 +00:00
|
|
|
} else {
|
2021-02-05 13:22:02 +00:00
|
|
|
channel->session().api().inviteLinks().clearMyPermanent(channel);
|
2020-12-29 12:39:10 +00:00
|
|
|
}
|
2019-07-05 13:38:38 +00:00
|
|
|
if (const auto location = update.vlocation()) {
|
|
|
|
channel->setLocation(*location);
|
|
|
|
} else {
|
|
|
|
channel->setLocation(MTP_channelLocationEmpty());
|
|
|
|
}
|
|
|
|
if (const auto chat = update.vlinked_chat_id()) {
|
|
|
|
channel->setLinkedChat(channel->owner().channelLoaded(chat->v));
|
|
|
|
} else {
|
|
|
|
channel->setLinkedChat(nullptr);
|
|
|
|
}
|
2019-04-23 09:40:14 +00:00
|
|
|
if (const auto history = channel->owner().historyLoaded(channel)) {
|
2019-07-05 13:38:38 +00:00
|
|
|
if (const auto available = update.vavailable_min_id()) {
|
|
|
|
history->clearUpTill(available->v);
|
|
|
|
}
|
|
|
|
const auto folderId = update.vfolder_id().value_or_empty();
|
2019-04-23 09:40:14 +00:00
|
|
|
const auto folder = folderId
|
|
|
|
? channel->owner().folderLoaded(folderId)
|
|
|
|
: nullptr;
|
2020-02-21 07:58:50 +00:00
|
|
|
auto &histories = channel->owner().histories();
|
2019-04-23 09:40:14 +00:00
|
|
|
if (folder && history->folder() != folder) {
|
|
|
|
// If history folder is unknown or not synced, request both.
|
2020-02-21 07:58:50 +00:00
|
|
|
histories.requestDialogEntry(history);
|
|
|
|
histories.requestDialogEntry(folder);
|
2019-04-23 09:40:14 +00:00
|
|
|
} else if (!history->folderKnown()
|
2019-07-05 13:38:38 +00:00
|
|
|
|| channel->pts() != update.vpts().v) {
|
2020-02-21 07:58:50 +00:00
|
|
|
histories.requestDialogEntry(history);
|
2019-04-23 09:40:14 +00:00
|
|
|
} else {
|
|
|
|
history->applyDialogFields(
|
|
|
|
history->folder(),
|
2019-07-05 13:38:38 +00:00
|
|
|
update.vunread_count().v,
|
|
|
|
update.vread_inbox_max_id().v,
|
|
|
|
update.vread_outbox_max_id().v);
|
2019-04-23 09:40:14 +00:00
|
|
|
}
|
|
|
|
}
|
2019-07-05 13:38:38 +00:00
|
|
|
if (const auto pinned = update.vpinned_msg_id()) {
|
2020-10-21 11:07:49 +00:00
|
|
|
SetTopPinnedMessageId(channel, pinned->v);
|
2019-04-23 09:40:14 +00:00
|
|
|
}
|
|
|
|
if (channel->isMegagroup()) {
|
2022-05-14 21:27:21 +00:00
|
|
|
auto commands = ranges::views::all(
|
|
|
|
update.vbot_info().v
|
|
|
|
) | ranges::views::transform(
|
|
|
|
Data::BotCommandsFromTL
|
|
|
|
) | ranges::to_vector;
|
|
|
|
|
|
|
|
if (channel->mgInfo->setBotCommands(std::move(commands))) {
|
2021-07-01 11:05:15 +00:00
|
|
|
channel->owner().botCommandsChanged(channel);
|
|
|
|
}
|
2019-07-05 13:38:38 +00:00
|
|
|
const auto stickerSet = update.vstickerset();
|
|
|
|
const auto set = stickerSet ? &stickerSet->c_stickerSet() : nullptr;
|
|
|
|
const auto newSetId = (set ? set->vid().v : 0);
|
2021-07-08 16:42:57 +00:00
|
|
|
const auto oldSetId = channel->mgInfo->stickerSet.id;
|
2019-04-23 09:40:14 +00:00
|
|
|
const auto stickersChanged = (canEditStickers != channel->canEditStickers())
|
|
|
|
|| (oldSetId != newSetId);
|
|
|
|
if (oldSetId != newSetId) {
|
2021-07-08 16:42:57 +00:00
|
|
|
channel->mgInfo->stickerSet = StickerSetIdentifier{
|
|
|
|
.id = set ? set->vid().v : 0,
|
|
|
|
.accessHash = set ? set->vaccess_hash().v : 0,
|
|
|
|
};
|
2019-04-23 09:40:14 +00:00
|
|
|
}
|
|
|
|
if (stickersChanged) {
|
2020-06-12 12:12:34 +00:00
|
|
|
session->changes().peerUpdated(channel, UpdateFlag::StickersSet);
|
2019-04-23 09:40:14 +00:00
|
|
|
}
|
|
|
|
}
|
2021-08-25 16:16:50 +00:00
|
|
|
channel->setThemeEmoji(qs(update.vtheme_emoticon().value_or_empty()));
|
2022-08-22 09:15:34 +00:00
|
|
|
if (const auto allowed = update.vavailable_reactions()) {
|
|
|
|
channel->setAllowedReactions(Data::Parse(*allowed));
|
|
|
|
} else {
|
|
|
|
channel->setAllowedReactions({});
|
|
|
|
}
|
2019-04-23 09:40:14 +00:00
|
|
|
channel->fullUpdated();
|
2021-10-12 08:39:07 +00:00
|
|
|
channel->setPendingRequestsCount(
|
2021-10-27 05:57:37 +00:00
|
|
|
update.vrequests_pending().value_or_empty(),
|
|
|
|
update.vrecent_requesters().value_or_empty());
|
2019-04-23 09:40:14 +00:00
|
|
|
|
|
|
|
if (canViewAdmins != channel->canViewAdmins()
|
|
|
|
|| canViewMembers != channel->canViewMembers()) {
|
2020-06-12 12:12:34 +00:00
|
|
|
session->changes().peerUpdated(channel, UpdateFlag::Rights);
|
2019-04-23 09:40:14 +00:00
|
|
|
}
|
|
|
|
|
2020-06-12 12:12:34 +00:00
|
|
|
session->api().applyNotifySettings(
|
2019-04-23 09:40:14 +00:00
|
|
|
MTP_inputNotifyPeer(channel->input),
|
2019-07-05 13:38:38 +00:00
|
|
|
update.vnotify_settings());
|
2020-02-20 08:45:25 +00:00
|
|
|
|
2021-11-09 13:50:33 +00:00
|
|
|
if (const auto sendAs = update.vdefault_send_as()) {
|
|
|
|
session->sendAsPeers().setChosen(channel, peerFromMTP(*sendAs));
|
|
|
|
} else {
|
|
|
|
session->sendAsPeers().setChosen(channel, PeerId());
|
|
|
|
}
|
|
|
|
|
2020-02-20 08:45:25 +00:00
|
|
|
// For clearUpTill() call.
|
|
|
|
channel->owner().sendHistoryChangeNotifications();
|
2019-04-23 09:40:14 +00:00
|
|
|
}
|
|
|
|
|
2019-01-13 08:03:34 +00:00
|
|
|
} // namespace Data
|