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
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "data/data_peer.h"
|
|
|
|
|
|
|
|
class ChatData : public PeerData {
|
|
|
|
public:
|
|
|
|
static constexpr auto kEssentialFlags = 0
|
|
|
|
| MTPDchat::Flag::f_creator
|
|
|
|
| MTPDchat::Flag::f_kicked
|
|
|
|
| MTPDchat::Flag::f_left
|
|
|
|
| MTPDchat::Flag::f_deactivated
|
|
|
|
| MTPDchat::Flag::f_migrated_to
|
|
|
|
| MTPDchat::Flag::f_admin_rights
|
|
|
|
| MTPDchat::Flag::f_default_banned_rights;
|
|
|
|
using Flags = Data::Flags<
|
|
|
|
MTPDchat::Flags,
|
|
|
|
kEssentialFlags>;
|
|
|
|
|
2019-01-08 13:57:22 +00:00
|
|
|
static constexpr auto kEssentialFullFlags = 0
|
|
|
|
| MTPDchatFull::Flag::f_can_set_username;
|
|
|
|
using FullFlags = Data::Flags<
|
|
|
|
MTPDchatFull::Flags,
|
|
|
|
kEssentialFullFlags>;
|
|
|
|
|
2019-01-05 10:50:04 +00:00
|
|
|
using AdminRight = ChatAdminRight;
|
|
|
|
using Restriction = ChatRestriction;
|
|
|
|
using AdminRights = ChatAdminRights;
|
|
|
|
using Restrictions = ChatRestrictions;
|
|
|
|
using AdminRightFlags = Data::Flags<AdminRights>;
|
|
|
|
using RestrictionFlags = Data::Flags<Restrictions>;
|
|
|
|
|
2019-01-04 11:09:48 +00:00
|
|
|
ChatData(not_null<Data::Session*> owner, PeerId id);
|
|
|
|
|
|
|
|
void setPhoto(const MTPChatPhoto &photo);
|
|
|
|
void setPhoto(PhotoId photoId, const MTPChatPhoto &photo);
|
|
|
|
|
|
|
|
void setName(const QString &newName);
|
|
|
|
|
|
|
|
void invalidateParticipants();
|
|
|
|
bool noParticipantInfo() const {
|
|
|
|
return (count > 0 || amIn()) && participants.empty();
|
|
|
|
}
|
|
|
|
|
|
|
|
void setFlags(MTPDchat::Flags which) {
|
|
|
|
_flags.set(which);
|
|
|
|
}
|
|
|
|
void addFlags(MTPDchat::Flags which) {
|
|
|
|
_flags.add(which);
|
|
|
|
}
|
|
|
|
void removeFlags(MTPDchat::Flags which) {
|
|
|
|
_flags.remove(which);
|
|
|
|
}
|
|
|
|
auto flags() const {
|
|
|
|
return _flags.current();
|
|
|
|
}
|
|
|
|
auto flagsValue() const {
|
|
|
|
return _flags.value();
|
|
|
|
}
|
|
|
|
|
2019-01-08 13:57:22 +00:00
|
|
|
void setFullFlags(MTPDchatFull::Flags which) {
|
|
|
|
_fullFlags.set(which);
|
|
|
|
}
|
|
|
|
void addFullFlags(MTPDchatFull::Flags which) {
|
|
|
|
_fullFlags.add(which);
|
|
|
|
}
|
|
|
|
void removeFullFlags(MTPDchatFull::Flags which) {
|
|
|
|
_fullFlags.remove(which);
|
|
|
|
}
|
|
|
|
auto fullFlags() const {
|
|
|
|
return _fullFlags.current();
|
|
|
|
}
|
|
|
|
auto fullFlagsValue() const {
|
|
|
|
return _fullFlags.value();
|
|
|
|
}
|
|
|
|
|
2019-01-05 10:50:04 +00:00
|
|
|
auto adminRights() const {
|
|
|
|
return _adminRights.current();
|
|
|
|
}
|
|
|
|
auto adminRightsValue() const {
|
|
|
|
return _adminRights.value();
|
|
|
|
}
|
|
|
|
void setAdminRights(const MTPChatAdminRights &rights);
|
|
|
|
bool hasAdminRights() const {
|
|
|
|
return (adminRights() != 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
auto defaultRestrictions() const {
|
|
|
|
return _defaultRestrictions.current();
|
|
|
|
}
|
|
|
|
auto defaultRestrictionsValue() const {
|
|
|
|
return _defaultRestrictions.value();
|
|
|
|
}
|
|
|
|
void setDefaultRestrictions(const MTPChatBannedRights &rights);
|
|
|
|
|
2019-01-04 11:09:48 +00:00
|
|
|
bool isForbidden() const {
|
|
|
|
return flags() & MTPDchat_ClientFlag::f_forbidden;
|
|
|
|
}
|
|
|
|
bool amIn() const {
|
2019-01-22 13:05:06 +00:00
|
|
|
return !isForbidden()
|
|
|
|
&& !isDeactivated()
|
|
|
|
&& !haveLeft()
|
|
|
|
&& !wasKicked();
|
2019-01-04 11:09:48 +00:00
|
|
|
}
|
|
|
|
bool haveLeft() const {
|
|
|
|
return flags() & MTPDchat::Flag::f_left;
|
|
|
|
}
|
|
|
|
bool wasKicked() const {
|
|
|
|
return flags() & MTPDchat::Flag::f_kicked;
|
|
|
|
}
|
|
|
|
bool amCreator() const {
|
|
|
|
return flags() & MTPDchat::Flag::f_creator;
|
|
|
|
}
|
|
|
|
bool isDeactivated() const {
|
|
|
|
return flags() & MTPDchat::Flag::f_deactivated;
|
|
|
|
}
|
|
|
|
bool isMigrated() const {
|
|
|
|
return flags() & MTPDchat::Flag::f_migrated_to;
|
|
|
|
}
|
2019-01-05 10:50:04 +00:00
|
|
|
|
2019-01-10 06:26:08 +00:00
|
|
|
static AdminRights DefaultAdminRights();
|
|
|
|
|
|
|
|
// Like in ChannelData.
|
2019-01-05 10:50:04 +00:00
|
|
|
bool canWrite() const;
|
|
|
|
bool canEditInformation() const;
|
2019-01-07 12:55:49 +00:00
|
|
|
bool canEditPermissions() const;
|
2019-01-08 13:57:22 +00:00
|
|
|
bool canEditUsername() const;
|
|
|
|
bool canEditPreHistoryHidden() const;
|
2019-01-05 10:50:04 +00:00
|
|
|
bool canAddMembers() const;
|
2019-01-10 06:26:08 +00:00
|
|
|
bool canAddAdmins() const;
|
|
|
|
bool canBanMembers() const;
|
|
|
|
bool canSendPolls() const;
|
|
|
|
bool anyoneCanAddMembers() const;
|
|
|
|
|
|
|
|
void applyEditAdmin(not_null<UserData*> user, bool isAdmin);
|
2019-01-05 10:50:04 +00:00
|
|
|
|
|
|
|
void setInviteLink(const QString &newInviteLink);
|
|
|
|
QString inviteLink() const {
|
|
|
|
return _inviteLink;
|
|
|
|
}
|
2019-01-13 08:03:34 +00:00
|
|
|
void refreshBotStatus();
|
|
|
|
|
|
|
|
enum class UpdateStatus {
|
|
|
|
Good,
|
|
|
|
TooOld,
|
|
|
|
Skipped,
|
|
|
|
};
|
|
|
|
int version() const {
|
|
|
|
return _version;
|
|
|
|
}
|
|
|
|
void setVersion(int version) {
|
|
|
|
_version = version;
|
|
|
|
}
|
|
|
|
UpdateStatus applyUpdateVersion(int version);
|
2019-01-05 10:50:04 +00:00
|
|
|
|
2019-01-14 06:34:51 +00:00
|
|
|
ChannelData *getMigrateToChannel() const;
|
|
|
|
void setMigrateToChannel(ChannelData *channel);
|
|
|
|
|
2019-01-05 10:50:04 +00:00
|
|
|
// Still public data members.
|
|
|
|
MTPint inputChat;
|
|
|
|
|
|
|
|
int count = 0;
|
|
|
|
TimeId date = 0;
|
|
|
|
UserId creator = 0;
|
|
|
|
|
2019-01-13 08:03:34 +00:00
|
|
|
base::flat_set<not_null<UserData*>> participants;
|
2019-01-04 11:09:48 +00:00
|
|
|
base::flat_set<not_null<UserData*>> invitedByMe;
|
|
|
|
base::flat_set<not_null<UserData*>> admins;
|
|
|
|
std::deque<not_null<UserData*>> lastAuthors;
|
|
|
|
base::flat_set<not_null<PeerData*>> markupSenders;
|
|
|
|
int botStatus = 0; // -1 - no bots, 0 - unknown, 1 - one bot, that sees all history, 2 - other
|
|
|
|
// ImagePtr photoFull;
|
|
|
|
|
|
|
|
private:
|
|
|
|
Flags _flags;
|
2019-01-08 13:57:22 +00:00
|
|
|
FullFlags _fullFlags;
|
2019-01-04 11:09:48 +00:00
|
|
|
QString _inviteLink;
|
|
|
|
|
2019-01-05 10:50:04 +00:00
|
|
|
RestrictionFlags _defaultRestrictions;
|
|
|
|
AdminRightFlags _adminRights;
|
2019-01-13 08:03:34 +00:00
|
|
|
int _version = 0;
|
2019-01-05 10:50:04 +00:00
|
|
|
|
2019-01-14 06:34:51 +00:00
|
|
|
ChannelData *_migratedTo = nullptr;
|
|
|
|
|
2019-01-04 11:09:48 +00:00
|
|
|
};
|
2019-01-13 08:03:34 +00:00
|
|
|
|
|
|
|
namespace Data {
|
|
|
|
|
|
|
|
void ApplyChatUpdate(
|
|
|
|
not_null<ChatData*> chat,
|
|
|
|
const MTPDupdateChatParticipants &update);
|
|
|
|
void ApplyChatUpdate(
|
|
|
|
not_null<ChatData*> chat,
|
|
|
|
const MTPDupdateChatParticipantAdd &update);
|
|
|
|
void ApplyChatUpdate(
|
|
|
|
not_null<ChatData*> chat,
|
|
|
|
const MTPDupdateChatParticipantDelete &update);
|
|
|
|
void ApplyChatUpdate(
|
|
|
|
not_null<ChatData*> chat,
|
|
|
|
const MTPDupdateChatParticipantAdmin &update);
|
|
|
|
void ApplyChatUpdate(
|
|
|
|
not_null<ChatData*> chat,
|
|
|
|
const MTPDupdateChatDefaultBannedRights &update);
|
2019-04-23 09:40:14 +00:00
|
|
|
void ApplyChatUpdate(
|
|
|
|
not_null<ChatData*> chat,
|
|
|
|
const MTPDchatFull &update);
|
|
|
|
void ApplyChatUpdate(
|
2019-01-13 08:03:34 +00:00
|
|
|
not_null<ChatData*> chat,
|
2019-04-23 09:40:14 +00:00
|
|
|
const MTPChatParticipants &update);
|
2019-01-13 08:03:34 +00:00
|
|
|
|
|
|
|
} // namespace Data
|