2014-05-30 08:53:19 +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.
|
2014-05-30 08:53:19 +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
|
2014-05-30 08:53:19 +00:00
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
2016-04-12 21:31:28 +00:00
|
|
|
#include "core/basic_types.h"
|
2018-01-13 12:45:11 +00:00
|
|
|
#include "data/data_types.h"
|
|
|
|
#include "data/data_peer.h"
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2018-01-13 12:45:11 +00:00
|
|
|
enum NewMessageType : char;
|
2017-02-23 10:59:19 +00:00
|
|
|
class Messenger;
|
2016-04-12 21:31:28 +00:00
|
|
|
class MainWindow;
|
2014-05-30 08:53:19 +00:00
|
|
|
class MainWidget;
|
2018-01-11 13:07:29 +00:00
|
|
|
class LocationCoords;
|
|
|
|
struct LocationData;
|
2018-01-11 19:33:26 +00:00
|
|
|
class HistoryItem;
|
2018-01-13 12:45:11 +00:00
|
|
|
class History;
|
|
|
|
class Histories;
|
2018-01-11 13:07:29 +00:00
|
|
|
namespace HistoryView {
|
2018-01-13 12:45:11 +00:00
|
|
|
class Element;
|
2018-01-11 13:07:29 +00:00
|
|
|
} // namespace HistoryView
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2018-01-11 19:33:26 +00:00
|
|
|
using HistoryItemsMap = base::flat_set<not_null<HistoryItem*>>;
|
2016-09-27 13:37:18 +00:00
|
|
|
using GifItems = QHash<Media::Clip::Reader*, HistoryItem*>;
|
2015-12-27 21:37:48 +00:00
|
|
|
|
2018-01-11 19:33:26 +00:00
|
|
|
enum RoundCorners {
|
|
|
|
SmallMaskCorners = 0x00, // for images
|
|
|
|
LargeMaskCorners,
|
|
|
|
|
|
|
|
BoxCorners,
|
|
|
|
MenuCorners,
|
|
|
|
BotKbOverCorners,
|
|
|
|
StickerCorners,
|
|
|
|
StickerSelectedCorners,
|
|
|
|
SelectedOverlaySmallCorners,
|
|
|
|
SelectedOverlayLargeCorners,
|
|
|
|
DateCorners,
|
|
|
|
DateSelectedCorners,
|
|
|
|
ForwardCorners,
|
|
|
|
MediaviewSaveCorners,
|
|
|
|
EmojiHoverCorners,
|
|
|
|
StickerHoverCorners,
|
|
|
|
BotKeyboardCorners,
|
|
|
|
PhotoSelectOverlayCorners,
|
|
|
|
|
|
|
|
Doc1Corners,
|
|
|
|
Doc2Corners,
|
|
|
|
Doc3Corners,
|
|
|
|
Doc4Corners,
|
|
|
|
|
|
|
|
InShadowCorners, // for photos without bg
|
|
|
|
InSelectedShadowCorners,
|
|
|
|
|
|
|
|
MessageInCorners, // with shadow
|
|
|
|
MessageInSelectedCorners,
|
|
|
|
MessageOutCorners,
|
|
|
|
MessageOutSelectedCorners,
|
|
|
|
|
|
|
|
RoundCornersCount
|
|
|
|
};
|
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
namespace App {
|
2016-04-12 21:31:28 +00:00
|
|
|
MainWindow *wnd();
|
2014-05-30 08:53:19 +00:00
|
|
|
MainWidget *main();
|
2015-03-02 12:34:16 +00:00
|
|
|
bool passcoded();
|
2014-05-30 08:53:19 +00:00
|
|
|
|
|
|
|
void logOut();
|
|
|
|
|
|
|
|
QString formatPhone(QString phone);
|
|
|
|
|
2016-07-08 16:59:46 +00:00
|
|
|
UserData *feedUser(const MTPUser &user);
|
2016-05-25 12:09:05 +00:00
|
|
|
UserData *feedUsers(const MTPVector<MTPUser> &users); // returns last user
|
2016-07-08 16:59:46 +00:00
|
|
|
PeerData *feedChat(const MTPChat &chat);
|
2016-05-25 12:09:05 +00:00
|
|
|
PeerData *feedChats(const MTPVector<MTPChat> &chats); // returns last chat
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2017-08-11 10:42:52 +00:00
|
|
|
void feedParticipants(const MTPChatParticipants &p, bool requestBotInfos);
|
|
|
|
void feedParticipantAdd(const MTPDupdateChatParticipantAdd &d);
|
|
|
|
void feedParticipantDelete(const MTPDupdateChatParticipantDelete &d);
|
|
|
|
void feedChatAdmins(const MTPDupdateChatAdmins &d);
|
|
|
|
void feedParticipantAdmin(const MTPDupdateChatParticipantAdmin &d);
|
2015-10-15 00:15:28 +00:00
|
|
|
bool checkEntitiesAndViewsUpdate(const MTPDmessage &m); // returns true if item found and it is not detached
|
2016-09-23 18:26:53 +00:00
|
|
|
void updateEditedMessage(const MTPMessage &m);
|
2015-12-27 21:37:48 +00:00
|
|
|
void addSavedGif(DocumentData *doc);
|
|
|
|
void checkSavedGif(HistoryItem *item);
|
2015-11-18 14:59:17 +00:00
|
|
|
void feedMsgs(const QVector<MTPMessage> &msgs, NewMessageType type);
|
2015-09-20 08:55:41 +00:00
|
|
|
void feedMsgs(const MTPVector<MTPMessage> &msgs, NewMessageType type);
|
2015-09-03 10:48:40 +00:00
|
|
|
void feedInboxRead(const PeerId &peer, MsgId upTo);
|
2016-06-22 18:41:13 +00:00
|
|
|
void feedOutboxRead(const PeerId &peer, MsgId upTo, TimeId when);
|
2015-09-03 10:48:40 +00:00
|
|
|
void feedWereDeleted(ChannelId channelId, const QVector<MTPint> &msgsIds);
|
2016-06-02 13:57:49 +00:00
|
|
|
void feedUserLink(MTPint userId, const MTPContactLink &myLink, const MTPContactLink &foreignLink);
|
2015-06-29 22:09:23 +00:00
|
|
|
|
2015-02-03 15:02:46 +00:00
|
|
|
ImagePtr image(const MTPPhotoSize &size);
|
|
|
|
|
2016-03-25 11:29:45 +00:00
|
|
|
PeerData *peer(const PeerId &id, PeerData::LoadedStatus restriction = PeerData::NotLoaded);
|
|
|
|
inline UserData *user(const PeerId &id, PeerData::LoadedStatus restriction = PeerData::NotLoaded) {
|
|
|
|
return asUser(peer(id, restriction));
|
|
|
|
}
|
|
|
|
inline ChatData *chat(const PeerId &id, PeerData::LoadedStatus restriction = PeerData::NotLoaded) {
|
|
|
|
return asChat(peer(id, restriction));
|
|
|
|
}
|
|
|
|
inline ChannelData *channel(const PeerId &id, PeerData::LoadedStatus restriction = PeerData::NotLoaded) {
|
|
|
|
return asChannel(peer(id, restriction));
|
|
|
|
}
|
|
|
|
inline UserData *user(UserId userId, PeerData::LoadedStatus restriction = PeerData::NotLoaded) {
|
|
|
|
return asUser(peer(peerFromUser(userId), restriction));
|
|
|
|
}
|
|
|
|
inline ChatData *chat(ChatId chatId, PeerData::LoadedStatus restriction = PeerData::NotLoaded) {
|
|
|
|
return asChat(peer(peerFromChat(chatId), restriction));
|
|
|
|
}
|
|
|
|
inline ChannelData *channel(ChannelId channelId, PeerData::LoadedStatus restriction = PeerData::NotLoaded) {
|
|
|
|
return asChannel(peer(peerFromChannel(channelId), restriction));
|
|
|
|
}
|
|
|
|
inline PeerData *peerLoaded(const PeerId &id) {
|
|
|
|
return peer(id, PeerData::FullLoaded);
|
|
|
|
}
|
|
|
|
inline UserData *userLoaded(const PeerId &id) {
|
|
|
|
return user(id, PeerData::FullLoaded);
|
|
|
|
}
|
|
|
|
inline ChatData *chatLoaded(const PeerId &id) {
|
|
|
|
return chat(id, PeerData::FullLoaded);
|
|
|
|
}
|
|
|
|
inline ChannelData *channelLoaded(const PeerId &id) {
|
|
|
|
return channel(id, PeerData::FullLoaded);
|
|
|
|
}
|
|
|
|
inline UserData *userLoaded(UserId userId) {
|
|
|
|
return user(userId, PeerData::FullLoaded);
|
|
|
|
}
|
|
|
|
inline ChatData *chatLoaded(ChatId chatId) {
|
|
|
|
return chat(chatId, PeerData::FullLoaded);
|
|
|
|
}
|
|
|
|
inline ChannelData *channelLoaded(ChannelId channelId) {
|
|
|
|
return channel(channelId, PeerData::FullLoaded);
|
|
|
|
}
|
2017-03-17 17:19:46 +00:00
|
|
|
void enumerateUsers(base::lambda<void(UserData*)> action);
|
2016-03-25 11:29:45 +00:00
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
UserData *self();
|
2015-12-28 22:06:27 +00:00
|
|
|
PeerData *peerByName(const QString &username);
|
2014-05-30 08:53:19 +00:00
|
|
|
QString peerName(const PeerData *peer, bool forDialogs = false);
|
2018-01-17 16:21:01 +00:00
|
|
|
|
2016-02-28 13:54:04 +00:00
|
|
|
LocationData *location(const LocationCoords &coords);
|
2014-11-12 20:18:00 +00:00
|
|
|
void forgetMedia();
|
2014-05-30 08:53:19 +00:00
|
|
|
|
|
|
|
MTPPhoto photoFromUserPhoto(MTPint userId, MTPint date, const MTPUserProfilePhoto &photo);
|
|
|
|
|
|
|
|
Histories &histories();
|
2017-08-31 17:53:03 +00:00
|
|
|
not_null<History*> history(const PeerId &peer);
|
2014-05-30 08:53:19 +00:00
|
|
|
History *historyLoaded(const PeerId &peer);
|
2015-09-03 10:48:40 +00:00
|
|
|
HistoryItem *histItemById(ChannelId channelId, MsgId itemId);
|
2017-08-31 17:53:03 +00:00
|
|
|
inline not_null<History*> history(const PeerData *peer) {
|
2017-08-17 09:06:26 +00:00
|
|
|
Assert(peer != nullptr);
|
2016-03-13 15:45:00 +00:00
|
|
|
return history(peer->id);
|
|
|
|
}
|
|
|
|
inline History *historyLoaded(const PeerData *peer) {
|
2016-03-22 15:23:34 +00:00
|
|
|
return peer ? historyLoaded(peer->id) : nullptr;
|
2016-03-13 15:45:00 +00:00
|
|
|
}
|
|
|
|
inline HistoryItem *histItemById(const ChannelData *channel, MsgId itemId) {
|
|
|
|
return histItemById(channel ? peerToChannel(channel->id) : 0, itemId);
|
|
|
|
}
|
2015-09-03 10:48:40 +00:00
|
|
|
inline HistoryItem *histItemById(const FullMsgId &msgId) {
|
|
|
|
return histItemById(msgId.channel, msgId.msg);
|
|
|
|
}
|
2018-01-19 17:10:58 +00:00
|
|
|
void historyRegItem(not_null<HistoryItem*> item);
|
|
|
|
void historyUnregItem(not_null<HistoryItem*> item);
|
|
|
|
void historyUpdateDependent(not_null<HistoryItem*> item);
|
2014-05-30 08:53:19 +00:00
|
|
|
void historyClearMsgs();
|
|
|
|
void historyClearItems();
|
2016-03-05 21:12:55 +00:00
|
|
|
void historyRegDependency(HistoryItem *dependent, HistoryItem *dependency);
|
|
|
|
void historyUnregDependency(HistoryItem *dependent, HistoryItem *dependency);
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2015-09-03 10:48:40 +00:00
|
|
|
void historyRegRandom(uint64 randomId, const FullMsgId &itemId);
|
2014-05-30 08:53:19 +00:00
|
|
|
void historyUnregRandom(uint64 randomId);
|
2015-09-03 10:48:40 +00:00
|
|
|
FullMsgId histItemByRandom(uint64 randomId);
|
|
|
|
void historyRegSentData(uint64 randomId, const PeerId &peerId, const QString &text);
|
|
|
|
void historyUnregSentData(uint64 randomId);
|
|
|
|
void histSentDataByItem(uint64 randomId, PeerId &peerId, QString &text);
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2018-01-11 19:33:26 +00:00
|
|
|
void hoveredItem(HistoryView::Element *item);
|
|
|
|
HistoryView::Element *hoveredItem();
|
|
|
|
void pressedItem(HistoryView::Element *item);
|
|
|
|
HistoryView::Element *pressedItem();
|
|
|
|
void hoveredLinkItem(HistoryView::Element *item);
|
|
|
|
HistoryView::Element *hoveredLinkItem();
|
|
|
|
void pressedLinkItem(HistoryView::Element *item);
|
|
|
|
HistoryView::Element *pressedLinkItem();
|
|
|
|
void mousedItem(HistoryView::Element *item);
|
|
|
|
HistoryView::Element *mousedItem();
|
2016-06-14 16:26:41 +00:00
|
|
|
void clearMousedItems();
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2015-10-23 16:06:56 +00:00
|
|
|
const style::font &monofont();
|
2015-10-06 19:49:23 +00:00
|
|
|
const QPixmap &emoji();
|
|
|
|
const QPixmap &emojiLarge();
|
2015-05-08 12:45:14 +00:00
|
|
|
const QPixmap &emojiSingle(EmojiPtr emoji, int32 fontHeight);
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2015-12-27 21:37:48 +00:00
|
|
|
void clearHistories();
|
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
void initMedia();
|
2015-12-27 21:37:48 +00:00
|
|
|
void deinitMedia();
|
2014-05-30 08:53:19 +00:00
|
|
|
|
|
|
|
void checkImageCacheSize();
|
|
|
|
|
|
|
|
bool isValidPhone(QString phone);
|
|
|
|
|
2016-03-02 18:34:42 +00:00
|
|
|
enum LaunchState {
|
|
|
|
Launched = 0,
|
|
|
|
QuitRequested = 1,
|
|
|
|
QuitProcessed = 2,
|
|
|
|
};
|
2014-05-30 08:53:19 +00:00
|
|
|
void quit();
|
2016-03-02 18:34:42 +00:00
|
|
|
bool quitting();
|
|
|
|
LaunchState launchState();
|
|
|
|
void setLaunchState(LaunchState state);
|
2016-10-28 12:44:28 +00:00
|
|
|
void restart();
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2016-11-28 15:45:07 +00:00
|
|
|
constexpr auto kFileSizeLimit = 1500 * 1024 * 1024; // Load files up to 1500mb
|
|
|
|
constexpr auto kImageSizeLimit = 64 * 1024 * 1024; // Open images up to 64mb jpg/png/gif
|
|
|
|
QImage readImage(QByteArray data, QByteArray *format = nullptr, bool opaque = true, bool *animated = nullptr);
|
|
|
|
QImage readImage(const QString &file, QByteArray *format = nullptr, bool opaque = true, bool *animated = nullptr, QByteArray *content = 0);
|
2016-05-27 10:57:11 +00:00
|
|
|
QPixmap pixmapFromImageInPlace(QImage &&image);
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2017-12-04 17:46:03 +00:00
|
|
|
void regMuted(not_null<PeerData*> peer, TimeMs changeIn);
|
|
|
|
void unregMuted(not_null<PeerData*> peer);
|
2015-04-30 13:53:36 +00:00
|
|
|
void updateMuted();
|
|
|
|
|
2017-12-18 17:50:25 +00:00
|
|
|
void complexOverlayRect(Painter &p, QRect rect, ImageRoundRadius radius, RectParts corners);
|
|
|
|
void complexLocationRect(Painter &p, QRect rect, ImageRoundRadius radius, RectParts corners);
|
2016-11-21 20:26:54 +00:00
|
|
|
|
2017-07-13 14:42:46 +00:00
|
|
|
QImage *cornersMask(ImageRoundRadius radius);
|
2016-12-23 13:21:01 +00:00
|
|
|
void roundRect(Painter &p, int32 x, int32 y, int32 w, int32 h, style::color bg, RoundCorners index, const style::color *shadow = nullptr, RectParts parts = RectPart::Full);
|
|
|
|
inline void roundRect(Painter &p, const QRect &rect, style::color bg, RoundCorners index, const style::color *shadow = nullptr, RectParts parts = RectPart::Full) {
|
2016-11-12 15:02:19 +00:00
|
|
|
return roundRect(p, rect.x(), rect.y(), rect.width(), rect.height(), bg, index, shadow, parts);
|
2015-05-20 19:28:24 +00:00
|
|
|
}
|
2016-12-23 13:21:01 +00:00
|
|
|
void roundShadow(Painter &p, int32 x, int32 y, int32 w, int32 h, style::color shadow, RoundCorners index, RectParts parts = RectPart::Full);
|
|
|
|
inline void roundShadow(Painter &p, const QRect &rect, style::color shadow, RoundCorners index, RectParts parts = RectPart::Full) {
|
2016-11-12 15:02:19 +00:00
|
|
|
return roundShadow(p, rect.x(), rect.y(), rect.width(), rect.height(), shadow, index, parts);
|
2015-05-22 11:14:52 +00:00
|
|
|
}
|
2016-12-23 13:21:01 +00:00
|
|
|
void roundRect(Painter &p, int32 x, int32 y, int32 w, int32 h, style::color bg, ImageRoundRadius radius, RectParts parts = RectPart::Full);
|
|
|
|
inline void roundRect(Painter &p, const QRect &rect, style::color bg, ImageRoundRadius radius, RectParts parts = RectPart::Full) {
|
2016-11-12 15:02:19 +00:00
|
|
|
return roundRect(p, rect.x(), rect.y(), rect.width(), rect.height(), bg, radius, parts);
|
2015-10-03 10:09:09 +00:00
|
|
|
}
|
2015-05-20 19:28:24 +00:00
|
|
|
|
2015-02-03 15:02:46 +00:00
|
|
|
struct WallPaper {
|
|
|
|
WallPaper(int32 id, ImagePtr thumb, ImagePtr full) : id(id), thumb(thumb), full(full) {
|
|
|
|
}
|
|
|
|
int32 id;
|
|
|
|
ImagePtr thumb;
|
|
|
|
ImagePtr full;
|
|
|
|
};
|
|
|
|
typedef QList<WallPaper> WallPapers;
|
|
|
|
DeclareSetting(WallPapers, ServerBackgrounds);
|
|
|
|
|
2015-11-20 13:34:37 +00:00
|
|
|
};
|