From 620d46393a2ef2689062d6ace94a839adb078a92 Mon Sep 17 00:00:00 2001 From: leha-bot Date: Tue, 23 Jul 2019 19:47:14 +0300 Subject: [PATCH] Extract some basic data definitions to data/data_types Related to #174. Partially inspired by https://github.com/telegramdesktop/tdesktop/commit/ffc20e44920465a4181320a050e22d4c599d0b12 --- Telegram/SourceFiles/data/data_types.h | 103 +++++++++++++++++++++++++ Telegram/SourceFiles/structs.h | 63 +-------------- 2 files changed, 105 insertions(+), 61 deletions(-) create mode 100644 Telegram/SourceFiles/data/data_types.h diff --git a/Telegram/SourceFiles/data/data_types.h b/Telegram/SourceFiles/data/data_types.h new file mode 100644 index 000000000..b746fcf23 --- /dev/null +++ b/Telegram/SourceFiles/data/data_types.h @@ -0,0 +1,103 @@ +// +// This file is part of Kepka, +// an unofficial desktop version of Telegram messaging app, +// see https://github.com/procxx/kepka +// +// Kepka 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. +// +// In addition, as a special exception, the copyright holders give permission +// to link the code of portions of this program with the OpenSSL library. +// +// Full license: https://github.com/procxx/kepka/blob/master/LICENSE +// Copyright (c) 2019- Kepka Contributors, https://github.com/procxx +// +/// @file data/data_types.h Common types, functions for data_types. +#pragma once + +#include +#include + +using VideoId = quint64; +using AudioId = quint64; +using DocumentId = quint64; +using WebPageId = quint64; +using GameId = quint64; + +using PeerId = quint64; + +using MediaKey = QPair; + +enum ActionOnLoad { ActionOnLoadNone, ActionOnLoadOpen, ActionOnLoadOpenWith, ActionOnLoadPlayInline }; + +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 +}; + +typedef qint32 UserId; +typedef qint32 ChatId; +typedef qint32 ChannelId; +constexpr ChannelId NoChannel = 0; + +typedef qint32 MsgId; + +/// @defgroup data_types.Constants +/// @{ + +constexpr const MsgId StartClientMsgId = -0x7FFFFFFF; +constexpr const MsgId EndClientMsgId = -0x40000000; +constexpr const MsgId ShowAtTheEndMsgId = -0x40000000; +constexpr const MsgId SwitchAtTopMsgId = -0x3FFFFFFF; +constexpr const MsgId ShowAtProfileMsgId = -0x3FFFFFFE; +constexpr const MsgId ShowAndStartBotMsgId = -0x3FFFFFD; +constexpr const MsgId ShowAtGameShareMsgId = -0x3FFFFFC; +constexpr const MsgId ServerMaxMsgId = 0x3FFFFFFF; +constexpr const MsgId ShowAtUnreadMsgId = 0; + +/// @} + +struct FullMsgId { + FullMsgId() = default; + FullMsgId(ChannelId channel, MsgId msg) + : channel(channel) + , msg(msg) {} + ChannelId channel = NoChannel; + MsgId msg = 0; +}; + +/// @brief Represents user continuous action. +struct SendAction { + enum class Type { + Typing, + RecordVideo, + UploadVideo, + RecordVoice, + UploadVoice, + RecordRound, + UploadRound, + UploadPhoto, + UploadFile, + ChooseLocation, + ChooseContact, + PlayGame, + }; + SendAction(Type type, TimeMs until, int progress = 0) + : type(type) + , until(until) + , progress(progress) {} + Type type; + TimeMs until; + int progress; +}; diff --git a/Telegram/SourceFiles/structs.h b/Telegram/SourceFiles/structs.h index 8143db697..444d0c678 100644 --- a/Telegram/SourceFiles/structs.h +++ b/Telegram/SourceFiles/structs.h @@ -31,28 +31,19 @@ #include "ui/images.h" #include "ui/text/text.h" #include "ui/twidget.h" +#include "data/data_types.h" #include "data/data_photo.h" -using MediaKey = QPair; - inline quint64 mediaMix32To64(qint32 a, qint32 b) { return (quint64(*reinterpret_cast(&a)) << 32) | quint64(*reinterpret_cast(&b)); } -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 -}; - // Old method, should not be used anymore. // inline MediaKey mediaKey(LocationType type, qint32 dc, const quint64 &id) { // return MediaKey(mediaMix32To64(type, dc), id); //} // New method when version was introduced, type is not relevant anymore (all files are Documents). + inline MediaKey mediaKey(LocationType type, qint32 dc, const quint64 &id, qint32 version) { return (version > 0) ? MediaKey(mediaMix32To64(version, dc), id) : MediaKey(mediaMix32To64(type, dc), id); } @@ -61,21 +52,6 @@ inline StorageKey mediaKey(const MTPDfileLocation &location) { return storageKey(location.vdc_id.v, location.vvolume_id.v, location.vlocal_id.v); } -typedef qint32 UserId; -typedef qint32 ChatId; -typedef qint32 ChannelId; -static const ChannelId NoChannel = 0; - -typedef qint32 MsgId; -struct FullMsgId { - FullMsgId() = default; - FullMsgId(ChannelId channel, MsgId msg) - : channel(channel) - , msg(msg) {} - ChannelId channel = NoChannel; - MsgId msg = 0; -}; - typedef quint64 PeerId; static const quint64 PeerIdMask = 0xFFFFFFFFULL; static const quint64 PeerIdTypeMask = 0x300000000ULL; @@ -197,18 +173,9 @@ inline bool operator<(const FullMsgId &a, const FullMsgId &b) { return a.channel < b.channel; } -constexpr const MsgId StartClientMsgId = -0x7FFFFFFF; -constexpr const MsgId EndClientMsgId = -0x40000000; inline constexpr bool isClientMsgId(MsgId id) { return id >= StartClientMsgId && id < EndClientMsgId; } -constexpr const MsgId ShowAtTheEndMsgId = -0x40000000; -constexpr const MsgId SwitchAtTopMsgId = -0x3FFFFFFF; -constexpr const MsgId ShowAtProfileMsgId = -0x3FFFFFFE; -constexpr const MsgId ShowAndStartBotMsgId = -0x3FFFFFD; -constexpr const MsgId ShowAtGameShareMsgId = -0x3FFFFFC; -constexpr const MsgId ServerMaxMsgId = 0x3FFFFFFF; -constexpr const MsgId ShowAtUnreadMsgId = 0; struct NotifySettings { NotifySettings() @@ -1114,8 +1081,6 @@ inline bool PeerData::canWrite() const { (isChat() ? asChat()->canWrite() : (isUser() ? asUser()->canWrite() : false)); } -enum ActionOnLoad { ActionOnLoadNone, ActionOnLoadOpen, ActionOnLoadOpenWith, ActionOnLoadPlayInline }; - typedef QMap PreparedPhotoThumbs; enum FileStatus { @@ -1589,27 +1554,3 @@ struct MessageCursor { inline bool operator==(const MessageCursor &a, const MessageCursor &b) { return (a.position == b.position) && (a.anchor == b.anchor) && (a.scroll == b.scroll); } - -struct SendAction { - enum class Type { - Typing, - RecordVideo, - UploadVideo, - RecordVoice, - UploadVoice, - RecordRound, - UploadRound, - UploadPhoto, - UploadFile, - ChooseLocation, - ChooseContact, - PlayGame, - }; - SendAction(Type type, TimeMs until, int progress = 0) - : type(type) - , until(until) - , progress(progress) {} - Type type; - TimeMs until; - int progress; -};