tdesktop/Telegram/SourceFiles/data/data_types.h

291 lines
7.2 KiB
C
Raw Normal View History

/*
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 "base/value_ordering.h"
2018-07-13 21:25:47 +00:00
#include "ui/text/text.h" // For QFIXED_MAX
#include "data/data_peer_id.h"
2021-09-30 06:04:55 +00:00
#include "data/data_msg_id.h"
class HistoryItem;
using HistoryItemsList = std::vector<not_null<HistoryItem*>>;
class StorageImageLocation;
class WebFileLocation;
struct GeoPointLocation;
namespace Storage {
namespace Cache {
struct Key;
} // namespace Cache
} // namespace Storage
2018-05-21 21:31:46 +00:00
namespace Ui {
class InputField;
} // namespace Ui
namespace Images {
enum class Option;
using Options = base::flags<Option>;
} // namespace Images
namespace Data {
struct UploadState {
2022-05-10 14:22:28 +00:00
explicit UploadState(int64 size) : size(size) {
}
2022-05-10 14:22:28 +00:00
int64 offset = 0;
int64 size = 0;
bool waitingForAlbum = false;
};
Storage::Cache::Key DocumentCacheKey(int32 dcId, uint64 id);
Storage::Cache::Key DocumentThumbCacheKey(int32 dcId, uint64 id);
Storage::Cache::Key WebDocumentCacheKey(const WebFileLocation &location);
Storage::Cache::Key UrlCacheKey(const QString &location);
Storage::Cache::Key GeoPointCacheKey(const GeoPointLocation &location);
2022-08-01 12:14:37 +00:00
Storage::Cache::Key AudioAlbumThumbCacheKey(
const AudioAlbumThumbLocation &location);
constexpr auto kImageCacheTag = uint8(0x01);
constexpr auto kStickerCacheTag = uint8(0x02);
constexpr auto kVoiceMessageCacheTag = uint8(0x03);
constexpr auto kVideoMessageCacheTag = uint8(0x04);
constexpr auto kAnimationCacheTag = uint8(0x05);
struct FileOrigin;
} // namespace Data
struct MessageGroupId {
PeerId peer = 0;
2019-05-31 21:51:57 +00:00
uint64 value = 0;
MessageGroupId() = default;
static MessageGroupId FromRaw(PeerId peer, uint64 value) {
2019-05-31 21:51:57 +00:00
auto result = MessageGroupId();
result.peer = peer;
result.value = value;
return result;
}
bool empty() const {
2019-05-31 21:51:57 +00:00
return !value;
}
explicit operator bool() const {
return !empty();
}
2019-05-31 21:51:57 +00:00
uint64 raw() const {
return value;
}
2019-05-31 21:51:57 +00:00
friend inline std::pair<uint64, uint64> value_ordering_helper(MessageGroupId value) {
return std::make_pair(value.value, value.peer.value);
}
};
class PeerData;
class UserData;
class ChatData;
class ChannelData;
struct BotInfo;
namespace Data {
2019-04-15 11:54:03 +00:00
class Folder;
} // namespace Data
2019-04-15 11:54:03 +00:00
using FolderId = int32;
2020-02-07 09:43:12 +00:00
using FilterId = int32;
using MessageIdsList = std::vector<FullMsgId>;
2018-12-17 08:16:06 +00:00
PeerId PeerFromMessage(const MTPmessage &message);
MTPDmessage::Flags FlagsFromMessage(const MTPmessage &message);
MsgId IdFromMessage(const MTPmessage &message);
TimeId DateFromMessage(const MTPmessage &message);
2021-09-30 06:04:55 +00:00
[[nodiscard]] inline MTPint MTP_int(MsgId id) noexcept {
return MTP_int(id.bare);
}
class DocumentData;
class PhotoData;
struct WebPageData;
struct GameData;
2018-12-18 05:43:11 +00:00
struct PollData;
using PhotoId = uint64;
using VideoId = uint64;
using AudioId = uint64;
using DocumentId = uint64;
using WebPageId = uint64;
using GameId = uint64;
2018-12-18 05:43:11 +00:00
using PollId = uint64;
2019-01-16 12:25:29 +00:00
using WallPaperId = uint64;
2021-10-24 21:33:53 +00:00
using CallId = uint64;
constexpr auto CancelledWebPageId = WebPageId(0xFFFFFFFFFFFFFFFFULL);
struct PreparedPhotoThumb {
QImage image;
QByteArray bytes;
};
using PreparedPhotoThumbs = base::flat_map<char, PreparedPhotoThumb>;
// [0] == -1 -- counting, [0] == -2 -- could not count
using VoiceWaveform = QVector<signed char>;
enum LocationType {
UnknownFileLocation = 0,
// 1, 2, etc are used as "version" value in mediaKey() method.
DocumentFileLocation = 0x4e45abe9, // mtpc_inputDocumentFileLocation
AudioFileLocation = 0x74dc404d, // mtpc_inputAudioFileLocation
VideoFileLocation = 0x3d0364ec, // mtpc_inputVideoFileLocation
SecureFileLocation = 0xcbc7ee28, // mtpc_inputSecureFileLocation
};
enum FileStatus : signed char {
FileDownloadFailed = -2,
FileUploadFailed = -1,
FileReady = 1,
};
// Don't change the values. This type is used for serialization.
enum DocumentType {
FileDocument = 0,
VideoDocument = 1,
SongDocument = 2,
StickerDocument = 3,
AnimatedDocument = 4,
VoiceDocument = 5,
RoundVideoDocument = 6,
2019-01-16 12:25:29 +00:00
WallPaperDocument = 7,
};
inline constexpr auto kStickerSideSize = 512;
[[nodiscard]] bool GoodStickerDimensions(int width, int height);
using MediaKey = QPair<uint64, uint64>;
struct MessageCursor {
MessageCursor() = default;
MessageCursor(int position, int anchor, int scroll)
2018-05-21 21:31:46 +00:00
: position(position)
, anchor(anchor)
, scroll(scroll) {
}
2018-05-21 21:31:46 +00:00
MessageCursor(not_null<const Ui::InputField*> field) {
fillFrom(field);
}
2018-05-21 21:31:46 +00:00
void fillFrom(not_null<const Ui::InputField*> field);
void applyTo(not_null<Ui::InputField*> field);
int position = 0;
int anchor = 0;
int scroll = QFIXED_MAX;
};
inline bool operator==(
const MessageCursor &a,
const MessageCursor &b) {
return (a.position == b.position)
&& (a.anchor == b.anchor)
&& (a.scroll == b.scroll);
}
inline bool operator!=(
const MessageCursor &a,
const MessageCursor &b) {
return !(a == b);
}
struct StickerSetIdentifier {
uint64 id = 0;
uint64 accessHash = 0;
QString shortName;
[[nodiscard]] bool empty() const {
return !id && shortName.isEmpty();
}
[[nodiscard]] explicit operator bool() const {
return !empty();
}
};
2021-07-28 11:55:02 +00:00
enum class MessageFlag : uint64 {
HideEdited = (1ULL << 0),
Legacy = (1ULL << 1),
HasReplyMarkup = (1ULL << 2),
HasFromId = (1ULL << 3),
HasPostAuthor = (1ULL << 4),
HasViews = (1ULL << 5),
HasReplyInfo = (1ULL << 6),
CanViewReactions = (1ULL << 7),
AdminLogEntry = (1ULL << 8),
Post = (1ULL << 9),
Silent = (1ULL << 10),
Outgoing = (1ULL << 11),
Pinned = (1ULL << 12),
MediaIsUnread = (1ULL << 13),
HasUnreadReaction = (1ULL << 14),
MentionsMe = (1ULL << 15),
IsOrWasScheduled = (1ULL << 16),
NoForwards = (1ULL << 17),
2021-07-28 11:55:02 +00:00
// Needs to return back to inline mode.
2022-09-27 06:25:26 +00:00
HasSwitchInlineButton = (1ULL << 18),
2021-07-28 11:55:02 +00:00
// For "shared links" indexing.
2022-09-27 06:25:26 +00:00
HasTextLinks = (1ULL << 19),
2021-07-28 11:55:02 +00:00
// Group / channel create or migrate service message.
2022-09-27 06:25:26 +00:00
IsGroupEssential = (1ULL << 20),
2021-07-28 11:55:02 +00:00
// Edited media is generated on the client
// and should not update media from server.
2022-09-27 06:25:26 +00:00
IsLocalUpdateMedia = (1ULL << 21),
2021-07-28 11:55:02 +00:00
// Sent from inline bot, need to re-set media when sent.
2022-09-27 06:25:26 +00:00
FromInlineBot = (1ULL << 22),
2021-07-28 11:55:02 +00:00
// Generated on the client side and should be unread.
2022-09-27 06:25:26 +00:00
ClientSideUnread = (1ULL << 23),
2021-07-28 11:55:02 +00:00
// In a supergroup.
2022-09-27 06:25:26 +00:00
HasAdminBadge = (1ULL << 24),
2021-07-28 11:55:02 +00:00
// Outgoing message that is being sent.
2022-09-27 06:25:26 +00:00
BeingSent = (1ULL << 25),
2021-07-28 11:55:02 +00:00
// Outgoing message and failed to be sent.
2022-09-27 06:25:26 +00:00
SendingFailed = (1ULL << 26),
2021-07-28 11:55:02 +00:00
// No media and only a several emoji or an only custom emoji text.
2022-09-27 06:25:26 +00:00
SpecialOnlyEmoji = (1ULL << 27),
2021-07-28 11:55:02 +00:00
// Message existing in the message history.
2022-09-27 06:25:26 +00:00
HistoryEntry = (1ULL << 28),
// Local message, not existing on the server.
2022-09-27 06:25:26 +00:00
Local = (1ULL << 29),
2021-07-28 11:55:02 +00:00
// Fake message for some UI element.
2022-09-27 06:25:26 +00:00
FakeHistoryItem = (1ULL << 30),
// Contact sign-up message, notification should be skipped for Silent.
2022-09-27 06:25:26 +00:00
IsContactSignUp = (1ULL << 31),
// Optimization for item text custom emoji repainting.
2022-09-27 06:25:26 +00:00
CustomEmojiRepainting = (1ULL << 32),
2021-07-28 11:55:02 +00:00
};
inline constexpr bool is_flag_type(MessageFlag) { return true; }
using MessageFlags = base::flags<MessageFlag>;