Skip to content

Commit

Permalink
Extract some basic data definitions to data/data_types
Browse files Browse the repository at this point in the history
Related to #174.
Partially inspired by telegramdesktop/tdesktop@ffc20e4
  • Loading branch information
leha-bot committed Jul 24, 2019
1 parent 90e334d commit 8b03593
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 61 deletions.
103 changes: 103 additions & 0 deletions Telegram/SourceFiles/data/data_types.h
Original file line number Diff line number Diff line change
@@ -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 <qglobal.h>
#include <QPair>

using VideoId = quint64;
using AudioId = quint64;
using DocumentId = quint64;
using WebPageId = quint64;
using GameId = quint64;

using PeerId = quint64;

using MediaKey = QPair<quint64, quint64>;

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;
};
63 changes: 2 additions & 61 deletions Telegram/SourceFiles/structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<quint64, quint64>;

inline quint64 mediaMix32To64(qint32 a, qint32 b) {
return (quint64(*reinterpret_cast<quint32 *>(&a)) << 32) | quint64(*reinterpret_cast<quint32 *>(&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);
}
Expand All @@ -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;
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -1114,8 +1081,6 @@ inline bool PeerData::canWrite() const {
(isChat() ? asChat()->canWrite() : (isUser() ? asUser()->canWrite() : false));
}

enum ActionOnLoad { ActionOnLoadNone, ActionOnLoadOpen, ActionOnLoadOpenWith, ActionOnLoadPlayInline };

typedef QMap<char, QPixmap> PreparedPhotoThumbs;

enum FileStatus {
Expand Down Expand Up @@ -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;
};

0 comments on commit 8b03593

Please sign in to comment.