forked from telegramdesktop/tdesktop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
facades.cpp
830 lines (686 loc) · 24 KB
/
facades.cpp
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
/*
This file is part of Telegram Desktop,
the official desktop version of Telegram messaging app, see https://telegram.org
Telegram Desktop 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/telegramdesktop/tdesktop/blob/master/LICENSE
Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
*/
#include "stdafx.h"
#include "profile/profile_section_memento.h"
#include "core/vector_of_moveable.h"
#include "core/click_handler_types.h"
#include "observer_peer.h"
#include "mainwindow.h"
#include "mainwidget.h"
#include "application.h"
#include "boxes/confirmbox.h"
#include "layerwidget.h"
#include "lang.h"
#include "core/observer.h"
Q_DECLARE_METATYPE(ClickHandlerPtr);
Q_DECLARE_METATYPE(Qt::MouseButton);
Q_DECLARE_METATYPE(Ui::ShowWay);
namespace App {
namespace internal {
void CallDelayed(int duration, base::lambda<void()> &&lambda) {
QTimer::singleShot(duration, base::lambda_slot_once(App::app(), std_::move(lambda)), SLOT(action()));
}
} // namespace internal
void sendBotCommand(PeerData *peer, UserData *bot, const QString &cmd, MsgId replyTo) {
if (auto m = main()) {
m->sendBotCommand(peer, bot, cmd, replyTo);
}
}
void hideSingleUseKeyboard(const HistoryItem *msg) {
if (auto m = main()) {
m->hideSingleUseKeyboard(msg->history()->peer, msg->id);
}
}
bool insertBotCommand(const QString &cmd, bool specialGif) {
if (auto m = main()) {
return m->insertBotCommand(cmd, specialGif);
}
return false;
}
void activateBotCommand(const HistoryItem *msg, int row, int col) {
const HistoryMessageReplyMarkup::Button *button = nullptr;
if (auto markup = msg->Get<HistoryMessageReplyMarkup>()) {
if (row < markup->rows.size()) {
auto &buttonRow = markup->rows[row];
if (col < buttonRow.size()) {
button = &buttonRow.at(col);
}
}
}
if (!button) return;
using ButtonType = HistoryMessageReplyMarkup::Button::Type;
switch (button->type) {
case ButtonType::Default: {
// Copy string before passing it to the sending method
// because the original button can be destroyed inside.
MsgId replyTo = (msg->id > 0) ? msg->id : 0;
sendBotCommand(msg->history()->peer, msg->fromOriginal()->asUser(), QString(button->text), replyTo);
} break;
case ButtonType::Callback:
case ButtonType::Game: {
if (auto m = main()) {
m->app_sendBotCallback(button, msg, row, col);
}
} break;
case ButtonType::Url: {
auto url = QString::fromUtf8(button->data);
auto skipConfirmation = false;
if (auto bot = msg->getMessageBot()) {
if (bot->isVerified()) {
skipConfirmation = true;
}
}
if (skipConfirmation) {
UrlClickHandler::doOpen(url);
} else {
HiddenUrlClickHandler::doOpen(url);
}
} break;
case ButtonType::RequestLocation: {
hideSingleUseKeyboard(msg);
Ui::show(Box<InformBox>(lang(lng_bot_share_location_unavailable)));
} break;
case ButtonType::RequestPhone: {
hideSingleUseKeyboard(msg);
Ui::show(Box<ConfirmBox>(lang(lng_bot_share_phone), lang(lng_bot_share_phone_confirm), [peerId = msg->history()->peer->id] {
if (auto m = App::main()) {
m->onShareContact(peerId, App::self());
}
}));
} break;
case ButtonType::SwitchInlineSame:
case ButtonType::SwitchInline: {
if (auto m = App::main()) {
if (auto bot = msg->getMessageBot()) {
auto tryFastSwitch = [bot, &button, msgId = msg->id]() -> bool {
auto samePeer = (button->type == ButtonType::SwitchInlineSame);
if (samePeer) {
Notify::switchInlineBotButtonReceived(QString::fromUtf8(button->data), bot, msgId);
return true;
} else if (bot->botInfo && bot->botInfo->inlineReturnPeerId) {
if (Notify::switchInlineBotButtonReceived(QString::fromUtf8(button->data))) {
return true;
}
}
return false;
};
if (!tryFastSwitch()) {
m->inlineSwitchLayer('@' + bot->username + ' ' + QString::fromUtf8(button->data));
}
}
}
} break;
}
}
void searchByHashtag(const QString &tag, PeerData *inPeer) {
if (MainWidget *m = main()) m->searchMessages(tag + ' ', (inPeer && inPeer->isChannel() && !inPeer->isMegagroup()) ? inPeer : 0);
}
void openPeerByName(const QString &username, MsgId msgId, const QString &startToken) {
if (MainWidget *m = main()) m->openPeerByName(username, msgId, startToken);
}
void joinGroupByHash(const QString &hash) {
if (MainWidget *m = main()) m->joinGroupByHash(hash);
}
void stickersBox(const QString &name) {
if (MainWidget *m = main()) m->stickersBox(MTP_inputStickerSetShortName(MTP_string(name)));
}
void openLocalUrl(const QString &url) {
if (MainWidget *m = main()) m->openLocalUrl(url);
}
bool forward(const PeerId &peer, ForwardWhatMessages what) {
if (MainWidget *m = main()) return m->onForward(peer, what);
return false;
}
void removeDialog(History *history) {
if (MainWidget *m = main()) {
m->removeDialog(history);
}
}
void showSettings() {
if (auto w = wnd()) {
w->showSettings();
}
}
void activateClickHandler(ClickHandlerPtr handler, Qt::MouseButton button) {
if (auto w = wnd()) {
qRegisterMetaType<ClickHandlerPtr>();
qRegisterMetaType<Qt::MouseButton>();
QMetaObject::invokeMethod(w, "app_activateClickHandler", Qt::QueuedConnection, Q_ARG(ClickHandlerPtr, handler), Q_ARG(Qt::MouseButton, button));
}
}
void logOutDelayed() {
App::CallDelayed(1, App::app(), [] {
App::logOut();
});
}
} // namespace App
namespace Ui {
namespace internal {
void showBox(object_ptr<BoxContent> content, ShowLayerOptions options) {
if (auto w = App::wnd()) {
w->ui_showBox(std_::move(content), options);
}
}
} // namespace internal
void showMediaPreview(DocumentData *document) {
if (auto w = App::wnd()) {
w->ui_showMediaPreview(document);
}
}
void showMediaPreview(PhotoData *photo) {
if (auto w = App::wnd()) {
w->ui_showMediaPreview(photo);
}
}
void hideMediaPreview() {
if (auto w = App::wnd()) {
w->ui_hideMediaPreview();
}
}
void hideLayer(bool fast) {
if (auto w = App::wnd()) {
w->ui_showBox({ nullptr }, CloseOtherLayers | (fast ? ForceFastShowLayer : AnimatedShowLayer));
}
}
void hideSettingsAndLayer(bool fast) {
if (auto w = App::wnd()) {
w->ui_hideSettingsAndLayer(fast ? ForceFastShowLayer : AnimatedShowLayer);
}
}
bool isLayerShown() {
if (auto w = App::wnd()) return w->ui_isLayerShown();
return false;
}
bool isMediaViewShown() {
if (auto w = App::wnd()) return w->ui_isMediaViewShown();
return false;
}
bool isInlineItemBeingChosen() {
if (auto main = App::main()) {
return main->ui_isInlineItemBeingChosen();
}
return false;
}
void repaintHistoryItem(const HistoryItem *item) {
if (auto main = App::main()) {
main->ui_repaintHistoryItem(item);
}
}
void repaintInlineItem(const InlineBots::Layout::ItemBase *layout) {
if (!layout) return;
if (auto main = App::main()) {
main->ui_repaintInlineItem(layout);
}
}
bool isInlineItemVisible(const InlineBots::Layout::ItemBase *layout) {
if (auto main = App::main()) {
return main->ui_isInlineItemVisible(layout);
}
return false;
}
void autoplayMediaInlineAsync(const FullMsgId &msgId) {
if (auto main = App::main()) {
QMetaObject::invokeMethod(main, "ui_autoplayMediaInlineAsync", Qt::QueuedConnection, Q_ARG(qint32, msgId.channel), Q_ARG(qint32, msgId.msg));
}
}
void showPeerProfile(const PeerId &peer) {
if (auto main = App::main()) {
main->showWideSection(Profile::SectionMemento(App::peer(peer)));
}
}
void showPeerOverview(const PeerId &peer, MediaOverviewType type) {
if (auto m = App::main()) {
m->showMediaOverview(App::peer(peer), type);
}
}
void showPeerHistory(const PeerId &peer, MsgId msgId, ShowWay way) {
if (MainWidget *m = App::main()) m->ui_showPeerHistory(peer, msgId, way);
}
void showPeerHistoryAsync(const PeerId &peer, MsgId msgId, ShowWay way) {
if (MainWidget *m = App::main()) {
qRegisterMetaType<Ui::ShowWay>();
QMetaObject::invokeMethod(m, "ui_showPeerHistoryAsync", Qt::QueuedConnection, Q_ARG(quint64, peer), Q_ARG(qint32, msgId), Q_ARG(Ui::ShowWay, way));
}
}
PeerData *getPeerForMouseAction() {
if (auto w = App::wnd()) {
return w->ui_getPeerForMouseAction();
}
return nullptr;
}
bool hideWindowNoQuit() {
if (!App::quitting()) {
if (auto w = App::wnd()) {
return w->hideNoQuit();
}
}
return false;
}
bool skipPaintEvent(QWidget *widget, QPaintEvent *event) {
if (auto w = App::wnd()) {
if (w->contentOverlapped(widget, event)) {
return true;
}
}
return false;
}
} // namespace Ui
namespace Notify {
void userIsBotChanged(UserData *user) {
if (MainWidget *m = App::main()) m->notify_userIsBotChanged(user);
}
void userIsContactChanged(UserData *user, bool fromThisApp) {
if (MainWidget *m = App::main()) m->notify_userIsContactChanged(user, fromThisApp);
}
void botCommandsChanged(UserData *user) {
if (MainWidget *m = App::main()) {
m->notify_botCommandsChanged(user);
}
peerUpdatedDelayed(user, PeerUpdate::Flag::BotCommandsChanged);
}
void inlineBotRequesting(bool requesting) {
if (MainWidget *m = App::main()) m->notify_inlineBotRequesting(requesting);
}
void replyMarkupUpdated(const HistoryItem *item) {
if (MainWidget *m = App::main()) {
m->notify_replyMarkupUpdated(item);
}
}
void inlineKeyboardMoved(const HistoryItem *item, int oldKeyboardTop, int newKeyboardTop) {
if (MainWidget *m = App::main()) {
m->notify_inlineKeyboardMoved(item, oldKeyboardTop, newKeyboardTop);
}
}
bool switchInlineBotButtonReceived(const QString &query, UserData *samePeerBot, MsgId samePeerReplyTo) {
if (auto m = App::main()) {
return m->notify_switchInlineBotButtonReceived(query, samePeerBot, samePeerReplyTo);
}
return false;
}
void migrateUpdated(PeerData *peer) {
if (MainWidget *m = App::main()) m->notify_migrateUpdated(peer);
}
void clipStopperHidden(ClipStopperType type) {
if (MainWidget *m = App::main()) m->notify_clipStopperHidden(type);
}
void historyItemLayoutChanged(const HistoryItem *item) {
if (MainWidget *m = App::main()) m->notify_historyItemLayoutChanged(item);
}
void inlineItemLayoutChanged(const InlineBots::Layout::ItemBase *layout) {
if (MainWidget *m = App::main()) m->notify_inlineItemLayoutChanged(layout);
}
void historyMuteUpdated(History *history) {
if (MainWidget *m = App::main()) m->notify_historyMuteUpdated(history);
}
void handlePendingHistoryUpdate() {
if (MainWidget *m = App::main()) {
m->notify_handlePendingHistoryUpdate();
}
for_const (HistoryItem *item, Global::PendingRepaintItems()) {
Ui::repaintHistoryItem(item);
}
Global::RefPendingRepaintItems().clear();
}
void unreadCounterUpdated() {
Global::RefHandleUnreadCounterUpdate().call();
}
} // namespace Notify
#define DefineReadOnlyVar(Namespace, Type, Name) const Type &Name() { \
t_assert_full(Namespace##Data != 0, #Namespace "Data != nullptr in " #Namespace "::" #Name, __FILE__, __LINE__); \
return Namespace##Data->Name; \
}
#define DefineRefVar(Namespace, Type, Name) DefineReadOnlyVar(Namespace, Type, Name) \
Type &Ref##Name() { \
t_assert_full(Namespace##Data != 0, #Namespace "Data != nullptr in " #Namespace "::Ref" #Name, __FILE__, __LINE__); \
return Namespace##Data->Name; \
}
#define DefineVar(Namespace, Type, Name) DefineRefVar(Namespace, Type, Name) \
void Set##Name(const Type &Name) { \
t_assert_full(Namespace##Data != 0, #Namespace "Data != nullptr in " #Namespace "::Set" #Name, __FILE__, __LINE__); \
Namespace##Data->Name = Name; \
}
namespace Sandbox {
namespace internal {
struct Data {
QString LangSystemISO;
int32 LangSystem = languageDefault;
QByteArray LastCrashDump;
ProxyData PreLaunchProxy;
};
} // namespace internal
} // namespace Sandbox
Sandbox::internal::Data *SandboxData = nullptr;
uint64 SandboxUserTag = 0;
namespace Sandbox {
bool CheckBetaVersionDir() {
QFile beta(cExeDir() + qsl("TelegramBeta_data/tdata/beta"));
if (cBetaVersion()) {
cForceWorkingDir(cExeDir() + qsl("TelegramBeta_data/"));
QDir().mkpath(cWorkingDir() + qstr("tdata"));
if (*BetaPrivateKey) {
cSetBetaPrivateKey(QByteArray(BetaPrivateKey));
}
if (beta.open(QIODevice::WriteOnly)) {
QDataStream dataStream(&beta);
dataStream.setVersion(QDataStream::Qt_5_3);
dataStream << quint64(cRealBetaVersion()) << cBetaPrivateKey();
} else {
LOG(("FATAL: Could not open '%1' for writing private key!").arg(beta.fileName()));
return false;
}
} else if (beta.exists()) {
cForceWorkingDir(cExeDir() + qsl("TelegramBeta_data/"));
if (beta.open(QIODevice::ReadOnly)) {
QDataStream dataStream(&beta);
dataStream.setVersion(QDataStream::Qt_5_3);
quint64 v;
QByteArray k;
dataStream >> v >> k;
if (dataStream.status() == QDataStream::Ok) {
cSetBetaVersion(qMax(v, AppVersion * 1000ULL));
cSetBetaPrivateKey(k);
cSetRealBetaVersion(v);
} else {
LOG(("FATAL: '%1' is corrupted, reinstall private beta!").arg(beta.fileName()));
return false;
}
} else {
LOG(("FATAL: could not open '%1' for reading private key!").arg(beta.fileName()));
return false;
}
}
return true;
}
void WorkingDirReady() {
if (QFile(cWorkingDir() + qsl("tdata/withtestmode")).exists()) {
cSetTestMode(true);
}
if (!cDebug() && QFile(cWorkingDir() + qsl("tdata/withdebug")).exists()) {
cSetDebug(true);
}
if (cBetaVersion()) {
cSetAlphaVersion(false);
} else if (!cAlphaVersion() && QFile(cWorkingDir() + qsl("tdata/devversion")).exists()) {
cSetAlphaVersion(true);
} else if (AppAlphaVersion) {
QFile f(cWorkingDir() + qsl("tdata/devversion"));
if (!f.exists() && f.open(QIODevice::WriteOnly)) {
f.write("1");
}
}
srand((int32)time(NULL));
SandboxUserTag = 0;
QFile usertag(cWorkingDir() + qsl("tdata/usertag"));
if (usertag.open(QIODevice::ReadOnly)) {
if (usertag.read(reinterpret_cast<char*>(&SandboxUserTag), sizeof(uint64)) != sizeof(uint64)) {
SandboxUserTag = 0;
}
usertag.close();
}
if (!SandboxUserTag) {
do {
memsetrnd_bad(SandboxUserTag);
} while (!SandboxUserTag);
if (usertag.open(QIODevice::WriteOnly)) {
usertag.write(reinterpret_cast<char*>(&SandboxUserTag), sizeof(uint64));
usertag.close();
}
}
}
object_ptr<SingleDelayedCall> MainThreadTaskHandler = { nullptr };
void MainThreadTaskAdded() {
if (!started()) {
return;
}
MainThreadTaskHandler->call();
}
void start() {
MainThreadTaskHandler.create(QCoreApplication::instance(), "onMainThreadTask");
SandboxData = new internal::Data();
SandboxData->LangSystemISO = psCurrentLanguage();
if (SandboxData->LangSystemISO.isEmpty()) SandboxData->LangSystemISO = qstr("en");
auto l = LangSystemISO().toLatin1();
for (auto i = 0; i < languageCount; ++i) {
if (l.at(0) == LanguageCodes[i][0] && l.at(1) == LanguageCodes[i][1]) {
SandboxData->LangSystem = i;
break;
}
}
}
bool started() {
return (SandboxData != nullptr);
}
void finish() {
delete SandboxData;
SandboxData = nullptr;
MainThreadTaskHandler.destroy();
}
uint64 UserTag() {
return SandboxUserTag;
}
DefineReadOnlyVar(Sandbox, QString, LangSystemISO);
DefineReadOnlyVar(Sandbox, int32, LangSystem);
DefineVar(Sandbox, QByteArray, LastCrashDump);
DefineVar(Sandbox, ProxyData, PreLaunchProxy);
} // namespace Sandbox
namespace Stickers {
Set *feedSet(const MTPDstickerSet &set) {
MTPDstickerSet::Flags flags = 0;
auto &sets = Global::RefStickerSets();
auto it = sets.find(set.vid.v);
auto title = stickerSetTitle(set);
if (it == sets.cend()) {
it = sets.insert(set.vid.v, Stickers::Set(set.vid.v, set.vaccess_hash.v, title, qs(set.vshort_name), set.vcount.v, set.vhash.v, set.vflags.v | MTPDstickerSet_ClientFlag::f_not_loaded));
} else {
it->access = set.vaccess_hash.v;
it->title = title;
it->shortName = qs(set.vshort_name);
flags = it->flags;
auto clientFlags = it->flags & (MTPDstickerSet_ClientFlag::f_featured | MTPDstickerSet_ClientFlag::f_unread | MTPDstickerSet_ClientFlag::f_not_loaded | MTPDstickerSet_ClientFlag::f_special);
it->flags = set.vflags.v | clientFlags;
if (it->count != set.vcount.v || it->hash != set.vhash.v || it->emoji.isEmpty()) {
it->count = set.vcount.v;
it->hash = set.vhash.v;
it->flags |= MTPDstickerSet_ClientFlag::f_not_loaded; // need to request this set
}
}
auto changedFlags = (flags ^ it->flags);
if (changedFlags & MTPDstickerSet::Flag::f_archived) {
auto index = Global::ArchivedStickerSetsOrder().indexOf(it->id);
if (it->flags & MTPDstickerSet::Flag::f_archived) {
if (index < 0) {
Global::RefArchivedStickerSetsOrder().push_front(it->id);
}
} else if (index >= 0) {
Global::RefArchivedStickerSetsOrder().removeAt(index);
}
}
return &it.value();
}
} // namespace Stickers
namespace Global {
namespace internal {
struct Data {
uint64 LaunchId = 0;
SingleDelayedCall HandleHistoryUpdate = { App::app(), "call_handleHistoryUpdate" };
SingleDelayedCall HandleUnreadCounterUpdate = { App::app(), "call_handleUnreadCounterUpdate" };
SingleDelayedCall HandleFileDialogQueue = { App::app(), "call_handleFileDialogQueue" };
SingleDelayedCall HandleDelayedPeerUpdates = { App::app(), "call_handleDelayedPeerUpdates" };
SingleDelayedCall HandleObservables = { App::app(), "call_handleObservables" };
Adaptive::Layout AdaptiveLayout = Adaptive::NormalLayout;
bool AdaptiveForWide = true;
base::Observable<void> AdaptiveChanged;
bool DialogsModeEnabled = false;
Dialogs::Mode DialogsMode = Dialogs::Mode::All;
bool ModerateModeEnabled = false;
bool ScreenIsLocked = false;
int32 DebugLoggingFlags = 0;
float64 RememberedSongVolume = kDefaultVolume;
float64 SongVolume = kDefaultVolume;
base::Observable<void> SongVolumeChanged;
float64 VideoVolume = kDefaultVolume;
base::Observable<void> VideoVolumeChanged;
// config
int32 ChatSizeMax = 200;
int32 MegagroupSizeMax = 1000;
int32 ForwardedCountMax = 100;
int32 OnlineUpdatePeriod = 120000;
int32 OfflineBlurTimeout = 5000;
int32 OfflineIdleTimeout = 30000;
int32 OnlineFocusTimeout = 1000;
int32 OnlineCloudTimeout = 300000;
int32 NotifyCloudDelay = 30000;
int32 NotifyDefaultDelay = 1500;
int32 ChatBigSize = 10;
int32 PushChatPeriod = 60000;
int32 PushChatLimit = 2;
int32 SavedGifsLimit = 200;
int32 EditTimeLimit = 172800;
int32 StickersRecentLimit = 30;
int32 PinnedDialogsCountMax = 5;
HiddenPinnedMessagesMap HiddenPinnedMessages;
PendingItemsMap PendingRepaintItems;
Stickers::Sets StickerSets;
Stickers::Order StickerSetsOrder;
TimeMs LastStickersUpdate = 0;
TimeMs LastRecentStickersUpdate = 0;
Stickers::Order FeaturedStickerSetsOrder;
int FeaturedStickerSetsUnreadCount = 0;
base::Observable<void> FeaturedStickerSetsUnreadCountChanged;
TimeMs LastFeaturedStickersUpdate = 0;
Stickers::Order ArchivedStickerSetsOrder;
MTP::DcOptions DcOptions;
CircleMasksMap CircleMasks;
base::Observable<void> SelfChanged;
bool AskDownloadPath = false;
QString DownloadPath;
QByteArray DownloadPathBookmark;
base::Observable<void> DownloadPathChanged;
bool SoundNotify = true;
bool DesktopNotify = true;
bool RestoreSoundNotifyFromTray = false;
bool IncludeMuted = true;
DBINotifyView NotifyView = dbinvShowPreview;
bool NativeNotifications = false;
int NotificationsCount = 3;
Notify::ScreenCorner NotificationsCorner = Notify::ScreenCorner::BottomRight;
bool NotificationsDemoIsShown = false;
base::Observable<Notify::ChangeType> NotifySettingsChanged;
DBIConnectionType ConnectionType = dbictAuto;
bool TryIPv6 = (cPlatform() == dbipWindows) ? false : true;
ProxyData ConnectionProxy;
base::Observable<void> ConnectionTypeChanged;
base::Observable<void> ChooseCustomLang;
int AutoLock = 3600;
bool LocalPasscode = false;
base::Observable<void> LocalPasscodeChanged;
base::Observable<HistoryItem*> ItemRemoved;
base::Observable<void> UnreadCounterUpdate;
base::Observable<void> PeerChooseCancel;
};
} // namespace internal
} // namespace Global
Global::internal::Data *GlobalData = nullptr;
namespace Global {
bool started() {
return GlobalData != nullptr;
}
void start() {
GlobalData = new internal::Data();
memset_rand(&GlobalData->LaunchId, sizeof(GlobalData->LaunchId));
}
void finish() {
delete GlobalData;
GlobalData = nullptr;
}
DefineReadOnlyVar(Global, uint64, LaunchId);
DefineRefVar(Global, SingleDelayedCall, HandleHistoryUpdate);
DefineRefVar(Global, SingleDelayedCall, HandleUnreadCounterUpdate);
DefineRefVar(Global, SingleDelayedCall, HandleFileDialogQueue);
DefineRefVar(Global, SingleDelayedCall, HandleDelayedPeerUpdates);
DefineRefVar(Global, SingleDelayedCall, HandleObservables);
DefineVar(Global, Adaptive::Layout, AdaptiveLayout);
DefineVar(Global, bool, AdaptiveForWide);
DefineRefVar(Global, base::Observable<void>, AdaptiveChanged);
DefineVar(Global, bool, DialogsModeEnabled);
DefineVar(Global, Dialogs::Mode, DialogsMode);
DefineVar(Global, bool, ModerateModeEnabled);
DefineVar(Global, bool, ScreenIsLocked);
DefineVar(Global, int32, DebugLoggingFlags);
DefineVar(Global, float64, RememberedSongVolume);
DefineVar(Global, float64, SongVolume);
DefineRefVar(Global, base::Observable<void>, SongVolumeChanged);
DefineVar(Global, float64, VideoVolume);
DefineRefVar(Global, base::Observable<void>, VideoVolumeChanged);
// config
DefineVar(Global, int32, ChatSizeMax);
DefineVar(Global, int32, MegagroupSizeMax);
DefineVar(Global, int32, ForwardedCountMax);
DefineVar(Global, int32, OnlineUpdatePeriod);
DefineVar(Global, int32, OfflineBlurTimeout);
DefineVar(Global, int32, OfflineIdleTimeout);
DefineVar(Global, int32, OnlineFocusTimeout);
DefineVar(Global, int32, OnlineCloudTimeout);
DefineVar(Global, int32, NotifyCloudDelay);
DefineVar(Global, int32, NotifyDefaultDelay);
DefineVar(Global, int32, ChatBigSize);
DefineVar(Global, int32, PushChatPeriod);
DefineVar(Global, int32, PushChatLimit);
DefineVar(Global, int32, SavedGifsLimit);
DefineVar(Global, int32, EditTimeLimit);
DefineVar(Global, int32, StickersRecentLimit);
DefineVar(Global, int32, PinnedDialogsCountMax);
DefineVar(Global, HiddenPinnedMessagesMap, HiddenPinnedMessages);
DefineRefVar(Global, PendingItemsMap, PendingRepaintItems);
DefineVar(Global, Stickers::Sets, StickerSets);
DefineVar(Global, Stickers::Order, StickerSetsOrder);
DefineVar(Global, TimeMs, LastStickersUpdate);
DefineVar(Global, TimeMs, LastRecentStickersUpdate);
DefineVar(Global, Stickers::Order, FeaturedStickerSetsOrder);
DefineVar(Global, int, FeaturedStickerSetsUnreadCount);
DefineRefVar(Global, base::Observable<void>, FeaturedStickerSetsUnreadCountChanged);
DefineVar(Global, TimeMs, LastFeaturedStickersUpdate);
DefineVar(Global, Stickers::Order, ArchivedStickerSetsOrder);
DefineVar(Global, MTP::DcOptions, DcOptions);
DefineRefVar(Global, CircleMasksMap, CircleMasks);
DefineRefVar(Global, base::Observable<void>, SelfChanged);
DefineVar(Global, bool, AskDownloadPath);
DefineVar(Global, QString, DownloadPath);
DefineVar(Global, QByteArray, DownloadPathBookmark);
DefineRefVar(Global, base::Observable<void>, DownloadPathChanged);
DefineVar(Global, bool, SoundNotify);
DefineVar(Global, bool, DesktopNotify);
DefineVar(Global, bool, RestoreSoundNotifyFromTray);
DefineVar(Global, bool, IncludeMuted);
DefineVar(Global, DBINotifyView, NotifyView);
DefineVar(Global, bool, NativeNotifications);
DefineVar(Global, int, NotificationsCount);
DefineVar(Global, Notify::ScreenCorner, NotificationsCorner);
DefineVar(Global, bool, NotificationsDemoIsShown);
DefineRefVar(Global, base::Observable<Notify::ChangeType>, NotifySettingsChanged);
DefineVar(Global, DBIConnectionType, ConnectionType);
DefineVar(Global, bool, TryIPv6);
DefineVar(Global, ProxyData, ConnectionProxy);
DefineRefVar(Global, base::Observable<void>, ConnectionTypeChanged);
DefineRefVar(Global, base::Observable<void>, ChooseCustomLang);
DefineVar(Global, int, AutoLock);
DefineVar(Global, bool, LocalPasscode);
DefineRefVar(Global, base::Observable<void>, LocalPasscodeChanged);
DefineRefVar(Global, base::Observable<HistoryItem*>, ItemRemoved);
DefineRefVar(Global, base::Observable<void>, UnreadCounterUpdate);
DefineRefVar(Global, base::Observable<void>, PeerChooseCancel);
} // namespace Global