-
Notifications
You must be signed in to change notification settings - Fork 7.2k
Expand file tree
/
Copy pathfacade.h
More file actions
128 lines (98 loc) · 3.59 KB
/
Copy pathfacade.h
File metadata and controls
128 lines (98 loc) · 3.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/*
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 "mtproto/type_utils.h"
#include "mtproto/mtp_instance.h"
namespace MTP {
namespace details {
[[nodiscard]] bool paused();
void pause();
void unpause();
[[nodiscard]] rpl::producer<> unpaused();
} // namespace details
// send(MTPhelp_GetConfig(), MTP::configDcId(dc)) - for dc enumeration
constexpr ShiftedDcId configDcId(DcId dcId) {
return ShiftDcId(dcId, kConfigDcShift);
}
// send(MTPauth_LogOut(), MTP::logoutDcId(dc)) - for logout of guest dcs enumeration
constexpr ShiftedDcId logoutDcId(DcId dcId) {
return ShiftDcId(dcId, kLogoutDcShift);
}
// send(MTPupload_GetFile(), MTP::updaterDcId(dc)) - for autoupdater
constexpr ShiftedDcId updaterDcId(DcId dcId) {
return ShiftDcId(dcId, kUpdaterDcShift);
}
// send(MTPupload_GetFile(), MTP::groupCallStreamDcId(dc)) - for group call stream
constexpr ShiftedDcId groupCallStreamDcId(DcId dcId) {
return ShiftDcId(dcId, kGroupCallStreamDcShift);
}
namespace details {
constexpr ShiftedDcId downloadDcId(DcId dcId, int index) {
Expects(index < kMaxMediaDcCount);
return ShiftDcId(dcId, kBaseDownloadDcShift + index);
};
} // namespace details
// send(req, callbacks, MTP::downloadDcId(dc, index)) - for download shifted dc id
inline ShiftedDcId downloadDcId(DcId dcId, int index) {
return details::downloadDcId(dcId, index);
}
inline constexpr bool isDownloadDcId(ShiftedDcId shiftedDcId) {
return (shiftedDcId >= details::downloadDcId(0, 0))
&& (shiftedDcId < details::downloadDcId(0, kMaxMediaDcCount - 1) + kDcShift);
}
inline constexpr bool isMediaClusterDcId(ShiftedDcId shiftedDcId) {
const auto shift = GetDcIdShift(shiftedDcId);
return isDownloadDcId(shiftedDcId)
|| (shift == kGroupCallStreamDcShift)
|| (shift == kExportMediaDcShift)
|| (shift == kUpdaterDcShift);
}
inline bool isCdnDc(MTPDdcOption::Flags flags) {
return (flags & MTPDdcOption::Flag::f_cdn);
}
inline bool isTemporaryDcId(ShiftedDcId shiftedDcId) {
auto dcId = BareDcId(shiftedDcId);
return (dcId >= Instance::Fields::kTemporaryMainDc);
}
inline DcId getRealIdFromTemporaryDcId(ShiftedDcId shiftedDcId) {
auto dcId = BareDcId(shiftedDcId);
return (dcId >= Instance::Fields::kTemporaryMainDc) ? (dcId - Instance::Fields::kTemporaryMainDc) : 0;
}
inline DcId getTemporaryIdFromRealDcId(ShiftedDcId shiftedDcId) {
auto dcId = BareDcId(shiftedDcId);
return (dcId < Instance::Fields::kTemporaryMainDc) ? (dcId + Instance::Fields::kTemporaryMainDc) : 0;
}
namespace details {
constexpr ShiftedDcId uploadDcId(DcId dcId, int index) {
return ShiftDcId(dcId, kBaseUploadDcShift + index);
};
} // namespace details
// send(req, callbacks, MTP::uploadDcId(index)) - for upload shifted dc id
// uploading always to the main dc so BareDcId(result) == 0
inline ShiftedDcId uploadDcId(int index) {
Expects(index >= 0 && index < kMaxMediaDcCount);
return details::uploadDcId(0, index);
};
constexpr bool isUploadDcId(ShiftedDcId shiftedDcId) {
return (shiftedDcId >= details::uploadDcId(0, 0))
&& (shiftedDcId < details::uploadDcId(0, kMaxMediaDcCount - 1) + kDcShift);
}
inline ShiftedDcId destroyKeyNextDcId(ShiftedDcId shiftedDcId) {
const auto shift = GetDcIdShift(shiftedDcId);
return ShiftDcId(BareDcId(shiftedDcId), shift ? (shift + 1) : kDestroyKeyStartDcShift);
}
enum {
DisconnectedState = 0,
ConnectingState = 1,
ConnectedState = 2,
};
enum {
RequestSent = 0,
RequestConnecting = 1,
RequestSending = 2
};
} // namespace MTP