2017-09-26 11:49:16 +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.
|
2017-09-26 11:49:16 +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
|
2017-09-26 11:49:16 +00:00
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "data/data_types.h"
|
|
|
|
#include "data/data_flags.h"
|
2017-12-04 17:46:03 +00:00
|
|
|
#include "data/data_notify_settings.h"
|
2017-09-26 11:49:16 +00:00
|
|
|
|
2017-12-05 08:43:18 +00:00
|
|
|
namespace Ui {
|
|
|
|
class EmptyUserpic;
|
|
|
|
} // namespace Ui
|
2017-09-26 11:49:16 +00:00
|
|
|
|
2019-01-03 12:36:01 +00:00
|
|
|
class AuthSession;
|
2017-12-05 08:43:18 +00:00
|
|
|
class PeerData;
|
|
|
|
class UserData;
|
|
|
|
class ChatData;
|
|
|
|
class ChannelData;
|
2017-09-26 11:49:16 +00:00
|
|
|
|
2017-12-05 08:43:18 +00:00
|
|
|
namespace Data {
|
2017-09-26 11:49:16 +00:00
|
|
|
|
2018-01-04 09:40:58 +00:00
|
|
|
class Feed;
|
2019-01-03 12:36:01 +00:00
|
|
|
class Session;
|
2018-01-04 09:40:58 +00:00
|
|
|
|
2017-12-05 08:43:18 +00:00
|
|
|
int PeerColorIndex(PeerId peerId);
|
|
|
|
int PeerColorIndex(int32 bareId);
|
|
|
|
style::color PeerUserpicColor(PeerId peerId);
|
2017-09-26 11:49:16 +00:00
|
|
|
|
2017-12-05 08:43:18 +00:00
|
|
|
} // namespace Data
|
2017-09-26 11:49:16 +00:00
|
|
|
|
2019-01-04 11:09:48 +00:00
|
|
|
using ChatAdminRight = MTPDchatAdminRights::Flag;
|
|
|
|
using ChatRestriction = MTPDchatBannedRights::Flag;
|
|
|
|
using ChatAdminRights = MTPDchatAdminRights::Flags;
|
|
|
|
using ChatRestrictions = MTPDchatBannedRights::Flags;
|
|
|
|
|
2017-09-26 11:49:16 +00:00
|
|
|
class PeerClickHandler : public ClickHandler {
|
|
|
|
public:
|
|
|
|
PeerClickHandler(not_null<PeerData*> peer);
|
2018-07-09 18:13:48 +00:00
|
|
|
void onClick(ClickContext context) const override;
|
2017-09-26 11:49:16 +00:00
|
|
|
|
|
|
|
not_null<PeerData*> peer() const {
|
|
|
|
return _peer;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
not_null<PeerData*> _peer;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
class PeerData {
|
|
|
|
protected:
|
2019-01-03 12:36:01 +00:00
|
|
|
PeerData(not_null<Data::Session*> owner, PeerId id);
|
2017-09-26 11:49:16 +00:00
|
|
|
PeerData(const PeerData &other) = delete;
|
|
|
|
PeerData &operator=(const PeerData &other) = delete;
|
|
|
|
|
|
|
|
public:
|
2017-12-04 17:46:03 +00:00
|
|
|
virtual ~PeerData();
|
2017-09-26 11:49:16 +00:00
|
|
|
|
2019-01-10 11:01:59 +00:00
|
|
|
[[nodiscard]] Data::Session &owner() const;
|
|
|
|
[[nodiscard]] AuthSession &session() const;
|
2019-01-03 12:36:01 +00:00
|
|
|
|
2019-01-10 11:01:59 +00:00
|
|
|
[[nodiscard]] bool isUser() const {
|
2017-09-26 11:49:16 +00:00
|
|
|
return peerIsUser(id);
|
|
|
|
}
|
2019-01-10 11:01:59 +00:00
|
|
|
[[nodiscard]] bool isChat() const {
|
2017-09-26 11:49:16 +00:00
|
|
|
return peerIsChat(id);
|
|
|
|
}
|
2019-01-10 11:01:59 +00:00
|
|
|
[[nodiscard]] bool isChannel() const {
|
2017-09-26 11:49:16 +00:00
|
|
|
return peerIsChannel(id);
|
|
|
|
}
|
2019-01-10 11:01:59 +00:00
|
|
|
[[nodiscard]] bool isSelf() const {
|
2017-09-26 11:49:16 +00:00
|
|
|
return (input.type() == mtpc_inputPeerSelf);
|
|
|
|
}
|
2019-01-10 11:01:59 +00:00
|
|
|
[[nodiscard]] bool isVerified() const;
|
|
|
|
[[nodiscard]] bool isMegagroup() const;
|
2017-12-04 17:46:03 +00:00
|
|
|
|
2019-01-10 11:01:59 +00:00
|
|
|
[[nodiscard]] std::optional<TimeId> notifyMuteUntil() const {
|
2018-04-09 17:48:29 +00:00
|
|
|
return _notify.muteUntil();
|
2017-12-04 17:46:03 +00:00
|
|
|
}
|
|
|
|
bool notifyChange(const MTPPeerNotifySettings &settings) {
|
|
|
|
return _notify.change(settings);
|
|
|
|
}
|
|
|
|
bool notifyChange(
|
2018-09-21 16:28:46 +00:00
|
|
|
std::optional<int> muteForSeconds,
|
|
|
|
std::optional<bool> silentPosts) {
|
2018-04-09 17:48:29 +00:00
|
|
|
return _notify.change(muteForSeconds, silentPosts);
|
2017-12-04 17:46:03 +00:00
|
|
|
}
|
2019-01-10 11:01:59 +00:00
|
|
|
[[nodiscard]] bool notifySettingsUnknown() const {
|
2017-12-04 17:46:03 +00:00
|
|
|
return _notify.settingsUnknown();
|
|
|
|
}
|
2019-01-10 11:01:59 +00:00
|
|
|
[[nodiscard]] std::optional<bool> notifySilentPosts() const {
|
2017-12-04 17:46:03 +00:00
|
|
|
return _notify.silentPosts();
|
|
|
|
}
|
2019-01-10 11:01:59 +00:00
|
|
|
[[nodiscard]] MTPinputPeerNotifySettings notifySerialize() const {
|
2017-12-04 17:46:03 +00:00
|
|
|
return _notify.serialize();
|
|
|
|
}
|
|
|
|
|
2019-01-10 11:01:59 +00:00
|
|
|
[[nodiscard]] bool canWrite() const;
|
|
|
|
[[nodiscard]] bool amRestricted(ChatRestriction right) const;
|
2019-01-05 10:50:04 +00:00
|
|
|
|
2019-01-10 11:01:59 +00:00
|
|
|
[[nodiscard]] UserData *asUser();
|
|
|
|
[[nodiscard]] const UserData *asUser() const;
|
|
|
|
[[nodiscard]] ChatData *asChat();
|
|
|
|
[[nodiscard]] const ChatData *asChat() const;
|
|
|
|
[[nodiscard]] ChannelData *asChannel();
|
|
|
|
[[nodiscard]] const ChannelData *asChannel() const;
|
|
|
|
[[nodiscard]] ChannelData *asMegagroup();
|
|
|
|
[[nodiscard]] const ChannelData *asMegagroup() const;
|
2019-01-13 13:28:05 +00:00
|
|
|
[[nodiscard]] ChatData *asChatNotMigrated();
|
|
|
|
[[nodiscard]] const ChatData *asChatNotMigrated() const;
|
|
|
|
[[nodiscard]] ChannelData *asChannelOrMigrated();
|
|
|
|
[[nodiscard]] const ChannelData *asChannelOrMigrated() const;
|
2017-09-26 11:49:16 +00:00
|
|
|
|
2019-01-10 11:01:59 +00:00
|
|
|
[[nodiscard]] ChatData *migrateFrom() const;
|
|
|
|
[[nodiscard]] ChannelData *migrateTo() const;
|
2019-01-14 06:34:51 +00:00
|
|
|
[[nodiscard]] not_null<PeerData*> migrateToOrMe();
|
|
|
|
[[nodiscard]] not_null<const PeerData*> migrateToOrMe() const;
|
2019-01-10 11:01:59 +00:00
|
|
|
[[nodiscard]] Data::Feed *feed() const;
|
2017-09-26 11:49:16 +00:00
|
|
|
|
|
|
|
void updateFull();
|
|
|
|
void updateFullForced();
|
|
|
|
void fullUpdated();
|
2019-01-10 11:01:59 +00:00
|
|
|
[[nodiscard]] bool wasFullUpdated() const {
|
2017-09-26 11:49:16 +00:00
|
|
|
return (_lastFullUpdate != 0);
|
|
|
|
}
|
|
|
|
|
2019-01-10 11:01:59 +00:00
|
|
|
[[nodiscard]] const Text &dialogName() const;
|
|
|
|
[[nodiscard]] const QString &shortName() const;
|
|
|
|
[[nodiscard]] QString userName() const;
|
2017-09-26 11:49:16 +00:00
|
|
|
|
2019-01-10 11:01:59 +00:00
|
|
|
[[nodiscard]] int32 bareId() const {
|
2017-09-26 11:49:16 +00:00
|
|
|
return int32(uint32(id & 0xFFFFFFFFULL));
|
|
|
|
}
|
|
|
|
|
2019-01-10 11:01:59 +00:00
|
|
|
[[nodiscard]] const base::flat_set<QString> &nameWords() const {
|
2017-10-24 17:11:35 +00:00
|
|
|
return _nameWords;
|
|
|
|
}
|
2019-01-10 11:01:59 +00:00
|
|
|
[[nodiscard]] const base::flat_set<QChar> &nameFirstLetters() const {
|
2018-01-22 09:33:09 +00:00
|
|
|
return _nameFirstLetters;
|
2017-10-24 17:11:35 +00:00
|
|
|
}
|
2017-09-26 11:49:16 +00:00
|
|
|
|
2017-12-05 06:41:43 +00:00
|
|
|
void setUserpic(
|
|
|
|
PhotoId photoId,
|
|
|
|
const StorageImageLocation &location,
|
|
|
|
ImagePtr userpic);
|
|
|
|
void setUserpicPhoto(const MTPPhoto &data);
|
2017-09-26 11:49:16 +00:00
|
|
|
void paintUserpic(
|
|
|
|
Painter &p,
|
|
|
|
int x,
|
|
|
|
int y,
|
|
|
|
int size) const;
|
|
|
|
void paintUserpicLeft(
|
|
|
|
Painter &p,
|
|
|
|
int x,
|
|
|
|
int y,
|
|
|
|
int w,
|
|
|
|
int size) const {
|
|
|
|
paintUserpic(p, rtl() ? (w - x - size) : x, y, size);
|
|
|
|
}
|
|
|
|
void paintUserpicRounded(
|
|
|
|
Painter &p,
|
|
|
|
int x,
|
|
|
|
int y,
|
|
|
|
int size) const;
|
|
|
|
void paintUserpicSquare(
|
|
|
|
Painter &p,
|
|
|
|
int x,
|
|
|
|
int y,
|
|
|
|
int size) const;
|
2018-10-11 15:54:57 +00:00
|
|
|
void loadUserpic(bool loadFirst = false, bool prior = true);
|
2019-01-10 11:01:59 +00:00
|
|
|
[[nodiscard]] bool userpicLoaded() const;
|
|
|
|
[[nodiscard]] bool useEmptyUserpic() const;
|
|
|
|
[[nodiscard]] StorageKey userpicUniqueKey() const;
|
2017-09-26 11:49:16 +00:00
|
|
|
void saveUserpic(const QString &path, int size) const;
|
|
|
|
void saveUserpicRounded(const QString &path, int size) const;
|
2019-01-10 11:01:59 +00:00
|
|
|
[[nodiscard]] QPixmap genUserpic(int size) const;
|
|
|
|
[[nodiscard]] QPixmap genUserpicRounded(int size) const;
|
|
|
|
[[nodiscard]] StorageImageLocation userpicLocation() const {
|
2017-11-20 19:54:05 +00:00
|
|
|
return _userpicLocation;
|
|
|
|
}
|
2019-01-10 11:01:59 +00:00
|
|
|
[[nodiscard]] bool userpicPhotoUnknown() const {
|
2017-12-05 06:41:43 +00:00
|
|
|
return (_userpicPhotoId == kUnknownPhotoId);
|
|
|
|
}
|
2019-01-10 11:01:59 +00:00
|
|
|
[[nodiscard]] PhotoId userpicPhotoId() const {
|
2017-12-05 06:41:43 +00:00
|
|
|
return userpicPhotoUnknown() ? 0 : _userpicPhotoId;
|
|
|
|
}
|
2019-01-10 11:01:59 +00:00
|
|
|
[[nodiscard]] Data::FileOrigin userpicOrigin() const;
|
|
|
|
[[nodiscard]] Data::FileOrigin userpicPhotoOrigin() const;
|
2017-09-26 11:49:16 +00:00
|
|
|
|
2019-01-04 07:57:07 +00:00
|
|
|
// If this string is not empty we must not allow to open the
|
|
|
|
// conversation and we must show this string instead.
|
2019-01-10 11:01:59 +00:00
|
|
|
[[nodiscard]] virtual QString unavailableReason() const {
|
2017-09-26 11:49:16 +00:00
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
2019-01-10 11:01:59 +00:00
|
|
|
[[nodiscard]] ClickHandlerPtr createOpenLink();
|
|
|
|
[[nodiscard]] const ClickHandlerPtr &openLink() {
|
2017-09-26 11:49:16 +00:00
|
|
|
if (!_openLink) {
|
|
|
|
_openLink = createOpenLink();
|
|
|
|
}
|
|
|
|
return _openLink;
|
|
|
|
}
|
|
|
|
|
2019-01-10 11:01:59 +00:00
|
|
|
[[nodiscard]] ImagePtr currentUserpic() const;
|
2017-09-26 11:49:16 +00:00
|
|
|
|
2019-01-10 11:01:59 +00:00
|
|
|
[[nodiscard]] bool canPinMessages() const;
|
|
|
|
[[nodiscard]] MsgId pinnedMessageId() const {
|
2018-10-31 11:29:14 +00:00
|
|
|
return _pinnedMessageId;
|
|
|
|
}
|
|
|
|
void setPinnedMessageId(MsgId messageId);
|
|
|
|
void clearPinnedMessage() {
|
|
|
|
setPinnedMessageId(0);
|
|
|
|
}
|
|
|
|
|
2019-01-08 13:57:22 +00:00
|
|
|
// Returns true if about text was changed.
|
|
|
|
bool setAbout(const QString &newAbout);
|
|
|
|
const QString &about() const {
|
|
|
|
return _about;
|
|
|
|
}
|
|
|
|
|
2019-01-10 11:01:59 +00:00
|
|
|
enum LoadedStatus {
|
|
|
|
NotLoaded = 0x00,
|
|
|
|
MinimalLoaded = 0x01,
|
|
|
|
FullLoaded = 0x02,
|
|
|
|
};
|
|
|
|
|
|
|
|
const PeerId id;
|
|
|
|
QString name;
|
|
|
|
Text nameText;
|
|
|
|
LoadedStatus loadedStatus = NotLoaded;
|
|
|
|
MTPinputPeer input;
|
|
|
|
|
|
|
|
int nameVersion = 1;
|
|
|
|
|
2017-09-26 11:49:16 +00:00
|
|
|
protected:
|
|
|
|
void updateNameDelayed(
|
|
|
|
const QString &newName,
|
|
|
|
const QString &newNameOrPhone,
|
|
|
|
const QString &newUsername);
|
2017-12-05 06:41:43 +00:00
|
|
|
void updateUserpic(PhotoId photoId, const MTPFileLocation &location);
|
|
|
|
void clearUserpic();
|
|
|
|
|
|
|
|
private:
|
|
|
|
void fillNames();
|
2017-12-05 08:43:18 +00:00
|
|
|
std::unique_ptr<Ui::EmptyUserpic> createEmptyUserpic() const;
|
|
|
|
void refreshEmptyUserpic() const;
|
2017-12-05 06:41:43 +00:00
|
|
|
|
2017-12-12 11:45:40 +00:00
|
|
|
void setUserpicChecked(
|
|
|
|
PhotoId photoId,
|
|
|
|
const StorageImageLocation &location,
|
|
|
|
ImagePtr userpic);
|
|
|
|
|
2017-12-05 06:41:43 +00:00
|
|
|
static constexpr auto kUnknownPhotoId = PhotoId(0xFFFFFFFFFFFFFFFFULL);
|
2017-09-26 11:49:16 +00:00
|
|
|
|
2019-01-03 12:36:01 +00:00
|
|
|
not_null<Data::Session*> _owner;
|
|
|
|
|
2017-09-26 11:49:16 +00:00
|
|
|
ImagePtr _userpic;
|
2017-12-05 06:41:43 +00:00
|
|
|
PhotoId _userpicPhotoId = kUnknownPhotoId;
|
2017-12-05 08:43:18 +00:00
|
|
|
mutable std::unique_ptr<Ui::EmptyUserpic> _userpicEmpty;
|
2017-11-20 19:54:05 +00:00
|
|
|
StorageImageLocation _userpicLocation;
|
2017-09-26 11:49:16 +00:00
|
|
|
|
2017-12-04 17:46:03 +00:00
|
|
|
Data::NotifySettings _notify;
|
|
|
|
|
2017-09-26 11:49:16 +00:00
|
|
|
ClickHandlerPtr _openLink;
|
2018-01-22 09:33:09 +00:00
|
|
|
base::flat_set<QString> _nameWords; // for filtering
|
|
|
|
base::flat_set<QChar> _nameFirstLetters;
|
2017-09-26 11:49:16 +00:00
|
|
|
|
|
|
|
TimeMs _lastFullUpdate = 0;
|
2018-10-31 11:29:14 +00:00
|
|
|
MsgId _pinnedMessageId = 0;
|
2017-09-26 11:49:16 +00:00
|
|
|
|
2019-01-08 13:57:22 +00:00
|
|
|
QString _about;
|
|
|
|
|
2017-09-26 11:49:16 +00:00
|
|
|
};
|