2015-04-04 20:01:34 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
|
|
|
the official desktop version of Telegram messaging app, see https://telegram.org
|
|
|
|
|
|
|
|
Telegram Desktop is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
It is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
2015-10-03 13:16:42 +00:00
|
|
|
In addition, as a special exception, the copyright holders give permission
|
|
|
|
to link the code of portions of this program with the OpenSSL library.
|
|
|
|
|
2015-04-04 20:01:34 +00:00
|
|
|
Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE
|
2016-02-08 10:56:18 +00:00
|
|
|
Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org
|
2015-04-04 20:01:34 +00:00
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
2016-03-25 11:29:45 +00:00
|
|
|
typedef int32 UserId;
|
|
|
|
typedef int32 ChatId;
|
2015-09-03 10:48:40 +00:00
|
|
|
typedef int32 ChannelId;
|
|
|
|
static const ChannelId NoChannel = 0;
|
|
|
|
|
2016-03-25 11:29:45 +00:00
|
|
|
typedef int32 MsgId;
|
|
|
|
struct FullMsgId {
|
|
|
|
FullMsgId() : channel(NoChannel), msg(0) {
|
|
|
|
}
|
|
|
|
FullMsgId(ChannelId channel, MsgId msg) : channel(channel), msg(msg) {
|
|
|
|
}
|
|
|
|
ChannelId channel;
|
|
|
|
MsgId msg;
|
|
|
|
};
|
|
|
|
|
2015-04-04 20:01:34 +00:00
|
|
|
typedef uint64 PeerId;
|
2015-09-03 10:48:40 +00:00
|
|
|
static const uint64 PeerIdMask = 0xFFFFFFFFULL;
|
|
|
|
static const uint64 PeerIdTypeMask = 0x300000000ULL;
|
|
|
|
static const uint64 PeerIdUserShift = 0x000000000ULL;
|
|
|
|
static const uint64 PeerIdChatShift = 0x100000000ULL;
|
|
|
|
static const uint64 PeerIdChannelShift = 0x200000000ULL;
|
|
|
|
inline bool peerIsUser(const PeerId &id) {
|
|
|
|
return (id & PeerIdTypeMask) == PeerIdUserShift;
|
|
|
|
}
|
|
|
|
inline bool peerIsChat(const PeerId &id) {
|
|
|
|
return (id & PeerIdTypeMask) == PeerIdChatShift;
|
|
|
|
}
|
|
|
|
inline bool peerIsChannel(const PeerId &id) {
|
|
|
|
return (id & PeerIdTypeMask) == PeerIdChannelShift;
|
|
|
|
}
|
2016-03-25 11:29:45 +00:00
|
|
|
inline PeerId peerFromUser(UserId user_id) {
|
2015-09-03 10:48:40 +00:00
|
|
|
return PeerIdUserShift | uint64(uint32(user_id));
|
|
|
|
}
|
2016-03-25 11:29:45 +00:00
|
|
|
inline PeerId peerFromChat(ChatId chat_id) {
|
2015-09-03 10:48:40 +00:00
|
|
|
return PeerIdChatShift | uint64(uint32(chat_id));
|
|
|
|
}
|
|
|
|
inline PeerId peerFromChannel(ChannelId channel_id) {
|
|
|
|
return PeerIdChannelShift | uint64(uint32(channel_id));
|
|
|
|
}
|
|
|
|
inline PeerId peerFromUser(const MTPint &user_id) {
|
|
|
|
return peerFromUser(user_id.v);
|
|
|
|
}
|
|
|
|
inline PeerId peerFromChat(const MTPint &chat_id) {
|
|
|
|
return peerFromChat(chat_id.v);
|
|
|
|
}
|
|
|
|
inline PeerId peerFromChannel(const MTPint &channel_id) {
|
|
|
|
return peerFromChannel(channel_id.v);
|
|
|
|
}
|
|
|
|
inline int32 peerToBareInt(const PeerId &id) {
|
|
|
|
return int32(uint32(id & PeerIdMask));
|
|
|
|
}
|
2016-03-25 11:29:45 +00:00
|
|
|
inline UserId peerToUser(const PeerId &id) {
|
2015-09-03 10:48:40 +00:00
|
|
|
return peerIsUser(id) ? peerToBareInt(id) : 0;
|
|
|
|
}
|
2016-03-25 11:29:45 +00:00
|
|
|
inline ChatId peerToChat(const PeerId &id) {
|
2015-09-03 10:48:40 +00:00
|
|
|
return peerIsChat(id) ? peerToBareInt(id) : 0;
|
|
|
|
}
|
|
|
|
inline ChannelId peerToChannel(const PeerId &id) {
|
|
|
|
return peerIsChannel(id) ? peerToBareInt(id) : NoChannel;
|
|
|
|
}
|
|
|
|
inline MTPint peerToBareMTPInt(const PeerId &id) {
|
|
|
|
return MTP_int(peerToBareInt(id));
|
|
|
|
}
|
|
|
|
inline PeerId peerFromMTP(const MTPPeer &peer) {
|
|
|
|
switch (peer.type()) {
|
|
|
|
case mtpc_peerUser: return peerFromUser(peer.c_peerUser().vuser_id);
|
|
|
|
case mtpc_peerChat: return peerFromChat(peer.c_peerChat().vchat_id);
|
|
|
|
case mtpc_peerChannel: return peerFromChannel(peer.c_peerChannel().vchannel_id);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
inline MTPpeer peerToMTP(const PeerId &id) {
|
|
|
|
if (peerIsUser(id)) {
|
|
|
|
return MTP_peerUser(peerToBareMTPInt(id));
|
|
|
|
} else if (peerIsChat(id)) {
|
|
|
|
return MTP_peerChat(peerToBareMTPInt(id));
|
|
|
|
} else if (peerIsChannel(id)) {
|
|
|
|
return MTP_peerChannel(peerToBareMTPInt(id));
|
|
|
|
}
|
|
|
|
return MTP_peerUser(MTP_int(0));
|
|
|
|
}
|
2015-09-20 08:55:41 +00:00
|
|
|
inline PeerId peerFromMessage(const MTPmessage &msg) {
|
2015-09-13 08:41:27 +00:00
|
|
|
PeerId from_id = 0, to_id = 0;
|
|
|
|
switch (msg.type()) {
|
|
|
|
case mtpc_message:
|
|
|
|
from_id = msg.c_message().has_from_id() ? peerFromUser(msg.c_message().vfrom_id) : 0;
|
|
|
|
to_id = peerFromMTP(msg.c_message().vto_id);
|
|
|
|
break;
|
|
|
|
case mtpc_messageService:
|
|
|
|
from_id = msg.c_messageService().has_from_id() ? peerFromUser(msg.c_messageService().vfrom_id) : 0;
|
|
|
|
to_id = peerFromMTP(msg.c_messageService().vto_id);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return (from_id && peerToUser(to_id) == MTP::authedId()) ? from_id : to_id;
|
|
|
|
}
|
2016-03-19 16:55:15 +00:00
|
|
|
inline MTPDmessage::Flags flagsFromMessage(const MTPmessage &msg) {
|
2015-09-20 08:55:41 +00:00
|
|
|
switch (msg.type()) {
|
|
|
|
case mtpc_message: return msg.c_message().vflags.v;
|
2016-04-06 11:07:05 +00:00
|
|
|
case mtpc_messageService: return mtpCastFlags(msg.c_messageService().vflags.v);
|
2015-09-20 08:55:41 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2016-03-25 11:29:45 +00:00
|
|
|
inline MsgId idFromMessage(const MTPmessage &msg) {
|
2015-09-21 20:57:42 +00:00
|
|
|
switch (msg.type()) {
|
|
|
|
case mtpc_messageEmpty: return msg.c_messageEmpty().vid.v;
|
|
|
|
case mtpc_message: return msg.c_message().vid.v;
|
|
|
|
case mtpc_messageService: return msg.c_messageService().vid.v;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2016-03-25 11:29:45 +00:00
|
|
|
inline TimeId dateFromMessage(const MTPmessage &msg) {
|
2015-11-18 13:11:56 +00:00
|
|
|
switch (msg.type()) {
|
|
|
|
case mtpc_message: return msg.c_message().vdate.v;
|
|
|
|
case mtpc_messageService: return msg.c_messageService().vdate.v;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2015-09-03 10:48:40 +00:00
|
|
|
|
2015-04-04 20:01:34 +00:00
|
|
|
typedef uint64 PhotoId;
|
|
|
|
typedef uint64 VideoId;
|
|
|
|
typedef uint64 AudioId;
|
|
|
|
typedef uint64 DocumentId;
|
|
|
|
typedef uint64 WebPageId;
|
2016-02-21 12:30:16 +00:00
|
|
|
static const WebPageId CancelledWebPageId = 0xFFFFFFFFFFFFFFFFULL;
|
|
|
|
|
2015-09-03 10:48:40 +00:00
|
|
|
inline bool operator==(const FullMsgId &a, const FullMsgId &b) {
|
|
|
|
return (a.channel == b.channel) && (a.msg == b.msg);
|
|
|
|
}
|
|
|
|
inline bool operator<(const FullMsgId &a, const FullMsgId &b) {
|
|
|
|
if (a.msg < b.msg) return true;
|
|
|
|
if (a.msg > b.msg) return false;
|
|
|
|
return a.channel < b.channel;
|
|
|
|
}
|
2015-04-04 20:01:34 +00:00
|
|
|
|
2016-04-08 14:16:52 +00:00
|
|
|
constexpr const MsgId StartClientMsgId = -0x7FFFFFFF;
|
|
|
|
constexpr const MsgId EndClientMsgId = -0x40000000;
|
|
|
|
inline constexpr bool isClientMsgId(MsgId id) {
|
2015-11-09 09:51:22 +00:00
|
|
|
return id >= StartClientMsgId && id < EndClientMsgId;
|
|
|
|
}
|
2016-04-08 14:16:52 +00:00
|
|
|
constexpr const MsgId ShowAtTheEndMsgId = -0x40000000;
|
|
|
|
constexpr const MsgId SwitchAtTopMsgId = -0x3FFFFFFF;
|
|
|
|
constexpr const MsgId ShowAtProfileMsgId = -0x3FFFFFFE;
|
|
|
|
constexpr const MsgId ShowAndStartBotMsgId = -0x3FFFFFD;
|
|
|
|
constexpr const MsgId ServerMaxMsgId = 0x3FFFFFFF;
|
|
|
|
constexpr const MsgId ShowAtUnreadMsgId = 0;
|
2015-07-17 19:17:37 +00:00
|
|
|
|
2015-04-04 20:01:34 +00:00
|
|
|
struct NotifySettings {
|
2016-03-19 16:55:15 +00:00
|
|
|
NotifySettings() : flags(MTPDpeerNotifySettings::Flag::f_show_previews), mute(0), sound("default") {
|
2015-04-04 20:01:34 +00:00
|
|
|
}
|
2016-03-19 16:55:15 +00:00
|
|
|
MTPDpeerNotifySettings::Flags flags;
|
2016-03-25 11:29:45 +00:00
|
|
|
TimeId mute;
|
2015-04-04 20:01:34 +00:00
|
|
|
string sound;
|
2016-02-22 11:15:24 +00:00
|
|
|
bool previews() const {
|
2016-03-19 16:55:15 +00:00
|
|
|
return flags & MTPDpeerNotifySettings::Flag::f_show_previews;
|
2016-02-22 11:15:24 +00:00
|
|
|
}
|
|
|
|
bool silent() const {
|
2016-03-19 16:55:15 +00:00
|
|
|
return flags & MTPDpeerNotifySettings::Flag::f_silent;
|
2016-02-22 11:15:24 +00:00
|
|
|
}
|
2015-04-04 20:01:34 +00:00
|
|
|
};
|
|
|
|
typedef NotifySettings *NotifySettingsPtr;
|
|
|
|
|
|
|
|
static const NotifySettingsPtr UnknownNotifySettings = NotifySettingsPtr(0);
|
|
|
|
static const NotifySettingsPtr EmptyNotifySettings = NotifySettingsPtr(1);
|
|
|
|
extern NotifySettings globalNotifyAll, globalNotifyUsers, globalNotifyChats;
|
|
|
|
extern NotifySettingsPtr globalNotifyAllPtr, globalNotifyUsersPtr, globalNotifyChatsPtr;
|
|
|
|
|
2016-03-25 11:29:45 +00:00
|
|
|
inline bool isNotifyMuted(NotifySettingsPtr settings, TimeId *changeIn = 0) {
|
2015-04-30 13:53:36 +00:00
|
|
|
if (settings != UnknownNotifySettings && settings != EmptyNotifySettings) {
|
2016-03-25 11:29:45 +00:00
|
|
|
TimeId t = unixtime();
|
2015-04-30 13:53:36 +00:00
|
|
|
if (settings->mute > t) {
|
|
|
|
if (changeIn) *changeIn = settings->mute - t + 1;
|
|
|
|
return true;
|
|
|
|
}
|
2015-04-04 20:01:34 +00:00
|
|
|
}
|
2015-04-30 13:53:36 +00:00
|
|
|
if (changeIn) *changeIn = 0;
|
|
|
|
return false;
|
2015-04-04 20:01:34 +00:00
|
|
|
}
|
|
|
|
|
2016-03-25 11:29:45 +00:00
|
|
|
static const int UserColorsCount = 8;
|
2015-12-12 22:29:33 +00:00
|
|
|
|
2016-03-25 11:29:45 +00:00
|
|
|
style::color peerColor(int index);
|
|
|
|
ImagePtr userDefPhoto(int index);
|
|
|
|
ImagePtr chatDefPhoto(int index);
|
|
|
|
ImagePtr channelDefPhoto(int index);
|
2015-04-04 20:01:34 +00:00
|
|
|
|
2015-08-07 12:11:50 +00:00
|
|
|
static const PhotoId UnknownPeerPhotoId = 0xFFFFFFFFFFFFFFFFULL;
|
|
|
|
|
2015-09-06 10:17:09 +00:00
|
|
|
inline const QString &emptyUsername() {
|
|
|
|
static QString empty;
|
|
|
|
return empty;
|
|
|
|
}
|
|
|
|
|
2016-03-29 17:17:00 +00:00
|
|
|
class PeerClickHandler : public LeftButtonClickHandler {
|
|
|
|
public:
|
|
|
|
PeerClickHandler(PeerData *peer) : _peer(peer) {
|
|
|
|
}
|
|
|
|
PeerData *peer() const {
|
|
|
|
return _peer;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
PeerData *_peer;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
class PeerOpenClickHandler : public PeerClickHandler {
|
|
|
|
public:
|
|
|
|
using PeerClickHandler::PeerClickHandler;
|
|
|
|
protected:
|
|
|
|
void onClickImpl() const override;
|
|
|
|
};
|
|
|
|
|
2015-09-03 10:48:40 +00:00
|
|
|
class UserData;
|
|
|
|
class ChatData;
|
|
|
|
class ChannelData;
|
2016-03-29 17:17:00 +00:00
|
|
|
|
2015-09-03 10:48:40 +00:00
|
|
|
class PeerData {
|
2016-03-23 13:21:26 +00:00
|
|
|
protected:
|
|
|
|
PeerData(const PeerId &id);
|
|
|
|
PeerData(const PeerData &other) = delete;
|
|
|
|
PeerData &operator=(const PeerData &other) = delete;
|
|
|
|
|
2015-09-03 10:48:40 +00:00
|
|
|
public:
|
2015-04-04 20:01:34 +00:00
|
|
|
virtual ~PeerData() {
|
|
|
|
if (notify != UnknownNotifySettings && notify != EmptyNotifySettings) {
|
2016-03-29 17:17:00 +00:00
|
|
|
deleteAndMark(notify);
|
2015-04-04 20:01:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-03 10:48:40 +00:00
|
|
|
bool isUser() const {
|
|
|
|
return peerIsUser(id);
|
|
|
|
}
|
|
|
|
bool isChat() const {
|
|
|
|
return peerIsChat(id);
|
|
|
|
}
|
|
|
|
bool isChannel() const {
|
|
|
|
return peerIsChannel(id);
|
|
|
|
}
|
2015-10-28 00:29:39 +00:00
|
|
|
bool isSelf() const {
|
|
|
|
return (input.type() == mtpc_inputPeerSelf);
|
|
|
|
}
|
2015-10-29 15:52:39 +00:00
|
|
|
bool isVerified() const;
|
2015-11-02 22:33:57 +00:00
|
|
|
bool isMegagroup() const;
|
2015-11-09 09:51:22 +00:00
|
|
|
bool canWrite() const;
|
2015-04-04 20:01:34 +00:00
|
|
|
UserData *asUser();
|
|
|
|
const UserData *asUser() const;
|
|
|
|
ChatData *asChat();
|
|
|
|
const ChatData *asChat() const;
|
2015-09-03 10:48:40 +00:00
|
|
|
ChannelData *asChannel();
|
|
|
|
const ChannelData *asChannel() const;
|
2016-06-03 07:20:24 +00:00
|
|
|
ChannelData *asMegagroup();
|
|
|
|
const ChannelData *asMegagroup() const;
|
2015-04-04 20:01:34 +00:00
|
|
|
|
2015-11-13 15:14:33 +00:00
|
|
|
ChatData *migrateFrom() const;
|
|
|
|
ChannelData *migrateTo() const;
|
|
|
|
|
2015-09-04 13:01:31 +00:00
|
|
|
const Text &dialogName() const;
|
|
|
|
const QString &shortName() const;
|
2015-09-06 10:17:09 +00:00
|
|
|
const QString &userName() const;
|
2015-04-04 20:01:34 +00:00
|
|
|
|
2015-09-03 10:48:40 +00:00
|
|
|
const PeerId id;
|
|
|
|
int32 bareId() const {
|
|
|
|
return int32(uint32(id & 0xFFFFFFFFULL));
|
|
|
|
}
|
2015-04-04 20:01:34 +00:00
|
|
|
|
|
|
|
QString name;
|
2015-09-04 13:01:31 +00:00
|
|
|
Text nameText;
|
2015-04-04 20:01:34 +00:00
|
|
|
typedef QSet<QString> Names;
|
|
|
|
Names names; // for filtering
|
|
|
|
typedef QSet<QChar> NameFirstChars;
|
|
|
|
NameFirstChars chars;
|
|
|
|
|
2016-03-25 11:29:45 +00:00
|
|
|
enum LoadedStatus {
|
|
|
|
NotLoaded = 0x00,
|
|
|
|
MinimalLoaded = 0x01,
|
|
|
|
FullLoaded = 0x02,
|
|
|
|
};
|
2016-05-25 12:09:05 +00:00
|
|
|
LoadedStatus loadedStatus = NotLoaded;
|
2015-04-04 20:01:34 +00:00
|
|
|
MTPinputPeer input;
|
|
|
|
|
2016-03-25 11:29:45 +00:00
|
|
|
int colorIndex;
|
2015-04-04 20:01:34 +00:00
|
|
|
style::color color;
|
2016-03-18 10:18:30 +00:00
|
|
|
|
|
|
|
void setUserpic(ImagePtr userpic);
|
|
|
|
void paintUserpic(Painter &p, int size, int x, int y) const;
|
|
|
|
void paintUserpicLeft(Painter &p, int size, int x, int y, int w) const {
|
|
|
|
paintUserpic(p, size, rtl() ? (w - x - size) : x, y);
|
|
|
|
}
|
|
|
|
void loadUserpic(bool loadFirst = false, bool prior = true) {
|
|
|
|
_userpic->load(loadFirst, prior);
|
|
|
|
}
|
2016-05-25 17:59:21 +00:00
|
|
|
bool userpicLoaded() const {
|
|
|
|
return _userpic->loaded();
|
|
|
|
}
|
2016-03-18 10:18:30 +00:00
|
|
|
StorageKey userpicUniqueKey() const;
|
2016-06-22 18:41:13 +00:00
|
|
|
void saveUserpic(const QString &path, int size) const;
|
2016-03-21 18:57:03 +00:00
|
|
|
QPixmap genUserpic(int size) const;
|
2016-03-18 10:18:30 +00:00
|
|
|
|
2016-05-25 12:09:05 +00:00
|
|
|
PhotoId photoId = UnknownPeerPhotoId;
|
2015-08-07 12:11:50 +00:00
|
|
|
StorageImageLocation photoLoc;
|
2015-04-04 20:01:34 +00:00
|
|
|
|
2016-05-25 12:09:05 +00:00
|
|
|
int nameVersion = 1;
|
2015-04-04 20:01:34 +00:00
|
|
|
|
2016-05-25 12:09:05 +00:00
|
|
|
NotifySettingsPtr notify = UnknownNotifySettings;
|
2015-09-03 10:48:40 +00:00
|
|
|
|
2016-03-23 13:21:26 +00:00
|
|
|
// if this string is not empty we must not allow to open the
|
|
|
|
// conversation and we must show this string instead
|
|
|
|
virtual QString restrictionReason() const {
|
|
|
|
return QString();
|
|
|
|
}
|
2016-03-18 10:18:30 +00:00
|
|
|
|
2016-03-29 17:17:00 +00:00
|
|
|
const ClickHandlerPtr &openLink() {
|
|
|
|
if (!_openLink) {
|
|
|
|
_openLink.reset(new PeerOpenClickHandler(this));
|
|
|
|
}
|
|
|
|
return _openLink;
|
|
|
|
}
|
2015-09-03 10:48:40 +00:00
|
|
|
|
2016-03-29 17:17:00 +00:00
|
|
|
protected:
|
2016-05-25 12:09:05 +00:00
|
|
|
void updateNameDelayed(const QString &newName, const QString &newNameOrPhone, const QString &newUsername);
|
|
|
|
|
2016-03-18 10:18:30 +00:00
|
|
|
ImagePtr _userpic;
|
|
|
|
ImagePtr currentUserpic() const;
|
2015-04-04 20:01:34 +00:00
|
|
|
|
|
|
|
private:
|
2016-05-25 12:09:05 +00:00
|
|
|
void fillNames();
|
|
|
|
|
2016-03-29 17:17:00 +00:00
|
|
|
ClickHandlerPtr _openLink;
|
|
|
|
|
2015-04-04 20:01:34 +00:00
|
|
|
};
|
|
|
|
|
2016-03-29 17:17:00 +00:00
|
|
|
static const uint64 UserNoAccess = 0xFFFFFFFFFFFFFFFFULL;
|
|
|
|
|
2015-07-03 15:55:22 +00:00
|
|
|
class BotCommand {
|
|
|
|
public:
|
|
|
|
BotCommand(const QString &command, const QString &description) : command(command), _description(description) {
|
|
|
|
}
|
|
|
|
QString command;
|
|
|
|
|
|
|
|
bool setDescription(const QString &description) {
|
|
|
|
if (_description != description) {
|
|
|
|
_description = description;
|
|
|
|
_descriptionText = Text();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-12-20 14:05:07 +00:00
|
|
|
const Text &descriptionText() const;
|
2015-07-03 15:55:22 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
QString _description;
|
|
|
|
mutable Text _descriptionText;
|
|
|
|
|
2015-06-10 12:48:26 +00:00
|
|
|
};
|
2015-07-03 15:55:22 +00:00
|
|
|
|
2015-06-10 12:48:26 +00:00
|
|
|
struct BotInfo {
|
2016-04-08 14:16:52 +00:00
|
|
|
bool inited = false;
|
|
|
|
bool readsAllHistory = false;
|
|
|
|
bool cantJoinGroups = false;
|
|
|
|
int version = 0;
|
2016-03-04 15:34:46 +00:00
|
|
|
QString description, inlinePlaceholder;
|
2015-06-10 12:48:26 +00:00
|
|
|
QList<BotCommand> commands;
|
2016-04-08 14:16:52 +00:00
|
|
|
Text text = Text{ int(st::msgMinWidth) }; // description
|
2015-06-17 19:43:03 +00:00
|
|
|
|
|
|
|
QString startToken, startGroupToken;
|
2016-04-08 14:16:52 +00:00
|
|
|
PeerId inlineReturnPeerId = 0;
|
2015-06-10 12:48:26 +00:00
|
|
|
};
|
|
|
|
|
2015-12-24 19:26:28 +00:00
|
|
|
class PhotoData;
|
2015-09-03 10:48:40 +00:00
|
|
|
class UserData : public PeerData {
|
|
|
|
public:
|
|
|
|
|
2016-03-23 13:21:26 +00:00
|
|
|
UserData(const PeerId &id) : PeerData(id) {
|
2015-04-04 20:01:34 +00:00
|
|
|
}
|
|
|
|
void setPhoto(const MTPUserProfilePhoto &photo);
|
2016-05-25 12:09:05 +00:00
|
|
|
|
|
|
|
void setName(const QString &newFirstName, const QString &newLastName
|
|
|
|
, const QString &newPhoneName, const QString &newUsername);
|
|
|
|
|
2015-04-04 20:01:34 +00:00
|
|
|
void setPhone(const QString &newPhone);
|
2016-03-25 11:29:45 +00:00
|
|
|
void setBotInfoVersion(int version);
|
2015-06-10 12:48:26 +00:00
|
|
|
void setBotInfo(const MTPBotInfo &info);
|
2015-09-04 13:01:31 +00:00
|
|
|
|
|
|
|
void setNameOrPhone(const QString &newNameOrPhone);
|
2015-04-04 20:01:34 +00:00
|
|
|
|
2016-06-22 18:41:13 +00:00
|
|
|
void madeAction(TimeId when); // pseudo-online
|
2015-06-10 12:48:26 +00:00
|
|
|
|
2016-03-23 13:21:26 +00:00
|
|
|
uint64 access = 0;
|
2015-08-07 12:11:50 +00:00
|
|
|
|
2016-03-23 13:21:26 +00:00
|
|
|
MTPDuser::Flags flags = { 0 };
|
2015-10-29 15:52:39 +00:00
|
|
|
bool isVerified() const {
|
2016-03-19 16:55:15 +00:00
|
|
|
return flags & MTPDuser::Flag::f_verified;
|
2015-10-29 15:52:39 +00:00
|
|
|
}
|
2016-04-01 16:37:23 +00:00
|
|
|
bool isBotInlineGeo() const {
|
|
|
|
return flags & MTPDuser::Flag::f_bot_inline_geo;
|
|
|
|
}
|
2015-11-09 09:51:22 +00:00
|
|
|
bool canWrite() const {
|
|
|
|
return access != UserNoAccess;
|
|
|
|
}
|
2016-05-27 15:45:35 +00:00
|
|
|
bool isContact() const {
|
|
|
|
return (contact > 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool canShareThisContact() const;
|
|
|
|
bool canAddContact() const {
|
|
|
|
return canShareThisContact() && !isContact();
|
|
|
|
}
|
|
|
|
|
|
|
|
// In feedUsers() we check only that.
|
|
|
|
// When actually trying to share contact we perform
|
|
|
|
// a full check by canShareThisContact() call.
|
|
|
|
bool canShareThisContactFast() const {
|
2016-05-31 19:27:11 +00:00
|
|
|
return !_phone.isEmpty();
|
2016-05-24 16:13:07 +00:00
|
|
|
}
|
2015-10-29 15:52:39 +00:00
|
|
|
|
2015-09-03 10:48:40 +00:00
|
|
|
MTPInputUser inputUser;
|
2015-08-07 12:11:50 +00:00
|
|
|
|
2015-04-04 20:01:34 +00:00
|
|
|
QString firstName;
|
|
|
|
QString lastName;
|
|
|
|
QString username;
|
2016-05-31 19:27:11 +00:00
|
|
|
const QString &phone() const {
|
|
|
|
return _phone;
|
|
|
|
}
|
2015-09-04 13:01:31 +00:00
|
|
|
QString nameOrPhone;
|
|
|
|
Text phoneText;
|
2016-03-25 11:29:45 +00:00
|
|
|
TimeId onlineTill = 0;
|
2016-03-23 13:21:26 +00:00
|
|
|
int32 contact = -1; // -1 - not contact, cant add (self, empty, deleted, foreign), 0 - not contact, can add (request), 1 - contact
|
2016-06-01 20:05:37 +00:00
|
|
|
|
|
|
|
enum class BlockStatus {
|
|
|
|
Unknown,
|
|
|
|
Blocked,
|
|
|
|
NotBlocked,
|
|
|
|
};
|
|
|
|
BlockStatus blockStatus() const {
|
|
|
|
return _blockStatus;
|
|
|
|
}
|
|
|
|
bool isBlocked() const {
|
|
|
|
return (blockStatus() == BlockStatus::Blocked);
|
|
|
|
}
|
|
|
|
void setBlockStatus(BlockStatus blockStatus);
|
2015-04-04 20:01:34 +00:00
|
|
|
|
|
|
|
typedef QList<PhotoData*> Photos;
|
|
|
|
Photos photos;
|
2016-03-25 11:29:45 +00:00
|
|
|
int photosCount = -1; // -1 not loaded, 0 all loaded
|
2015-06-10 12:48:26 +00:00
|
|
|
|
2016-05-31 19:27:11 +00:00
|
|
|
bool setAbout(const QString &newAbout);
|
|
|
|
const QString &about() const {
|
|
|
|
return _about;
|
|
|
|
}
|
2016-03-04 15:34:46 +00:00
|
|
|
|
2016-07-13 17:34:57 +00:00
|
|
|
std_::unique_ptr<BotInfo> botInfo;
|
2016-03-23 13:21:26 +00:00
|
|
|
|
|
|
|
QString restrictionReason() const override {
|
|
|
|
return _restrictionReason;
|
|
|
|
}
|
|
|
|
void setRestrictionReason(const QString &reason) {
|
|
|
|
_restrictionReason = reason;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
QString _restrictionReason;
|
2016-05-31 19:27:11 +00:00
|
|
|
QString _about;
|
|
|
|
QString _phone;
|
2016-06-01 20:05:37 +00:00
|
|
|
BlockStatus _blockStatus = BlockStatus::Unknown;
|
2016-03-23 13:21:26 +00:00
|
|
|
|
2015-04-04 20:01:34 +00:00
|
|
|
};
|
|
|
|
|
2015-09-03 10:48:40 +00:00
|
|
|
class ChatData : public PeerData {
|
|
|
|
public:
|
2016-05-25 12:09:05 +00:00
|
|
|
ChatData(const PeerId &id) : PeerData(id), inputChat(MTP_int(bareId())) {
|
2015-04-04 20:01:34 +00:00
|
|
|
}
|
2015-06-29 22:09:23 +00:00
|
|
|
void setPhoto(const MTPChatPhoto &photo, const PhotoId &phId = UnknownPeerPhotoId);
|
2016-05-25 12:09:05 +00:00
|
|
|
|
|
|
|
void setName(const QString &newName);
|
|
|
|
|
2016-06-03 21:46:45 +00:00
|
|
|
void invalidateParticipants();
|
2015-11-02 02:28:24 +00:00
|
|
|
bool noParticipantInfo() const {
|
|
|
|
return (count > 0 || amIn()) && participants.isEmpty();
|
2015-10-29 19:10:49 +00:00
|
|
|
}
|
2015-09-03 10:48:40 +00:00
|
|
|
|
2015-09-16 21:15:13 +00:00
|
|
|
MTPint inputChat;
|
2015-09-03 10:48:40 +00:00
|
|
|
|
2016-05-25 12:09:05 +00:00
|
|
|
ChannelData *migrateToPtr = nullptr;
|
2015-11-09 09:51:22 +00:00
|
|
|
|
2016-05-25 12:09:05 +00:00
|
|
|
int count = 0;
|
|
|
|
TimeId date = 0;
|
|
|
|
int version = 0;
|
|
|
|
UserId creator = 0;
|
2015-09-21 20:57:42 +00:00
|
|
|
|
2016-05-25 12:09:05 +00:00
|
|
|
MTPDchat::Flags flags = 0;
|
|
|
|
bool isForbidden = false;
|
2015-10-29 19:10:49 +00:00
|
|
|
bool amIn() const {
|
|
|
|
return !isForbidden && !haveLeft() && !wasKicked();
|
|
|
|
}
|
|
|
|
bool canEdit() const {
|
2015-11-06 17:48:49 +00:00
|
|
|
return !isDeactivated() && (amCreator() || (adminsEnabled() ? amAdmin() : amIn()));
|
|
|
|
}
|
|
|
|
bool canWrite() const {
|
|
|
|
return !isDeactivated() && amIn();
|
2015-10-29 19:10:49 +00:00
|
|
|
}
|
|
|
|
bool haveLeft() const {
|
2016-03-19 16:55:15 +00:00
|
|
|
return flags & MTPDchat::Flag::f_left;
|
2015-10-29 19:10:49 +00:00
|
|
|
}
|
|
|
|
bool wasKicked() const {
|
2016-03-19 16:55:15 +00:00
|
|
|
return flags & MTPDchat::Flag::f_kicked;
|
2015-10-29 19:10:49 +00:00
|
|
|
}
|
|
|
|
bool adminsEnabled() const {
|
2016-03-19 16:55:15 +00:00
|
|
|
return flags & MTPDchat::Flag::f_admins_enabled;
|
2015-10-29 19:10:49 +00:00
|
|
|
}
|
|
|
|
bool amCreator() const {
|
2016-03-19 16:55:15 +00:00
|
|
|
return flags & MTPDchat::Flag::f_creator;
|
2015-10-29 19:10:49 +00:00
|
|
|
}
|
|
|
|
bool amAdmin() const {
|
2016-03-24 16:27:38 +00:00
|
|
|
return (flags & MTPDchat::Flag::f_admin) && adminsEnabled();
|
2015-10-29 19:10:49 +00:00
|
|
|
}
|
2015-11-03 17:49:10 +00:00
|
|
|
bool isDeactivated() const {
|
2016-03-19 16:55:15 +00:00
|
|
|
return flags & MTPDchat::Flag::f_deactivated;
|
2015-11-03 17:49:10 +00:00
|
|
|
}
|
2015-11-06 17:48:49 +00:00
|
|
|
bool isMigrated() const {
|
2016-03-19 16:55:15 +00:00
|
|
|
return flags & MTPDchat::Flag::f_migrated_to;
|
2015-11-06 17:48:49 +00:00
|
|
|
}
|
2016-03-25 11:29:45 +00:00
|
|
|
typedef QMap<UserData*, int> Participants;
|
2015-04-04 20:01:34 +00:00
|
|
|
Participants participants;
|
2016-03-10 15:42:01 +00:00
|
|
|
typedef OrderedSet<UserData*> InvitedByMe;
|
2015-10-29 19:10:49 +00:00
|
|
|
InvitedByMe invitedByMe;
|
2016-03-10 15:42:01 +00:00
|
|
|
typedef OrderedSet<UserData*> Admins;
|
2015-10-29 19:10:49 +00:00
|
|
|
Admins admins;
|
2015-04-04 20:01:34 +00:00
|
|
|
typedef QList<UserData*> LastAuthors;
|
|
|
|
LastAuthors lastAuthors;
|
2016-03-10 15:42:01 +00:00
|
|
|
typedef OrderedSet<PeerData*> MarkupSenders;
|
2015-06-17 19:43:03 +00:00
|
|
|
MarkupSenders markupSenders;
|
2016-05-25 12:09:05 +00:00
|
|
|
int botStatus = 0; // -1 - no bots, 0 - unknown, 1 - one bot, that sees all history, 2 - other
|
2015-08-07 12:11:50 +00:00
|
|
|
// ImagePtr photoFull;
|
2016-06-01 13:07:03 +00:00
|
|
|
|
|
|
|
void setInviteLink(const QString &newInviteLink);
|
|
|
|
QString inviteLink() const {
|
|
|
|
return _inviteLink;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
QString _inviteLink;
|
|
|
|
|
2015-04-04 20:01:34 +00:00
|
|
|
};
|
|
|
|
|
2015-09-13 08:41:27 +00:00
|
|
|
enum PtsSkippedQueue {
|
|
|
|
SkippedUpdate,
|
|
|
|
SkippedUpdates,
|
|
|
|
};
|
|
|
|
class PtsWaiter {
|
|
|
|
public:
|
|
|
|
|
2016-03-12 16:32:28 +00:00
|
|
|
PtsWaiter()
|
|
|
|
: _good(0)
|
|
|
|
, _last(0)
|
|
|
|
, _count(0)
|
|
|
|
, _applySkippedLevel(0)
|
|
|
|
, _requesting(false)
|
|
|
|
, _waitingForSkipped(false)
|
|
|
|
, _waitingForShortPoll(false) {
|
2015-09-13 08:41:27 +00:00
|
|
|
}
|
|
|
|
void init(int32 pts) {
|
|
|
|
_good = _last = _count = pts;
|
|
|
|
clearSkippedUpdates();
|
|
|
|
}
|
|
|
|
bool inited() const {
|
|
|
|
return _good > 0;
|
|
|
|
}
|
|
|
|
void setRequesting(bool isRequesting) {
|
|
|
|
_requesting = isRequesting;
|
2015-09-20 09:54:22 +00:00
|
|
|
if (_requesting) {
|
|
|
|
clearSkippedUpdates();
|
|
|
|
}
|
2015-09-13 08:41:27 +00:00
|
|
|
}
|
|
|
|
bool requesting() const {
|
|
|
|
return _requesting;
|
|
|
|
}
|
2015-09-20 08:55:41 +00:00
|
|
|
bool waitingForSkipped() const {
|
|
|
|
return _waitingForSkipped;
|
|
|
|
}
|
|
|
|
bool waitingForShortPoll() const {
|
|
|
|
return _waitingForShortPoll;
|
|
|
|
}
|
2015-09-20 09:54:22 +00:00
|
|
|
void setWaitingForSkipped(ChannelData *channel, int32 ms); // < 0 - not waiting
|
|
|
|
void setWaitingForShortPoll(ChannelData *channel, int32 ms); // < 0 - not waiting
|
2015-09-13 08:41:27 +00:00
|
|
|
int32 current() const{
|
|
|
|
return _good;
|
|
|
|
}
|
|
|
|
bool updated(ChannelData *channel, int32 pts, int32 count);
|
|
|
|
bool updated(ChannelData *channel, int32 pts, int32 count, const MTPUpdates &updates);
|
|
|
|
bool updated(ChannelData *channel, int32 pts, int32 count, const MTPUpdate &update);
|
|
|
|
void applySkippedUpdates(ChannelData *channel);
|
|
|
|
void clearSkippedUpdates();
|
|
|
|
|
|
|
|
private:
|
2015-09-21 20:57:42 +00:00
|
|
|
bool check(ChannelData *channel, int32 pts, int32 count); // return false if need to save that update and apply later
|
2015-09-13 08:41:27 +00:00
|
|
|
uint64 ptsKey(PtsSkippedQueue queue);
|
2015-09-20 08:55:41 +00:00
|
|
|
void checkForWaiting(ChannelData *channel);
|
2015-09-13 08:41:27 +00:00
|
|
|
QMap<uint64, PtsSkippedQueue> _queue;
|
|
|
|
QMap<uint64, MTPUpdate> _updateQueue;
|
|
|
|
QMap<uint64, MTPUpdates> _updatesQueue;
|
|
|
|
int32 _good, _last, _count;
|
|
|
|
int32 _applySkippedLevel;
|
2015-09-20 08:55:41 +00:00
|
|
|
bool _requesting, _waitingForSkipped, _waitingForShortPoll;
|
2015-09-13 08:41:27 +00:00
|
|
|
};
|
|
|
|
|
2015-11-06 17:48:49 +00:00
|
|
|
struct MegagroupInfo {
|
2016-03-04 15:34:46 +00:00
|
|
|
MegagroupInfo()
|
|
|
|
: botStatus(0)
|
|
|
|
, pinnedMsgId(0)
|
|
|
|
, joinedMessageFound(false)
|
|
|
|
, lastParticipantsStatus(LastParticipantsUpToDate)
|
|
|
|
, lastParticipantsCount(0)
|
|
|
|
, migrateFromPtr(0) {
|
2015-11-06 17:48:49 +00:00
|
|
|
}
|
|
|
|
typedef QList<UserData*> LastParticipants;
|
|
|
|
LastParticipants lastParticipants;
|
2016-03-10 15:42:01 +00:00
|
|
|
typedef OrderedSet<UserData*> LastAdmins;
|
2015-11-09 09:51:22 +00:00
|
|
|
LastAdmins lastAdmins;
|
2016-03-10 15:42:01 +00:00
|
|
|
typedef OrderedSet<PeerData*> MarkupSenders;
|
2015-11-06 17:48:49 +00:00
|
|
|
MarkupSenders markupSenders;
|
2016-03-10 15:42:01 +00:00
|
|
|
typedef OrderedSet<UserData*> Bots;
|
2015-11-09 09:51:22 +00:00
|
|
|
Bots bots;
|
2015-11-06 17:48:49 +00:00
|
|
|
int32 botStatus; // -1 - no bots, 0 - unknown, 1 - one bot, that sees all history, 2 - other
|
2015-11-19 15:56:29 +00:00
|
|
|
|
2016-03-04 15:34:46 +00:00
|
|
|
MsgId pinnedMsgId;
|
2015-11-20 18:24:44 +00:00
|
|
|
bool joinedMessageFound;
|
|
|
|
|
2015-11-19 15:56:29 +00:00
|
|
|
enum LastParticipantsStatus {
|
|
|
|
LastParticipantsUpToDate = 0x00,
|
|
|
|
LastParticipantsAdminsOutdated = 0x01,
|
|
|
|
LastParticipantsCountOutdated = 0x02,
|
|
|
|
};
|
|
|
|
mutable int32 lastParticipantsStatus;
|
|
|
|
int32 lastParticipantsCount;
|
|
|
|
|
2015-11-13 15:14:33 +00:00
|
|
|
ChatData *migrateFromPtr;
|
2015-11-06 17:48:49 +00:00
|
|
|
};
|
|
|
|
|
2015-09-03 10:48:40 +00:00
|
|
|
class ChannelData : public PeerData {
|
|
|
|
public:
|
2016-05-25 12:09:05 +00:00
|
|
|
ChannelData(const PeerId &id) : PeerData(id), inputChannel(MTP_inputChannel(MTP_int(bareId()), MTP_long(0))) {
|
2015-09-03 10:48:40 +00:00
|
|
|
}
|
|
|
|
void setPhoto(const MTPChatPhoto &photo, const PhotoId &phId = UnknownPeerPhotoId);
|
2016-05-25 12:09:05 +00:00
|
|
|
|
2015-09-06 10:17:09 +00:00
|
|
|
void setName(const QString &name, const QString &username);
|
2015-09-03 10:48:40 +00:00
|
|
|
|
2015-09-23 17:43:08 +00:00
|
|
|
void updateFull(bool force = false);
|
2015-09-21 20:57:42 +00:00
|
|
|
void fullUpdated();
|
|
|
|
|
2016-03-23 13:21:26 +00:00
|
|
|
uint64 access = 0;
|
2015-09-03 10:48:40 +00:00
|
|
|
|
2015-09-16 21:15:13 +00:00
|
|
|
MTPinputChannel inputChannel;
|
2015-09-03 10:48:40 +00:00
|
|
|
|
2016-05-31 19:27:11 +00:00
|
|
|
QString username;
|
|
|
|
|
|
|
|
// Returns true if about text was changed.
|
|
|
|
bool setAbout(const QString &newAbout);
|
|
|
|
const QString &about() const {
|
|
|
|
return _about;
|
|
|
|
}
|
2015-09-21 20:57:42 +00:00
|
|
|
|
2016-06-02 13:02:55 +00:00
|
|
|
int membersCount() const {
|
|
|
|
return _membersCount;
|
|
|
|
}
|
|
|
|
void setMembersCount(int newMembersCount);
|
|
|
|
|
|
|
|
int adminsCount() const {
|
|
|
|
return _adminsCount;
|
|
|
|
}
|
|
|
|
void setAdminsCount(int newAdminsCount);
|
|
|
|
|
2016-03-23 13:21:26 +00:00
|
|
|
int32 date = 0;
|
|
|
|
int version = 0;
|
|
|
|
MTPDchannel::Flags flags = { 0 };
|
|
|
|
MTPDchannelFull::Flags flagsFull = { 0 };
|
|
|
|
MegagroupInfo *mgInfo = nullptr;
|
2015-11-19 15:56:29 +00:00
|
|
|
bool lastParticipantsCountOutdated() const {
|
|
|
|
if (!mgInfo || !(mgInfo->lastParticipantsStatus & MegagroupInfo::LastParticipantsCountOutdated)) {
|
|
|
|
return false;
|
|
|
|
}
|
2016-06-02 13:02:55 +00:00
|
|
|
if (mgInfo->lastParticipantsCount == membersCount()) {
|
2015-11-19 15:56:29 +00:00
|
|
|
mgInfo->lastParticipantsStatus &= ~MegagroupInfo::LastParticipantsCountOutdated;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2015-11-13 15:14:33 +00:00
|
|
|
void flagsUpdated();
|
2016-06-04 20:29:16 +00:00
|
|
|
void selfAdminUpdated();
|
2015-11-02 22:33:57 +00:00
|
|
|
bool isMegagroup() const {
|
2016-03-19 16:55:15 +00:00
|
|
|
return flags & MTPDchannel::Flag::f_megagroup;
|
2015-11-02 22:33:57 +00:00
|
|
|
}
|
2015-09-21 20:57:42 +00:00
|
|
|
bool isBroadcast() const {
|
2016-03-19 16:55:15 +00:00
|
|
|
return flags & MTPDchannel::Flag::f_broadcast;
|
2015-09-21 20:57:42 +00:00
|
|
|
}
|
|
|
|
bool isPublic() const {
|
2016-03-19 16:55:15 +00:00
|
|
|
return flags & MTPDchannel::Flag::f_username;
|
2015-09-21 20:57:42 +00:00
|
|
|
}
|
|
|
|
bool amCreator() const {
|
2016-03-19 16:55:15 +00:00
|
|
|
return flags & MTPDchannel::Flag::f_creator;
|
2015-09-21 20:57:42 +00:00
|
|
|
}
|
|
|
|
bool amEditor() const {
|
2016-03-19 16:55:15 +00:00
|
|
|
return flags & MTPDchannel::Flag::f_editor;
|
2015-09-21 20:57:42 +00:00
|
|
|
}
|
|
|
|
bool amModerator() const {
|
2016-03-19 16:55:15 +00:00
|
|
|
return flags & MTPDchannel::Flag::f_moderator;
|
2015-09-21 20:57:42 +00:00
|
|
|
}
|
|
|
|
bool haveLeft() const {
|
2016-03-19 16:55:15 +00:00
|
|
|
return flags & MTPDchannel::Flag::f_left;
|
2015-09-21 20:57:42 +00:00
|
|
|
}
|
|
|
|
bool wasKicked() const {
|
2016-03-19 16:55:15 +00:00
|
|
|
return flags & MTPDchannel::Flag::f_kicked;
|
2015-09-21 20:57:42 +00:00
|
|
|
}
|
2015-09-23 17:43:08 +00:00
|
|
|
bool amIn() const {
|
|
|
|
return !isForbidden && !haveLeft() && !wasKicked();
|
|
|
|
}
|
2015-09-21 20:57:42 +00:00
|
|
|
bool canPublish() const {
|
|
|
|
return amCreator() || amEditor();
|
|
|
|
}
|
2015-11-09 09:51:22 +00:00
|
|
|
bool canWrite() const {
|
|
|
|
return amIn() && (canPublish() || !isBroadcast());
|
|
|
|
}
|
2016-06-02 13:02:55 +00:00
|
|
|
bool canViewMembers() const {
|
2016-03-19 16:55:15 +00:00
|
|
|
return flagsFull & MTPDchannelFull::Flag::f_can_view_participants;
|
2015-10-12 21:02:10 +00:00
|
|
|
}
|
2016-06-02 13:02:55 +00:00
|
|
|
bool canViewAdmins() const {
|
|
|
|
return (isMegagroup() || amCreator() || amEditor() || amModerator());
|
|
|
|
}
|
2016-02-17 16:37:21 +00:00
|
|
|
bool addsSignature() const {
|
2016-03-19 16:55:15 +00:00
|
|
|
return flags & MTPDchannel::Flag::f_signatures;
|
2016-02-17 16:37:21 +00:00
|
|
|
}
|
2016-03-23 13:21:26 +00:00
|
|
|
bool isForbidden = true;
|
2015-09-23 17:43:08 +00:00
|
|
|
bool isVerified() const {
|
2016-03-19 16:55:15 +00:00
|
|
|
return flags & MTPDchannel::Flag::f_verified;
|
2015-09-23 17:43:08 +00:00
|
|
|
}
|
2016-06-02 13:02:55 +00:00
|
|
|
bool canAddMembers() const {
|
2016-03-19 16:55:15 +00:00
|
|
|
return amCreator() || amEditor() || (flags & MTPDchannel::Flag::f_democracy);
|
2016-02-14 18:29:17 +00:00
|
|
|
}
|
2016-05-24 16:13:07 +00:00
|
|
|
bool canEditPhoto() const {
|
|
|
|
return amCreator() || (amEditor() && isMegagroup());
|
|
|
|
}
|
|
|
|
bool canEditUsername() const {
|
|
|
|
return amCreator() && (flagsFull & MTPDchannelFull::Flag::f_can_set_username);
|
|
|
|
}
|
2016-06-02 13:02:55 +00:00
|
|
|
bool canDelete() const {
|
|
|
|
return amCreator() && (membersCount() <= 1000);
|
|
|
|
}
|
2015-09-03 10:48:40 +00:00
|
|
|
|
|
|
|
// ImagePtr photoFull;
|
2016-06-01 13:07:03 +00:00
|
|
|
|
|
|
|
void setInviteLink(const QString &newInviteLink);
|
|
|
|
QString inviteLink() const {
|
|
|
|
return _inviteLink;
|
|
|
|
}
|
2015-09-13 08:41:27 +00:00
|
|
|
|
2016-03-23 13:21:26 +00:00
|
|
|
int32 inviter = 0; // > 0 - user who invited me to channel, < 0 - not in channel
|
2015-09-21 20:57:42 +00:00
|
|
|
QDateTime inviteDate;
|
|
|
|
|
2015-09-13 17:27:29 +00:00
|
|
|
void ptsInit(int32 pts) {
|
|
|
|
_ptsWaiter.init(pts);
|
|
|
|
}
|
2015-09-13 08:41:27 +00:00
|
|
|
void ptsReceived(int32 pts) {
|
2015-09-20 09:54:22 +00:00
|
|
|
if (_ptsWaiter.updated(this, pts, 0)) {
|
|
|
|
_ptsWaiter.applySkippedUpdates(this);
|
|
|
|
}
|
2015-09-13 08:41:27 +00:00
|
|
|
}
|
|
|
|
bool ptsUpdated(int32 pts, int32 count) {
|
|
|
|
return _ptsWaiter.updated(this, pts, count);
|
|
|
|
}
|
|
|
|
bool ptsUpdated(int32 pts, int32 count, const MTPUpdate &update) {
|
|
|
|
return _ptsWaiter.updated(this, pts, count, update);
|
|
|
|
}
|
|
|
|
int32 pts() const {
|
|
|
|
return _ptsWaiter.current();
|
|
|
|
}
|
|
|
|
bool ptsInited() const {
|
|
|
|
return _ptsWaiter.inited();
|
|
|
|
}
|
|
|
|
bool ptsRequesting() const {
|
|
|
|
return _ptsWaiter.requesting();
|
|
|
|
}
|
|
|
|
void ptsSetRequesting(bool isRequesting) {
|
|
|
|
return _ptsWaiter.setRequesting(isRequesting);
|
|
|
|
}
|
2015-09-20 09:54:22 +00:00
|
|
|
void ptsApplySkippedUpdates() {
|
|
|
|
return _ptsWaiter.applySkippedUpdates(this);
|
2015-09-13 08:41:27 +00:00
|
|
|
}
|
2015-09-20 09:54:22 +00:00
|
|
|
void ptsWaitingForShortPoll(int32 ms) { // < 0 - not waiting
|
|
|
|
return _ptsWaiter.setWaitingForShortPoll(this, ms);
|
2015-09-20 08:55:41 +00:00
|
|
|
}
|
2015-09-13 08:41:27 +00:00
|
|
|
|
2016-03-23 13:21:26 +00:00
|
|
|
QString restrictionReason() const override {
|
|
|
|
return _restrictionReason;
|
|
|
|
}
|
|
|
|
void setRestrictionReason(const QString &reason) {
|
|
|
|
_restrictionReason = reason;
|
|
|
|
}
|
|
|
|
|
2015-11-06 17:48:49 +00:00
|
|
|
~ChannelData();
|
|
|
|
|
2015-09-13 08:41:27 +00:00
|
|
|
private:
|
|
|
|
PtsWaiter _ptsWaiter;
|
2016-03-23 13:21:26 +00:00
|
|
|
uint64 _lastFullUpdate = 0;
|
|
|
|
|
2016-06-02 13:02:55 +00:00
|
|
|
int _membersCount = 1;
|
|
|
|
int _adminsCount = 1;
|
|
|
|
|
2016-03-23 13:21:26 +00:00
|
|
|
QString _restrictionReason;
|
2016-05-31 19:27:11 +00:00
|
|
|
QString _about;
|
2016-03-23 13:21:26 +00:00
|
|
|
|
2016-06-01 13:07:03 +00:00
|
|
|
QString _inviteLink;
|
|
|
|
|
2015-09-03 10:48:40 +00:00
|
|
|
};
|
|
|
|
|
2016-03-25 11:29:45 +00:00
|
|
|
inline bool isUser(const PeerData *peer) {
|
|
|
|
return peer ? peer->isUser() : false;
|
|
|
|
}
|
2015-09-03 10:48:40 +00:00
|
|
|
inline UserData *PeerData::asUser() {
|
2016-03-25 11:29:45 +00:00
|
|
|
return isUser() ? static_cast<UserData*>(this) : nullptr;
|
|
|
|
}
|
|
|
|
inline UserData *asUser(PeerData *peer) {
|
|
|
|
return peer ? peer->asUser() : nullptr;
|
2015-09-03 10:48:40 +00:00
|
|
|
}
|
|
|
|
inline const UserData *PeerData::asUser() const {
|
2016-03-25 11:29:45 +00:00
|
|
|
return isUser() ? static_cast<const UserData*>(this) : nullptr;
|
|
|
|
}
|
|
|
|
inline const UserData *asUser(const PeerData *peer) {
|
|
|
|
return peer ? peer->asUser() : nullptr;
|
|
|
|
}
|
|
|
|
inline bool isChat(const PeerData *peer) {
|
|
|
|
return peer ? peer->isChat() : false;
|
2015-09-03 10:48:40 +00:00
|
|
|
}
|
|
|
|
inline ChatData *PeerData::asChat() {
|
2016-03-25 11:29:45 +00:00
|
|
|
return isChat() ? static_cast<ChatData*>(this) : nullptr;
|
|
|
|
}
|
|
|
|
inline ChatData *asChat(PeerData *peer) {
|
|
|
|
return peer ? peer->asChat() : nullptr;
|
2015-09-03 10:48:40 +00:00
|
|
|
}
|
|
|
|
inline const ChatData *PeerData::asChat() const {
|
2016-03-25 11:29:45 +00:00
|
|
|
return isChat() ? static_cast<const ChatData*>(this) : nullptr;
|
|
|
|
}
|
|
|
|
inline const ChatData *asChat(const PeerData *peer) {
|
|
|
|
return peer ? peer->asChat() : nullptr;
|
|
|
|
}
|
|
|
|
inline bool isChannel(const PeerData *peer) {
|
|
|
|
return peer ? peer->isChannel() : false;
|
2015-09-03 10:48:40 +00:00
|
|
|
}
|
|
|
|
inline ChannelData *PeerData::asChannel() {
|
2016-03-25 11:29:45 +00:00
|
|
|
return isChannel() ? static_cast<ChannelData*>(this) : nullptr;
|
|
|
|
}
|
|
|
|
inline ChannelData *asChannel(PeerData *peer) {
|
|
|
|
return peer ? peer->asChannel() : nullptr;
|
2015-09-03 10:48:40 +00:00
|
|
|
}
|
|
|
|
inline const ChannelData *PeerData::asChannel() const {
|
2016-03-25 11:29:45 +00:00
|
|
|
return isChannel() ? static_cast<const ChannelData*>(this) : nullptr;
|
|
|
|
}
|
|
|
|
inline const ChannelData *asChannel(const PeerData *peer) {
|
|
|
|
return peer ? peer->asChannel() : nullptr;
|
|
|
|
}
|
2016-06-03 07:20:24 +00:00
|
|
|
inline ChannelData *PeerData::asMegagroup() {
|
|
|
|
return isMegagroup() ? static_cast<ChannelData*>(this) : nullptr;
|
|
|
|
}
|
|
|
|
inline ChannelData *asMegagroup(PeerData *peer) {
|
|
|
|
return peer ? peer->asMegagroup() : nullptr;
|
|
|
|
}
|
|
|
|
inline const ChannelData *PeerData::asMegagroup() const {
|
|
|
|
return isMegagroup() ? static_cast<const ChannelData*>(this) : nullptr;
|
|
|
|
}
|
|
|
|
inline const ChannelData *asMegagroup(const PeerData *peer) {
|
|
|
|
return peer ? peer->asMegagroup() : nullptr;
|
|
|
|
}
|
2016-03-25 11:29:45 +00:00
|
|
|
inline bool isMegagroup(const PeerData *peer) {
|
|
|
|
return peer ? peer->isMegagroup() : false;
|
2015-09-03 10:48:40 +00:00
|
|
|
}
|
2015-11-13 15:14:33 +00:00
|
|
|
inline ChatData *PeerData::migrateFrom() const {
|
2016-03-25 11:29:45 +00:00
|
|
|
return (isMegagroup() && asChannel()->amIn()) ? asChannel()->mgInfo->migrateFromPtr : nullptr;
|
2015-11-13 15:14:33 +00:00
|
|
|
}
|
|
|
|
inline ChannelData *PeerData::migrateTo() const {
|
2016-03-25 11:29:45 +00:00
|
|
|
return (isChat() && asChat()->migrateToPtr && asChat()->migrateToPtr->amIn()) ? asChat()->migrateToPtr : nullptr;
|
2015-11-13 15:14:33 +00:00
|
|
|
}
|
2015-09-06 10:17:09 +00:00
|
|
|
inline const Text &PeerData::dialogName() const {
|
2015-11-18 13:11:56 +00:00
|
|
|
return migrateTo() ? migrateTo()->dialogName() : ((isUser() && !asUser()->phoneText.isEmpty()) ? asUser()->phoneText : nameText);
|
2015-09-06 10:17:09 +00:00
|
|
|
}
|
|
|
|
inline const QString &PeerData::shortName() const {
|
|
|
|
return isUser() ? asUser()->firstName : name;
|
|
|
|
}
|
|
|
|
inline const QString &PeerData::userName() const {
|
|
|
|
return isUser() ? asUser()->username : (isChannel() ? asChannel()->username : emptyUsername());
|
|
|
|
}
|
2015-10-29 15:52:39 +00:00
|
|
|
inline bool PeerData::isVerified() const {
|
|
|
|
return isUser() ? asUser()->isVerified() : (isChannel() ? asChannel()->isVerified() : false);
|
|
|
|
}
|
2015-11-02 22:33:57 +00:00
|
|
|
inline bool PeerData::isMegagroup() const {
|
|
|
|
return isChannel() ? asChannel()->isMegagroup() : false;
|
|
|
|
}
|
2015-11-09 09:51:22 +00:00
|
|
|
inline bool PeerData::canWrite() const {
|
|
|
|
return isChannel() ? asChannel()->canWrite() : (isChat() ? asChat()->canWrite() : (isUser() ? asUser()->canWrite() : false));
|
|
|
|
}
|
2015-09-06 10:17:09 +00:00
|
|
|
|
2015-12-24 19:26:28 +00:00
|
|
|
enum ActionOnLoad {
|
|
|
|
ActionOnLoadNone,
|
|
|
|
ActionOnLoadOpen,
|
|
|
|
ActionOnLoadOpenWith,
|
|
|
|
ActionOnLoadPlayInline
|
|
|
|
};
|
|
|
|
|
2015-04-04 20:01:34 +00:00
|
|
|
typedef QMap<char, QPixmap> PreparedPhotoThumbs;
|
2015-12-24 19:26:28 +00:00
|
|
|
class PhotoData {
|
|
|
|
public:
|
|
|
|
PhotoData(const PhotoId &id, const uint64 &access = 0, int32 date = 0, const ImagePtr &thumb = ImagePtr(), const ImagePtr &medium = ImagePtr(), const ImagePtr &full = ImagePtr());
|
|
|
|
|
|
|
|
void automaticLoad(const HistoryItem *item);
|
2015-12-27 21:37:48 +00:00
|
|
|
void automaticLoadSettingsChanged();
|
2015-12-24 19:26:28 +00:00
|
|
|
|
2015-12-25 13:09:14 +00:00
|
|
|
void download();
|
2015-12-24 19:26:28 +00:00
|
|
|
bool loaded() const;
|
|
|
|
bool loading() const;
|
|
|
|
bool displayLoading() const;
|
|
|
|
void cancel();
|
|
|
|
float64 progress() const;
|
|
|
|
int32 loadOffset() const;
|
|
|
|
bool uploading() const;
|
|
|
|
|
|
|
|
void forget();
|
|
|
|
ImagePtr makeReplyPreview();
|
|
|
|
|
|
|
|
~PhotoData();
|
|
|
|
|
2015-04-04 20:01:34 +00:00
|
|
|
PhotoId id;
|
|
|
|
uint64 access;
|
|
|
|
int32 date;
|
|
|
|
ImagePtr thumb, replyPreview;
|
|
|
|
ImagePtr medium;
|
|
|
|
ImagePtr full;
|
2015-09-03 10:48:40 +00:00
|
|
|
|
|
|
|
PeerData *peer; // for chat and channel photos connection
|
2015-04-04 20:01:34 +00:00
|
|
|
// geo, caption
|
|
|
|
|
2015-12-24 19:26:28 +00:00
|
|
|
struct UploadingData {
|
|
|
|
UploadingData(int32 size) : offset(0), size(size) {
|
|
|
|
}
|
|
|
|
int32 offset, size;
|
|
|
|
};
|
|
|
|
UploadingData *uploadingData;
|
|
|
|
|
2015-12-25 13:09:14 +00:00
|
|
|
private:
|
|
|
|
void notifyLayoutChanged() const;
|
|
|
|
|
2015-04-04 20:01:34 +00:00
|
|
|
};
|
|
|
|
|
2016-03-29 17:17:00 +00:00
|
|
|
class PhotoClickHandler : public LeftButtonClickHandler {
|
2015-04-04 20:01:34 +00:00
|
|
|
public:
|
2016-03-29 17:17:00 +00:00
|
|
|
PhotoClickHandler(PhotoData *photo, PeerData *peer = 0) : _photo(photo), _peer(peer) {
|
2015-04-04 20:01:34 +00:00
|
|
|
}
|
|
|
|
PhotoData *photo() const {
|
|
|
|
return _photo;
|
|
|
|
}
|
|
|
|
PeerData *peer() const {
|
|
|
|
return _peer;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
PhotoData *_photo;
|
|
|
|
PeerData *_peer;
|
2015-12-24 19:26:28 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2016-03-29 17:17:00 +00:00
|
|
|
class PhotoOpenClickHandler : public PhotoClickHandler {
|
2015-12-25 13:09:14 +00:00
|
|
|
public:
|
2016-03-29 17:17:00 +00:00
|
|
|
using PhotoClickHandler::PhotoClickHandler;
|
|
|
|
protected:
|
|
|
|
void onClickImpl() const override;
|
2015-12-25 13:09:14 +00:00
|
|
|
};
|
|
|
|
|
2016-03-29 17:17:00 +00:00
|
|
|
class PhotoSaveClickHandler : public PhotoClickHandler {
|
2015-12-24 19:26:28 +00:00
|
|
|
public:
|
2016-03-29 17:17:00 +00:00
|
|
|
using PhotoClickHandler::PhotoClickHandler;
|
|
|
|
protected:
|
|
|
|
void onClickImpl() const override;
|
|
|
|
};
|
2015-12-24 19:26:28 +00:00
|
|
|
|
2016-03-29 17:17:00 +00:00
|
|
|
class PhotoCancelClickHandler : public PhotoClickHandler {
|
|
|
|
public:
|
|
|
|
using PhotoClickHandler::PhotoClickHandler;
|
|
|
|
protected:
|
|
|
|
void onClickImpl() const override;
|
2015-04-04 20:01:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enum FileStatus {
|
2015-12-08 19:07:50 +00:00
|
|
|
FileDownloadFailed = -2,
|
|
|
|
FileUploadFailed = -1,
|
2015-04-04 20:01:34 +00:00
|
|
|
FileUploading = 0,
|
|
|
|
FileReady = 1,
|
|
|
|
};
|
|
|
|
|
2015-06-30 21:07:05 +00:00
|
|
|
enum DocumentType {
|
|
|
|
FileDocument = 0,
|
|
|
|
VideoDocument = 1,
|
|
|
|
SongDocument = 2,
|
|
|
|
StickerDocument = 3,
|
|
|
|
AnimatedDocument = 4,
|
2016-02-12 16:35:06 +00:00
|
|
|
VoiceDocument = 5,
|
2015-06-30 21:07:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct DocumentAdditionalData {
|
2016-04-09 05:57:55 +00:00
|
|
|
virtual ~DocumentAdditionalData();
|
2015-06-30 21:07:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct StickerData : public DocumentAdditionalData {
|
2015-05-11 12:44:27 +00:00
|
|
|
StickerData() : set(MTP_inputStickerSetEmpty()) {
|
|
|
|
}
|
|
|
|
ImagePtr img;
|
|
|
|
QString alt;
|
|
|
|
|
|
|
|
MTPInputStickerSet set;
|
2015-06-19 21:58:01 +00:00
|
|
|
bool setInstalled() const;
|
|
|
|
|
2015-05-19 15:46:45 +00:00
|
|
|
StorageImageLocation loc; // doc thumb location
|
2015-12-24 19:26:28 +00:00
|
|
|
|
2015-05-11 12:44:27 +00:00
|
|
|
};
|
|
|
|
|
2015-06-30 21:07:05 +00:00
|
|
|
struct SongData : public DocumentAdditionalData {
|
|
|
|
SongData() : duration(0) {
|
|
|
|
}
|
|
|
|
int32 duration;
|
|
|
|
QString title, performer;
|
2015-12-24 19:26:28 +00:00
|
|
|
|
2015-04-04 20:01:34 +00:00
|
|
|
};
|
2015-06-30 21:07:05 +00:00
|
|
|
|
2016-02-12 16:35:06 +00:00
|
|
|
typedef QVector<char> VoiceWaveform; // [0] == -1 -- counting, [0] == -2 -- could not count
|
|
|
|
struct VoiceData : public DocumentAdditionalData {
|
|
|
|
VoiceData() : duration(0), wavemax(0) {
|
|
|
|
}
|
|
|
|
~VoiceData();
|
|
|
|
int32 duration;
|
|
|
|
VoiceWaveform waveform;
|
|
|
|
char wavemax;
|
|
|
|
};
|
|
|
|
|
2015-12-19 14:37:28 +00:00
|
|
|
bool fileIsImage(const QString &name, const QString &mime);
|
|
|
|
|
2016-04-09 05:57:55 +00:00
|
|
|
namespace Serialize {
|
|
|
|
class Document;
|
|
|
|
} // namespace Serialize;
|
|
|
|
|
2015-12-24 19:26:28 +00:00
|
|
|
class DocumentData {
|
|
|
|
public:
|
2016-04-09 05:57:55 +00:00
|
|
|
static DocumentData *create(DocumentId id);
|
2016-07-08 13:56:53 +00:00
|
|
|
static DocumentData *create(DocumentId id, int32 dc, uint64 accessHash, int32 version, const QVector<MTPDocumentAttribute> &attributes);
|
2016-04-09 05:57:55 +00:00
|
|
|
static DocumentData *create(DocumentId id, const QString &url, const QVector<MTPDocumentAttribute> &attributes);
|
|
|
|
|
2015-04-04 20:01:34 +00:00
|
|
|
void setattributes(const QVector<MTPDocumentAttribute> &attributes);
|
|
|
|
|
2015-12-24 19:26:28 +00:00
|
|
|
void automaticLoad(const HistoryItem *item); // auto load sticker or video
|
2015-12-27 21:37:48 +00:00
|
|
|
void automaticLoadSettingsChanged();
|
2015-04-04 20:01:34 +00:00
|
|
|
|
2016-03-16 11:54:37 +00:00
|
|
|
enum FilePathResolveType {
|
|
|
|
FilePathResolveCached,
|
|
|
|
FilePathResolveChecked,
|
|
|
|
FilePathResolveSaveFromData,
|
|
|
|
FilePathResolveSaveFromDataSilent,
|
|
|
|
};
|
|
|
|
bool loaded(FilePathResolveType type = FilePathResolveCached) const;
|
2015-12-24 19:26:28 +00:00
|
|
|
bool loading() const;
|
|
|
|
bool displayLoading() const;
|
|
|
|
void save(const QString &toFile, ActionOnLoad action = ActionOnLoadNone, const FullMsgId &actionMsgId = FullMsgId(), LoadFromCloudSetting fromCloud = LoadFromCloudOrLocal, bool autoLoading = false);
|
|
|
|
void cancel();
|
|
|
|
float64 progress() const;
|
|
|
|
int32 loadOffset() const;
|
|
|
|
bool uploading() const;
|
2015-12-12 22:29:33 +00:00
|
|
|
|
2015-12-24 19:26:28 +00:00
|
|
|
QByteArray data() const;
|
|
|
|
const FileLocation &location(bool check = false) const;
|
|
|
|
void setLocation(const FileLocation &loc);
|
2015-04-04 20:01:34 +00:00
|
|
|
|
2016-03-16 11:54:37 +00:00
|
|
|
QString filepath(FilePathResolveType type = FilePathResolveCached, bool forceSavingAs = false) const;
|
|
|
|
|
2015-12-24 19:26:28 +00:00
|
|
|
bool saveToCache() const;
|
2015-12-12 22:29:33 +00:00
|
|
|
|
2015-12-24 19:26:28 +00:00
|
|
|
void performActionOnLoad();
|
2015-12-12 22:29:33 +00:00
|
|
|
|
2015-12-24 19:26:28 +00:00
|
|
|
void forget();
|
|
|
|
ImagePtr makeReplyPreview();
|
2015-04-04 20:01:34 +00:00
|
|
|
|
2015-06-30 21:07:05 +00:00
|
|
|
StickerData *sticker() {
|
2016-04-10 19:20:48 +00:00
|
|
|
return (type == StickerDocument) ? static_cast<StickerData*>(_additional.get()) : nullptr;
|
2015-06-30 21:07:05 +00:00
|
|
|
}
|
2015-12-24 19:26:28 +00:00
|
|
|
void checkSticker() {
|
|
|
|
StickerData *s = sticker();
|
|
|
|
if (!s) return;
|
|
|
|
|
2016-04-02 11:20:53 +00:00
|
|
|
automaticLoad(nullptr);
|
2015-12-24 19:26:28 +00:00
|
|
|
if (s->img->isNull() && loaded()) {
|
|
|
|
if (_data.isEmpty()) {
|
2015-12-24 20:29:33 +00:00
|
|
|
const FileLocation &loc(location(true));
|
|
|
|
if (loc.accessEnable()) {
|
|
|
|
s->img = ImagePtr(loc.name());
|
|
|
|
loc.accessDisable();
|
2015-12-24 19:26:28 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
s->img = ImagePtr(_data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-06-30 21:07:05 +00:00
|
|
|
SongData *song() {
|
2016-04-10 19:20:48 +00:00
|
|
|
return (type == SongDocument) ? static_cast<SongData*>(_additional.get()) : nullptr;
|
2015-06-30 21:07:05 +00:00
|
|
|
}
|
2016-03-25 11:29:45 +00:00
|
|
|
const SongData *song() const {
|
2016-04-10 19:20:48 +00:00
|
|
|
return (type == SongDocument) ? static_cast<const SongData*>(_additional.get()) : nullptr;
|
2016-03-25 11:29:45 +00:00
|
|
|
}
|
2016-02-12 16:35:06 +00:00
|
|
|
VoiceData *voice() {
|
2016-04-10 19:20:48 +00:00
|
|
|
return (type == VoiceDocument) ? static_cast<VoiceData*>(_additional.get()) : nullptr;
|
2016-02-12 16:35:06 +00:00
|
|
|
}
|
|
|
|
const VoiceData *voice() const {
|
2016-04-10 19:20:48 +00:00
|
|
|
return (type == VoiceDocument) ? static_cast<const VoiceData*>(_additional.get()) : nullptr;
|
2016-02-12 16:35:06 +00:00
|
|
|
}
|
2015-12-24 19:26:28 +00:00
|
|
|
bool isAnimation() const {
|
2015-12-18 21:36:16 +00:00
|
|
|
return (type == AnimatedDocument) || !mime.compare(qstr("image/gif"), Qt::CaseInsensitive);
|
|
|
|
}
|
2015-12-28 15:34:45 +00:00
|
|
|
bool isGifv() const {
|
|
|
|
return (type == AnimatedDocument) && !mime.compare(qstr("video/mp4"), Qt::CaseInsensitive);
|
|
|
|
}
|
2016-02-12 16:35:06 +00:00
|
|
|
bool isMusic() const {
|
2016-04-10 19:20:48 +00:00
|
|
|
return (type == SongDocument) ? !static_cast<SongData*>(_additional.get())->title.isEmpty() : false;
|
2016-02-12 16:35:06 +00:00
|
|
|
}
|
2016-02-12 18:18:32 +00:00
|
|
|
bool isVideo() const {
|
|
|
|
return (type == VideoDocument);
|
|
|
|
}
|
2015-12-28 15:34:45 +00:00
|
|
|
int32 duration() const {
|
2016-02-12 18:18:32 +00:00
|
|
|
return (isAnimation() || isVideo()) ? _duration : -1;
|
2015-12-28 15:34:45 +00:00
|
|
|
}
|
2015-12-10 13:37:45 +00:00
|
|
|
bool isImage() const {
|
2016-02-12 18:18:32 +00:00
|
|
|
return !isAnimation() && !isVideo() && (_duration > 0);
|
2015-12-10 13:37:45 +00:00
|
|
|
}
|
|
|
|
void recountIsImage();
|
2016-02-12 16:35:06 +00:00
|
|
|
void setData(const QByteArray &data) {
|
|
|
|
_data = data;
|
|
|
|
}
|
2015-04-04 20:01:34 +00:00
|
|
|
|
2016-07-08 13:56:53 +00:00
|
|
|
bool setRemoteVersion(int32 version); // Returns true if version has changed.
|
2016-04-09 05:57:55 +00:00
|
|
|
void setRemoteLocation(int32 dc, uint64 access);
|
|
|
|
void setContentUrl(const QString &url);
|
2016-04-10 11:13:37 +00:00
|
|
|
bool hasRemoteLocation() const {
|
|
|
|
return (_dc != 0 && _access != 0);
|
|
|
|
}
|
2016-04-09 05:57:55 +00:00
|
|
|
bool isValid() const {
|
2016-04-10 11:13:37 +00:00
|
|
|
return hasRemoteLocation() || !_url.isEmpty();
|
2016-04-09 05:57:55 +00:00
|
|
|
}
|
|
|
|
MTPInputDocument mtpInput() const {
|
|
|
|
if (_access) {
|
|
|
|
return MTP_inputDocument(MTP_long(id), MTP_long(_access));
|
|
|
|
}
|
|
|
|
return MTP_inputDocumentEmpty();
|
|
|
|
}
|
|
|
|
|
2016-04-10 14:53:01 +00:00
|
|
|
// When we have some client-side generated document
|
|
|
|
// (for example for displaying an external inline bot result)
|
|
|
|
// and it has downloaded data, we can collect that data from it
|
|
|
|
// to (this) received from the server "same" document.
|
|
|
|
void collectLocalData(DocumentData *local);
|
|
|
|
|
2015-12-24 19:26:28 +00:00
|
|
|
~DocumentData();
|
2015-12-11 18:11:38 +00:00
|
|
|
|
2015-04-04 20:01:34 +00:00
|
|
|
DocumentId id;
|
2016-04-09 05:57:55 +00:00
|
|
|
DocumentType type = FileDocument;
|
2015-04-04 20:01:34 +00:00
|
|
|
QSize dimensions;
|
2016-04-09 05:57:55 +00:00
|
|
|
int32 date = 0;
|
2015-05-11 12:44:27 +00:00
|
|
|
QString name, mime;
|
2015-04-04 20:01:34 +00:00
|
|
|
ImagePtr thumb, replyPreview;
|
2016-04-09 05:57:55 +00:00
|
|
|
int32 size = 0;
|
2015-04-04 20:01:34 +00:00
|
|
|
|
2016-04-09 05:57:55 +00:00
|
|
|
FileStatus status = FileReady;
|
|
|
|
int32 uploadOffset = 0;
|
2015-04-04 20:01:34 +00:00
|
|
|
|
|
|
|
int32 md5[8];
|
2015-11-26 17:34:52 +00:00
|
|
|
|
2016-02-12 18:18:32 +00:00
|
|
|
MediaKey mediaKey() const {
|
2016-07-08 13:56:53 +00:00
|
|
|
return ::mediaKey(locationType(), _dc, id, _version);
|
2016-02-12 18:18:32 +00:00
|
|
|
}
|
|
|
|
|
2015-11-26 17:34:52 +00:00
|
|
|
private:
|
2016-07-08 13:56:53 +00:00
|
|
|
DocumentData(DocumentId id, int32 dc, uint64 accessHash, int32 version, const QString &url, const QVector<MTPDocumentAttribute> &attributes);
|
2015-11-26 17:34:52 +00:00
|
|
|
|
2016-04-09 05:57:55 +00:00
|
|
|
friend class Serialize::Document;
|
2015-12-10 13:37:45 +00:00
|
|
|
|
2016-03-16 11:54:37 +00:00
|
|
|
LocationType locationType() const {
|
|
|
|
return voice() ? AudioFileLocation : (isVideo() ? VideoFileLocation : DocumentFileLocation);
|
|
|
|
}
|
|
|
|
|
2016-07-08 13:56:53 +00:00
|
|
|
// Two types of location: from MTProto by dc+access+version or from web by url
|
2016-04-09 05:57:55 +00:00
|
|
|
int32 _dc = 0;
|
|
|
|
uint64 _access = 0;
|
2016-07-08 13:56:53 +00:00
|
|
|
int32 _version = 0;
|
2016-04-09 05:57:55 +00:00
|
|
|
QString _url;
|
|
|
|
|
|
|
|
FileLocation _location;
|
|
|
|
QByteArray _data;
|
2016-04-10 19:20:48 +00:00
|
|
|
std_::unique_ptr<DocumentAdditionalData> _additional;
|
2016-04-09 05:57:55 +00:00
|
|
|
int32 _duration = -1;
|
|
|
|
|
|
|
|
ActionOnLoad _actionOnLoad = ActionOnLoadNone;
|
2015-12-24 19:26:28 +00:00
|
|
|
FullMsgId _actionOnLoadMsgId;
|
2016-04-09 05:57:55 +00:00
|
|
|
mutable FileLoader *_loader = nullptr;
|
2015-12-24 19:26:28 +00:00
|
|
|
|
|
|
|
void notifyLayoutChanged() const;
|
|
|
|
|
2015-04-04 20:01:34 +00:00
|
|
|
};
|
|
|
|
|
2016-02-12 16:35:06 +00:00
|
|
|
VoiceWaveform documentWaveformDecode(const QByteArray &encoded5bit);
|
|
|
|
QByteArray documentWaveformEncode5bit(const VoiceWaveform &waveform);
|
|
|
|
|
2016-06-30 12:03:32 +00:00
|
|
|
class AudioMsgId {
|
|
|
|
public:
|
|
|
|
enum class Type {
|
|
|
|
Unknown,
|
|
|
|
Voice,
|
|
|
|
Song,
|
|
|
|
Video,
|
|
|
|
};
|
|
|
|
|
|
|
|
AudioMsgId() {
|
2015-09-03 10:48:40 +00:00
|
|
|
}
|
2016-06-30 12:03:32 +00:00
|
|
|
AudioMsgId(DocumentData *audio, const FullMsgId &msgId) : _audio(audio), _contextId(msgId) {
|
2016-07-05 17:44:02 +00:00
|
|
|
setTypeFromAudio();
|
2015-06-30 21:07:05 +00:00
|
|
|
}
|
2016-06-30 12:03:32 +00:00
|
|
|
AudioMsgId(DocumentData *audio, ChannelId channelId, MsgId msgId) : _audio(audio), _contextId(channelId, msgId) {
|
2016-07-05 17:44:02 +00:00
|
|
|
setTypeFromAudio();
|
|
|
|
}
|
|
|
|
AudioMsgId(Type type) : _type(type) {
|
2015-06-30 21:07:05 +00:00
|
|
|
}
|
2015-12-24 19:26:28 +00:00
|
|
|
|
2016-06-30 12:03:32 +00:00
|
|
|
Type type() const {
|
|
|
|
return _type;
|
2016-02-12 16:35:06 +00:00
|
|
|
}
|
2016-06-30 12:03:32 +00:00
|
|
|
DocumentData *audio() const {
|
|
|
|
return _audio;
|
2016-02-12 16:35:06 +00:00
|
|
|
}
|
2016-06-30 12:03:32 +00:00
|
|
|
FullMsgId contextId() const {
|
|
|
|
return _contextId;
|
2016-02-12 16:35:06 +00:00
|
|
|
}
|
2016-04-10 18:18:26 +00:00
|
|
|
|
|
|
|
explicit operator bool() const {
|
2016-07-13 11:24:31 +00:00
|
|
|
return _audio || (_type == Type::Video);
|
2016-06-30 12:03:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2016-07-05 17:44:02 +00:00
|
|
|
void setTypeFromAudio() {
|
2016-06-30 12:03:32 +00:00
|
|
|
if (_audio->voice()) {
|
|
|
|
_type = Type::Voice;
|
|
|
|
} else if (_audio->song()) {
|
|
|
|
_type = Type::Song;
|
|
|
|
} else if (_audio->isVideo()) {
|
|
|
|
_type = Type::Video;
|
|
|
|
} else {
|
|
|
|
_type = Type::Unknown;
|
|
|
|
}
|
2016-02-12 16:35:06 +00:00
|
|
|
}
|
2016-06-30 12:03:32 +00:00
|
|
|
|
|
|
|
DocumentData *_audio = nullptr;
|
|
|
|
Type _type = Type::Unknown;
|
|
|
|
FullMsgId _contextId;
|
2016-02-12 16:35:06 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
inline bool operator<(const AudioMsgId &a, const AudioMsgId &b) {
|
2016-06-30 12:03:32 +00:00
|
|
|
return quintptr(a.audio()) < quintptr(b.audio()) || (quintptr(a.audio()) == quintptr(b.audio()) && a.contextId() < b.contextId());
|
2016-02-12 16:35:06 +00:00
|
|
|
}
|
|
|
|
inline bool operator==(const AudioMsgId &a, const AudioMsgId &b) {
|
2016-06-30 12:03:32 +00:00
|
|
|
return a.audio() == b.audio() && a.contextId() == b.contextId();
|
2016-02-12 16:35:06 +00:00
|
|
|
}
|
|
|
|
inline bool operator!=(const AudioMsgId &a, const AudioMsgId &b) {
|
|
|
|
return !(a == b);
|
|
|
|
}
|
|
|
|
|
2016-03-29 17:17:00 +00:00
|
|
|
class DocumentClickHandler : public LeftButtonClickHandler {
|
2015-04-04 20:01:34 +00:00
|
|
|
public:
|
2016-03-29 17:17:00 +00:00
|
|
|
DocumentClickHandler(DocumentData *document) : _document(document) {
|
2015-04-04 20:01:34 +00:00
|
|
|
}
|
|
|
|
DocumentData *document() const {
|
|
|
|
return _document;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
DocumentData *_document;
|
2015-12-24 19:26:28 +00:00
|
|
|
|
2015-04-04 20:01:34 +00:00
|
|
|
};
|
|
|
|
|
2016-03-29 17:17:00 +00:00
|
|
|
class DocumentSaveClickHandler : public DocumentClickHandler {
|
2015-04-04 20:01:34 +00:00
|
|
|
public:
|
2016-03-29 17:17:00 +00:00
|
|
|
using DocumentClickHandler::DocumentClickHandler;
|
2015-04-19 10:29:19 +00:00
|
|
|
static void doSave(DocumentData *document, bool forceSavingAs = false);
|
2016-03-29 17:17:00 +00:00
|
|
|
protected:
|
|
|
|
void onClickImpl() const override;
|
2015-04-04 20:01:34 +00:00
|
|
|
};
|
|
|
|
|
2016-03-29 17:17:00 +00:00
|
|
|
class DocumentOpenClickHandler : public DocumentClickHandler {
|
2015-04-04 20:01:34 +00:00
|
|
|
public:
|
2016-03-29 17:17:00 +00:00
|
|
|
using DocumentClickHandler::DocumentClickHandler;
|
2015-12-24 19:26:28 +00:00
|
|
|
static void doOpen(DocumentData *document, ActionOnLoad action = ActionOnLoadOpen);
|
2016-03-29 17:17:00 +00:00
|
|
|
protected:
|
|
|
|
void onClickImpl() const override;
|
2015-12-21 13:14:29 +00:00
|
|
|
};
|
|
|
|
|
2016-03-29 17:17:00 +00:00
|
|
|
class GifOpenClickHandler : public DocumentOpenClickHandler {
|
2016-02-12 16:35:06 +00:00
|
|
|
public:
|
2016-03-29 17:17:00 +00:00
|
|
|
using DocumentOpenClickHandler::DocumentOpenClickHandler;
|
|
|
|
protected:
|
|
|
|
void onClickImpl() const override;
|
2015-04-04 20:01:34 +00:00
|
|
|
};
|
|
|
|
|
2016-03-29 17:17:00 +00:00
|
|
|
class DocumentCancelClickHandler : public DocumentClickHandler {
|
2015-04-04 20:01:34 +00:00
|
|
|
public:
|
2016-03-29 17:17:00 +00:00
|
|
|
using DocumentClickHandler::DocumentClickHandler;
|
|
|
|
protected:
|
|
|
|
void onClickImpl() const override;
|
2015-04-04 20:01:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enum WebPageType {
|
|
|
|
WebPagePhoto,
|
|
|
|
WebPageVideo,
|
|
|
|
WebPageProfile,
|
|
|
|
WebPageArticle
|
|
|
|
};
|
|
|
|
inline WebPageType toWebPageType(const QString &type) {
|
2015-06-27 13:02:00 +00:00
|
|
|
if (type == qstr("photo")) return WebPagePhoto;
|
|
|
|
if (type == qstr("video")) return WebPageVideo;
|
|
|
|
if (type == qstr("profile")) return WebPageProfile;
|
2015-04-04 20:01:34 +00:00
|
|
|
return WebPageArticle;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct WebPageData {
|
2016-04-08 09:20:10 +00:00
|
|
|
WebPageData(const WebPageId &id, WebPageType type = WebPageArticle, const QString &url = QString(), const QString &displayUrl = QString(), const QString &siteName = QString(), const QString &title = QString(), const QString &description = QString(), DocumentData *doc = nullptr, PhotoData *photo = nullptr, int32 duration = 0, const QString &author = QString(), int32 pendingTill = -1);
|
2015-12-31 15:27:21 +00:00
|
|
|
|
2015-04-04 20:01:34 +00:00
|
|
|
void forget() {
|
|
|
|
if (photo) photo->forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
WebPageId id;
|
|
|
|
WebPageType type;
|
|
|
|
QString url, displayUrl, siteName, title, description;
|
|
|
|
int32 duration;
|
|
|
|
QString author;
|
|
|
|
PhotoData *photo;
|
2016-04-08 09:20:10 +00:00
|
|
|
DocumentData *document;
|
2015-04-04 20:01:34 +00:00
|
|
|
int32 pendingTill;
|
2015-12-24 19:26:28 +00:00
|
|
|
|
2015-04-04 20:01:34 +00:00
|
|
|
};
|
|
|
|
|
2015-04-19 10:29:19 +00:00
|
|
|
QString saveFileName(const QString &title, const QString &filter, const QString &prefix, QString name, bool savingAs, const QDir &dir = QDir());
|
2015-04-04 20:01:34 +00:00
|
|
|
MsgId clientMsgId();
|
|
|
|
|
|
|
|
struct MessageCursor {
|
|
|
|
MessageCursor() : position(0), anchor(0), scroll(QFIXED_MAX) {
|
|
|
|
}
|
|
|
|
MessageCursor(int position, int anchor, int scroll) : position(position), anchor(anchor), scroll(scroll) {
|
|
|
|
}
|
|
|
|
MessageCursor(const QTextEdit &edit) {
|
|
|
|
fillFrom(edit);
|
|
|
|
}
|
|
|
|
void fillFrom(const QTextEdit &edit) {
|
|
|
|
QTextCursor c = edit.textCursor();
|
|
|
|
position = c.position();
|
|
|
|
anchor = c.anchor();
|
|
|
|
QScrollBar *s = edit.verticalScrollBar();
|
2015-11-13 15:14:33 +00:00
|
|
|
scroll = (s && (s->value() != s->maximum())) ? s->value() : QFIXED_MAX;
|
2015-04-04 20:01:34 +00:00
|
|
|
}
|
2016-01-02 00:58:43 +00:00
|
|
|
void applyTo(QTextEdit &edit) {
|
2015-04-04 20:01:34 +00:00
|
|
|
QTextCursor c = edit.textCursor();
|
|
|
|
c.setPosition(anchor, QTextCursor::MoveAnchor);
|
|
|
|
c.setPosition(position, QTextCursor::KeepAnchor);
|
|
|
|
edit.setTextCursor(c);
|
|
|
|
QScrollBar *s = edit.verticalScrollBar();
|
|
|
|
if (s) s->setValue(scroll);
|
|
|
|
}
|
|
|
|
int position, anchor, scroll;
|
|
|
|
};
|
2016-02-25 10:32:31 +00:00
|
|
|
|
|
|
|
inline bool operator==(const MessageCursor &a, const MessageCursor &b) {
|
|
|
|
return (a.position == b.position) && (a.anchor == b.anchor) && (a.scroll == b.scroll);
|
|
|
|
}
|
2016-04-12 21:31:28 +00:00
|
|
|
|
|
|
|
struct LocationCoords {
|
|
|
|
LocationCoords() : lat(0), lon(0) {
|
|
|
|
}
|
|
|
|
LocationCoords(float64 lat, float64 lon) : lat(lat), lon(lon) {
|
|
|
|
}
|
|
|
|
LocationCoords(const MTPDgeoPoint &point) : lat(point.vlat.v), lon(point.vlong.v) {
|
|
|
|
}
|
|
|
|
float64 lat, lon;
|
|
|
|
};
|
|
|
|
inline bool operator==(const LocationCoords &a, const LocationCoords &b) {
|
|
|
|
return (a.lat == b.lat) && (a.lon == b.lon);
|
|
|
|
}
|
|
|
|
inline bool operator<(const LocationCoords &a, const LocationCoords &b) {
|
|
|
|
return (a.lat < b.lat) || ((a.lat == b.lat) && (a.lon < b.lon));
|
|
|
|
}
|
|
|
|
inline uint qHash(const LocationCoords &t, uint seed = 0) {
|
|
|
|
return qHash(QtPrivate::QHashCombine().operator()(qHash(t.lat), t.lon), seed);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct LocationData {
|
|
|
|
LocationData(const LocationCoords &coords) : coords(coords), loading(false) {
|
|
|
|
}
|
|
|
|
|
|
|
|
LocationCoords coords;
|
|
|
|
ImagePtr thumb;
|
|
|
|
bool loading;
|
|
|
|
|
|
|
|
void load();
|
|
|
|
};
|
|
|
|
|
|
|
|
class LocationClickHandler : public ClickHandler {
|
|
|
|
public:
|
|
|
|
LocationClickHandler(const LocationCoords &coords) : _coords(coords) {
|
|
|
|
setup();
|
|
|
|
}
|
|
|
|
|
2016-04-29 12:00:48 +00:00
|
|
|
void onClick(Qt::MouseButton button) const override;
|
2016-04-12 21:31:28 +00:00
|
|
|
|
|
|
|
QString tooltip() const override {
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
2016-04-29 12:00:48 +00:00
|
|
|
QString dragText() const override {
|
2016-04-12 21:31:28 +00:00
|
|
|
return _text;
|
|
|
|
}
|
2016-04-29 12:00:48 +00:00
|
|
|
|
|
|
|
void copyToClipboard() const override {
|
|
|
|
if (!_text.isEmpty()) {
|
|
|
|
QApplication::clipboard()->setText(_text);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
QString copyToClipboardContextItemText() const override;
|
2016-04-12 21:31:28 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
void setup();
|
|
|
|
LocationCoords _coords;
|
|
|
|
QString _text;
|
|
|
|
|
|
|
|
};
|