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"
|
2021-11-21 19:48:08 +00:00
|
|
|
#include "data/data_chat_participant_status.h"
|
2022-05-14 21:27:21 +00:00
|
|
|
#include "data/data_peer_bot_commands.h"
|
2022-05-14 20:50:02 +00:00
|
|
|
|
2021-11-21 19:48:08 +00:00
|
|
|
enum class ChatAdminRight;
|
2019-01-04 11:09:48 +00:00
|
|
|
|
2021-07-08 12:11:46 +00:00
|
|
|
enum class ChatDataFlag {
|
|
|
|
Left = (1 << 0),
|
2022-04-06 12:27:23 +00:00
|
|
|
//Kicked = (1 << 1),
|
2021-07-08 12:11:46 +00:00
|
|
|
Creator = (1 << 2),
|
|
|
|
Deactivated = (1 << 3),
|
|
|
|
Forbidden = (1 << 4),
|
|
|
|
CallActive = (1 << 5),
|
|
|
|
CallNotEmpty = (1 << 6),
|
|
|
|
CanSetUsername = (1 << 7),
|
2021-11-05 14:03:17 +00:00
|
|
|
NoForwards = (1 << 8),
|
2021-07-08 12:11:46 +00:00
|
|
|
};
|
|
|
|
inline constexpr bool is_flag_type(ChatDataFlag) { return true; };
|
|
|
|
using ChatDataFlags = base::flags<ChatDataFlag>;
|
|
|
|
|
2022-09-20 09:35:47 +00:00
|
|
|
class ChatData final : public PeerData {
|
2019-01-04 11:09:48 +00:00
|
|
|
public:
|
2021-07-08 12:11:46 +00:00
|
|
|
using Flag = ChatDataFlag;
|
|
|
|
using Flags = Data::Flags<ChatDataFlags>;
|
2019-01-08 13:57:22 +00:00
|
|
|
|
2019-01-04 11:09:48 +00:00
|
|
|
ChatData(not_null<Data::Session*> owner, PeerId id);
|
|
|
|
|
|
|
|
void setName(const QString &newName);
|
2021-03-30 08:16:05 +00:00
|
|
|
void setPhoto(const MTPChatPhoto &photo);
|
2019-01-04 11:09:48 +00:00
|
|
|
|
|
|
|
void invalidateParticipants();
|
2021-02-12 10:40:55 +00:00
|
|
|
[[nodiscard]] bool noParticipantInfo() const {
|
2019-01-04 11:09:48 +00:00
|
|
|
return (count > 0 || amIn()) && participants.empty();
|
|
|
|
}
|
|
|
|
|
2021-07-08 12:11:46 +00:00
|
|
|
void setFlags(ChatDataFlags which) {
|
2019-01-04 11:09:48 +00:00
|
|
|
_flags.set(which);
|
|
|
|
}
|
2021-07-08 12:11:46 +00:00
|
|
|
void addFlags(ChatDataFlags which) {
|
2019-01-04 11:09:48 +00:00
|
|
|
_flags.add(which);
|
|
|
|
}
|
2021-07-08 12:11:46 +00:00
|
|
|
void removeFlags(ChatDataFlags which) {
|
2019-01-04 11:09:48 +00:00
|
|
|
_flags.remove(which);
|
|
|
|
}
|
2021-02-12 10:40:55 +00:00
|
|
|
[[nodiscard]] auto flags() const {
|
2019-01-04 11:09:48 +00:00
|
|
|
return _flags.current();
|
|
|
|
}
|
2021-02-12 10:40:55 +00:00
|
|
|
[[nodiscard]] auto flagsValue() const {
|
2019-01-04 11:09:48 +00:00
|
|
|
return _flags.value();
|
|
|
|
}
|
|
|
|
|
2021-02-12 10:40:55 +00:00
|
|
|
[[nodiscard]] auto adminRights() const {
|
2019-01-05 10:50:04 +00:00
|
|
|
return _adminRights.current();
|
|
|
|
}
|
2021-02-12 10:40:55 +00:00
|
|
|
[[nodiscard]] auto adminRightsValue() const {
|
2019-01-05 10:50:04 +00:00
|
|
|
return _adminRights.value();
|
|
|
|
}
|
2021-07-08 10:34:06 +00:00
|
|
|
void setAdminRights(ChatAdminRights rights);
|
2021-02-12 10:40:55 +00:00
|
|
|
[[nodiscard]] bool hasAdminRights() const {
|
2019-01-05 10:50:04 +00:00
|
|
|
return (adminRights() != 0);
|
|
|
|
}
|
|
|
|
|
2021-02-12 10:40:55 +00:00
|
|
|
[[nodiscard]] auto defaultRestrictions() const {
|
2019-01-05 10:50:04 +00:00
|
|
|
return _defaultRestrictions.current();
|
|
|
|
}
|
2021-02-12 10:40:55 +00:00
|
|
|
[[nodiscard]] auto defaultRestrictionsValue() const {
|
2019-01-05 10:50:04 +00:00
|
|
|
return _defaultRestrictions.value();
|
|
|
|
}
|
2021-07-08 10:34:06 +00:00
|
|
|
void setDefaultRestrictions(ChatRestrictions rights);
|
2019-01-05 10:50:04 +00:00
|
|
|
|
2021-02-12 10:40:55 +00:00
|
|
|
[[nodiscard]] bool isForbidden() const {
|
2021-07-08 12:11:46 +00:00
|
|
|
return flags() & Flag::Forbidden;
|
2019-01-04 11:09:48 +00:00
|
|
|
}
|
2021-02-12 10:40:55 +00:00
|
|
|
[[nodiscard]] bool amIn() const {
|
2022-04-06 12:27:23 +00:00
|
|
|
return !isForbidden() && !isDeactivated() && !haveLeft();
|
2019-01-04 11:09:48 +00:00
|
|
|
}
|
2021-02-12 10:40:55 +00:00
|
|
|
[[nodiscard]] bool haveLeft() const {
|
2021-07-08 12:11:46 +00:00
|
|
|
return flags() & ChatDataFlag::Left;
|
2019-01-04 11:09:48 +00:00
|
|
|
}
|
2021-02-12 10:40:55 +00:00
|
|
|
[[nodiscard]] bool amCreator() const {
|
2021-07-08 12:11:46 +00:00
|
|
|
return flags() & ChatDataFlag::Creator;
|
2019-01-04 11:09:48 +00:00
|
|
|
}
|
2021-02-12 10:40:55 +00:00
|
|
|
[[nodiscard]] bool isDeactivated() const {
|
2021-07-08 12:11:46 +00:00
|
|
|
return flags() & ChatDataFlag::Deactivated;
|
2019-01-04 11:09:48 +00:00
|
|
|
}
|
2021-02-12 10:40:55 +00:00
|
|
|
[[nodiscard]] bool isMigrated() const {
|
2021-07-08 12:11:46 +00:00
|
|
|
return (_migratedTo != nullptr);
|
2019-01-04 11:09:48 +00:00
|
|
|
}
|
2019-01-05 10:50:04 +00:00
|
|
|
|
2021-07-08 10:34:06 +00:00
|
|
|
[[nodiscard]] ChatAdminRightsInfo defaultAdminRights(
|
|
|
|
not_null<UserData*> user);
|
2019-01-10 06:26:08 +00:00
|
|
|
|
|
|
|
// Like in ChannelData.
|
2021-11-05 14:03:17 +00:00
|
|
|
[[nodiscard]] bool allowsForwarding() const;
|
2021-02-02 16:38:30 +00:00
|
|
|
[[nodiscard]] bool canEditInformation() const;
|
|
|
|
[[nodiscard]] bool canEditPermissions() const;
|
|
|
|
[[nodiscard]] bool canEditUsername() const;
|
|
|
|
[[nodiscard]] bool canEditPreHistoryHidden() const;
|
|
|
|
[[nodiscard]] bool canDeleteMessages() const;
|
|
|
|
[[nodiscard]] bool canAddMembers() const;
|
|
|
|
[[nodiscard]] bool canAddAdmins() const;
|
|
|
|
[[nodiscard]] bool canBanMembers() const;
|
|
|
|
[[nodiscard]] bool anyoneCanAddMembers() const;
|
2019-01-10 06:26:08 +00:00
|
|
|
|
|
|
|
void applyEditAdmin(not_null<UserData*> user, bool isAdmin);
|
2019-01-05 10:50:04 +00:00
|
|
|
|
|
|
|
void setInviteLink(const QString &newInviteLink);
|
2020-12-14 12:52:18 +00:00
|
|
|
[[nodiscard]] QString inviteLink() const {
|
2019-01-05 10:50:04 +00:00
|
|
|
return _inviteLink;
|
|
|
|
}
|
2020-12-14 12:52:18 +00:00
|
|
|
[[nodiscard]] bool canHaveInviteLink() const;
|
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);
|
|
|
|
|
2020-12-14 12:52:18 +00:00
|
|
|
[[nodiscard]] Data::GroupCall *groupCall() const {
|
|
|
|
return _call.get();
|
|
|
|
}
|
2021-04-12 11:36:19 +00:00
|
|
|
void setGroupCall(
|
|
|
|
const MTPInputGroupCall &call,
|
2022-02-25 11:14:15 +00:00
|
|
|
TimeId scheduleDate = 0,
|
|
|
|
bool rtmp = false);
|
2020-12-14 12:52:18 +00:00
|
|
|
void clearGroupCall();
|
2021-03-05 08:14:34 +00:00
|
|
|
void setGroupCallDefaultJoinAs(PeerId peerId);
|
|
|
|
[[nodiscard]] PeerId groupCallDefaultJoinAs() const;
|
2020-12-14 12:52:18 +00:00
|
|
|
|
2022-05-14 21:27:21 +00:00
|
|
|
void setBotCommands(const std::vector<Data::BotCommands> &commands);
|
|
|
|
[[nodiscard]] const Data::ChatBotCommands &botCommands() const {
|
2021-07-01 11:05:15 +00:00
|
|
|
return _botCommands;
|
|
|
|
}
|
|
|
|
|
2021-10-12 08:39:07 +00:00
|
|
|
[[nodiscard]] int pendingRequestsCount() const {
|
|
|
|
return _pendingRequestsCount;
|
|
|
|
}
|
2021-10-27 05:57:37 +00:00
|
|
|
[[nodiscard]] const std::vector<UserId> &recentRequesters() const {
|
|
|
|
return _recentRequesters;
|
|
|
|
}
|
|
|
|
void setPendingRequestsCount(
|
|
|
|
int count,
|
|
|
|
const QVector<MTPlong> &recentRequesters);
|
|
|
|
void setPendingRequestsCount(
|
|
|
|
int count,
|
|
|
|
std::vector<UserId> recentRequesters);
|
2021-10-12 08:39:07 +00:00
|
|
|
|
2022-08-22 09:15:34 +00:00
|
|
|
void setAllowedReactions(Data::AllowedReactions value);
|
|
|
|
[[nodiscard]] const Data::AllowedReactions &allowedReactions() const;
|
2021-12-07 11:11:27 +00:00
|
|
|
|
2019-01-05 10:50:04 +00:00
|
|
|
// Still public data members.
|
2021-08-25 08:15:05 +00:00
|
|
|
const MTPlong inputChat;
|
2019-01-05 10:50:04 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
private:
|
|
|
|
Flags _flags;
|
|
|
|
QString _inviteLink;
|
|
|
|
|
2021-11-21 19:48:08 +00:00
|
|
|
Data::Flags<ChatRestrictions> _defaultRestrictions;
|
|
|
|
Data::Flags<ChatAdminRights> _adminRights;
|
2019-01-13 08:03:34 +00:00
|
|
|
int _version = 0;
|
2021-10-12 08:39:07 +00:00
|
|
|
int _pendingRequestsCount = 0;
|
2021-10-27 05:57:37 +00:00
|
|
|
std::vector<UserId> _recentRequesters;
|
2019-01-05 10:50:04 +00:00
|
|
|
|
2022-08-22 09:15:34 +00:00
|
|
|
Data::AllowedReactions _allowedReactions;
|
2021-12-07 11:11:27 +00:00
|
|
|
|
2020-12-14 12:52:18 +00:00
|
|
|
std::unique_ptr<Data::GroupCall> _call;
|
2021-03-05 08:14:34 +00:00
|
|
|
PeerId _callDefaultJoinAs = 0;
|
2022-05-14 21:27:21 +00:00
|
|
|
Data::ChatBotCommands _botCommands;
|
2020-12-14 12:52:18 +00:00
|
|
|
|
2019-01-14 06:34:51 +00:00
|
|
|
ChannelData *_migratedTo = nullptr;
|
2020-12-14 12:52:18 +00:00
|
|
|
rpl::lifetime _lifetime;
|
2019-01-14 06:34:51 +00:00
|
|
|
|
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
|