2019-01-04 15:09:48 +04: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_chat.h"
|
|
|
|
|
|
|
|
#include "observer_peer.h"
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
using UpdateFlag = Notify::PeerUpdate::Flag;
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
ChatData::ChatData(not_null<Data::Session*> owner, PeerId id)
|
|
|
|
: PeerData(owner, id)
|
|
|
|
, inputChat(MTP_int(bareId())) {
|
|
|
|
}
|
|
|
|
|
|
|
|
void ChatData::setPhoto(const MTPChatPhoto &photo) {
|
|
|
|
setPhoto(userpicPhotoId(), photo);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ChatData::setPhoto(PhotoId photoId, const MTPChatPhoto &photo) {
|
|
|
|
if (photo.type() == mtpc_chatPhoto) {
|
|
|
|
const auto &data = photo.c_chatPhoto();
|
|
|
|
updateUserpic(photoId, data.vphoto_small);
|
|
|
|
} else {
|
|
|
|
clearUserpic();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-05 14:50:04 +04:00
|
|
|
bool ChatData::actionsUnavailable() const {
|
|
|
|
return isDeactivated() || !amIn();
|
|
|
|
}
|
|
|
|
|
2019-01-10 10:26:08 +04:00
|
|
|
auto ChatData::DefaultAdminRights() -> AdminRights {
|
|
|
|
using Flag = AdminRight;
|
|
|
|
return Flag::f_change_info
|
|
|
|
| Flag::f_delete_messages
|
|
|
|
| Flag::f_ban_users
|
|
|
|
| Flag::f_invite_users
|
|
|
|
| Flag::f_pin_messages;
|
|
|
|
}
|
|
|
|
|
2019-01-05 14:50:04 +04:00
|
|
|
bool ChatData::canWrite() const {
|
|
|
|
// Duplicated in Data::CanWriteValue().
|
|
|
|
return !actionsUnavailable()
|
2019-01-10 10:26:08 +04:00
|
|
|
&& !amRestricted(Restriction::f_send_messages);
|
2019-01-05 14:50:04 +04:00
|
|
|
}
|
|
|
|
|
2019-01-04 15:09:48 +04:00
|
|
|
bool ChatData::canEditInformation() const {
|
2019-01-05 14:50:04 +04:00
|
|
|
return !actionsUnavailable()
|
2019-01-10 10:26:08 +04:00
|
|
|
&& !amRestricted(Restriction::f_change_info);
|
2019-01-05 14:50:04 +04:00
|
|
|
}
|
|
|
|
|
2019-01-07 16:55:49 +04:00
|
|
|
bool ChatData::canEditPermissions() const {
|
|
|
|
return !actionsUnavailable()
|
|
|
|
&& (amCreator() || hasAdminRights());
|
|
|
|
}
|
|
|
|
|
2019-01-08 17:57:22 +04:00
|
|
|
bool ChatData::canEditUsername() const {
|
|
|
|
return amCreator()
|
|
|
|
&& (fullFlags() & MTPDchatFull::Flag::f_can_set_username);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ChatData::canEditPreHistoryHidden() const {
|
|
|
|
return amCreator();
|
|
|
|
}
|
|
|
|
|
2019-01-05 14:50:04 +04:00
|
|
|
bool ChatData::canAddMembers() const {
|
|
|
|
return !actionsUnavailable()
|
2019-01-10 10:26:08 +04:00
|
|
|
&& !amRestricted(Restriction::f_invite_users);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ChatData::canSendPolls() const {
|
|
|
|
return !actionsUnavailable()
|
|
|
|
&& !amRestricted(Restriction::f_send_polls);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ChatData::canAddAdmins() const {
|
|
|
|
return !actionsUnavailable()
|
|
|
|
&& amCreator();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ChatData::canBanMembers() const {
|
|
|
|
return amCreator()
|
|
|
|
|| (adminRights() & AdminRight::f_ban_users);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ChatData::anyoneCanAddMembers() const {
|
|
|
|
return !(defaultRestrictions() & Restriction::f_invite_users);
|
2019-01-04 15:09:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void ChatData::setName(const QString &newName) {
|
|
|
|
updateNameDelayed(newName.isEmpty() ? name : newName, QString(), QString());
|
|
|
|
}
|
|
|
|
|
2019-01-10 10:26:08 +04:00
|
|
|
void ChatData::applyEditAdmin(not_null<UserData*> user, bool isAdmin) {
|
|
|
|
auto flags = Notify::PeerUpdate::Flag::AdminsChanged
|
|
|
|
| Notify::PeerUpdate::Flag::None;
|
|
|
|
if (isAdmin) {
|
|
|
|
admins.emplace(user);
|
|
|
|
} else {
|
|
|
|
admins.remove(user);
|
|
|
|
}
|
|
|
|
Notify::peerUpdatedDelayed(
|
|
|
|
this,
|
|
|
|
Notify::PeerUpdate::Flag::AdminsChanged);
|
|
|
|
}
|
|
|
|
|
2019-01-04 15:09:48 +04:00
|
|
|
void ChatData::invalidateParticipants() {
|
|
|
|
// #TODO groups
|
|
|
|
participants.clear();
|
|
|
|
admins.clear();
|
|
|
|
//removeFlags(MTPDchat::Flag::f_admin);
|
|
|
|
invitedByMe.clear();
|
|
|
|
botStatus = 0;
|
2019-01-05 14:50:04 +04:00
|
|
|
Notify::peerUpdatedDelayed(
|
|
|
|
this,
|
|
|
|
UpdateFlag::MembersChanged | UpdateFlag::AdminsChanged);
|
2019-01-04 15:09:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void ChatData::setInviteLink(const QString &newInviteLink) {
|
|
|
|
if (newInviteLink != _inviteLink) {
|
|
|
|
_inviteLink = newInviteLink;
|
|
|
|
Notify::peerUpdatedDelayed(this, UpdateFlag::InviteLinkChanged);
|
|
|
|
}
|
|
|
|
}
|
2019-01-05 14:50:04 +04:00
|
|
|
|
|
|
|
void ChatData::setAdminRights(const MTPChatAdminRights &rights) {
|
|
|
|
if (rights.c_chatAdminRights().vflags.v == adminRights()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_adminRights.set(rights.c_chatAdminRights().vflags.v);
|
|
|
|
Notify::peerUpdatedDelayed(
|
|
|
|
this,
|
|
|
|
(UpdateFlag::RightsChanged
|
|
|
|
| UpdateFlag::AdminsChanged
|
|
|
|
| UpdateFlag::BannedUsersChanged));
|
|
|
|
}
|
|
|
|
|
|
|
|
void ChatData::setDefaultRestrictions(const MTPChatBannedRights &rights) {
|
|
|
|
if (rights.c_chatBannedRights().vflags.v == defaultRestrictions()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_defaultRestrictions.set(rights.c_chatBannedRights().vflags.v);
|
|
|
|
Notify::peerUpdatedDelayed(this, UpdateFlag::RightsChanged);
|
|
|
|
}
|