2014-05-30 08:53:19 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2014-12-01 10:47:38 +00:00
|
|
|
the official desktop version of Telegram messaging app, see https://telegram.org
|
2014-05-30 08:53:19 +00:00
|
|
|
|
|
|
|
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.
|
|
|
|
|
2015-10-03 13:16:42 +00:00
|
|
|
In addition, as a special exception, the copyright holders give permission
|
|
|
|
to link the code of portions of this program with the OpenSSL library.
|
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE
|
2017-01-11 18:31:31 +00:00
|
|
|
Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
2014-05-30 08:53:19 +00:00
|
|
|
*/
|
|
|
|
#include "stdafx.h"
|
2016-04-09 20:41:20 +00:00
|
|
|
#include "app.h"
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2016-08-30 05:24:16 +00:00
|
|
|
#ifdef OS_MAC_OLD
|
2016-04-21 17:57:29 +00:00
|
|
|
#include <libexif/exif-data.h>
|
2016-08-30 05:24:16 +00:00
|
|
|
#endif // OS_MAC_OLD
|
2016-04-21 17:57:29 +00:00
|
|
|
|
|
|
|
#include "styles/style_overview.h"
|
2016-08-03 11:02:53 +00:00
|
|
|
#include "styles/style_mediaview.h"
|
2016-10-27 14:10:28 +00:00
|
|
|
#include "styles/style_stickers.h"
|
2016-11-16 10:44:06 +00:00
|
|
|
#include "styles/style_history.h"
|
2016-12-13 17:07:56 +00:00
|
|
|
#include "styles/style_boxes.h"
|
2016-04-09 20:41:20 +00:00
|
|
|
#include "lang.h"
|
2016-06-09 11:51:24 +00:00
|
|
|
#include "data/data_abstract_structure.h"
|
|
|
|
#include "history/history_service_layout.h"
|
2016-09-27 13:37:18 +00:00
|
|
|
#include "history/history_location_manager.h"
|
2016-09-28 10:15:03 +00:00
|
|
|
#include "history/history_media_types.h"
|
2016-07-05 17:44:02 +00:00
|
|
|
#include "media/media_audio.h"
|
2016-07-08 13:56:53 +00:00
|
|
|
#include "inline_bots/inline_bot_layout_item.h"
|
2014-05-30 08:53:19 +00:00
|
|
|
#include "application.h"
|
|
|
|
#include "fileuploader.h"
|
|
|
|
#include "mainwidget.h"
|
2014-11-22 09:45:04 +00:00
|
|
|
#include "localstorage.h"
|
2016-04-12 21:31:28 +00:00
|
|
|
#include "apiwrap.h"
|
2015-07-21 14:55:23 +00:00
|
|
|
#include "numbers.h"
|
2016-05-24 16:13:07 +00:00
|
|
|
#include "observer_peer.h"
|
2016-10-28 12:44:28 +00:00
|
|
|
#include "window/window_theme.h"
|
2016-10-02 13:54:27 +00:00
|
|
|
#include "window/notifications_manager.h"
|
2016-10-17 10:55:17 +00:00
|
|
|
#include "platform/platform_notifications_manager.h"
|
2015-07-21 14:55:23 +00:00
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
namespace {
|
2016-03-02 18:34:42 +00:00
|
|
|
App::LaunchState _launchState = App::Launched;
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2016-09-27 13:37:18 +00:00
|
|
|
UserData *self = nullptr;
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2016-09-27 13:37:18 +00:00
|
|
|
using PeersData = QHash<PeerId, PeerData*>;
|
2014-05-30 08:53:19 +00:00
|
|
|
PeersData peersData;
|
|
|
|
|
2016-09-27 13:37:18 +00:00
|
|
|
using MutedPeers = QMap<PeerData*, bool>;
|
2015-04-30 13:53:36 +00:00
|
|
|
MutedPeers mutedPeers;
|
|
|
|
|
2016-09-27 13:37:18 +00:00
|
|
|
using UpdatedPeers = QMap<PeerData*, bool>;
|
2015-06-29 22:09:23 +00:00
|
|
|
UpdatedPeers updatedPeers;
|
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
PhotosData photosData;
|
2015-12-27 21:37:48 +00:00
|
|
|
DocumentsData documentsData;
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2016-09-27 13:37:18 +00:00
|
|
|
using LocationsData = QHash<LocationCoords, LocationData*>;
|
2016-02-28 13:54:04 +00:00
|
|
|
LocationsData locationsData;
|
2014-11-12 20:18:00 +00:00
|
|
|
|
2016-09-27 13:37:18 +00:00
|
|
|
using WebPagesData = QHash<WebPageId, WebPageData*>;
|
2015-04-04 20:01:34 +00:00
|
|
|
WebPagesData webPagesData;
|
|
|
|
|
2016-09-27 13:37:18 +00:00
|
|
|
using GamesData = QHash<GameId, GameData*>;
|
|
|
|
GamesData gamesData;
|
|
|
|
|
2015-12-25 13:09:14 +00:00
|
|
|
PhotoItems photoItems;
|
2014-05-30 08:53:19 +00:00
|
|
|
DocumentItems documentItems;
|
2015-04-04 20:01:34 +00:00
|
|
|
WebPageItems webPageItems;
|
2016-09-27 13:37:18 +00:00
|
|
|
GameItems gameItems;
|
2015-12-12 22:29:33 +00:00
|
|
|
SharedContactItems sharedContactItems;
|
2015-12-15 14:50:51 +00:00
|
|
|
GifItems gifItems;
|
2015-12-12 22:29:33 +00:00
|
|
|
|
2016-09-27 13:37:18 +00:00
|
|
|
using DependentItemsSet = OrderedSet<HistoryItem*>;
|
|
|
|
using DependentItems = QMap<HistoryItem*, DependentItemsSet>;
|
2016-03-05 21:12:55 +00:00
|
|
|
DependentItems dependentItems;
|
2014-05-30 08:53:19 +00:00
|
|
|
|
|
|
|
Histories histories;
|
|
|
|
|
2016-09-27 13:37:18 +00:00
|
|
|
using MsgsData = QHash<MsgId, HistoryItem*>;
|
2014-05-30 08:53:19 +00:00
|
|
|
MsgsData msgsData;
|
2016-09-27 13:37:18 +00:00
|
|
|
using ChannelMsgsData = QMap<ChannelId, MsgsData>;
|
2015-09-03 10:48:40 +00:00
|
|
|
ChannelMsgsData channelMsgsData;
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2016-09-27 13:37:18 +00:00
|
|
|
using RandomData = QMap<uint64, FullMsgId>;
|
2014-05-30 08:53:19 +00:00
|
|
|
RandomData randomData;
|
|
|
|
|
2016-09-27 13:37:18 +00:00
|
|
|
using SentData = QMap<uint64, QPair<PeerId, QString>>;
|
2015-09-03 10:48:40 +00:00
|
|
|
SentData sentData;
|
2015-08-24 10:53:04 +00:00
|
|
|
|
2016-06-14 16:26:41 +00:00
|
|
|
HistoryItem *hoveredItem = nullptr,
|
|
|
|
*pressedItem = nullptr,
|
|
|
|
*hoveredLinkItem = nullptr,
|
|
|
|
*pressedLinkItem = nullptr,
|
|
|
|
*contextItem = nullptr,
|
|
|
|
*mousedItem = nullptr;
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2016-09-27 13:37:18 +00:00
|
|
|
QPixmap *emoji = nullptr, *emojiLarge = nullptr;
|
2015-10-23 16:06:56 +00:00
|
|
|
style::font monofont;
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2015-10-03 10:09:09 +00:00
|
|
|
struct CornersPixmaps {
|
|
|
|
CornersPixmaps() {
|
|
|
|
memset(p, 0, sizeof(p));
|
|
|
|
}
|
|
|
|
QPixmap *p[4];
|
|
|
|
};
|
|
|
|
CornersPixmaps corners[RoundCornersCount];
|
2016-09-27 13:37:18 +00:00
|
|
|
using CornersMap = QMap<uint32, CornersPixmaps>;
|
2015-10-03 10:09:09 +00:00
|
|
|
CornersMap cornersMap;
|
2016-09-27 13:37:18 +00:00
|
|
|
QImage *cornersMaskLarge[4] = { nullptr }, *cornersMaskSmall[4] = { nullptr };
|
2015-05-20 19:28:24 +00:00
|
|
|
|
2016-09-27 13:37:18 +00:00
|
|
|
using EmojiMap = QMap<uint64, QPixmap>;
|
2015-10-06 19:49:23 +00:00
|
|
|
EmojiMap mainEmojiMap;
|
|
|
|
QMap<int32, EmojiMap> otherEmojiMap;
|
2014-05-30 08:53:19 +00:00
|
|
|
|
|
|
|
int32 serviceImageCacheSize = 0;
|
|
|
|
|
2016-09-27 13:37:18 +00:00
|
|
|
using LastPhotosList = QLinkedList<PhotoData*>;
|
2014-05-30 08:53:19 +00:00
|
|
|
LastPhotosList lastPhotos;
|
2016-09-27 13:37:18 +00:00
|
|
|
using LastPhotosMap = QHash<PhotoData*, LastPhotosList::iterator>;
|
2014-05-30 08:53:19 +00:00
|
|
|
LastPhotosMap lastPhotosMap;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace App {
|
|
|
|
|
|
|
|
QString formatPhone(QString phone) {
|
2015-07-21 14:55:23 +00:00
|
|
|
if (phone.isEmpty()) return QString();
|
2016-06-08 16:40:33 +00:00
|
|
|
if (phone.at(0) == '0') return phone;
|
|
|
|
|
2015-07-21 14:55:23 +00:00
|
|
|
QString number = phone;
|
|
|
|
for (const QChar *ch = phone.constData(), *e = ch + phone.size(); ch != e; ++ch) {
|
|
|
|
if (ch->unicode() < '0' || ch->unicode() > '9') {
|
|
|
|
number = phone.replace(QRegularExpression(qsl("[^\\d]")), QString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
QVector<int> groups = phoneNumberParse(number);
|
|
|
|
if (groups.isEmpty()) return '+' + number;
|
|
|
|
|
|
|
|
QString result;
|
|
|
|
result.reserve(number.size() + groups.size() + 1);
|
|
|
|
result.append('+');
|
|
|
|
int32 sum = 0;
|
|
|
|
for (int32 i = 0, l = groups.size(); i < l; ++i) {
|
|
|
|
result.append(number.midRef(sum, groups.at(i)));
|
|
|
|
sum += groups.at(i);
|
|
|
|
if (sum < number.size()) result.append(' ');
|
|
|
|
}
|
|
|
|
if (sum < number.size()) result.append(number.midRef(sum));
|
|
|
|
return result;
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2016-01-11 15:43:29 +00:00
|
|
|
AppClass *app() {
|
|
|
|
return AppClass::app();
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2016-04-12 21:31:28 +00:00
|
|
|
MainWindow *wnd() {
|
2016-01-11 15:43:29 +00:00
|
|
|
return AppClass::wnd();
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
MainWidget *main() {
|
2016-04-12 21:31:28 +00:00
|
|
|
if (auto w = wnd()) {
|
|
|
|
return w->mainWidget();
|
|
|
|
}
|
|
|
|
return nullptr;
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2015-03-02 12:34:16 +00:00
|
|
|
bool passcoded() {
|
2016-04-12 21:31:28 +00:00
|
|
|
if (auto w = wnd()) {
|
|
|
|
return w->passcodeWidget();
|
|
|
|
}
|
|
|
|
return false;
|
2015-03-02 12:34:16 +00:00
|
|
|
}
|
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
FileUploader *uploader() {
|
|
|
|
return app() ? app()->uploader() : 0;
|
|
|
|
}
|
|
|
|
|
2015-03-19 09:18:19 +00:00
|
|
|
ApiWrap *api() {
|
|
|
|
return main() ? main()->api() : 0;
|
|
|
|
}
|
|
|
|
|
2016-03-31 14:06:40 +00:00
|
|
|
namespace {
|
2014-05-30 08:53:19 +00:00
|
|
|
bool loggedOut() {
|
2016-08-28 19:16:23 +00:00
|
|
|
if (Global::LocalPasscode()) {
|
|
|
|
Global::SetLocalPasscode(false);
|
|
|
|
Global::RefLocalPasscodeChanged().notify();
|
2015-03-02 12:34:16 +00:00
|
|
|
}
|
2017-01-19 08:24:43 +00:00
|
|
|
Media::Player::mixer()->stopAndClear();
|
2016-04-12 21:31:28 +00:00
|
|
|
if (auto w = wnd()) {
|
2014-11-22 09:45:04 +00:00
|
|
|
w->tempDirDelete(Local::ClearManagerAll);
|
2014-07-06 03:32:21 +00:00
|
|
|
w->notifyClearFast();
|
2016-11-04 19:50:35 +00:00
|
|
|
w->setupIntro();
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
2016-09-21 11:44:20 +00:00
|
|
|
MTP::setAuthedId(0);
|
2015-03-02 12:34:16 +00:00
|
|
|
Local::reset();
|
2016-10-28 12:44:28 +00:00
|
|
|
Window::Theme::Background()->reset();
|
2015-03-02 12:34:16 +00:00
|
|
|
|
2015-01-26 13:04:41 +00:00
|
|
|
cSetOtherOnline(0);
|
2014-05-30 08:53:19 +00:00
|
|
|
histories().clear();
|
|
|
|
globalNotifyAllPtr = UnknownNotifySettings;
|
|
|
|
globalNotifyUsersPtr = UnknownNotifySettings;
|
|
|
|
globalNotifyChatsPtr = UnknownNotifySettings;
|
2015-12-28 17:23:27 +00:00
|
|
|
if (App::uploader()) App::uploader()->clear();
|
2014-05-30 08:53:19 +00:00
|
|
|
clearStorageImages();
|
2016-04-12 21:31:28 +00:00
|
|
|
if (auto w = wnd()) {
|
2016-09-21 11:44:20 +00:00
|
|
|
w->updateConnectingStatus();
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2016-03-31 14:06:40 +00:00
|
|
|
} // namespace
|
2014-05-30 08:53:19 +00:00
|
|
|
|
|
|
|
void logOut() {
|
2015-03-02 12:34:16 +00:00
|
|
|
if (MTP::started()) {
|
|
|
|
MTP::logoutKeys(rpcDone(&loggedOut), rpcFail(&loggedOut));
|
|
|
|
} else {
|
|
|
|
loggedOut();
|
|
|
|
MTP::start();
|
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2016-06-03 07:20:24 +00:00
|
|
|
TimeId onlineForSort(UserData *user, TimeId now) {
|
2015-06-10 12:48:26 +00:00
|
|
|
if (isServiceUser(user->id) || user->botInfo) {
|
2015-06-15 17:19:24 +00:00
|
|
|
return -1;
|
2015-06-10 12:48:26 +00:00
|
|
|
}
|
2016-06-03 07:20:24 +00:00
|
|
|
TimeId online = user->onlineTill;
|
2014-11-18 12:41:33 +00:00
|
|
|
if (online <= 0) {
|
|
|
|
switch (online) {
|
2015-01-23 11:02:45 +00:00
|
|
|
case 0:
|
|
|
|
case -1: return online;
|
|
|
|
|
2014-11-18 12:41:33 +00:00
|
|
|
case -2: {
|
|
|
|
QDate yesterday(date(now).date());
|
2015-11-18 13:11:56 +00:00
|
|
|
return int32(QDateTime(yesterday.addDays(-3)).toTime_t()) + (unixtime() - myunixtime());
|
2014-11-18 12:41:33 +00:00
|
|
|
} break;
|
|
|
|
|
|
|
|
case -3: {
|
|
|
|
QDate weekago(date(now).date());
|
2015-11-18 13:11:56 +00:00
|
|
|
return int32(QDateTime(weekago.addDays(-7)).toTime_t()) + (unixtime() - myunixtime());
|
2014-11-18 12:41:33 +00:00
|
|
|
} break;
|
|
|
|
|
|
|
|
case -4: {
|
|
|
|
QDate monthago(date(now).date());
|
2015-11-18 13:11:56 +00:00
|
|
|
return int32(QDateTime(monthago.addDays(-30)).toTime_t()) + (unixtime() - myunixtime());
|
2014-11-18 12:41:33 +00:00
|
|
|
} break;
|
|
|
|
}
|
2015-01-23 11:02:45 +00:00
|
|
|
return -online;
|
2014-11-18 12:41:33 +00:00
|
|
|
}
|
|
|
|
return online;
|
|
|
|
}
|
|
|
|
|
2016-06-03 07:20:24 +00:00
|
|
|
int32 onlineWillChangeIn(UserData *user, TimeId now) {
|
2015-06-10 12:48:26 +00:00
|
|
|
if (isServiceUser(user->id) || user->botInfo) {
|
|
|
|
return 86400;
|
|
|
|
}
|
2016-06-03 07:20:24 +00:00
|
|
|
return onlineWillChangeIn(user->onlineTill, now);
|
|
|
|
}
|
|
|
|
|
|
|
|
int32 onlineWillChangeIn(TimeId online, TimeId now) {
|
2015-06-10 12:48:26 +00:00
|
|
|
if (online <= 0) {
|
2015-01-23 09:48:21 +00:00
|
|
|
if (-online > now) return -online - now;
|
|
|
|
return 86400;
|
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
if (online > now) {
|
|
|
|
return online - now;
|
|
|
|
}
|
|
|
|
int32 minutes = (now - online) / 60;
|
|
|
|
if (minutes < 60) {
|
|
|
|
return (minutes + 1) * 60 - (now - online);
|
|
|
|
}
|
|
|
|
int32 hours = (now - online) / 3600;
|
|
|
|
if (hours < 12) {
|
|
|
|
return (hours + 1) * 3600 - (now - online);
|
|
|
|
}
|
|
|
|
QDateTime dNow(date(now)), dTomorrow(dNow.date().addDays(1));
|
|
|
|
return dNow.secsTo(dTomorrow);
|
|
|
|
}
|
|
|
|
|
2016-06-03 07:20:24 +00:00
|
|
|
QString onlineText(UserData *user, TimeId now, bool precise) {
|
2015-08-12 18:01:32 +00:00
|
|
|
if (isNotificationsUser(user->id)) {
|
2014-11-22 09:45:04 +00:00
|
|
|
return lang(lng_status_service_notifications);
|
2015-06-10 12:48:26 +00:00
|
|
|
} else if (user->botInfo) {
|
|
|
|
return lang(lng_status_bot);
|
2016-06-09 14:31:10 +00:00
|
|
|
} else if (isServiceUser(user->id)) {
|
|
|
|
return lang(lng_status_support);
|
2014-11-22 09:45:04 +00:00
|
|
|
}
|
2016-06-03 07:20:24 +00:00
|
|
|
return onlineText(user->onlineTill, now, precise);
|
|
|
|
}
|
|
|
|
|
|
|
|
QString onlineText(TimeId online, TimeId now, bool precise) {
|
2014-11-14 23:23:35 +00:00
|
|
|
if (online <= 0) {
|
|
|
|
switch (online) {
|
|
|
|
case 0: return lang(lng_status_offline);
|
2015-01-23 09:48:21 +00:00
|
|
|
case -1: return lang(lng_status_invisible);
|
2014-11-14 23:23:35 +00:00
|
|
|
case -2: return lang(lng_status_recently);
|
|
|
|
case -3: return lang(lng_status_last_week);
|
|
|
|
case -4: return lang(lng_status_last_month);
|
|
|
|
}
|
2015-01-23 09:48:21 +00:00
|
|
|
return (-online > now) ? lang(lng_status_online) : lang(lng_status_recently);
|
2014-11-14 23:23:35 +00:00
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
if (online > now) {
|
|
|
|
return lang(lng_status_online);
|
|
|
|
}
|
|
|
|
QString when;
|
2014-07-18 10:37:34 +00:00
|
|
|
if (precise) {
|
|
|
|
QDateTime dOnline(date(online)), dNow(date(now));
|
|
|
|
if (dOnline.date() == dNow.date()) {
|
2015-02-10 18:55:04 +00:00
|
|
|
return lng_status_lastseen_today(lt_time, dOnline.time().toString(cTimeFormat()));
|
2014-07-18 10:37:34 +00:00
|
|
|
} else if (dOnline.date().addDays(1) == dNow.date()) {
|
2015-02-10 18:55:04 +00:00
|
|
|
return lng_status_lastseen_yesterday(lt_time, dOnline.time().toString(cTimeFormat()));
|
2014-07-18 10:37:34 +00:00
|
|
|
}
|
2015-02-10 18:55:04 +00:00
|
|
|
return lng_status_lastseen_date_time(lt_date, dOnline.date().toString(qsl("dd.MM.yy")), lt_time, dOnline.time().toString(cTimeFormat()));
|
2014-07-18 10:37:34 +00:00
|
|
|
}
|
|
|
|
int32 minutes = (now - online) / 60;
|
2014-05-30 08:53:19 +00:00
|
|
|
if (!minutes) {
|
2014-12-18 18:40:49 +00:00
|
|
|
return lang(lng_status_lastseen_now);
|
2014-05-30 08:53:19 +00:00
|
|
|
} else if (minutes < 60) {
|
2014-12-18 18:40:49 +00:00
|
|
|
return lng_status_lastseen_minutes(lt_count, minutes);
|
|
|
|
}
|
|
|
|
int32 hours = (now - online) / 3600;
|
|
|
|
if (hours < 12) {
|
|
|
|
return lng_status_lastseen_hours(lt_count, hours);
|
|
|
|
}
|
|
|
|
QDateTime dOnline(date(online)), dNow(date(now));
|
|
|
|
if (dOnline.date() == dNow.date()) {
|
2015-02-10 18:55:04 +00:00
|
|
|
return lng_status_lastseen_today(lt_time, dOnline.time().toString(cTimeFormat()));
|
2014-12-18 18:40:49 +00:00
|
|
|
} else if (dOnline.date().addDays(1) == dNow.date()) {
|
2015-02-10 18:55:04 +00:00
|
|
|
return lng_status_lastseen_yesterday(lt_time, dOnline.time().toString(cTimeFormat()));
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
2014-12-18 18:40:49 +00:00
|
|
|
return lng_status_lastseen_date(lt_date, dOnline.date().toString(qsl("dd.MM.yy")));
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2016-03-23 13:21:26 +00:00
|
|
|
namespace {
|
|
|
|
// we should get a full restriction in "{fulltype}: {reason}" format and we
|
|
|
|
// need to find a "-all" tag in {fulltype}, otherwise ignore this restriction
|
|
|
|
QString extractRestrictionReason(const QString &fullRestriction) {
|
|
|
|
int fullTypeEnd = fullRestriction.indexOf(':');
|
|
|
|
if (fullTypeEnd <= 0) {
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
|
|
|
// {fulltype} is in "{type}-{tag}-{tag}-{tag}" format
|
|
|
|
// if we find "all" tag we return the restriction string
|
2016-08-31 17:58:46 +00:00
|
|
|
auto typeTags = fullRestriction.mid(0, fullTypeEnd).split('-').mid(1);
|
|
|
|
#ifndef OS_MAC_STORE
|
|
|
|
auto restrictionApplies = typeTags.contains(qsl("all"));
|
|
|
|
#else // OS_MAC_STORE
|
|
|
|
auto restrictionApplies = typeTags.contains(qsl("all")) || typeTags.contains(qsl("ios"));
|
|
|
|
#endif // OS_MAC_STORE
|
|
|
|
if (restrictionApplies) {
|
2016-03-23 13:21:26 +00:00
|
|
|
return fullRestriction.midRef(fullTypeEnd + 1).trimmed().toString();
|
|
|
|
}
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-03 07:20:24 +00:00
|
|
|
bool onlineColorUse(UserData *user, TimeId now) {
|
2015-06-24 17:24:48 +00:00
|
|
|
if (isServiceUser(user->id) || user->botInfo) {
|
|
|
|
return false;
|
|
|
|
}
|
2016-06-03 07:20:24 +00:00
|
|
|
return onlineColorUse(user->onlineTill, now);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool onlineColorUse(TimeId online, TimeId now) {
|
2015-01-23 11:02:45 +00:00
|
|
|
if (online <= 0) {
|
|
|
|
switch (online) {
|
|
|
|
case 0:
|
|
|
|
case -1:
|
|
|
|
case -2:
|
|
|
|
case -3:
|
|
|
|
case -4: return false;
|
|
|
|
}
|
|
|
|
return (-online > now);
|
|
|
|
}
|
|
|
|
return (online > now);
|
|
|
|
}
|
|
|
|
|
2016-07-08 16:59:46 +00:00
|
|
|
UserData *feedUser(const MTPUser &user) {
|
|
|
|
UserData *data = nullptr;
|
|
|
|
bool wasContact = false, minimal = false;
|
|
|
|
const MTPUserStatus *status = 0, emptyStatus = MTP_userStatusEmpty();
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2016-07-08 16:59:46 +00:00
|
|
|
Notify::PeerUpdate update;
|
|
|
|
using UpdateFlag = Notify::PeerUpdate::Flag;
|
2016-05-24 16:13:07 +00:00
|
|
|
|
2016-07-08 16:59:46 +00:00
|
|
|
switch (user.type()) {
|
|
|
|
case mtpc_userEmpty: {
|
2016-10-12 19:34:25 +00:00
|
|
|
auto &d = user.c_userEmpty();
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2016-10-12 19:34:25 +00:00
|
|
|
auto peer = peerFromUser(d.vid.v);
|
2016-07-08 16:59:46 +00:00
|
|
|
data = App::user(peer);
|
|
|
|
auto canShareThisContact = data->canShareThisContactFast();
|
|
|
|
wasContact = data->isContact();
|
2016-05-24 16:13:07 +00:00
|
|
|
|
2016-07-08 16:59:46 +00:00
|
|
|
data->input = MTP_inputPeerUser(d.vid, MTP_long(0));
|
|
|
|
data->inputUser = MTP_inputUser(d.vid, MTP_long(0));
|
|
|
|
data->setName(lang(lng_deleted), QString(), QString(), QString());
|
|
|
|
data->setPhoto(MTP_userProfilePhotoEmpty());
|
2017-01-16 13:27:11 +00:00
|
|
|
data->setIsInaccessible();
|
2016-07-08 16:59:46 +00:00
|
|
|
data->flags = 0;
|
|
|
|
data->setBotInfoVersion(-1);
|
|
|
|
status = &emptyStatus;
|
|
|
|
data->contact = -1;
|
|
|
|
|
|
|
|
if (canShareThisContact != data->canShareThisContactFast()) update.flags |= UpdateFlag::UserCanShareContact;
|
|
|
|
if (wasContact != data->isContact()) update.flags |= UpdateFlag::UserIsContact;
|
|
|
|
} break;
|
|
|
|
case mtpc_user: {
|
2016-10-12 19:34:25 +00:00
|
|
|
auto &d = user.c_user();
|
2016-07-08 16:59:46 +00:00
|
|
|
minimal = d.is_min();
|
|
|
|
|
2016-10-12 19:34:25 +00:00
|
|
|
auto peer = peerFromUser(d.vid.v);
|
2016-07-08 16:59:46 +00:00
|
|
|
data = App::user(peer);
|
|
|
|
auto canShareThisContact = data->canShareThisContactFast();
|
|
|
|
wasContact = data->isContact();
|
|
|
|
if (!minimal) {
|
|
|
|
data->flags = d.vflags.v;
|
|
|
|
if (d.is_self()) {
|
|
|
|
data->input = MTP_inputPeerSelf();
|
|
|
|
data->inputUser = MTP_inputUserSelf();
|
|
|
|
} else if (!d.has_access_hash()) {
|
2017-01-16 13:27:11 +00:00
|
|
|
data->input = MTP_inputPeerUser(d.vid, MTP_long(data->isInaccessible() ? 0 : data->access));
|
|
|
|
data->inputUser = MTP_inputUser(d.vid, MTP_long(data->isInaccessible() ? 0 : data->access));
|
2016-07-08 16:59:46 +00:00
|
|
|
} else {
|
|
|
|
data->input = MTP_inputPeerUser(d.vid, d.vaccess_hash);
|
|
|
|
data->inputUser = MTP_inputUser(d.vid, d.vaccess_hash);
|
|
|
|
}
|
|
|
|
if (d.is_restricted()) {
|
|
|
|
data->setRestrictionReason(extractRestrictionReason(qs(d.vrestriction_reason)));
|
|
|
|
} else {
|
|
|
|
data->setRestrictionReason(QString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (d.is_deleted()) {
|
|
|
|
if (!data->phone().isEmpty()) {
|
|
|
|
data->setPhone(QString());
|
|
|
|
update.flags |= UpdateFlag::UserPhoneChanged;
|
|
|
|
}
|
2014-10-22 18:39:03 +00:00
|
|
|
data->setName(lang(lng_deleted), QString(), QString(), QString());
|
2014-05-30 08:53:19 +00:00
|
|
|
data->setPhoto(MTP_userProfilePhotoEmpty());
|
2017-01-16 13:27:11 +00:00
|
|
|
data->setIsInaccessible();
|
2015-04-02 10:33:19 +00:00
|
|
|
status = &emptyStatus;
|
2016-07-08 16:59:46 +00:00
|
|
|
} else {
|
|
|
|
// apply first_name and last_name from minimal user only if we don't have
|
|
|
|
// local values for first name and last name already, otherwise skip
|
|
|
|
bool noLocalName = data->firstName.isEmpty() && data->lastName.isEmpty();
|
|
|
|
QString fname = (!minimal || noLocalName) ? (d.has_first_name() ? textOneLine(qs(d.vfirst_name)) : QString()) : data->firstName;
|
|
|
|
QString lname = (!minimal || noLocalName) ? (d.has_last_name() ? textOneLine(qs(d.vlast_name)) : QString()) : data->lastName;
|
|
|
|
|
|
|
|
QString phone = minimal ? data->phone() : (d.has_phone() ? qs(d.vphone) : QString());
|
|
|
|
QString uname = minimal ? data->username : (d.has_username() ? textOneLine(qs(d.vusername)) : QString());
|
|
|
|
|
|
|
|
bool phoneChanged = (data->phone() != phone);
|
|
|
|
if (phoneChanged) {
|
|
|
|
data->setPhone(phone);
|
|
|
|
update.flags |= UpdateFlag::UserPhoneChanged;
|
2015-06-10 12:48:26 +00:00
|
|
|
}
|
2016-07-08 16:59:46 +00:00
|
|
|
bool nameChanged = (data->firstName != fname) || (data->lastName != lname);
|
2015-07-21 14:55:23 +00:00
|
|
|
|
2016-07-08 16:59:46 +00:00
|
|
|
bool showPhone = !isServiceUser(data->id) && !d.is_self() && !d.is_contact() && !d.is_mutual_contact();
|
|
|
|
bool showPhoneChanged = !isServiceUser(data->id) && !d.is_self() && ((showPhone && data->contact) || (!showPhone && !data->contact));
|
|
|
|
if (minimal) {
|
|
|
|
showPhoneChanged = false;
|
|
|
|
showPhone = !isServiceUser(data->id) && (data->id != peerFromUser(MTP::authedId())) && !data->contact;
|
|
|
|
}
|
2015-07-21 14:55:23 +00:00
|
|
|
|
2016-07-08 16:59:46 +00:00
|
|
|
// see also Local::readPeer
|
2015-08-07 12:11:50 +00:00
|
|
|
|
2016-07-08 16:59:46 +00:00
|
|
|
QString pname = (showPhoneChanged || phoneChanged || nameChanged) ? ((showPhone && !phone.isEmpty()) ? formatPhone(phone) : QString()) : data->nameOrPhone;
|
2015-07-21 14:55:23 +00:00
|
|
|
|
2016-07-08 16:59:46 +00:00
|
|
|
if (!minimal && d.is_self() && uname != data->username) {
|
|
|
|
SignalHandlers::setCrashAnnotation("Username", uname);
|
2015-06-10 12:48:26 +00:00
|
|
|
}
|
2016-07-08 16:59:46 +00:00
|
|
|
data->setName(fname, lname, pname, uname);
|
|
|
|
if (d.has_photo()) {
|
|
|
|
data->setPhoto(d.vphoto);
|
|
|
|
} else {
|
|
|
|
data->setPhoto(MTP_userProfilePhotoEmpty());
|
|
|
|
}
|
|
|
|
if (d.has_access_hash()) data->access = d.vaccess_hash.v;
|
|
|
|
status = d.has_status() ? &d.vstatus : &emptyStatus;
|
|
|
|
}
|
|
|
|
if (!minimal) {
|
|
|
|
if (d.has_bot_info_version()) {
|
|
|
|
data->setBotInfoVersion(d.vbot_info_version.v);
|
|
|
|
data->botInfo->readsAllHistory = d.is_bot_chat_history();
|
|
|
|
if (data->botInfo->cantJoinGroups != d.is_bot_nochats()) {
|
|
|
|
data->botInfo->cantJoinGroups = d.is_bot_nochats();
|
|
|
|
update.flags |= UpdateFlag::BotCanAddToGroups;
|
2016-02-18 16:36:33 +00:00
|
|
|
}
|
2016-07-08 16:59:46 +00:00
|
|
|
data->botInfo->inlinePlaceholder = d.has_bot_inline_placeholder() ? '_' + qs(d.vbot_inline_placeholder) : QString();
|
|
|
|
} else {
|
|
|
|
data->setBotInfoVersion(-1);
|
|
|
|
}
|
|
|
|
data->contact = (d.is_contact() || d.is_mutual_contact()) ? 1 : (data->phone().isEmpty() ? -1 : 0);
|
|
|
|
if (data->contact == 1 && cReportSpamStatuses().value(data->id, dbiprsHidden) != dbiprsHidden) {
|
|
|
|
cRefReportSpamStatuses().insert(data->id, dbiprsHidden);
|
|
|
|
Local::writeReportSpamStatuses();
|
|
|
|
}
|
|
|
|
if (d.is_self() && ::self != data) {
|
|
|
|
::self = data;
|
2016-08-27 04:49:18 +00:00
|
|
|
Global::RefSelfChanged().notify();
|
2014-11-18 12:40:43 +00:00
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2016-07-08 16:59:46 +00:00
|
|
|
if (canShareThisContact != data->canShareThisContactFast()) update.flags |= UpdateFlag::UserCanShareContact;
|
|
|
|
if (wasContact != data->isContact()) update.flags |= UpdateFlag::UserIsContact;
|
|
|
|
} break;
|
|
|
|
}
|
2014-07-14 05:16:21 +00:00
|
|
|
|
2016-07-08 16:59:46 +00:00
|
|
|
if (!data) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2016-06-03 07:20:24 +00:00
|
|
|
|
2016-07-08 16:59:46 +00:00
|
|
|
if (minimal) {
|
|
|
|
if (data->loadedStatus == PeerData::NotLoaded) {
|
|
|
|
data->loadedStatus = PeerData::MinimalLoaded;
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
2016-07-08 16:59:46 +00:00
|
|
|
} else if (data->loadedStatus != PeerData::FullLoaded) {
|
|
|
|
data->loadedStatus = PeerData::FullLoaded;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto oldOnlineTill = data->onlineTill;
|
|
|
|
if (status && !minimal) switch (status->type()) {
|
|
|
|
case mtpc_userStatusEmpty: data->onlineTill = 0; break;
|
|
|
|
case mtpc_userStatusRecently:
|
|
|
|
if (data->onlineTill > -10) { // don't modify pseudo-online
|
|
|
|
data->onlineTill = -2;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case mtpc_userStatusLastWeek: data->onlineTill = -3; break;
|
|
|
|
case mtpc_userStatusLastMonth: data->onlineTill = -4; break;
|
|
|
|
case mtpc_userStatusOffline: data->onlineTill = status->c_userStatusOffline().vwas_online.v; break;
|
|
|
|
case mtpc_userStatusOnline: data->onlineTill = status->c_userStatusOnline().vexpires.v; break;
|
|
|
|
}
|
|
|
|
if (oldOnlineTill != data->onlineTill) {
|
|
|
|
update.flags |= UpdateFlag::UserOnlineChanged;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (data->contact < 0 && !data->phone().isEmpty() && peerToUser(data->id) != MTP::authedId()) {
|
|
|
|
data->contact = 0;
|
|
|
|
}
|
|
|
|
if (App::main()) {
|
|
|
|
if ((data->contact > 0 && !wasContact) || (wasContact && data->contact < 1)) {
|
|
|
|
Notify::userIsContactChanged(data);
|
2016-06-03 07:20:24 +00:00
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2016-07-08 16:59:46 +00:00
|
|
|
markPeerUpdated(data);
|
|
|
|
if (update.flags) {
|
|
|
|
update.peer = data;
|
|
|
|
Notify::peerUpdatedDelayed(update);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
2016-07-08 16:59:46 +00:00
|
|
|
}
|
|
|
|
return data;
|
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2016-07-08 16:59:46 +00:00
|
|
|
UserData *feedUsers(const MTPVector<MTPUser> &users) {
|
|
|
|
UserData *result = nullptr;
|
|
|
|
for_const (auto &user, users.c_vector().v) {
|
|
|
|
if (auto feededUser = feedUser(user)) {
|
|
|
|
result = feededUser;
|
2015-06-29 22:09:23 +00:00
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
2014-12-03 13:10:32 +00:00
|
|
|
|
2016-05-24 16:13:07 +00:00
|
|
|
return result;
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2016-07-08 16:59:46 +00:00
|
|
|
PeerData *feedChat(const MTPChat &chat) {
|
|
|
|
PeerData *data = nullptr;
|
|
|
|
bool minimal = false;
|
2016-05-24 16:13:07 +00:00
|
|
|
|
2016-07-08 16:59:46 +00:00
|
|
|
Notify::PeerUpdate update;
|
|
|
|
using UpdateFlag = Notify::PeerUpdate::Flag;
|
2016-05-24 16:13:07 +00:00
|
|
|
|
2016-07-08 16:59:46 +00:00
|
|
|
switch (chat.type()) {
|
|
|
|
case mtpc_chat: {
|
|
|
|
auto &d(chat.c_chat());
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2016-07-08 16:59:46 +00:00
|
|
|
data = App::chat(peerFromChat(d.vid.v));
|
|
|
|
auto cdata = data->asChat();
|
|
|
|
auto canEdit = cdata->canEdit();
|
2015-09-03 10:48:40 +00:00
|
|
|
|
2016-07-08 16:59:46 +00:00
|
|
|
if (cdata->version < d.vversion.v) {
|
|
|
|
cdata->version = d.vversion.v;
|
|
|
|
cdata->invalidateParticipants();
|
|
|
|
}
|
2015-09-06 10:17:09 +00:00
|
|
|
|
2016-07-08 16:59:46 +00:00
|
|
|
data->input = MTP_inputPeerChat(d.vid);
|
|
|
|
cdata->setName(qs(d.vtitle));
|
|
|
|
cdata->setPhoto(d.vphoto);
|
|
|
|
cdata->date = d.vdate.v;
|
2015-10-29 19:10:49 +00:00
|
|
|
|
2016-07-08 16:59:46 +00:00
|
|
|
if (d.has_migrated_to() && d.vmigrated_to.type() == mtpc_inputChannel) {
|
|
|
|
const auto &c(d.vmigrated_to.c_inputChannel());
|
|
|
|
ChannelData *channel = App::channel(peerFromChannel(c.vchannel_id));
|
|
|
|
if (!channel->mgInfo) {
|
|
|
|
channel->flags |= MTPDchannel::Flag::f_megagroup;
|
|
|
|
channel->flagsUpdated();
|
|
|
|
}
|
|
|
|
if (!channel->access) {
|
|
|
|
channel->input = MTP_inputPeerChannel(c.vchannel_id, c.vaccess_hash);
|
|
|
|
channel->inputChannel = d.vmigrated_to;
|
|
|
|
channel->access = d.vmigrated_to.c_inputChannel().vaccess_hash.v;
|
|
|
|
}
|
|
|
|
bool updatedTo = (cdata->migrateToPtr != channel), updatedFrom = (channel->mgInfo->migrateFromPtr != cdata);
|
|
|
|
if (updatedTo) {
|
|
|
|
cdata->migrateToPtr = channel;
|
|
|
|
}
|
|
|
|
if (updatedFrom) {
|
|
|
|
channel->mgInfo->migrateFromPtr = cdata;
|
|
|
|
if (History *h = App::historyLoaded(cdata->id)) {
|
|
|
|
if (History *hto = App::historyLoaded(channel->id)) {
|
|
|
|
if (!h->isEmpty()) {
|
|
|
|
h->clear(true);
|
|
|
|
}
|
|
|
|
if (hto->inChatList(Dialogs::Mode::All) && h->inChatList(Dialogs::Mode::All)) {
|
|
|
|
App::removeDialog(h);
|
2015-11-13 15:14:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-07-08 16:59:46 +00:00
|
|
|
Notify::migrateUpdated(channel);
|
|
|
|
update.flags |= UpdateFlag::MigrationChanged;
|
2015-11-13 15:14:33 +00:00
|
|
|
}
|
2016-07-08 16:59:46 +00:00
|
|
|
if (updatedTo) {
|
|
|
|
Notify::migrateUpdated(cdata);
|
|
|
|
update.flags |= UpdateFlag::MigrationChanged;
|
2015-10-29 19:10:49 +00:00
|
|
|
}
|
2016-07-08 16:59:46 +00:00
|
|
|
}
|
2015-10-29 19:10:49 +00:00
|
|
|
|
2016-07-08 16:59:46 +00:00
|
|
|
if (!(cdata->flags & MTPDchat::Flag::f_admins_enabled) && (d.vflags.v & MTPDchat::Flag::f_admins_enabled)) {
|
2015-11-02 02:28:24 +00:00
|
|
|
cdata->invalidateParticipants();
|
2016-07-08 16:59:46 +00:00
|
|
|
}
|
|
|
|
cdata->flags = d.vflags.v;
|
2015-09-03 10:48:40 +00:00
|
|
|
|
2016-07-08 16:59:46 +00:00
|
|
|
cdata->count = d.vparticipants_count.v;
|
|
|
|
cdata->isForbidden = false;
|
|
|
|
if (canEdit != cdata->canEdit()) {
|
|
|
|
update.flags |= UpdateFlag::ChatCanEdit;
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case mtpc_chatForbidden: {
|
|
|
|
auto &d(chat.c_chatForbidden());
|
|
|
|
|
|
|
|
data = App::chat(peerFromChat(d.vid.v));
|
|
|
|
auto cdata = data->asChat();
|
|
|
|
auto canEdit = cdata->canEdit();
|
|
|
|
|
|
|
|
data->input = MTP_inputPeerChat(d.vid);
|
|
|
|
cdata->setName(qs(d.vtitle));
|
|
|
|
cdata->setPhoto(MTP_chatPhotoEmpty());
|
|
|
|
cdata->date = 0;
|
|
|
|
cdata->count = -1;
|
|
|
|
cdata->invalidateParticipants();
|
|
|
|
cdata->flags = 0;
|
|
|
|
cdata->isForbidden = true;
|
|
|
|
if (canEdit != cdata->canEdit()) {
|
|
|
|
update.flags |= UpdateFlag::ChatCanEdit;
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case mtpc_channel: {
|
|
|
|
auto &d(chat.c_channel());
|
2016-05-24 16:13:07 +00:00
|
|
|
|
2016-07-08 16:59:46 +00:00
|
|
|
auto peerId = peerFromChannel(d.vid.v);
|
|
|
|
minimal = d.is_min();
|
|
|
|
if (minimal) {
|
|
|
|
data = App::channelLoaded(peerId);
|
|
|
|
if (!data) {
|
|
|
|
return nullptr; // minimal is not loaded, need to make getDifference
|
2016-06-04 20:29:16 +00:00
|
|
|
}
|
2016-07-08 16:59:46 +00:00
|
|
|
} else {
|
2016-05-25 17:59:21 +00:00
|
|
|
data = App::channel(peerId);
|
2016-07-08 16:59:46 +00:00
|
|
|
data->input = MTP_inputPeerChannel(d.vid, d.has_access_hash() ? d.vaccess_hash : MTP_long(0));
|
|
|
|
}
|
2015-09-13 19:15:45 +00:00
|
|
|
|
2016-07-08 16:59:46 +00:00
|
|
|
auto cdata = data->asChannel();
|
|
|
|
auto wasInChannel = cdata->amIn();
|
|
|
|
auto canEditPhoto = cdata->canEditPhoto();
|
|
|
|
auto canViewAdmins = cdata->canViewAdmins();
|
|
|
|
auto canViewMembers = cdata->canViewMembers();
|
|
|
|
auto canAddMembers = cdata->canAddMembers();
|
|
|
|
auto wasEditor = cdata->amEditor();
|
2016-05-24 16:13:07 +00:00
|
|
|
|
2016-07-08 16:59:46 +00:00
|
|
|
if (minimal) {
|
|
|
|
auto mask = MTPDchannel::Flag::f_broadcast | MTPDchannel::Flag::f_verified | MTPDchannel::Flag::f_megagroup | MTPDchannel::Flag::f_democracy;
|
|
|
|
cdata->flags = (cdata->flags & ~mask) | (d.vflags.v & mask);
|
|
|
|
} else {
|
2015-09-16 21:15:13 +00:00
|
|
|
cdata->inputChannel = MTP_inputChannel(d.vid, d.vaccess_hash);
|
2015-09-13 19:15:45 +00:00
|
|
|
cdata->access = d.vaccess_hash.v;
|
2016-07-08 16:59:46 +00:00
|
|
|
cdata->date = d.vdate.v;
|
|
|
|
if (cdata->version < d.vversion.v) {
|
|
|
|
cdata->version = d.vversion.v;
|
2016-06-04 20:29:16 +00:00
|
|
|
}
|
2016-07-08 16:59:46 +00:00
|
|
|
if (d.is_restricted()) {
|
|
|
|
cdata->setRestrictionReason(extractRestrictionReason(qs(d.vrestriction_reason)));
|
|
|
|
} else {
|
|
|
|
cdata->setRestrictionReason(QString());
|
|
|
|
}
|
|
|
|
cdata->flags = d.vflags.v;
|
|
|
|
}
|
|
|
|
cdata->flagsUpdated();
|
2015-09-13 19:15:45 +00:00
|
|
|
|
2016-07-08 16:59:46 +00:00
|
|
|
QString uname = d.has_username() ? textOneLine(qs(d.vusername)) : QString();
|
|
|
|
cdata->setName(qs(d.vtitle), uname);
|
2016-06-03 12:45:33 +00:00
|
|
|
|
2016-07-08 16:59:46 +00:00
|
|
|
cdata->isForbidden = false;
|
|
|
|
cdata->setPhoto(d.vphoto);
|
2015-09-13 19:15:45 +00:00
|
|
|
|
2016-07-08 16:59:46 +00:00
|
|
|
if (wasInChannel != cdata->amIn()) update.flags |= UpdateFlag::ChannelAmIn;
|
|
|
|
if (canEditPhoto != cdata->canEditPhoto()) update.flags |= UpdateFlag::ChannelCanEditPhoto;
|
|
|
|
if (canViewAdmins != cdata->canViewAdmins()) update.flags |= UpdateFlag::ChannelCanViewAdmins;
|
|
|
|
if (canViewMembers != cdata->canViewMembers()) update.flags |= UpdateFlag::ChannelCanViewMembers;
|
|
|
|
if (canAddMembers != cdata->canAddMembers()) update.flags |= UpdateFlag::ChannelCanAddMembers;
|
|
|
|
if (wasEditor != cdata->amEditor()) {
|
|
|
|
cdata->selfAdminUpdated();
|
|
|
|
update.flags |= (UpdateFlag::ChannelAmEditor | UpdateFlag::AdminsChanged);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
2016-07-08 16:59:46 +00:00
|
|
|
} break;
|
|
|
|
case mtpc_channelForbidden: {
|
|
|
|
auto &d(chat.c_channelForbidden());
|
|
|
|
|
|
|
|
auto peerId = peerFromChannel(d.vid.v);
|
|
|
|
data = App::channel(peerId);
|
|
|
|
data->input = MTP_inputPeerChannel(d.vid, d.vaccess_hash);
|
|
|
|
|
|
|
|
auto cdata = data->asChannel();
|
|
|
|
auto wasInChannel = cdata->amIn();
|
|
|
|
auto canEditPhoto = cdata->canEditPhoto();
|
|
|
|
auto canViewAdmins = cdata->canViewAdmins();
|
|
|
|
auto canViewMembers = cdata->canViewMembers();
|
|
|
|
auto canAddMembers = cdata->canAddMembers();
|
|
|
|
auto wasEditor = cdata->amEditor();
|
|
|
|
|
|
|
|
cdata->inputChannel = MTP_inputChannel(d.vid, d.vaccess_hash);
|
|
|
|
|
|
|
|
auto mask = mtpCastFlags(MTPDchannelForbidden::Flag::f_broadcast | MTPDchannelForbidden::Flag::f_megagroup);
|
|
|
|
cdata->flags = (cdata->flags & ~mask) | (mtpCastFlags(d.vflags) & mask);
|
|
|
|
cdata->flagsUpdated();
|
|
|
|
|
|
|
|
cdata->setName(qs(d.vtitle), QString());
|
|
|
|
|
|
|
|
cdata->access = d.vaccess_hash.v;
|
|
|
|
cdata->setPhoto(MTP_chatPhotoEmpty());
|
|
|
|
cdata->date = 0;
|
|
|
|
cdata->setMembersCount(0);
|
|
|
|
cdata->isForbidden = true;
|
|
|
|
|
|
|
|
if (wasInChannel != cdata->amIn()) update.flags |= UpdateFlag::ChannelAmIn;
|
|
|
|
if (canEditPhoto != cdata->canEditPhoto()) update.flags |= UpdateFlag::ChannelCanEditPhoto;
|
|
|
|
if (canViewAdmins != cdata->canViewAdmins()) update.flags |= UpdateFlag::ChannelCanViewAdmins;
|
|
|
|
if (canViewMembers != cdata->canViewMembers()) update.flags |= UpdateFlag::ChannelCanViewMembers;
|
|
|
|
if (canAddMembers != cdata->canAddMembers()) update.flags |= UpdateFlag::ChannelCanAddMembers;
|
|
|
|
if (wasEditor != cdata->amEditor()) {
|
|
|
|
cdata->selfAdminUpdated();
|
|
|
|
update.flags |= (UpdateFlag::ChannelAmEditor | UpdateFlag::AdminsChanged);
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
if (!data) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2016-07-08 16:59:46 +00:00
|
|
|
if (minimal) {
|
|
|
|
if (data->loadedStatus == PeerData::NotLoaded) {
|
|
|
|
data->loadedStatus = PeerData::MinimalLoaded;
|
2016-03-25 11:29:45 +00:00
|
|
|
}
|
2016-07-08 16:59:46 +00:00
|
|
|
} else if (data->loadedStatus != PeerData::FullLoaded) {
|
|
|
|
data->loadedStatus = PeerData::FullLoaded;
|
|
|
|
}
|
|
|
|
if (App::main()) {
|
|
|
|
markPeerUpdated(data);
|
|
|
|
if (update.flags) {
|
|
|
|
update.peer = data;
|
|
|
|
Notify::peerUpdatedDelayed(update);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
PeerData *feedChats(const MTPVector<MTPChat> &chats) {
|
|
|
|
PeerData *result = nullptr;
|
|
|
|
for_const (auto &chat, chats.c_vector().v) {
|
|
|
|
if (auto feededChat = feedChat(chat)) {
|
|
|
|
result = feededChat;
|
2015-06-29 22:09:23 +00:00
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
2016-05-24 16:13:07 +00:00
|
|
|
return result;
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2015-06-29 22:09:23 +00:00
|
|
|
void feedParticipants(const MTPChatParticipants &p, bool requestBotInfos, bool emitPeerUpdated) {
|
|
|
|
ChatData *chat = 0;
|
2014-05-30 08:53:19 +00:00
|
|
|
switch (p.type()) {
|
|
|
|
case mtpc_chatParticipantsForbidden: {
|
2016-04-08 10:44:35 +00:00
|
|
|
const auto &d(p.c_chatParticipantsForbidden());
|
2015-06-29 22:09:23 +00:00
|
|
|
chat = App::chat(d.vchat_id.v);
|
2014-05-30 08:53:19 +00:00
|
|
|
chat->count = -1;
|
2015-11-02 02:28:24 +00:00
|
|
|
chat->invalidateParticipants();
|
2014-05-30 08:53:19 +00:00
|
|
|
} break;
|
2015-06-29 22:09:23 +00:00
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
case mtpc_chatParticipants: {
|
2016-04-08 10:44:35 +00:00
|
|
|
const auto &d(p.c_chatParticipants());
|
2015-06-29 22:09:23 +00:00
|
|
|
chat = App::chat(d.vchat_id.v);
|
2016-06-03 21:46:45 +00:00
|
|
|
auto canEdit = chat->canEdit();
|
2015-06-29 22:09:23 +00:00
|
|
|
if (!requestBotInfos || chat->version <= d.vversion.v) { // !requestBotInfos is true on getFullChat result
|
2014-05-30 08:53:19 +00:00
|
|
|
chat->version = d.vversion.v;
|
2016-04-08 10:44:35 +00:00
|
|
|
const auto &v(d.vparticipants.c_vector().v);
|
2014-05-30 08:53:19 +00:00
|
|
|
chat->count = v.size();
|
|
|
|
int32 pversion = chat->participants.isEmpty() ? 1 : (chat->participants.begin().value() + 1);
|
2015-10-29 19:10:49 +00:00
|
|
|
chat->invitedByMe = ChatData::InvitedByMe();
|
|
|
|
chat->admins = ChatData::Admins();
|
2016-03-19 16:55:15 +00:00
|
|
|
chat->flags &= ~MTPDchat::Flag::f_admin;
|
2014-05-30 08:53:19 +00:00
|
|
|
for (QVector<MTPChatParticipant>::const_iterator i = v.cbegin(), e = v.cend(); i != e; ++i) {
|
2015-10-29 19:10:49 +00:00
|
|
|
int32 uid = 0, inviter = 0;
|
|
|
|
switch (i->type()) {
|
|
|
|
case mtpc_chatParticipantCreator: {
|
2016-04-08 10:44:35 +00:00
|
|
|
const auto &p(i->c_chatParticipantCreator());
|
2015-10-29 19:10:49 +00:00
|
|
|
uid = p.vuser_id.v;
|
|
|
|
chat->creator = uid;
|
|
|
|
} break;
|
|
|
|
case mtpc_chatParticipantAdmin: {
|
2016-04-08 10:44:35 +00:00
|
|
|
const auto &p(i->c_chatParticipantAdmin());
|
2015-10-29 19:10:49 +00:00
|
|
|
uid = p.vuser_id.v;
|
|
|
|
inviter = p.vinviter_id.v;
|
|
|
|
} break;
|
|
|
|
case mtpc_chatParticipant: {
|
2016-04-08 10:44:35 +00:00
|
|
|
const auto &p(i->c_chatParticipant());
|
2015-10-29 19:10:49 +00:00
|
|
|
uid = p.vuser_id.v;
|
|
|
|
inviter = p.vinviter_id.v;
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
if (!uid) continue;
|
|
|
|
|
|
|
|
UserData *user = App::userLoaded(uid);
|
2014-05-30 08:53:19 +00:00
|
|
|
if (user) {
|
|
|
|
chat->participants[user] = pversion;
|
2015-10-29 19:10:49 +00:00
|
|
|
if (inviter == MTP::authedId()) {
|
2016-03-10 15:42:01 +00:00
|
|
|
chat->invitedByMe.insert(user);
|
2015-10-29 19:10:49 +00:00
|
|
|
}
|
|
|
|
if (i->type() == mtpc_chatParticipantAdmin) {
|
2016-03-10 15:42:01 +00:00
|
|
|
chat->admins.insert(user);
|
2015-11-02 05:49:25 +00:00
|
|
|
if (user->isSelf()) {
|
2016-03-19 16:55:15 +00:00
|
|
|
chat->flags |= MTPDchat::Flag::f_admin;
|
2015-11-02 05:49:25 +00:00
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
} else {
|
2015-11-02 02:28:24 +00:00
|
|
|
chat->invalidateParticipants();
|
2014-05-30 08:53:19 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!chat->participants.isEmpty()) {
|
2015-06-18 17:24:54 +00:00
|
|
|
History *h = App::historyLoaded(chat->id);
|
|
|
|
bool found = !h || !h->lastKeyboardFrom;
|
2015-06-15 17:19:24 +00:00
|
|
|
int32 botStatus = -1;
|
2014-05-30 08:53:19 +00:00
|
|
|
for (ChatData::Participants::iterator i = chat->participants.begin(), e = chat->participants.end(); i != e;) {
|
|
|
|
if (i.value() < pversion) {
|
|
|
|
i = chat->participants.erase(i);
|
|
|
|
} else {
|
2015-06-15 17:19:24 +00:00
|
|
|
if (i.key()->botInfo) {
|
2015-11-20 13:34:37 +00:00
|
|
|
botStatus = 2;// (botStatus > 0/* || !i.key()->botInfo->readsAllHistory*/) ? 2 : 1;
|
2015-10-03 11:33:51 +00:00
|
|
|
if (requestBotInfos && !i.key()->botInfo->inited && App::api()) App::api()->requestFullPeer(i.key());
|
2015-06-15 17:19:24 +00:00
|
|
|
}
|
2015-06-18 17:24:54 +00:00
|
|
|
if (!found && i.key()->id == h->lastKeyboardFrom) {
|
|
|
|
found = true;
|
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
++i;
|
|
|
|
}
|
|
|
|
}
|
2015-06-15 17:19:24 +00:00
|
|
|
chat->botStatus = botStatus;
|
2015-06-18 17:24:54 +00:00
|
|
|
if (!found) {
|
2015-11-24 16:19:18 +00:00
|
|
|
h->clearLastKeyboard();
|
2015-06-18 17:24:54 +00:00
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
}
|
2016-06-03 21:46:45 +00:00
|
|
|
if (canEdit != chat->canEdit()) {
|
|
|
|
Notify::peerUpdatedDelayed(chat, Notify::PeerUpdate::Flag::ChatCanEdit);
|
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
} break;
|
|
|
|
}
|
2016-06-03 21:46:45 +00:00
|
|
|
Notify::peerUpdatedDelayed(chat, Notify::PeerUpdate::Flag::MembersChanged | Notify::PeerUpdate::Flag::AdminsChanged);
|
2015-06-29 22:09:23 +00:00
|
|
|
if (chat && App::main()) {
|
|
|
|
if (emitPeerUpdated) {
|
|
|
|
App::main()->peerUpdated(chat);
|
|
|
|
} else {
|
|
|
|
markPeerUpdated(chat);
|
|
|
|
}
|
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2015-06-29 22:09:23 +00:00
|
|
|
void feedParticipantAdd(const MTPDupdateChatParticipantAdd &d, bool emitPeerUpdated) {
|
2014-05-30 08:53:19 +00:00
|
|
|
ChatData *chat = App::chat(d.vchat_id.v);
|
2015-10-29 19:10:49 +00:00
|
|
|
if (chat->version + 1 < d.vversion.v) {
|
2015-11-02 02:28:24 +00:00
|
|
|
chat->version = d.vversion.v;
|
2015-10-29 19:10:49 +00:00
|
|
|
chat->invalidateParticipants();
|
2015-11-02 02:28:24 +00:00
|
|
|
App::api()->requestPeer(chat);
|
2015-10-29 19:10:49 +00:00
|
|
|
if (App::main()) {
|
|
|
|
if (emitPeerUpdated) {
|
|
|
|
App::main()->peerUpdated(chat);
|
|
|
|
} else {
|
|
|
|
markPeerUpdated(chat);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (chat->version <= d.vversion.v && chat->count >= 0) {
|
2014-05-30 08:53:19 +00:00
|
|
|
chat->version = d.vversion.v;
|
|
|
|
UserData *user = App::userLoaded(d.vuser_id.v);
|
|
|
|
if (user) {
|
|
|
|
if (chat->participants.isEmpty() && chat->count) {
|
|
|
|
chat->count++;
|
2015-06-15 17:19:24 +00:00
|
|
|
chat->botStatus = 0;
|
2014-05-30 08:53:19 +00:00
|
|
|
} else if (chat->participants.find(user) == chat->participants.end()) {
|
|
|
|
chat->participants[user] = (chat->participants.isEmpty() ? 1 : chat->participants.begin().value());
|
|
|
|
if (d.vinviter_id.v == MTP::authedId()) {
|
2016-03-10 15:42:01 +00:00
|
|
|
chat->invitedByMe.insert(user);
|
2014-05-30 08:53:19 +00:00
|
|
|
} else {
|
2015-10-29 19:10:49 +00:00
|
|
|
chat->invitedByMe.remove(user);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
chat->count++;
|
2015-06-15 17:19:24 +00:00
|
|
|
if (user->botInfo) {
|
2015-11-20 13:34:37 +00:00
|
|
|
chat->botStatus = 2;// (chat->botStatus > 0/* || !user->botInfo->readsAllHistory*/) ? 2 : 1;
|
2015-10-03 11:33:51 +00:00
|
|
|
if (!user->botInfo->inited && App::api()) App::api()->requestFullPeer(user);
|
2015-06-15 17:19:24 +00:00
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
} else {
|
2015-11-02 02:28:24 +00:00
|
|
|
chat->invalidateParticipants();
|
2014-05-30 08:53:19 +00:00
|
|
|
chat->count++;
|
|
|
|
}
|
2016-06-03 07:20:24 +00:00
|
|
|
Notify::peerUpdatedDelayed(chat, Notify::PeerUpdate::Flag::MembersChanged);
|
2015-06-29 22:09:23 +00:00
|
|
|
if (App::main()) {
|
|
|
|
if (emitPeerUpdated) {
|
|
|
|
App::main()->peerUpdated(chat);
|
|
|
|
} else {
|
|
|
|
markPeerUpdated(chat);
|
|
|
|
}
|
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-29 22:09:23 +00:00
|
|
|
void feedParticipantDelete(const MTPDupdateChatParticipantDelete &d, bool emitPeerUpdated) {
|
2014-05-30 08:53:19 +00:00
|
|
|
ChatData *chat = App::chat(d.vchat_id.v);
|
2015-10-29 19:10:49 +00:00
|
|
|
if (chat->version + 1 < d.vversion.v) {
|
2015-11-02 02:28:24 +00:00
|
|
|
chat->version = d.vversion.v;
|
2015-10-29 19:10:49 +00:00
|
|
|
chat->invalidateParticipants();
|
2015-11-02 02:28:24 +00:00
|
|
|
App::api()->requestPeer(chat);
|
2015-10-29 19:10:49 +00:00
|
|
|
if (App::main()) {
|
|
|
|
if (emitPeerUpdated) {
|
|
|
|
App::main()->peerUpdated(chat);
|
|
|
|
} else {
|
|
|
|
markPeerUpdated(chat);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (chat->version <= d.vversion.v && chat->count > 0) {
|
2014-05-30 08:53:19 +00:00
|
|
|
chat->version = d.vversion.v;
|
2016-06-03 21:46:45 +00:00
|
|
|
auto canEdit = chat->canEdit();
|
2014-05-30 08:53:19 +00:00
|
|
|
UserData *user = App::userLoaded(d.vuser_id.v);
|
|
|
|
if (user) {
|
|
|
|
if (chat->participants.isEmpty()) {
|
2015-11-02 02:28:24 +00:00
|
|
|
if (chat->count > 0) {
|
|
|
|
chat->count--;
|
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
} else {
|
|
|
|
ChatData::Participants::iterator i = chat->participants.find(user);
|
|
|
|
if (i != chat->participants.end()) {
|
|
|
|
chat->participants.erase(i);
|
|
|
|
chat->count--;
|
2015-10-29 19:10:49 +00:00
|
|
|
chat->invitedByMe.remove(user);
|
|
|
|
chat->admins.remove(user);
|
2015-11-02 05:49:25 +00:00
|
|
|
if (user->isSelf()) {
|
2016-03-19 16:55:15 +00:00
|
|
|
chat->flags &= ~MTPDchat::Flag::f_admin;
|
2015-11-02 05:49:25 +00:00
|
|
|
}
|
2015-06-18 17:24:54 +00:00
|
|
|
|
|
|
|
History *h = App::historyLoaded(chat->id);
|
|
|
|
if (h && h->lastKeyboardFrom == user->id) {
|
2015-11-24 16:19:18 +00:00
|
|
|
h->clearLastKeyboard();
|
2015-06-18 17:24:54 +00:00
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
2015-06-15 17:19:24 +00:00
|
|
|
if (chat->botStatus > 0 && user->botInfo) {
|
|
|
|
int32 botStatus = -1;
|
|
|
|
for (ChatData::Participants::const_iterator j = chat->participants.cbegin(), e = chat->participants.cend(); j != e; ++j) {
|
|
|
|
if (j.key()->botInfo) {
|
2015-11-20 13:34:37 +00:00
|
|
|
if (true || botStatus > 0/* || !j.key()->botInfo->readsAllHistory*/) {
|
2015-06-15 17:19:24 +00:00
|
|
|
botStatus = 2;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
botStatus = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
chat->botStatus = botStatus;
|
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
} else {
|
2015-11-02 02:28:24 +00:00
|
|
|
chat->invalidateParticipants();
|
2014-05-30 08:53:19 +00:00
|
|
|
chat->count--;
|
|
|
|
}
|
2016-06-03 21:46:45 +00:00
|
|
|
if (canEdit != chat->canEdit()) {
|
|
|
|
Notify::peerUpdatedDelayed(chat, Notify::PeerUpdate::Flag::ChatCanEdit);
|
|
|
|
}
|
2016-06-03 07:20:24 +00:00
|
|
|
Notify::peerUpdatedDelayed(chat, Notify::PeerUpdate::Flag::MembersChanged);
|
2015-06-29 22:09:23 +00:00
|
|
|
if (App::main()) {
|
|
|
|
if (emitPeerUpdated) {
|
|
|
|
App::main()->peerUpdated(chat);
|
2015-10-29 19:10:49 +00:00
|
|
|
} else {
|
|
|
|
markPeerUpdated(chat);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void feedChatAdmins(const MTPDupdateChatAdmins &d, bool emitPeerUpdated) {
|
|
|
|
ChatData *chat = App::chat(d.vchat_id.v);
|
|
|
|
if (chat->version <= d.vversion.v) {
|
|
|
|
bool badVersion = (chat->version + 1 < d.vversion.v);
|
|
|
|
if (badVersion) {
|
|
|
|
chat->invalidateParticipants();
|
2015-11-02 02:28:24 +00:00
|
|
|
App::api()->requestPeer(chat);
|
2015-10-29 19:10:49 +00:00
|
|
|
}
|
|
|
|
chat->version = d.vversion.v;
|
|
|
|
if (mtpIsTrue(d.venabled)) {
|
|
|
|
if (!badVersion) {
|
2015-11-02 02:28:24 +00:00
|
|
|
chat->invalidateParticipants();
|
2015-10-29 19:10:49 +00:00
|
|
|
}
|
2016-06-03 21:46:45 +00:00
|
|
|
chat->flags |= MTPDchat::Flag::f_admins_enabled;
|
2015-10-29 19:10:49 +00:00
|
|
|
} else {
|
2016-03-19 16:55:15 +00:00
|
|
|
chat->flags &= ~MTPDchat::Flag::f_admins_enabled;
|
2015-10-29 19:10:49 +00:00
|
|
|
}
|
2016-06-03 21:46:45 +00:00
|
|
|
Notify::peerUpdatedDelayed(chat, Notify::PeerUpdate::Flag::AdminsChanged);
|
2015-10-29 19:10:49 +00:00
|
|
|
if (emitPeerUpdated) {
|
|
|
|
App::main()->peerUpdated(chat);
|
|
|
|
} else {
|
|
|
|
markPeerUpdated(chat);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void feedParticipantAdmin(const MTPDupdateChatParticipantAdmin &d, bool emitPeerUpdated) {
|
|
|
|
ChatData *chat = App::chat(d.vchat_id.v);
|
|
|
|
if (chat->version + 1 < d.vversion.v) {
|
2015-11-02 02:28:24 +00:00
|
|
|
chat->version = d.vversion.v;
|
2015-10-29 19:10:49 +00:00
|
|
|
chat->invalidateParticipants();
|
2015-11-02 02:28:24 +00:00
|
|
|
App::api()->requestPeer(chat);
|
2015-10-29 19:10:49 +00:00
|
|
|
if (App::main()) {
|
|
|
|
if (emitPeerUpdated) {
|
|
|
|
App::main()->peerUpdated(chat);
|
|
|
|
} else {
|
|
|
|
markPeerUpdated(chat);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (chat->version <= d.vversion.v && chat->count > 0) {
|
|
|
|
chat->version = d.vversion.v;
|
2016-06-03 21:46:45 +00:00
|
|
|
auto canEdit = chat->canEdit();
|
2015-10-29 19:10:49 +00:00
|
|
|
UserData *user = App::userLoaded(d.vuser_id.v);
|
|
|
|
if (user) {
|
|
|
|
if (mtpIsTrue(d.vis_admin)) {
|
2015-11-02 05:49:25 +00:00
|
|
|
if (user->isSelf()) {
|
2016-03-19 16:55:15 +00:00
|
|
|
chat->flags |= MTPDchat::Flag::f_admin;
|
2015-11-02 05:49:25 +00:00
|
|
|
}
|
2015-11-02 02:28:24 +00:00
|
|
|
if (chat->noParticipantInfo()) {
|
|
|
|
App::api()->requestFullPeer(chat);
|
|
|
|
} else {
|
2016-03-10 15:42:01 +00:00
|
|
|
chat->admins.insert(user);
|
2015-11-02 02:28:24 +00:00
|
|
|
}
|
2015-10-29 19:10:49 +00:00
|
|
|
} else {
|
2015-11-02 05:49:25 +00:00
|
|
|
if (user->isSelf()) {
|
2016-03-19 16:55:15 +00:00
|
|
|
chat->flags &= ~MTPDchat::Flag::f_admin;
|
2015-11-02 05:49:25 +00:00
|
|
|
}
|
2015-10-29 19:10:49 +00:00
|
|
|
chat->admins.remove(user);
|
|
|
|
}
|
|
|
|
} else {
|
2015-11-02 02:28:24 +00:00
|
|
|
chat->invalidateParticipants();
|
2015-10-29 19:10:49 +00:00
|
|
|
}
|
2016-06-03 21:46:45 +00:00
|
|
|
if (canEdit != chat->canEdit()) {
|
|
|
|
Notify::peerUpdatedDelayed(chat, Notify::PeerUpdate::Flag::ChatCanEdit);
|
|
|
|
}
|
|
|
|
Notify::peerUpdatedDelayed(chat, Notify::PeerUpdate::Flag::AdminsChanged);
|
2015-10-29 19:10:49 +00:00
|
|
|
if (App::main()) {
|
|
|
|
if (emitPeerUpdated) {
|
|
|
|
App::main()->peerUpdated(chat);
|
2015-06-29 22:09:23 +00:00
|
|
|
} else {
|
|
|
|
markPeerUpdated(chat);
|
|
|
|
}
|
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-15 00:15:28 +00:00
|
|
|
bool checkEntitiesAndViewsUpdate(const MTPDmessage &m) {
|
2016-10-12 19:34:25 +00:00
|
|
|
auto peerId = peerFromMTP(m.vto_id);
|
2015-09-03 10:48:40 +00:00
|
|
|
if (m.has_from_id() && peerToUser(peerId) == MTP::authedId()) {
|
|
|
|
peerId = peerFromUser(m.vfrom_id);
|
|
|
|
}
|
2016-10-12 19:34:25 +00:00
|
|
|
if (auto existing = App::histItemById(peerToChannel(peerId), m.vid.v)) {
|
2016-05-06 17:33:48 +00:00
|
|
|
auto text = qs(m.vmessage);
|
|
|
|
auto entities = m.has_entities() ? entitiesFromMTP(m.ventities.c_vector().v) : EntitiesInText();
|
|
|
|
existing->setText({ text, entities });
|
2016-04-01 10:23:40 +00:00
|
|
|
existing->updateMedia(m.has_media() ? (&m.vmedia) : nullptr);
|
2016-10-20 15:26:55 +00:00
|
|
|
existing->updateReplyMarkup(m.has_reply_markup() ? (&m.vreply_markup) : nullptr);
|
2016-03-19 16:55:15 +00:00
|
|
|
existing->setViewsCount(m.has_views() ? m.vviews.v : -1);
|
2016-01-03 01:43:42 +00:00
|
|
|
existing->addToOverview(AddToOverviewNew);
|
2015-10-15 00:15:28 +00:00
|
|
|
|
2015-12-27 21:37:48 +00:00
|
|
|
if (!existing->detached()) {
|
|
|
|
App::checkSavedGif(existing);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2015-09-01 21:33:44 +00:00
|
|
|
}
|
2015-10-15 00:15:28 +00:00
|
|
|
return false;
|
2015-09-01 21:33:44 +00:00
|
|
|
}
|
|
|
|
|
2016-09-23 18:26:53 +00:00
|
|
|
template <typename TMTPDclass>
|
|
|
|
void updateEditedMessage(const TMTPDclass &m) {
|
|
|
|
auto peerId = peerFromMTP(m.vto_id);
|
2016-02-18 16:36:33 +00:00
|
|
|
if (m.has_from_id() && peerToUser(peerId) == MTP::authedId()) {
|
|
|
|
peerId = peerFromUser(m.vfrom_id);
|
|
|
|
}
|
2016-09-23 18:26:53 +00:00
|
|
|
if (auto existing = App::histItemById(peerToChannel(peerId), m.vid.v)) {
|
2016-04-01 10:23:40 +00:00
|
|
|
existing->applyEdition(m);
|
2016-02-18 16:36:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-23 18:26:53 +00:00
|
|
|
void updateEditedMessage(const MTPMessage &m) {
|
|
|
|
if (m.type() == mtpc_message) { // apply message edit
|
|
|
|
App::updateEditedMessage(m.c_message());
|
|
|
|
} else if (m.type() == mtpc_messageService) {
|
|
|
|
App::updateEditedMessage(m.c_messageService());
|
2016-06-13 18:42:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-27 21:37:48 +00:00
|
|
|
void addSavedGif(DocumentData *doc) {
|
|
|
|
SavedGifs &saved(cRefSavedGifs());
|
|
|
|
int32 index = saved.indexOf(doc);
|
|
|
|
if (index) {
|
|
|
|
if (index > 0) saved.remove(index);
|
|
|
|
saved.push_front(doc);
|
2016-02-18 16:36:33 +00:00
|
|
|
if (saved.size() > Global::SavedGifsLimit()) saved.pop_back();
|
2015-12-27 21:37:48 +00:00
|
|
|
Local::writeSavedGifs();
|
|
|
|
|
|
|
|
if (App::main()) emit App::main()->savedGifsUpdated();
|
2016-01-09 07:11:23 +00:00
|
|
|
cSetLastSavedGifsUpdate(0);
|
|
|
|
App::main()->updateStickers();
|
2015-12-27 21:37:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void checkSavedGif(HistoryItem *item) {
|
2016-03-25 11:29:45 +00:00
|
|
|
if (!item->Has<HistoryMessageForwarded>() && (item->out() || item->history()->peer == App::self())) {
|
2015-12-27 21:37:48 +00:00
|
|
|
if (HistoryMedia *media = item->getMedia()) {
|
|
|
|
if (DocumentData *doc = media->getDocument()) {
|
2015-12-28 15:34:45 +00:00
|
|
|
if (doc->isGifv()) {
|
2015-12-27 21:37:48 +00:00
|
|
|
addSavedGif(doc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-18 14:59:17 +00:00
|
|
|
void feedMsgs(const QVector<MTPMessage> &msgs, NewMessageType type) {
|
2015-09-04 13:01:31 +00:00
|
|
|
QMap<uint64, int32> msgsIds;
|
2015-11-18 14:59:17 +00:00
|
|
|
for (int32 i = 0, l = msgs.size(); i < l; ++i) {
|
2016-04-08 10:44:35 +00:00
|
|
|
const auto &msg(msgs.at(i));
|
2014-05-30 08:53:19 +00:00
|
|
|
switch (msg.type()) {
|
2015-09-01 21:33:44 +00:00
|
|
|
case mtpc_message: {
|
2016-04-08 10:44:35 +00:00
|
|
|
const auto &d(msg.c_message());
|
2015-10-15 00:15:28 +00:00
|
|
|
bool needToAdd = true;
|
2015-09-20 08:55:41 +00:00
|
|
|
if (type == NewMessageUnread) { // new message, index my forwarded messages to links overview
|
2015-10-15 00:15:28 +00:00
|
|
|
if (checkEntitiesAndViewsUpdate(d)) { // already in blocks
|
|
|
|
LOG(("Skipping message, because it is already in blocks!"));
|
|
|
|
needToAdd = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (needToAdd) {
|
|
|
|
msgsIds.insert((uint64(uint32(d.vid.v)) << 32) | uint64(i), i);
|
2015-09-01 21:33:44 +00:00
|
|
|
}
|
|
|
|
} break;
|
2015-09-04 13:01:31 +00:00
|
|
|
case mtpc_messageEmpty: msgsIds.insert((uint64(uint32(msg.c_messageEmpty().vid.v)) << 32) | uint64(i), i); break;
|
|
|
|
case mtpc_messageService: msgsIds.insert((uint64(uint32(msg.c_messageService().vid.v)) << 32) | uint64(i), i); break;
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
}
|
2015-09-04 13:01:31 +00:00
|
|
|
for (QMap<uint64, int32>::const_iterator i = msgsIds.cbegin(), e = msgsIds.cend(); i != e; ++i) {
|
2015-11-18 14:59:17 +00:00
|
|
|
histories().addNewMessage(msgs.at(i.value()), type);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-18 14:59:17 +00:00
|
|
|
void feedMsgs(const MTPVector<MTPMessage> &msgs, NewMessageType type) {
|
|
|
|
return feedMsgs(msgs.c_vector().v, type);
|
|
|
|
}
|
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
ImagePtr image(const MTPPhotoSize &size) {
|
|
|
|
switch (size.type()) {
|
|
|
|
case mtpc_photoSize: {
|
2016-09-29 11:37:16 +00:00
|
|
|
auto &d = size.c_photoSize();
|
2014-05-30 08:53:19 +00:00
|
|
|
if (d.vlocation.type() == mtpc_fileLocation) {
|
2016-09-29 11:37:16 +00:00
|
|
|
auto &l = d.vlocation.c_fileLocation();
|
2015-05-19 15:46:45 +00:00
|
|
|
return ImagePtr(StorageImageLocation(d.vw.v, d.vh.v, l.vdc_id.v, l.vvolume_id.v, l.vlocal_id.v, l.vsecret.v), d.vsize.v);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case mtpc_photoCachedSize: {
|
2016-09-29 11:37:16 +00:00
|
|
|
auto &d = size.c_photoCachedSize();
|
2014-05-30 08:53:19 +00:00
|
|
|
if (d.vlocation.type() == mtpc_fileLocation) {
|
2016-09-29 11:37:16 +00:00
|
|
|
auto &l = d.vlocation.c_fileLocation();
|
|
|
|
auto bytes = qba(d.vbytes);
|
2015-05-19 15:46:45 +00:00
|
|
|
return ImagePtr(StorageImageLocation(d.vw.v, d.vh.v, l.vdc_id.v, l.vvolume_id.v, l.vlocal_id.v, l.vsecret.v), bytes);
|
2014-05-30 08:53:19 +00:00
|
|
|
} else if (d.vlocation.type() == mtpc_fileLocationUnavailable) {
|
2016-09-29 11:37:16 +00:00
|
|
|
auto bytes = qba(d.vbytes);
|
2015-05-19 15:46:45 +00:00
|
|
|
return ImagePtr(StorageImageLocation(d.vw.v, d.vh.v, 0, 0, 0, 0), bytes);
|
2016-01-03 01:43:42 +00:00
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
} break;
|
|
|
|
}
|
|
|
|
return ImagePtr();
|
|
|
|
}
|
|
|
|
|
2015-08-07 12:11:50 +00:00
|
|
|
StorageImageLocation imageLocation(int32 w, int32 h, const MTPFileLocation &loc) {
|
|
|
|
if (loc.type() == mtpc_fileLocation) {
|
2016-04-08 10:44:35 +00:00
|
|
|
const auto &l(loc.c_fileLocation());
|
2015-08-07 12:11:50 +00:00
|
|
|
return StorageImageLocation(w, h, l.vdc_id.v, l.vvolume_id.v, l.vlocal_id.v, l.vsecret.v);
|
|
|
|
}
|
|
|
|
return StorageImageLocation(w, h, 0, 0, 0, 0);
|
|
|
|
}
|
|
|
|
|
2015-05-19 15:46:45 +00:00
|
|
|
StorageImageLocation imageLocation(const MTPPhotoSize &size) {
|
|
|
|
switch (size.type()) {
|
|
|
|
case mtpc_photoSize: {
|
2016-04-08 10:44:35 +00:00
|
|
|
const auto &d(size.c_photoSize());
|
2015-08-07 12:11:50 +00:00
|
|
|
return imageLocation(d.vw.v, d.vh.v, d.vlocation);
|
2015-05-19 15:46:45 +00:00
|
|
|
} break;
|
|
|
|
case mtpc_photoCachedSize: {
|
2016-04-08 10:44:35 +00:00
|
|
|
const auto &d(size.c_photoCachedSize());
|
2015-08-07 12:11:50 +00:00
|
|
|
return imageLocation(d.vw.v, d.vh.v, d.vlocation);
|
2015-05-19 15:46:45 +00:00
|
|
|
} break;
|
|
|
|
}
|
|
|
|
return StorageImageLocation();
|
|
|
|
}
|
2016-01-03 01:43:42 +00:00
|
|
|
|
2015-09-03 10:48:40 +00:00
|
|
|
void feedInboxRead(const PeerId &peer, MsgId upTo) {
|
2016-06-09 19:28:58 +00:00
|
|
|
if (auto history = App::historyLoaded(peer)) {
|
|
|
|
history->inboxRead(upTo);
|
2015-03-13 13:01:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-22 18:41:13 +00:00
|
|
|
void feedOutboxRead(const PeerId &peer, MsgId upTo, TimeId when) {
|
2016-06-09 19:28:58 +00:00
|
|
|
if (auto history = App::historyLoaded(peer)) {
|
|
|
|
history->outboxRead(upTo);
|
|
|
|
if (history->lastMsg && history->lastMsg->out() && history->lastMsg->id <= upTo) {
|
2016-12-05 11:01:08 +00:00
|
|
|
if (App::main()) App::main()->dlgUpdated(history->peer, history->lastMsg->id);
|
2016-06-09 19:28:58 +00:00
|
|
|
}
|
|
|
|
history->updateChatListEntry();
|
|
|
|
|
|
|
|
if (history->peer->isUser()) {
|
2016-06-22 18:41:13 +00:00
|
|
|
history->peer->asUser()->madeAction(when);
|
2015-06-28 12:37:10 +00:00
|
|
|
}
|
2015-03-13 13:01:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-03 10:48:40 +00:00
|
|
|
inline MsgsData *fetchMsgsData(ChannelId channelId, bool insert = true) {
|
|
|
|
if (channelId == NoChannel) return &msgsData;
|
|
|
|
ChannelMsgsData::iterator i = channelMsgsData.find(channelId);
|
|
|
|
if (i == channelMsgsData.cend()) {
|
|
|
|
if (insert) {
|
|
|
|
i = channelMsgsData.insert(channelId, MsgsData());
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return &(*i);
|
|
|
|
}
|
|
|
|
|
|
|
|
void feedWereDeleted(ChannelId channelId, const QVector<MTPint> &msgsIds) {
|
|
|
|
MsgsData *data = fetchMsgsData(channelId, false);
|
|
|
|
if (!data) return;
|
|
|
|
|
2015-09-19 09:13:21 +00:00
|
|
|
ChannelHistory *channelHistory = (channelId == NoChannel) ? 0 : App::historyLoaded(peerFromChannel(channelId))->asChannelHistory();
|
|
|
|
|
|
|
|
QMap<History*, bool> historiesToCheck;
|
2014-05-30 08:53:19 +00:00
|
|
|
for (QVector<MTPint>::const_iterator i = msgsIds.cbegin(), e = msgsIds.cend(); i != e; ++i) {
|
2015-09-03 10:48:40 +00:00
|
|
|
MsgsData::const_iterator j = data->constFind(i->v);
|
|
|
|
if (j != data->cend()) {
|
2014-05-30 08:53:19 +00:00
|
|
|
History *h = (*j)->history();
|
2015-09-19 09:13:21 +00:00
|
|
|
(*j)->destroy();
|
|
|
|
if (!h->lastMsg) historiesToCheck.insert(h, true);
|
2015-11-20 18:24:44 +00:00
|
|
|
} else {
|
|
|
|
if (channelHistory) {
|
2016-04-11 10:59:01 +00:00
|
|
|
if (channelHistory->unreadCount() > 0 && i->v >= channelHistory->inboxReadBefore) {
|
|
|
|
channelHistory->setUnreadCount(channelHistory->unreadCount() - 1);
|
2015-11-20 18:24:44 +00:00
|
|
|
}
|
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
}
|
2015-09-19 09:13:21 +00:00
|
|
|
if (main()) {
|
|
|
|
for (QMap<History*, bool>::const_iterator i = historiesToCheck.cbegin(), e = historiesToCheck.cend(); i != e; ++i) {
|
|
|
|
main()->checkPeerHistory(i.key()->peer);
|
|
|
|
}
|
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2016-06-02 13:57:49 +00:00
|
|
|
void feedUserLink(MTPint userId, const MTPContactLink &myLink, const MTPContactLink &foreignLink) {
|
2014-05-30 08:53:19 +00:00
|
|
|
UserData *user = userLoaded(userId.v);
|
|
|
|
if (user) {
|
2016-05-27 15:45:35 +00:00
|
|
|
auto wasContact = user->isContact();
|
2015-07-21 14:55:23 +00:00
|
|
|
bool wasShowPhone = !user->contact;
|
2014-05-30 08:53:19 +00:00
|
|
|
switch (myLink.type()) {
|
2015-03-13 13:01:25 +00:00
|
|
|
case mtpc_contactLinkContact:
|
2014-05-30 08:53:19 +00:00
|
|
|
user->contact = 1;
|
2016-03-12 16:32:28 +00:00
|
|
|
if (user->contact == 1 && cReportSpamStatuses().value(user->id, dbiprsHidden) != dbiprsHidden) {
|
|
|
|
cRefReportSpamStatuses().insert(user->id, dbiprsHidden);
|
2015-09-08 17:22:29 +00:00
|
|
|
Local::writeReportSpamStatuses();
|
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
break;
|
2015-03-13 13:01:25 +00:00
|
|
|
case mtpc_contactLinkHasPhone:
|
|
|
|
user->contact = 0;
|
|
|
|
break;
|
|
|
|
case mtpc_contactLinkNone:
|
|
|
|
case mtpc_contactLinkUnknown:
|
|
|
|
user->contact = -1;
|
2014-05-30 08:53:19 +00:00
|
|
|
break;
|
|
|
|
}
|
2015-12-13 11:17:15 +00:00
|
|
|
if (user->contact < 1) {
|
2016-05-31 19:27:11 +00:00
|
|
|
if (user->contact < 0 && !user->phone().isEmpty() && peerToUser(user->id) != MTP::authedId()) {
|
2014-05-30 08:53:19 +00:00
|
|
|
user->contact = 0;
|
|
|
|
}
|
2015-12-13 11:17:15 +00:00
|
|
|
}
|
2016-05-27 15:45:35 +00:00
|
|
|
|
|
|
|
if (wasContact != user->isContact()) {
|
2016-06-01 20:05:37 +00:00
|
|
|
Notify::peerUpdatedDelayed(user, Notify::PeerUpdate::Flag::UserIsContact);
|
2016-05-27 15:45:35 +00:00
|
|
|
}
|
2015-12-13 11:17:15 +00:00
|
|
|
if ((user->contact > 0 && !wasContact) || (wasContact && user->contact < 1)) {
|
|
|
|
Notify::userIsContactChanged(user);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
2015-07-21 14:55:23 +00:00
|
|
|
|
2015-10-28 00:29:39 +00:00
|
|
|
bool showPhone = !isServiceUser(user->id) && !user->isSelf() && !user->contact;
|
|
|
|
bool showPhoneChanged = !isServiceUser(user->id) && !user->isSelf() && ((showPhone && !wasShowPhone) || (!showPhone && wasShowPhone));
|
2015-07-21 14:55:23 +00:00
|
|
|
if (showPhoneChanged) {
|
2016-06-02 13:57:49 +00:00
|
|
|
user->setName(textOneLine(user->firstName), textOneLine(user->lastName), showPhone ? App::formatPhone(user->phone()) : QString(), textOneLine(user->username));
|
2015-06-29 22:09:23 +00:00
|
|
|
}
|
2016-05-25 12:09:05 +00:00
|
|
|
markPeerUpdated(user);
|
2015-06-29 22:09:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void markPeerUpdated(PeerData *data) {
|
|
|
|
updatedPeers.insert(data, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void clearPeerUpdated(PeerData *data) {
|
|
|
|
updatedPeers.remove(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
void emitPeerUpdated() {
|
|
|
|
if (!updatedPeers.isEmpty() && App::main()) {
|
|
|
|
UpdatedPeers upd = updatedPeers;
|
|
|
|
updatedPeers.clear();
|
|
|
|
|
|
|
|
for (UpdatedPeers::const_iterator i = upd.cbegin(), e = upd.cend(); i != e; ++i) {
|
|
|
|
App::main()->peerUpdated(i.key());
|
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PhotoData *feedPhoto(const MTPPhoto &photo, PhotoData *convert) {
|
|
|
|
switch (photo.type()) {
|
|
|
|
case mtpc_photo: {
|
|
|
|
return feedPhoto(photo.c_photo(), convert);
|
|
|
|
} break;
|
|
|
|
case mtpc_photoEmpty: {
|
2015-08-12 18:01:32 +00:00
|
|
|
return App::photoSet(photo.c_photoEmpty().vid.v, convert, 0, 0, ImagePtr(), ImagePtr(), ImagePtr());
|
2014-05-30 08:53:19 +00:00
|
|
|
} break;
|
|
|
|
}
|
|
|
|
return App::photo(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
PhotoData *feedPhoto(const MTPPhoto &photo, const PreparedPhotoThumbs &thumbs) {
|
2014-08-15 11:19:32 +00:00
|
|
|
const QPixmap *thumb = 0, *medium = 0, *full = 0;
|
|
|
|
int32 thumbLevel = -1, mediumLevel = -1, fullLevel = -1;
|
2014-05-30 08:53:19 +00:00
|
|
|
for (PreparedPhotoThumbs::const_iterator i = thumbs.cbegin(), e = thumbs.cend(); i != e; ++i) {
|
2014-08-15 11:19:32 +00:00
|
|
|
int32 newThumbLevel = -1, newMediumLevel = -1, newFullLevel = -1;
|
2014-05-30 08:53:19 +00:00
|
|
|
switch (i.key()) {
|
2014-08-15 11:19:32 +00:00
|
|
|
case 's': newThumbLevel = 0; newMediumLevel = 5; newFullLevel = 4; break; // box 100x100
|
|
|
|
case 'm': newThumbLevel = 2; newMediumLevel = 0; newFullLevel = 3; break; // box 320x320
|
2014-12-12 16:27:03 +00:00
|
|
|
case 'x': newThumbLevel = 5; newMediumLevel = 3; newFullLevel = 1; break; // box 800x800
|
|
|
|
case 'y': newThumbLevel = 6; newMediumLevel = 6; newFullLevel = 0; break; // box 1280x1280
|
2015-12-24 19:26:28 +00:00
|
|
|
case 'w': newThumbLevel = 8; newMediumLevel = 8; newFullLevel = 2; break; // box 2560x2560 // if loading this fix HistoryPhoto::updateFrom
|
2014-08-15 11:19:32 +00:00
|
|
|
case 'a': newThumbLevel = 1; newMediumLevel = 4; newFullLevel = 8; break; // crop 160x160
|
|
|
|
case 'b': newThumbLevel = 3; newMediumLevel = 1; newFullLevel = 7; break; // crop 320x320
|
|
|
|
case 'c': newThumbLevel = 4; newMediumLevel = 2; newFullLevel = 6; break; // crop 640x640
|
|
|
|
case 'd': newThumbLevel = 7; newMediumLevel = 7; newFullLevel = 5; break; // crop 1280x1280
|
|
|
|
}
|
|
|
|
if (newThumbLevel < 0 || newMediumLevel < 0 || newFullLevel < 0) {
|
2014-05-30 08:53:19 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (thumbLevel < 0 || newThumbLevel < thumbLevel) {
|
|
|
|
thumbLevel = newThumbLevel;
|
|
|
|
thumb = &i.value();
|
|
|
|
}
|
2014-08-15 11:19:32 +00:00
|
|
|
if (mediumLevel < 0 || newMediumLevel < mediumLevel) {
|
|
|
|
mediumLevel = newMediumLevel;
|
|
|
|
medium = &i.value();
|
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
if (fullLevel < 0 || newFullLevel < fullLevel) {
|
|
|
|
fullLevel = newFullLevel;
|
|
|
|
full = &i.value();
|
|
|
|
}
|
|
|
|
}
|
2014-08-15 11:19:32 +00:00
|
|
|
if (!thumb || !medium || !full) {
|
2014-05-30 08:53:19 +00:00
|
|
|
return App::photo(0);
|
|
|
|
}
|
|
|
|
switch (photo.type()) {
|
|
|
|
case mtpc_photo: {
|
2016-04-08 10:44:35 +00:00
|
|
|
const auto &ph(photo.c_photo());
|
2015-08-12 18:01:32 +00:00
|
|
|
return App::photoSet(ph.vid.v, 0, ph.vaccess_hash.v, ph.vdate.v, ImagePtr(*thumb, "JPG"), ImagePtr(*medium, "JPG"), ImagePtr(*full, "JPG"));
|
2014-05-30 08:53:19 +00:00
|
|
|
} break;
|
|
|
|
case mtpc_photoEmpty: return App::photo(photo.c_photoEmpty().vid.v);
|
|
|
|
}
|
|
|
|
return App::photo(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
PhotoData *feedPhoto(const MTPDphoto &photo, PhotoData *convert) {
|
2016-04-08 10:44:35 +00:00
|
|
|
const auto &sizes(photo.vsizes.c_vector().v);
|
2014-08-15 11:19:32 +00:00
|
|
|
const MTPPhotoSize *thumb = 0, *medium = 0, *full = 0;
|
|
|
|
int32 thumbLevel = -1, mediumLevel = -1, fullLevel = -1;
|
2014-05-30 08:53:19 +00:00
|
|
|
for (QVector<MTPPhotoSize>::const_iterator i = sizes.cbegin(), e = sizes.cend(); i != e; ++i) {
|
|
|
|
char size = 0;
|
|
|
|
switch (i->type()) {
|
|
|
|
case mtpc_photoSize: {
|
2016-09-29 11:37:16 +00:00
|
|
|
auto &s = i->c_photoSize().vtype.c_string().v;
|
2014-05-30 08:53:19 +00:00
|
|
|
if (s.size()) size = s[0];
|
|
|
|
} break;
|
2016-01-03 01:43:42 +00:00
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
case mtpc_photoCachedSize: {
|
2016-09-29 11:37:16 +00:00
|
|
|
auto &s = i->c_photoCachedSize().vtype.c_string().v;
|
2014-05-30 08:53:19 +00:00
|
|
|
if (s.size()) size = s[0];
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
if (!size) continue;
|
|
|
|
|
2014-08-15 11:19:32 +00:00
|
|
|
int32 newThumbLevel = -1, newMediumLevel = -1, newFullLevel = -1;
|
2014-05-30 08:53:19 +00:00
|
|
|
switch (size) {
|
2014-08-15 11:19:32 +00:00
|
|
|
case 's': newThumbLevel = 0; newMediumLevel = 5; newFullLevel = 4; break; // box 100x100
|
|
|
|
case 'm': newThumbLevel = 2; newMediumLevel = 0; newFullLevel = 3; break; // box 320x320
|
2014-12-12 16:27:03 +00:00
|
|
|
case 'x': newThumbLevel = 5; newMediumLevel = 3; newFullLevel = 1; break; // box 800x800
|
|
|
|
case 'y': newThumbLevel = 6; newMediumLevel = 6; newFullLevel = 0; break; // box 1280x1280
|
2014-08-15 11:19:32 +00:00
|
|
|
case 'w': newThumbLevel = 8; newMediumLevel = 8; newFullLevel = 2; break; // box 2560x2560
|
|
|
|
case 'a': newThumbLevel = 1; newMediumLevel = 4; newFullLevel = 8; break; // crop 160x160
|
|
|
|
case 'b': newThumbLevel = 3; newMediumLevel = 1; newFullLevel = 7; break; // crop 320x320
|
|
|
|
case 'c': newThumbLevel = 4; newMediumLevel = 2; newFullLevel = 6; break; // crop 640x640
|
|
|
|
case 'd': newThumbLevel = 7; newMediumLevel = 7; newFullLevel = 5; break; // crop 1280x1280
|
|
|
|
}
|
|
|
|
if (newThumbLevel < 0 || newMediumLevel < 0 || newFullLevel < 0) {
|
2014-05-30 08:53:19 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (thumbLevel < 0 || newThumbLevel < thumbLevel) {
|
|
|
|
thumbLevel = newThumbLevel;
|
|
|
|
thumb = &(*i);
|
|
|
|
}
|
2014-08-15 11:19:32 +00:00
|
|
|
if (mediumLevel < 0 || newMediumLevel < mediumLevel) {
|
|
|
|
mediumLevel = newMediumLevel;
|
|
|
|
medium = &(*i);
|
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
if (fullLevel < 0 || newFullLevel < fullLevel) {
|
|
|
|
fullLevel = newFullLevel;
|
|
|
|
full = &(*i);
|
|
|
|
}
|
|
|
|
}
|
2014-08-15 11:19:32 +00:00
|
|
|
if (thumb && medium && full) {
|
2015-08-12 18:01:32 +00:00
|
|
|
return App::photoSet(photo.vid.v, convert, photo.vaccess_hash.v, photo.vdate.v, App::image(*thumb), App::image(*medium), App::image(*full));
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
2015-08-12 18:01:32 +00:00
|
|
|
return App::photoSet(photo.vid.v, convert, 0, 0, ImagePtr(), ImagePtr(), ImagePtr());
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
2016-01-03 01:43:42 +00:00
|
|
|
|
2015-01-02 14:55:24 +00:00
|
|
|
DocumentData *feedDocument(const MTPdocument &document, const QPixmap &thumb) {
|
2014-05-30 08:53:19 +00:00
|
|
|
switch (document.type()) {
|
|
|
|
case mtpc_document: {
|
2016-09-27 13:37:18 +00:00
|
|
|
auto &d = document.c_document();
|
2016-07-08 13:56:53 +00:00
|
|
|
return App::documentSet(d.vid.v, 0, d.vaccess_hash.v, d.vversion.v, d.vdate.v, d.vattributes.c_vector().v, qs(d.vmime_type), ImagePtr(thumb, "JPG"), d.vdc_id.v, d.vsize.v, StorageImageLocation());
|
2014-05-30 08:53:19 +00:00
|
|
|
} break;
|
|
|
|
case mtpc_documentEmpty: return App::document(document.c_documentEmpty().vid.v);
|
|
|
|
}
|
|
|
|
return App::document(0);
|
|
|
|
}
|
|
|
|
|
2015-01-02 14:55:24 +00:00
|
|
|
DocumentData *feedDocument(const MTPdocument &document, DocumentData *convert) {
|
2014-05-30 08:53:19 +00:00
|
|
|
switch (document.type()) {
|
|
|
|
case mtpc_document: {
|
2015-01-02 14:55:24 +00:00
|
|
|
return feedDocument(document.c_document(), convert);
|
2014-05-30 08:53:19 +00:00
|
|
|
} break;
|
|
|
|
case mtpc_documentEmpty: {
|
2016-07-08 13:56:53 +00:00
|
|
|
return App::documentSet(document.c_documentEmpty().vid.v, convert, 0, 0, 0, QVector<MTPDocumentAttribute>(), QString(), ImagePtr(), 0, 0, StorageImageLocation());
|
2014-05-30 08:53:19 +00:00
|
|
|
} break;
|
|
|
|
}
|
|
|
|
return App::document(0);
|
|
|
|
}
|
|
|
|
|
2015-01-02 14:55:24 +00:00
|
|
|
DocumentData *feedDocument(const MTPDdocument &document, DocumentData *convert) {
|
2016-07-08 13:56:53 +00:00
|
|
|
return App::documentSet(document.vid.v, convert, document.vaccess_hash.v, document.vversion.v, document.vdate.v, document.vattributes.c_vector().v, qs(document.vmime_type), App::image(document.vthumb), document.vdc_id.v, document.vsize.v, App::imageLocation(document.vthumb));
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2015-04-04 20:01:34 +00:00
|
|
|
WebPageData *feedWebPage(const MTPDwebPage &webpage, WebPageData *convert) {
|
2015-08-30 14:57:21 +00:00
|
|
|
return App::webPageSet(webpage.vid.v, convert, webpage.has_type() ? qs(webpage.vtype) : qsl("article"), qs(webpage.vurl), qs(webpage.vdisplay_url), webpage.has_site_name() ? qs(webpage.vsite_name) : QString(), webpage.has_title() ? qs(webpage.vtitle) : QString(), webpage.has_description() ? qs(webpage.vdescription) : QString(), webpage.has_photo() ? App::feedPhoto(webpage.vphoto) : 0, webpage.has_document() ? App::feedDocument(webpage.vdocument) : 0, webpage.has_duration() ? webpage.vduration.v : 0, webpage.has_author() ? qs(webpage.vauthor) : QString(), 0);
|
2015-04-04 20:01:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
WebPageData *feedWebPage(const MTPDwebPagePending &webpage, WebPageData *convert) {
|
2015-08-30 14:57:21 +00:00
|
|
|
return App::webPageSet(webpage.vid.v, convert, QString(), QString(), QString(), QString(), QString(), QString(), 0, 0, 0, QString(), webpage.vdate.v);
|
2015-04-04 20:01:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
WebPageData *feedWebPage(const MTPWebPage &webpage) {
|
|
|
|
switch (webpage.type()) {
|
|
|
|
case mtpc_webPage: return App::feedWebPage(webpage.c_webPage());
|
2015-05-20 19:28:24 +00:00
|
|
|
case mtpc_webPageEmpty: {
|
|
|
|
WebPageData *page = App::webPage(webpage.c_webPageEmpty().vid.v);
|
|
|
|
if (page->pendingTill > 0) page->pendingTill = -1; // failed
|
|
|
|
return page;
|
|
|
|
} break;
|
2015-04-04 20:01:34 +00:00
|
|
|
case mtpc_webPagePending: return App::feedWebPage(webpage.c_webPagePending());
|
2016-12-13 07:59:57 +00:00
|
|
|
case mtpc_webPageNotModified: LOG(("API Error: webPageNotModified is unexpected in feedWebPage().")); break;
|
2015-04-04 20:01:34 +00:00
|
|
|
}
|
2016-09-27 13:37:18 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
GameData *feedGame(const MTPDgame &game, GameData *convert) {
|
2016-09-28 10:15:03 +00:00
|
|
|
return App::gameSet(game.vid.v, convert, game.vaccess_hash.v, qs(game.vshort_name), qs(game.vtitle), qs(game.vdescription), App::feedPhoto(game.vphoto), game.has_document() ? App::feedDocument(game.vdocument) : nullptr);
|
2015-04-04 20:01:34 +00:00
|
|
|
}
|
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
UserData *curUser() {
|
|
|
|
return user(MTP::authedId());
|
|
|
|
}
|
|
|
|
|
2016-03-25 11:29:45 +00:00
|
|
|
PeerData *peer(const PeerId &id, PeerData::LoadedStatus restriction) {
|
|
|
|
if (!id) return nullptr;
|
|
|
|
|
|
|
|
auto i = peersData.constFind(id);
|
2014-05-30 08:53:19 +00:00
|
|
|
if (i == peersData.cend()) {
|
2016-03-25 11:29:45 +00:00
|
|
|
PeerData *newData = nullptr;
|
2015-09-03 10:48:40 +00:00
|
|
|
if (peerIsUser(id)) {
|
|
|
|
newData = new UserData(id);
|
|
|
|
} else if (peerIsChat(id)) {
|
|
|
|
newData = new ChatData(id);
|
|
|
|
} else if (peerIsChannel(id)) {
|
|
|
|
newData = new ChannelData(id);
|
|
|
|
}
|
2016-03-25 11:29:45 +00:00
|
|
|
t_assert(newData != nullptr);
|
2015-09-03 10:48:40 +00:00
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
newData->input = MTPinputPeer(MTP_inputPeerEmpty());
|
2015-09-03 10:48:40 +00:00
|
|
|
i = peersData.insert(id, newData);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
2016-03-25 11:29:45 +00:00
|
|
|
switch (restriction) {
|
|
|
|
case PeerData::MinimalLoaded: {
|
|
|
|
if (i.value()->loadedStatus == PeerData::NotLoaded) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case PeerData::FullLoaded: {
|
|
|
|
if (i.value()->loadedStatus != PeerData::FullLoaded) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
return i.value();
|
|
|
|
}
|
|
|
|
|
|
|
|
UserData *self() {
|
|
|
|
return ::self;
|
|
|
|
}
|
|
|
|
|
2015-12-28 22:06:27 +00:00
|
|
|
PeerData *peerByName(const QString &username) {
|
|
|
|
QString uname(username.trimmed());
|
2016-03-31 14:06:40 +00:00
|
|
|
for_const (PeerData *peer, peersData) {
|
|
|
|
if (!peer->userName().compare(uname, Qt::CaseInsensitive)) {
|
|
|
|
return peer;
|
2014-12-03 13:10:32 +00:00
|
|
|
}
|
|
|
|
}
|
2016-03-31 14:06:40 +00:00
|
|
|
return nullptr;
|
2014-12-03 13:10:32 +00:00
|
|
|
}
|
|
|
|
|
2015-12-31 15:27:21 +00:00
|
|
|
void updateImage(ImagePtr &old, ImagePtr now) {
|
|
|
|
if (now->isNull()) return;
|
|
|
|
if (old->isNull()) {
|
|
|
|
old = now;
|
|
|
|
} else if (DelayedStorageImage *img = old->toDelayedStorageImage()) {
|
|
|
|
StorageImageLocation loc = now->location();
|
|
|
|
if (!loc.isNull()) {
|
|
|
|
img->setStorageLocation(loc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-21 14:55:23 +00:00
|
|
|
PhotoData *photo(const PhotoId &photo) {
|
2015-12-27 21:37:48 +00:00
|
|
|
PhotosData::const_iterator i = ::photosData.constFind(photo);
|
|
|
|
if (i == ::photosData.cend()) {
|
|
|
|
i = ::photosData.insert(photo, new PhotoData(photo));
|
2015-07-21 14:55:23 +00:00
|
|
|
}
|
|
|
|
return i.value();
|
|
|
|
}
|
|
|
|
|
2015-08-12 18:01:32 +00:00
|
|
|
PhotoData *photoSet(const PhotoId &photo, PhotoData *convert, const uint64 &access, int32 date, const ImagePtr &thumb, const ImagePtr &medium, const ImagePtr &full) {
|
2014-05-30 08:53:19 +00:00
|
|
|
if (convert) {
|
|
|
|
if (convert->id != photo) {
|
2015-12-27 21:37:48 +00:00
|
|
|
PhotosData::iterator i = ::photosData.find(convert->id);
|
|
|
|
if (i != ::photosData.cend() && i.value() == convert) {
|
|
|
|
::photosData.erase(i);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
convert->id = photo;
|
2015-12-24 19:26:28 +00:00
|
|
|
delete convert->uploadingData;
|
|
|
|
convert->uploadingData = 0;
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
2015-12-31 05:34:43 +00:00
|
|
|
if (date) {
|
|
|
|
convert->access = access;
|
2014-05-30 08:53:19 +00:00
|
|
|
convert->date = date;
|
2015-12-31 15:27:21 +00:00
|
|
|
updateImage(convert->thumb, thumb);
|
|
|
|
updateImage(convert->medium, medium);
|
|
|
|
updateImage(convert->full, full);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
}
|
2015-12-27 21:37:48 +00:00
|
|
|
PhotosData::const_iterator i = ::photosData.constFind(photo);
|
2014-05-30 08:53:19 +00:00
|
|
|
PhotoData *result;
|
|
|
|
LastPhotosMap::iterator inLastIter = lastPhotosMap.end();
|
2015-12-27 21:37:48 +00:00
|
|
|
if (i == ::photosData.cend()) {
|
2014-05-30 08:53:19 +00:00
|
|
|
if (convert) {
|
|
|
|
result = convert;
|
|
|
|
} else {
|
2015-08-12 18:01:32 +00:00
|
|
|
result = new PhotoData(photo, access, date, thumb, medium, full);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
2015-12-27 21:37:48 +00:00
|
|
|
::photosData.insert(photo, result);
|
2014-05-30 08:53:19 +00:00
|
|
|
} else {
|
|
|
|
result = i.value();
|
2015-12-31 05:34:43 +00:00
|
|
|
if (result != convert && date) {
|
2014-05-30 08:53:19 +00:00
|
|
|
result->access = access;
|
|
|
|
result->date = date;
|
2015-12-31 15:27:21 +00:00
|
|
|
updateImage(result->thumb, thumb);
|
|
|
|
updateImage(result->medium, medium);
|
|
|
|
updateImage(result->full, full);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
inLastIter = lastPhotosMap.find(result);
|
|
|
|
}
|
|
|
|
if (inLastIter == lastPhotosMap.end()) { // insert new one
|
|
|
|
if (lastPhotos.size() == MaxPhotosInMemory) {
|
|
|
|
lastPhotos.front()->forget();
|
|
|
|
lastPhotosMap.remove(lastPhotos.front());
|
|
|
|
lastPhotos.pop_front();
|
|
|
|
}
|
|
|
|
lastPhotosMap.insert(result, lastPhotos.insert(lastPhotos.end(), result));
|
|
|
|
} else {
|
|
|
|
lastPhotos.erase(inLastIter.value()); // move to back
|
|
|
|
(*inLastIter) = lastPhotos.insert(lastPhotos.end(), result);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2015-05-19 15:46:45 +00:00
|
|
|
DocumentData *document(const DocumentId &document) {
|
2015-12-27 21:37:48 +00:00
|
|
|
DocumentsData::const_iterator i = ::documentsData.constFind(document);
|
|
|
|
if (i == ::documentsData.cend()) {
|
2016-04-09 05:57:55 +00:00
|
|
|
i = ::documentsData.insert(document, DocumentData::create(document));
|
2015-05-19 15:46:45 +00:00
|
|
|
}
|
|
|
|
return i.value();
|
|
|
|
}
|
|
|
|
|
2016-07-08 13:56:53 +00:00
|
|
|
DocumentData *documentSet(const DocumentId &document, DocumentData *convert, const uint64 &access, int32 version, int32 date, const QVector<MTPDocumentAttribute> &attributes, const QString &mime, const ImagePtr &thumb, int32 dc, int32 size, const StorageImageLocation &thumbLocation) {
|
|
|
|
bool versionChanged = false;
|
2015-06-10 12:48:26 +00:00
|
|
|
bool sentSticker = false;
|
2014-05-30 08:53:19 +00:00
|
|
|
if (convert) {
|
2016-04-09 05:57:55 +00:00
|
|
|
MediaKey oldKey = convert->mediaKey();
|
2016-07-08 13:56:53 +00:00
|
|
|
bool idChanged = (convert->id != document);
|
|
|
|
if (idChanged) {
|
2015-12-27 21:37:48 +00:00
|
|
|
DocumentsData::iterator i = ::documentsData.find(convert->id);
|
|
|
|
if (i != ::documentsData.cend() && i.value() == convert) {
|
|
|
|
::documentsData.erase(i);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
2016-02-12 18:18:32 +00:00
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
convert->id = document;
|
|
|
|
convert->status = FileReady;
|
2016-02-12 18:18:32 +00:00
|
|
|
sentSticker = (convert->sticker() != 0);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
2015-12-31 05:34:43 +00:00
|
|
|
if (date) {
|
2014-12-22 23:11:37 +00:00
|
|
|
convert->setattributes(attributes);
|
2016-07-08 13:56:53 +00:00
|
|
|
versionChanged = convert->setRemoteVersion(version);
|
2016-04-09 05:57:55 +00:00
|
|
|
convert->setRemoteLocation(dc, access);
|
|
|
|
convert->date = date;
|
2014-05-30 08:53:19 +00:00
|
|
|
convert->mime = mime;
|
2016-07-08 13:56:53 +00:00
|
|
|
if (!thumb->isNull() && (convert->thumb->isNull() || convert->thumb->width() < thumb->width() || convert->thumb->height() < thumb->height() || versionChanged)) {
|
2016-02-12 18:18:32 +00:00
|
|
|
updateImage(convert->thumb, thumb);
|
2015-05-19 15:46:45 +00:00
|
|
|
}
|
2015-12-31 05:34:43 +00:00
|
|
|
convert->size = size;
|
|
|
|
convert->recountIsImage();
|
|
|
|
if (convert->sticker() && convert->sticker()->loc.isNull() && !thumbLocation.isNull()) {
|
|
|
|
convert->sticker()->loc = thumbLocation;
|
2015-05-19 15:46:45 +00:00
|
|
|
}
|
2016-04-09 05:57:55 +00:00
|
|
|
|
|
|
|
MediaKey newKey = convert->mediaKey();
|
2016-07-08 13:56:53 +00:00
|
|
|
if (idChanged) {
|
2016-04-09 05:57:55 +00:00
|
|
|
if (convert->voice()) {
|
|
|
|
Local::copyAudio(oldKey, newKey);
|
|
|
|
} else if (convert->sticker() || convert->isAnimation()) {
|
|
|
|
Local::copyStickerImage(oldKey, newKey);
|
|
|
|
}
|
|
|
|
}
|
2015-05-19 15:46:45 +00:00
|
|
|
}
|
2015-12-31 15:27:21 +00:00
|
|
|
|
|
|
|
if (cSavedGifs().indexOf(convert) >= 0) { // id changed
|
|
|
|
Local::writeSavedGifs();
|
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
2015-12-27 21:37:48 +00:00
|
|
|
DocumentsData::const_iterator i = ::documentsData.constFind(document);
|
2014-05-30 08:53:19 +00:00
|
|
|
DocumentData *result;
|
2015-12-27 21:37:48 +00:00
|
|
|
if (i == ::documentsData.cend()) {
|
2014-05-30 08:53:19 +00:00
|
|
|
if (convert) {
|
|
|
|
result = convert;
|
|
|
|
} else {
|
2016-07-08 13:56:53 +00:00
|
|
|
result = DocumentData::create(document, dc, access, version, attributes);
|
2016-04-09 05:57:55 +00:00
|
|
|
result->date = date;
|
|
|
|
result->mime = mime;
|
|
|
|
result->thumb = thumb;
|
|
|
|
result->size = size;
|
2015-12-10 13:37:45 +00:00
|
|
|
result->recountIsImage();
|
2016-02-12 18:18:32 +00:00
|
|
|
if (result->sticker()) {
|
|
|
|
result->sticker()->loc = thumbLocation;
|
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
2015-12-27 21:37:48 +00:00
|
|
|
::documentsData.insert(document, result);
|
2014-05-30 08:53:19 +00:00
|
|
|
} else {
|
|
|
|
result = i.value();
|
2015-12-31 05:34:43 +00:00
|
|
|
if (result != convert && date) {
|
|
|
|
result->setattributes(attributes);
|
2016-07-08 13:56:53 +00:00
|
|
|
versionChanged = result->setRemoteVersion(version);
|
2016-04-09 05:57:55 +00:00
|
|
|
if (!result->isValid()) {
|
|
|
|
result->setRemoteLocation(dc, access);
|
|
|
|
}
|
|
|
|
result->date = date;
|
2015-12-31 05:34:43 +00:00
|
|
|
result->mime = mime;
|
2016-07-08 13:56:53 +00:00
|
|
|
if (!thumb->isNull() && (result->thumb->isNull() || result->thumb->width() < thumb->width() || result->thumb->height() < thumb->height() || versionChanged)) {
|
2015-01-02 14:55:24 +00:00
|
|
|
result->thumb = thumb;
|
2015-12-31 05:34:43 +00:00
|
|
|
}
|
|
|
|
result->size = size;
|
|
|
|
result->recountIsImage();
|
|
|
|
if (result->sticker() && result->sticker()->loc.isNull() && !thumbLocation.isNull()) {
|
|
|
|
result->sticker()->loc = thumbLocation;
|
2015-01-02 14:55:24 +00:00
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
}
|
2016-02-12 18:18:32 +00:00
|
|
|
if (sentSticker && App::main()) {
|
|
|
|
App::main()->incrementSticker(result);
|
|
|
|
}
|
2016-07-08 13:56:53 +00:00
|
|
|
if (versionChanged) {
|
2016-07-21 10:09:47 +00:00
|
|
|
if (result->sticker() && result->sticker()->set.type() == mtpc_inputStickerSetID) {
|
|
|
|
auto it = Global::StickerSets().constFind(result->sticker()->set.c_inputStickerSetID().vid.v);
|
|
|
|
if (it != Global::StickerSets().cend()) {
|
|
|
|
if (it->id == Stickers::CloudRecentSetId) {
|
|
|
|
Local::writeRecentStickers();
|
|
|
|
} else if (it->flags & MTPDstickerSet::Flag::f_archived) {
|
|
|
|
Local::writeArchivedStickers();
|
|
|
|
} else if (it->flags & MTPDstickerSet::Flag::f_installed) {
|
|
|
|
Local::writeInstalledStickers();
|
|
|
|
}
|
|
|
|
if (it->flags & MTPDstickerSet_ClientFlag::f_featured) {
|
|
|
|
Local::writeFeaturedStickers();
|
|
|
|
}
|
|
|
|
}
|
2016-07-08 13:56:53 +00:00
|
|
|
}
|
|
|
|
auto &items = App::documentItems();
|
|
|
|
auto i = items.constFind(result);
|
|
|
|
if (i != items.cend()) {
|
2016-09-27 13:37:18 +00:00
|
|
|
for_const (auto item, i.value()) {
|
|
|
|
item->setPendingInitDimensions();
|
2016-07-08 13:56:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2015-07-21 14:55:23 +00:00
|
|
|
WebPageData *webPage(const WebPageId &webPage) {
|
2016-09-27 13:37:18 +00:00
|
|
|
auto i = webPagesData.constFind(webPage);
|
2015-07-21 14:55:23 +00:00
|
|
|
if (i == webPagesData.cend()) {
|
|
|
|
i = webPagesData.insert(webPage, new WebPageData(webPage));
|
|
|
|
}
|
|
|
|
return i.value();
|
|
|
|
}
|
|
|
|
|
2016-04-08 09:20:10 +00:00
|
|
|
WebPageData *webPageSet(const WebPageId &webPage, WebPageData *convert, const QString &type, const QString &url, const QString &displayUrl, const QString &siteName, const QString &title, const QString &description, PhotoData *photo, DocumentData *document, int32 duration, const QString &author, int32 pendingTill) {
|
2015-04-04 20:01:34 +00:00
|
|
|
if (convert) {
|
|
|
|
if (convert->id != webPage) {
|
2016-09-27 13:37:18 +00:00
|
|
|
auto i = webPagesData.find(convert->id);
|
2015-04-04 20:01:34 +00:00
|
|
|
if (i != webPagesData.cend() && i.value() == convert) {
|
|
|
|
webPagesData.erase(i);
|
|
|
|
}
|
|
|
|
convert->id = webPage;
|
|
|
|
}
|
2015-04-07 23:03:32 +00:00
|
|
|
if ((convert->url.isEmpty() && !url.isEmpty()) || (convert->pendingTill && convert->pendingTill != pendingTill && pendingTill >= -1)) {
|
2015-04-04 20:01:34 +00:00
|
|
|
convert->type = toWebPageType(type);
|
2016-09-28 11:38:35 +00:00
|
|
|
convert->url = textClean(url);
|
|
|
|
convert->displayUrl = textClean(displayUrl);
|
|
|
|
convert->siteName = textClean(siteName);
|
|
|
|
convert->title = textOneLine(textClean(title));
|
|
|
|
convert->description = textClean(description);
|
2015-04-04 20:01:34 +00:00
|
|
|
convert->photo = photo;
|
2016-04-08 09:20:10 +00:00
|
|
|
convert->document = document;
|
2015-04-04 20:01:34 +00:00
|
|
|
convert->duration = duration;
|
2016-09-28 11:38:35 +00:00
|
|
|
convert->author = textClean(author);
|
2015-04-04 20:01:34 +00:00
|
|
|
if (convert->pendingTill > 0 && pendingTill <= 0 && api()) api()->clearWebPageRequest(convert);
|
|
|
|
convert->pendingTill = pendingTill;
|
2015-04-07 23:03:32 +00:00
|
|
|
if (App::main()) App::main()->webPageUpdated(convert);
|
2015-04-04 20:01:34 +00:00
|
|
|
}
|
|
|
|
}
|
2016-09-27 13:37:18 +00:00
|
|
|
auto i = webPagesData.constFind(webPage);
|
2015-04-04 20:01:34 +00:00
|
|
|
WebPageData *result;
|
|
|
|
if (i == webPagesData.cend()) {
|
|
|
|
if (convert) {
|
|
|
|
result = convert;
|
|
|
|
} else {
|
2016-04-08 09:20:10 +00:00
|
|
|
result = new WebPageData(webPage, toWebPageType(type), url, displayUrl, siteName, title, description, document, photo, duration, author, (pendingTill >= -1) ? pendingTill : -1);
|
2015-04-04 20:01:34 +00:00
|
|
|
if (pendingTill > 0 && api()) {
|
|
|
|
api()->requestWebPageDelayed(result);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
webPagesData.insert(webPage, result);
|
|
|
|
} else {
|
|
|
|
result = i.value();
|
|
|
|
if (result != convert) {
|
2015-04-07 23:03:32 +00:00
|
|
|
if ((result->url.isEmpty() && !url.isEmpty()) || (result->pendingTill && result->pendingTill != pendingTill && pendingTill >= -1)) {
|
2015-04-04 20:01:34 +00:00
|
|
|
result->type = toWebPageType(type);
|
2016-09-28 11:38:35 +00:00
|
|
|
result->url = textClean(url);
|
|
|
|
result->displayUrl = textClean(displayUrl);
|
|
|
|
result->siteName = textClean(siteName);
|
|
|
|
result->title = textOneLine(textClean(title));
|
|
|
|
result->description = textClean(description);
|
2015-04-04 20:01:34 +00:00
|
|
|
result->photo = photo;
|
2016-04-08 09:20:10 +00:00
|
|
|
result->document = document;
|
2015-04-04 20:01:34 +00:00
|
|
|
result->duration = duration;
|
2016-09-28 11:38:35 +00:00
|
|
|
result->author = textClean(author);
|
2015-04-04 20:01:34 +00:00
|
|
|
if (result->pendingTill > 0 && pendingTill <= 0 && api()) api()->clearWebPageRequest(result);
|
|
|
|
result->pendingTill = pendingTill;
|
2015-04-07 23:03:32 +00:00
|
|
|
if (App::main()) App::main()->webPageUpdated(result);
|
2015-04-04 20:01:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
2016-01-03 01:43:42 +00:00
|
|
|
|
2016-09-27 13:37:18 +00:00
|
|
|
GameData *game(const GameId &game) {
|
|
|
|
auto i = gamesData.constFind(game);
|
|
|
|
if (i == gamesData.cend()) {
|
|
|
|
i = gamesData.insert(game, new GameData(game));
|
|
|
|
}
|
|
|
|
return i.value();
|
|
|
|
}
|
|
|
|
|
2016-09-28 10:15:03 +00:00
|
|
|
GameData *gameSet(const GameId &game, GameData *convert, const uint64 &accessHash, const QString &shortName, const QString &title, const QString &description, PhotoData *photo, DocumentData *document) {
|
2016-09-27 13:37:18 +00:00
|
|
|
if (convert) {
|
|
|
|
if (convert->id != game) {
|
|
|
|
auto i = gamesData.find(convert->id);
|
|
|
|
if (i != gamesData.cend() && i.value() == convert) {
|
|
|
|
gamesData.erase(i);
|
|
|
|
}
|
|
|
|
convert->id = game;
|
2016-09-28 16:23:25 +00:00
|
|
|
convert->accessHash = 0;
|
2016-09-27 13:37:18 +00:00
|
|
|
}
|
2016-09-28 16:23:25 +00:00
|
|
|
if (!convert->accessHash && accessHash) {
|
2016-09-27 13:37:18 +00:00
|
|
|
convert->accessHash = accessHash;
|
2016-09-28 11:38:35 +00:00
|
|
|
convert->shortName = textClean(shortName);
|
|
|
|
convert->title = textOneLine(textClean(title));
|
|
|
|
convert->description = textClean(description);
|
2016-09-27 13:37:18 +00:00
|
|
|
convert->photo = photo;
|
|
|
|
convert->document = document;
|
|
|
|
if (App::main()) App::main()->gameUpdated(convert);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
auto i = gamesData.constFind(game);
|
|
|
|
GameData *result;
|
|
|
|
if (i == gamesData.cend()) {
|
|
|
|
if (convert) {
|
|
|
|
result = convert;
|
|
|
|
} else {
|
2016-09-28 10:15:03 +00:00
|
|
|
result = new GameData(game, accessHash, shortName, title, description, photo, document);
|
2016-09-27 13:37:18 +00:00
|
|
|
}
|
|
|
|
gamesData.insert(game, result);
|
|
|
|
} else {
|
|
|
|
result = i.value();
|
|
|
|
if (result != convert) {
|
2016-09-28 16:23:25 +00:00
|
|
|
if (!result->accessHash && accessHash) {
|
2016-09-27 13:37:18 +00:00
|
|
|
result->accessHash = accessHash;
|
2016-09-28 11:38:35 +00:00
|
|
|
result->shortName = textClean(shortName);
|
|
|
|
result->title = textOneLine(textClean(title));
|
|
|
|
result->description = textClean(description);
|
2016-09-27 13:37:18 +00:00
|
|
|
result->photo = photo;
|
|
|
|
result->document = document;
|
|
|
|
if (App::main()) App::main()->gameUpdated(result);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-02-28 13:54:04 +00:00
|
|
|
LocationData *location(const LocationCoords &coords) {
|
2016-09-27 13:37:18 +00:00
|
|
|
auto i = locationsData.constFind(coords);
|
2016-02-28 13:54:04 +00:00
|
|
|
if (i == locationsData.cend()) {
|
|
|
|
i = locationsData.insert(coords, new LocationData(coords));
|
2015-07-21 14:55:23 +00:00
|
|
|
}
|
|
|
|
return i.value();
|
|
|
|
}
|
2016-01-03 01:43:42 +00:00
|
|
|
|
2014-11-12 20:18:00 +00:00
|
|
|
void forgetMedia() {
|
|
|
|
lastPhotos.clear();
|
|
|
|
lastPhotosMap.clear();
|
2016-09-27 13:37:18 +00:00
|
|
|
for_const (auto photo, ::photosData) {
|
|
|
|
photo->forget();
|
2014-11-12 20:18:00 +00:00
|
|
|
}
|
2016-09-27 13:37:18 +00:00
|
|
|
for_const (auto document, ::documentsData) {
|
|
|
|
document->forget();
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
2016-09-27 13:37:18 +00:00
|
|
|
for_const (auto location, ::locationsData) {
|
|
|
|
location->thumb->forget();
|
2014-11-12 20:18:00 +00:00
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
MTPPhoto photoFromUserPhoto(MTPint userId, MTPint date, const MTPUserProfilePhoto &photo) {
|
|
|
|
if (photo.type() == mtpc_userProfilePhoto) {
|
2016-04-08 10:44:35 +00:00
|
|
|
const auto &uphoto(photo.c_userProfilePhoto());
|
2016-01-03 01:43:42 +00:00
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
QVector<MTPPhotoSize> photoSizes;
|
|
|
|
photoSizes.push_back(MTP_photoSize(MTP_string("a"), uphoto.vphoto_small, MTP_int(160), MTP_int(160), MTP_int(0)));
|
|
|
|
photoSizes.push_back(MTP_photoSize(MTP_string("c"), uphoto.vphoto_big, MTP_int(640), MTP_int(640), MTP_int(0)));
|
|
|
|
|
2016-09-13 10:03:21 +00:00
|
|
|
MTPDphoto::Flags photoFlags = 0;
|
|
|
|
return MTP_photo(MTP_flags(photoFlags), uphoto.vphoto_id, MTP_long(0), date, MTP_vector<MTPPhotoSize>(photoSizes));
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
return MTP_photoEmpty(MTP_long(0));
|
|
|
|
}
|
|
|
|
|
|
|
|
QString peerName(const PeerData *peer, bool forDialogs) {
|
2015-09-04 13:01:31 +00:00
|
|
|
return peer ? ((forDialogs && peer->isUser() && !peer->asUser()->nameOrPhone.isEmpty()) ? peer->asUser()->nameOrPhone : peer->name) : lang(lng_deleted);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Histories &histories() {
|
|
|
|
return ::histories;
|
|
|
|
}
|
|
|
|
|
2015-09-07 07:52:37 +00:00
|
|
|
History *history(const PeerId &peer) {
|
2016-09-25 19:04:02 +00:00
|
|
|
return ::histories.findOrInsert(peer);
|
2015-09-07 07:52:37 +00:00
|
|
|
}
|
|
|
|
|
2016-05-20 16:01:06 +00:00
|
|
|
History *historyFromDialog(const PeerId &peer, int32 unreadCnt, int32 maxInboxRead, int32 maxOutboxRead) {
|
|
|
|
return ::histories.findOrInsert(peer, unreadCnt, maxInboxRead, maxOutboxRead);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
2016-01-03 01:43:42 +00:00
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
History *historyLoaded(const PeerId &peer) {
|
2015-09-19 09:13:21 +00:00
|
|
|
return ::histories.find(peer);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2015-09-03 10:48:40 +00:00
|
|
|
HistoryItem *histItemById(ChannelId channelId, MsgId itemId) {
|
2016-04-10 18:18:26 +00:00
|
|
|
if (!itemId) return nullptr;
|
|
|
|
|
2016-10-12 19:34:25 +00:00
|
|
|
auto data = fetchMsgsData(channelId, false);
|
2016-04-10 18:18:26 +00:00
|
|
|
if (!data) return nullptr;
|
2015-09-03 10:48:40 +00:00
|
|
|
|
2016-04-10 18:18:26 +00:00
|
|
|
auto i = data->constFind(itemId);
|
2015-09-03 10:48:40 +00:00
|
|
|
if (i != data->cend()) {
|
2014-05-30 08:53:19 +00:00
|
|
|
return i.value();
|
|
|
|
}
|
2016-04-10 18:18:26 +00:00
|
|
|
return nullptr;
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2015-12-23 12:55:32 +00:00
|
|
|
void historyRegItem(HistoryItem *item) {
|
2015-09-03 10:48:40 +00:00
|
|
|
MsgsData *data = fetchMsgsData(item->channelId());
|
|
|
|
MsgsData::const_iterator i = data->constFind(item->id);
|
|
|
|
if (i == data->cend()) {
|
|
|
|
data->insert(item->id, item);
|
2015-12-23 12:55:32 +00:00
|
|
|
} else if (i.value() != item) {
|
|
|
|
LOG(("App Error: trying to historyRegItem() an already registered item"));
|
|
|
|
i.value()->destroy();
|
2015-09-03 10:48:40 +00:00
|
|
|
data->insert(item->id, item);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
2014-07-04 11:12:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void historyItemDetached(HistoryItem *item) {
|
2014-05-30 08:53:19 +00:00
|
|
|
if (::hoveredItem == item) {
|
2016-04-14 19:24:42 +00:00
|
|
|
hoveredItem(nullptr);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
if (::pressedItem == item) {
|
2016-04-14 19:24:42 +00:00
|
|
|
pressedItem(nullptr);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
if (::hoveredLinkItem == item) {
|
2016-04-14 19:24:42 +00:00
|
|
|
hoveredLinkItem(nullptr);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
if (::pressedLinkItem == item) {
|
2016-04-14 19:24:42 +00:00
|
|
|
pressedLinkItem(nullptr);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
if (::contextItem == item) {
|
2016-04-14 19:24:42 +00:00
|
|
|
contextItem(nullptr);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
if (::mousedItem == item) {
|
2016-04-14 19:24:42 +00:00
|
|
|
mousedItem(nullptr);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
2014-07-04 11:12:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void historyUnregItem(HistoryItem *item) {
|
2016-10-02 13:54:27 +00:00
|
|
|
auto data = fetchMsgsData(item->channelId(), false);
|
2015-09-03 10:48:40 +00:00
|
|
|
if (!data) return;
|
|
|
|
|
2016-03-25 15:20:34 +00:00
|
|
|
auto i = data->find(item->id);
|
2015-09-03 10:48:40 +00:00
|
|
|
if (i != data->cend()) {
|
2014-07-04 11:12:54 +00:00
|
|
|
if (i.value() == item) {
|
2015-09-03 10:48:40 +00:00
|
|
|
data->erase(i);
|
2014-07-04 11:12:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
historyItemDetached(item);
|
2016-03-25 15:20:34 +00:00
|
|
|
auto j = ::dependentItems.find(item);
|
2016-03-05 21:12:55 +00:00
|
|
|
if (j != ::dependentItems.cend()) {
|
2016-03-25 20:46:35 +00:00
|
|
|
DependentItemsSet items;
|
|
|
|
std::swap(items, j.value());
|
2016-03-05 21:12:55 +00:00
|
|
|
::dependentItems.erase(j);
|
2016-03-25 20:46:35 +00:00
|
|
|
|
2016-10-02 13:54:27 +00:00
|
|
|
for_const (auto dependent, items) {
|
2016-03-25 15:20:34 +00:00
|
|
|
dependent->dependencyItemRemoved(item);
|
2015-03-19 09:18:19 +00:00
|
|
|
}
|
|
|
|
}
|
2016-10-02 13:54:27 +00:00
|
|
|
if (auto manager = Window::Notifications::manager()) {
|
|
|
|
manager->clearFromItem(item);
|
|
|
|
}
|
2016-10-14 17:10:15 +00:00
|
|
|
if (Global::started() && !App::quitting()) {
|
|
|
|
Global::RefItemRemoved().notify(item, true);
|
2014-10-10 13:47:39 +00:00
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2016-03-11 12:20:58 +00:00
|
|
|
void historyUpdateDependent(HistoryItem *item) {
|
|
|
|
DependentItems::iterator j = ::dependentItems.find(item);
|
|
|
|
if (j != ::dependentItems.cend()) {
|
2016-03-25 15:20:34 +00:00
|
|
|
for_const (HistoryItem *dependent, j.value()) {
|
|
|
|
dependent->updateDependencyItem();
|
2016-03-11 12:20:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (App::main()) {
|
|
|
|
App::main()->itemEdited(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
void historyClearMsgs() {
|
2016-03-05 21:12:55 +00:00
|
|
|
::dependentItems.clear();
|
2015-12-28 06:19:29 +00:00
|
|
|
|
2014-07-04 11:12:54 +00:00
|
|
|
QVector<HistoryItem*> toDelete;
|
2016-03-25 15:20:34 +00:00
|
|
|
for_const (HistoryItem *item, msgsData) {
|
|
|
|
if (item->detached()) {
|
|
|
|
toDelete.push_back(item);
|
2014-07-04 11:12:54 +00:00
|
|
|
}
|
|
|
|
}
|
2016-03-25 15:20:34 +00:00
|
|
|
for_const (const MsgsData &chMsgsData, channelMsgsData) {
|
|
|
|
for_const (HistoryItem *item, chMsgsData) {
|
|
|
|
if (item->detached()) {
|
|
|
|
toDelete.push_back(item);
|
2015-09-04 13:01:31 +00:00
|
|
|
}
|
2015-09-03 10:48:40 +00:00
|
|
|
}
|
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
msgsData.clear();
|
2015-09-03 10:48:40 +00:00
|
|
|
channelMsgsData.clear();
|
|
|
|
for (int32 i = 0, l = toDelete.size(); i < l; ++i) {
|
2014-07-04 11:12:54 +00:00
|
|
|
delete toDelete[i];
|
|
|
|
}
|
2015-09-03 10:48:40 +00:00
|
|
|
|
2016-06-14 16:26:41 +00:00
|
|
|
clearMousedItems();
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void historyClearItems() {
|
|
|
|
randomData.clear();
|
2015-09-03 10:48:40 +00:00
|
|
|
sentData.clear();
|
2015-04-30 13:53:36 +00:00
|
|
|
mutedPeers.clear();
|
2015-06-29 22:09:23 +00:00
|
|
|
updatedPeers.clear();
|
2015-08-07 12:11:50 +00:00
|
|
|
cSetSavedPeers(SavedPeers());
|
|
|
|
cSetSavedPeersByTime(SavedPeersByTime());
|
2016-02-28 12:36:23 +00:00
|
|
|
cSetRecentInlineBots(RecentInlineBots());
|
2016-09-29 11:37:16 +00:00
|
|
|
|
|
|
|
for_const (auto peer, ::peersData) {
|
2016-03-31 14:06:40 +00:00
|
|
|
delete peer;
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
2016-09-29 11:37:16 +00:00
|
|
|
::peersData.clear();
|
|
|
|
for_const (auto game, ::gamesData) {
|
|
|
|
delete game;
|
|
|
|
}
|
|
|
|
::gamesData.clear();
|
|
|
|
for_const (auto webpage, ::webPagesData) {
|
|
|
|
delete webpage;
|
|
|
|
}
|
|
|
|
::webPagesData.clear();
|
|
|
|
for_const (auto photo, ::photosData) {
|
2016-03-31 14:06:40 +00:00
|
|
|
delete photo;
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
2015-12-27 21:37:48 +00:00
|
|
|
::photosData.clear();
|
2016-09-29 11:37:16 +00:00
|
|
|
for_const (auto document, ::documentsData) {
|
2016-03-31 14:06:40 +00:00
|
|
|
delete document;
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
2015-12-27 21:37:48 +00:00
|
|
|
::documentsData.clear();
|
2016-09-29 11:37:16 +00:00
|
|
|
|
2015-04-04 20:01:34 +00:00
|
|
|
if (api()) api()->clearWebPageRequests();
|
2015-01-02 16:09:05 +00:00
|
|
|
cSetRecentStickers(RecentStickerPack());
|
2016-03-19 16:55:15 +00:00
|
|
|
Global::SetStickerSets(Stickers::Sets());
|
|
|
|
Global::SetStickerSetsOrder(Stickers::Order());
|
|
|
|
Global::SetLastStickersUpdate(0);
|
2016-07-15 15:58:52 +00:00
|
|
|
Global::SetLastRecentStickersUpdate(0);
|
2016-06-28 18:05:38 +00:00
|
|
|
Global::SetFeaturedStickerSetsOrder(Stickers::Order());
|
2016-11-22 09:48:13 +00:00
|
|
|
if (Global::FeaturedStickerSetsUnreadCount() != 0) {
|
|
|
|
Global::SetFeaturedStickerSetsUnreadCount(0);
|
|
|
|
Global::RefFeaturedStickerSetsUnreadCountChanged().notify();
|
|
|
|
}
|
2016-06-28 18:05:38 +00:00
|
|
|
Global::SetLastFeaturedStickersUpdate(0);
|
2016-07-21 13:57:31 +00:00
|
|
|
Global::SetArchivedStickerSetsOrder(Stickers::Order());
|
2015-12-27 21:37:48 +00:00
|
|
|
cSetSavedGifs(SavedGifs());
|
|
|
|
cSetLastSavedGifsUpdate(0);
|
2015-09-09 08:19:25 +00:00
|
|
|
cSetReportSpamStatuses(ReportSpamStatuses());
|
2016-02-15 11:11:07 +00:00
|
|
|
cSetAutoDownloadPhoto(0);
|
|
|
|
cSetAutoDownloadAudio(0);
|
|
|
|
cSetAutoDownloadGif(0);
|
2015-12-25 13:09:14 +00:00
|
|
|
::photoItems.clear();
|
2014-05-30 08:53:19 +00:00
|
|
|
::documentItems.clear();
|
2015-04-04 20:01:34 +00:00
|
|
|
::webPageItems.clear();
|
2016-09-27 13:37:18 +00:00
|
|
|
::gameItems.clear();
|
2015-12-12 22:29:33 +00:00
|
|
|
::sharedContactItems.clear();
|
2015-12-15 14:50:51 +00:00
|
|
|
::gifItems.clear();
|
2014-05-30 08:53:19 +00:00
|
|
|
lastPhotos.clear();
|
|
|
|
lastPhotosMap.clear();
|
2016-08-27 04:49:18 +00:00
|
|
|
::self = nullptr;
|
|
|
|
Global::RefSelfChanged().notify(true);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
2015-03-19 09:18:19 +00:00
|
|
|
|
2016-03-05 21:12:55 +00:00
|
|
|
void historyRegDependency(HistoryItem *dependent, HistoryItem *dependency) {
|
|
|
|
::dependentItems[dependency].insert(dependent);
|
2015-03-19 09:18:19 +00:00
|
|
|
}
|
|
|
|
|
2016-03-05 21:12:55 +00:00
|
|
|
void historyUnregDependency(HistoryItem *dependent, HistoryItem *dependency) {
|
2016-03-25 20:46:35 +00:00
|
|
|
auto i = ::dependentItems.find(dependency);
|
2016-03-05 21:12:55 +00:00
|
|
|
if (i != ::dependentItems.cend()) {
|
|
|
|
i.value().remove(dependent);
|
2015-03-19 09:18:19 +00:00
|
|
|
if (i.value().isEmpty()) {
|
2016-03-05 21:12:55 +00:00
|
|
|
::dependentItems.erase(i);
|
2015-03-19 09:18:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-03 10:48:40 +00:00
|
|
|
void historyRegRandom(uint64 randomId, const FullMsgId &itemId) {
|
2014-05-30 08:53:19 +00:00
|
|
|
randomData.insert(randomId, itemId);
|
|
|
|
}
|
|
|
|
|
|
|
|
void historyUnregRandom(uint64 randomId) {
|
|
|
|
randomData.remove(randomId);
|
|
|
|
}
|
|
|
|
|
2015-09-03 10:48:40 +00:00
|
|
|
FullMsgId histItemByRandom(uint64 randomId) {
|
2014-05-30 08:53:19 +00:00
|
|
|
RandomData::const_iterator i = randomData.constFind(randomId);
|
|
|
|
if (i != randomData.cend()) {
|
|
|
|
return i.value();
|
|
|
|
}
|
2015-09-03 10:48:40 +00:00
|
|
|
return FullMsgId();
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2015-09-03 10:48:40 +00:00
|
|
|
void historyRegSentData(uint64 randomId, const PeerId &peerId, const QString &text) {
|
|
|
|
sentData.insert(randomId, qMakePair(peerId, text));
|
2015-08-24 10:53:04 +00:00
|
|
|
}
|
|
|
|
|
2015-09-03 10:48:40 +00:00
|
|
|
void historyUnregSentData(uint64 randomId) {
|
|
|
|
sentData.remove(randomId);
|
2015-08-24 10:53:04 +00:00
|
|
|
}
|
|
|
|
|
2015-09-03 10:48:40 +00:00
|
|
|
void histSentDataByItem(uint64 randomId, PeerId &peerId, QString &text) {
|
|
|
|
QPair<PeerId, QString> d = sentData.value(randomId);
|
|
|
|
peerId = d.first;
|
|
|
|
text = d.second;
|
2015-08-24 10:53:04 +00:00
|
|
|
}
|
|
|
|
|
2016-12-23 13:21:01 +00:00
|
|
|
void prepareCorners(RoundCorners index, int32 radius, const QBrush &brush, const style::color *shadow = nullptr, QImage *cors = nullptr) {
|
2015-05-20 19:28:24 +00:00
|
|
|
int32 r = radius * cIntRetinaFactor(), s = st::msgShadow * cIntRetinaFactor();
|
|
|
|
QImage rect(r * 3, r * 3 + (shadow ? s : 0), QImage::Format_ARGB32_Premultiplied), localCors[4];
|
|
|
|
{
|
2016-12-03 12:10:35 +00:00
|
|
|
Painter p(&rect);
|
|
|
|
PainterHighQualityEnabler hq(p);
|
|
|
|
|
2015-05-20 19:28:24 +00:00
|
|
|
p.setCompositionMode(QPainter::CompositionMode_Source);
|
2016-10-31 12:29:26 +00:00
|
|
|
p.fillRect(QRect(0, 0, rect.width(), rect.height()), Qt::transparent);
|
2015-05-20 19:28:24 +00:00
|
|
|
p.setCompositionMode(QPainter::CompositionMode_SourceOver);
|
|
|
|
p.setPen(Qt::NoPen);
|
|
|
|
if (shadow) {
|
|
|
|
p.setBrush((*shadow)->b);
|
|
|
|
p.drawRoundedRect(0, s, r * 3, r * 3, r, r);
|
|
|
|
}
|
2016-12-23 13:21:01 +00:00
|
|
|
p.setBrush(brush);
|
2015-05-20 19:28:24 +00:00
|
|
|
p.drawRoundedRect(0, 0, r * 3, r * 3, r, r);
|
|
|
|
}
|
|
|
|
if (!cors) cors = localCors;
|
|
|
|
cors[0] = rect.copy(0, 0, r, r);
|
|
|
|
cors[1] = rect.copy(r * 2, 0, r, r);
|
|
|
|
cors[2] = rect.copy(0, r * 2, r, r + (shadow ? s : 0));
|
|
|
|
cors[3] = rect.copy(r * 2, r * 2, r, r + (shadow ? s : 0));
|
2016-07-07 12:35:14 +00:00
|
|
|
if (index != SmallMaskCorners && index != LargeMaskCorners) {
|
2015-10-03 10:09:09 +00:00
|
|
|
for (int i = 0; i < 4; ++i) {
|
2016-07-13 17:34:57 +00:00
|
|
|
::corners[index].p[i] = new QPixmap(pixmapFromImageInPlace(std_::move(cors[i])));
|
2015-10-03 10:09:09 +00:00
|
|
|
::corners[index].p[i]->setDevicePixelRatio(cRetinaFactor());
|
|
|
|
}
|
2015-05-20 19:28:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-23 16:06:56 +00:00
|
|
|
void tryFontFamily(QString &family, const QString &tryFamily) {
|
|
|
|
if (family.isEmpty()) {
|
|
|
|
if (!QFontInfo(QFont(tryFamily)).family().trimmed().compare(tryFamily, Qt::CaseInsensitive)) {
|
|
|
|
family = tryFamily;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-14 19:56:26 +00:00
|
|
|
int msgRadius() {
|
|
|
|
static int MsgRadius = ([]() {
|
2016-11-18 16:27:47 +00:00
|
|
|
return st::historyMessageRadius;
|
2016-08-14 19:56:26 +00:00
|
|
|
auto minMsgHeight = (st::msgPadding.top() + st::msgFont->height + st::msgPadding.bottom());
|
|
|
|
return minMsgHeight / 2;
|
|
|
|
})();
|
|
|
|
return MsgRadius;
|
|
|
|
}
|
|
|
|
|
2016-12-20 13:03:51 +00:00
|
|
|
void createCorners() {
|
2015-05-20 19:28:24 +00:00
|
|
|
QImage mask[4];
|
2016-12-23 13:21:01 +00:00
|
|
|
prepareCorners(LargeMaskCorners, msgRadius(), QColor(255, 255, 255), nullptr, mask);
|
2015-05-20 19:28:24 +00:00
|
|
|
for (int i = 0; i < 4; ++i) {
|
2016-07-07 12:35:14 +00:00
|
|
|
::cornersMaskLarge[i] = new QImage(mask[i].convertToFormat(QImage::Format_ARGB32_Premultiplied));
|
|
|
|
::cornersMaskLarge[i]->setDevicePixelRatio(cRetinaFactor());
|
|
|
|
}
|
2016-12-23 13:21:01 +00:00
|
|
|
prepareCorners(SmallMaskCorners, st::buttonRadius, QColor(255, 255, 255), nullptr, mask);
|
2016-07-07 12:35:14 +00:00
|
|
|
for (int i = 0; i < 4; ++i) {
|
|
|
|
::cornersMaskSmall[i] = new QImage(mask[i].convertToFormat(QImage::Format_ARGB32_Premultiplied));
|
|
|
|
::cornersMaskSmall[i]->setDevicePixelRatio(cRetinaFactor());
|
|
|
|
}
|
2016-11-09 13:40:51 +00:00
|
|
|
prepareCorners(MenuCorners, st::buttonRadius, st::menuBg);
|
2016-12-13 17:07:56 +00:00
|
|
|
prepareCorners(BoxCorners, st::boxRadius, st::boxBg);
|
2016-12-21 15:05:58 +00:00
|
|
|
prepareCorners(BotKbOverCorners, st::dateRadius, st::msgBotKbOverBgAdd);
|
2016-07-08 10:06:41 +00:00
|
|
|
prepareCorners(StickerCorners, st::dateRadius, st::msgServiceBg);
|
2016-12-21 15:05:58 +00:00
|
|
|
prepareCorners(StickerSelectedCorners, st::dateRadius, st::msgServiceBgSelected);
|
2016-07-07 12:35:14 +00:00
|
|
|
prepareCorners(SelectedOverlaySmallCorners, st::buttonRadius, st::msgSelectOverlay);
|
2016-08-14 19:56:26 +00:00
|
|
|
prepareCorners(SelectedOverlayLargeCorners, msgRadius(), st::msgSelectOverlay);
|
2016-07-08 10:06:41 +00:00
|
|
|
prepareCorners(DateCorners, st::dateRadius, st::msgDateImgBg);
|
|
|
|
prepareCorners(DateSelectedCorners, st::dateRadius, st::msgDateImgBgSelected);
|
2016-08-14 19:56:26 +00:00
|
|
|
prepareCorners(InShadowCorners, msgRadius(), st::msgInShadow);
|
|
|
|
prepareCorners(InSelectedShadowCorners, msgRadius(), st::msgInShadowSelected);
|
2016-12-21 15:05:58 +00:00
|
|
|
prepareCorners(ForwardCorners, msgRadius(), st::historyForwardChooseBg);
|
|
|
|
prepareCorners(MediaviewSaveCorners, st::mediaviewControllerRadius, st::mediaviewSaveMsgBg);
|
2016-07-07 12:35:14 +00:00
|
|
|
prepareCorners(EmojiHoverCorners, st::buttonRadius, st::emojiPanHover);
|
|
|
|
prepareCorners(StickerHoverCorners, st::buttonRadius, st::emojiPanHover);
|
|
|
|
prepareCorners(BotKeyboardCorners, st::buttonRadius, st::botKbBg);
|
|
|
|
prepareCorners(BotKeyboardOverCorners, st::buttonRadius, st::botKbOverBg);
|
|
|
|
prepareCorners(BotKeyboardDownCorners, st::buttonRadius, st::botKbDownBg);
|
|
|
|
prepareCorners(PhotoSelectOverlayCorners, st::buttonRadius, st::overviewPhotoSelectOverlay);
|
|
|
|
|
2016-12-21 15:05:58 +00:00
|
|
|
prepareCorners(Doc1Corners, st::buttonRadius, st::msgFile1Bg);
|
|
|
|
prepareCorners(Doc2Corners, st::buttonRadius, st::msgFile2Bg);
|
|
|
|
prepareCorners(Doc3Corners, st::buttonRadius, st::msgFile3Bg);
|
|
|
|
prepareCorners(Doc4Corners, st::buttonRadius, st::msgFile4Bg);
|
2015-05-20 19:28:24 +00:00
|
|
|
|
2016-08-14 19:56:26 +00:00
|
|
|
prepareCorners(MessageInCorners, msgRadius(), st::msgInBg, &st::msgInShadow);
|
|
|
|
prepareCorners(MessageInSelectedCorners, msgRadius(), st::msgInBgSelected, &st::msgInShadowSelected);
|
|
|
|
prepareCorners(MessageOutCorners, msgRadius(), st::msgOutBg, &st::msgOutShadow);
|
|
|
|
prepareCorners(MessageOutSelectedCorners, msgRadius(), st::msgOutBgSelected, &st::msgOutShadowSelected);
|
2016-12-20 13:03:51 +00:00
|
|
|
}
|
2016-11-03 10:33:57 +00:00
|
|
|
|
2016-12-20 13:03:51 +00:00
|
|
|
void clearCorners() {
|
|
|
|
for (int j = 0; j < 4; ++j) {
|
|
|
|
for (int i = 0; i < RoundCornersCount; ++i) {
|
|
|
|
delete ::corners[i].p[j]; ::corners[i].p[j] = nullptr;
|
2016-11-03 10:33:57 +00:00
|
|
|
}
|
2016-12-20 13:03:51 +00:00
|
|
|
delete ::cornersMaskSmall[j]; ::cornersMaskSmall[j] = nullptr;
|
|
|
|
delete ::cornersMaskLarge[j]; ::cornersMaskLarge[j] = nullptr;
|
|
|
|
}
|
|
|
|
for (auto i = ::cornersMap.cbegin(), e = ::cornersMap.cend(); i != e; ++i) {
|
|
|
|
for (int j = 0; j < 4; ++j) {
|
|
|
|
delete i->p[j];
|
2016-11-03 10:33:57 +00:00
|
|
|
}
|
2016-12-20 13:03:51 +00:00
|
|
|
}
|
|
|
|
::cornersMap.clear();
|
|
|
|
}
|
2016-11-03 10:33:57 +00:00
|
|
|
|
2016-12-20 13:03:51 +00:00
|
|
|
void initMedia() {
|
|
|
|
if (!::monofont) {
|
|
|
|
QString family;
|
|
|
|
tryFontFamily(family, qsl("Consolas"));
|
|
|
|
tryFontFamily(family, qsl("Liberation Mono"));
|
|
|
|
tryFontFamily(family, qsl("Menlo"));
|
|
|
|
tryFontFamily(family, qsl("Courier"));
|
|
|
|
if (family.isEmpty()) family = QFontDatabase::systemFont(QFontDatabase::FixedFont).family();
|
|
|
|
::monofont = style::font(st::normalFont->f.pixelSize(), 0, family);
|
|
|
|
}
|
|
|
|
emojiInit();
|
|
|
|
if (!::emoji) {
|
|
|
|
::emoji = new QPixmap(QLatin1String(EName));
|
|
|
|
if (cRetina()) ::emoji->setDevicePixelRatio(cRetinaFactor());
|
|
|
|
}
|
|
|
|
if (!::emojiLarge) {
|
|
|
|
::emojiLarge = new QPixmap(QLatin1String(EmojiNames[EIndex + 1]));
|
|
|
|
if (cRetina()) ::emojiLarge->setDevicePixelRatio(cRetinaFactor());
|
|
|
|
}
|
|
|
|
|
|
|
|
createCorners();
|
|
|
|
|
|
|
|
using Update = Window::Theme::BackgroundUpdate;
|
|
|
|
static auto subscription = Window::Theme::Background()->add_subscription([](const Update &update) {
|
2016-12-23 13:21:01 +00:00
|
|
|
if (update.paletteChanged()) {
|
2016-12-20 13:03:51 +00:00
|
|
|
clearCorners();
|
|
|
|
createCorners();
|
|
|
|
|
|
|
|
if (App::main()) {
|
|
|
|
App::main()->updateScrollColors();
|
|
|
|
}
|
|
|
|
HistoryLayout::serviceColorsUpdated();
|
|
|
|
} else if (update.type == Update::Type::New) {
|
|
|
|
for (int i = 0; i < 4; ++i) {
|
|
|
|
delete ::corners[StickerCorners].p[i]; ::corners[StickerCorners].p[i] = nullptr;
|
|
|
|
delete ::corners[StickerSelectedCorners].p[i]; ::corners[StickerSelectedCorners].p[i] = nullptr;
|
|
|
|
}
|
|
|
|
prepareCorners(StickerCorners, st::dateRadius, st::msgServiceBg);
|
2016-12-21 15:05:58 +00:00
|
|
|
prepareCorners(StickerSelectedCorners, st::dateRadius, st::msgServiceBgSelected);
|
2016-12-20 13:03:51 +00:00
|
|
|
|
|
|
|
if (App::main()) {
|
|
|
|
App::main()->updateScrollColors();
|
|
|
|
}
|
|
|
|
HistoryLayout::serviceColorsUpdated();
|
2016-11-03 10:33:57 +00:00
|
|
|
}
|
|
|
|
});
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
2016-01-03 01:43:42 +00:00
|
|
|
|
2015-12-27 21:37:48 +00:00
|
|
|
void clearHistories() {
|
2016-03-29 17:17:00 +00:00
|
|
|
ClickHandler::clearActive();
|
|
|
|
ClickHandler::unpressed();
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2014-07-04 11:12:54 +00:00
|
|
|
histories().clear();
|
2016-01-03 01:43:42 +00:00
|
|
|
|
2015-12-27 21:37:48 +00:00
|
|
|
clearStorageImages();
|
|
|
|
cSetServerBackgrounds(WallPapers());
|
2014-07-04 11:12:54 +00:00
|
|
|
|
2015-12-27 21:37:48 +00:00
|
|
|
serviceImageCacheSize = imageCacheSize();
|
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2015-12-27 21:37:48 +00:00
|
|
|
void deinitMedia() {
|
|
|
|
delete ::emoji;
|
2016-12-20 13:03:51 +00:00
|
|
|
::emoji = nullptr;
|
2015-12-27 21:37:48 +00:00
|
|
|
delete ::emojiLarge;
|
2016-12-20 13:03:51 +00:00
|
|
|
::emojiLarge = nullptr;
|
|
|
|
|
|
|
|
clearCorners();
|
|
|
|
|
2015-12-27 21:37:48 +00:00
|
|
|
mainEmojiMap.clear();
|
|
|
|
otherEmojiMap.clear();
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2016-06-09 11:51:24 +00:00
|
|
|
Data::clearGlobalStructures();
|
2016-04-09 20:41:20 +00:00
|
|
|
|
2015-12-27 21:37:48 +00:00
|
|
|
clearAllImages();
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void hoveredItem(HistoryItem *item) {
|
|
|
|
::hoveredItem = item;
|
|
|
|
}
|
|
|
|
|
|
|
|
HistoryItem *hoveredItem() {
|
|
|
|
return ::hoveredItem;
|
|
|
|
}
|
|
|
|
|
|
|
|
void pressedItem(HistoryItem *item) {
|
|
|
|
::pressedItem = item;
|
|
|
|
}
|
|
|
|
|
|
|
|
HistoryItem *pressedItem() {
|
|
|
|
return ::pressedItem;
|
|
|
|
}
|
2016-01-03 01:43:42 +00:00
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
void hoveredLinkItem(HistoryItem *item) {
|
|
|
|
::hoveredLinkItem = item;
|
|
|
|
}
|
|
|
|
|
|
|
|
HistoryItem *hoveredLinkItem() {
|
|
|
|
return ::hoveredLinkItem;
|
|
|
|
}
|
|
|
|
|
|
|
|
void pressedLinkItem(HistoryItem *item) {
|
|
|
|
::pressedLinkItem = item;
|
|
|
|
}
|
|
|
|
|
|
|
|
HistoryItem *pressedLinkItem() {
|
|
|
|
return ::pressedLinkItem;
|
|
|
|
}
|
2016-01-03 01:43:42 +00:00
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
void contextItem(HistoryItem *item) {
|
|
|
|
::contextItem = item;
|
|
|
|
}
|
|
|
|
|
|
|
|
HistoryItem *contextItem() {
|
|
|
|
return ::contextItem;
|
|
|
|
}
|
|
|
|
|
|
|
|
void mousedItem(HistoryItem *item) {
|
|
|
|
::mousedItem = item;
|
|
|
|
}
|
|
|
|
|
|
|
|
HistoryItem *mousedItem() {
|
|
|
|
return ::mousedItem;
|
|
|
|
}
|
|
|
|
|
2016-06-14 16:26:41 +00:00
|
|
|
void clearMousedItems() {
|
|
|
|
hoveredItem(nullptr);
|
|
|
|
pressedItem(nullptr);
|
|
|
|
hoveredLinkItem(nullptr);
|
|
|
|
pressedLinkItem(nullptr);
|
|
|
|
contextItem(nullptr);
|
|
|
|
mousedItem(nullptr);
|
|
|
|
}
|
|
|
|
|
2015-10-23 16:06:56 +00:00
|
|
|
const style::font &monofont() {
|
|
|
|
return ::monofont;
|
|
|
|
}
|
|
|
|
|
2015-10-06 19:49:23 +00:00
|
|
|
const QPixmap &emoji() {
|
|
|
|
return *::emoji;
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2015-10-06 19:49:23 +00:00
|
|
|
const QPixmap &emojiLarge() {
|
|
|
|
return *::emojiLarge;
|
2015-05-08 12:45:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const QPixmap &emojiSingle(EmojiPtr emoji, int32 fontHeight) {
|
2016-10-31 12:29:26 +00:00
|
|
|
EmojiMap *map = &(fontHeight == st::msgFont->height ? mainEmojiMap : otherEmojiMap[fontHeight]);
|
2015-10-06 19:49:23 +00:00
|
|
|
EmojiMap::const_iterator i = map->constFind(emojiKey(emoji));
|
2014-05-30 08:53:19 +00:00
|
|
|
if (i == map->cend()) {
|
2015-05-08 12:45:14 +00:00
|
|
|
QImage img(ESize + st::emojiPadding * cIntRetinaFactor() * 2, fontHeight * cIntRetinaFactor(), QImage::Format_ARGB32_Premultiplied);
|
2014-06-15 12:31:03 +00:00
|
|
|
if (cRetina()) img.setDevicePixelRatio(cRetinaFactor());
|
2014-05-30 08:53:19 +00:00
|
|
|
{
|
|
|
|
QPainter p(&img);
|
2015-05-08 12:45:14 +00:00
|
|
|
QPainter::CompositionMode m = p.compositionMode();
|
2014-05-30 08:53:19 +00:00
|
|
|
p.setCompositionMode(QPainter::CompositionMode_Source);
|
|
|
|
p.fillRect(0, 0, img.width(), img.height(), Qt::transparent);
|
2015-05-08 12:45:14 +00:00
|
|
|
p.setCompositionMode(m);
|
|
|
|
emojiDraw(p, emoji, st::emojiPadding * cIntRetinaFactor(), (fontHeight * cIntRetinaFactor() - ESize) / 2);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
2016-07-13 17:34:57 +00:00
|
|
|
i = map->insert(emojiKey(emoji), App::pixmapFromImageInPlace(std_::move(img)));
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
return i.value();
|
|
|
|
}
|
|
|
|
|
|
|
|
void playSound() {
|
2016-10-17 10:55:17 +00:00
|
|
|
if (Global::SoundNotify() && !Platform::Notifications::skipAudio()) {
|
2017-01-19 08:24:43 +00:00
|
|
|
Media::Player::PlayNotify();
|
2016-10-17 10:55:17 +00:00
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void checkImageCacheSize() {
|
|
|
|
int64 nowImageCacheSize = imageCacheSize();
|
|
|
|
if (nowImageCacheSize > serviceImageCacheSize + MemoryForImageCache) {
|
2014-11-12 20:18:00 +00:00
|
|
|
App::forgetMedia();
|
2014-05-30 08:53:19 +00:00
|
|
|
serviceImageCacheSize = imageCacheSize();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isValidPhone(QString phone) {
|
|
|
|
phone = phone.replace(QRegularExpression(qsl("[^\\d]")), QString());
|
2014-10-17 12:57:14 +00:00
|
|
|
return phone.length() >= 8 || phone == qsl("777") || phone == qsl("333") || phone == qsl("111") || (phone.startsWith(qsl("42")) && (phone.length() == 2 || phone.length() == 5 || phone == qsl("4242")));
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void quit() {
|
2016-03-02 18:34:42 +00:00
|
|
|
if (quitting()) return;
|
|
|
|
setLaunchState(QuitRequested);
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2016-06-07 19:59:39 +00:00
|
|
|
if (auto window = wnd()) {
|
2016-06-21 15:58:07 +00:00
|
|
|
if (!Sandbox::isSavingSession()) {
|
|
|
|
window->hide();
|
|
|
|
}
|
2016-06-07 19:59:39 +00:00
|
|
|
}
|
|
|
|
if (auto mainwidget = main()) {
|
|
|
|
mainwidget->saveDraftToCloud();
|
|
|
|
}
|
|
|
|
if (auto apiwrap = api()) {
|
|
|
|
if (apiwrap->hasUnsavedDrafts()) {
|
|
|
|
apiwrap->saveDraftsToCloud();
|
|
|
|
QTimer::singleShot(SaveDraftBeforeQuitTimeout, Application::instance(), SLOT(quit()));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2016-01-11 15:43:29 +00:00
|
|
|
Application::quit();
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2016-03-02 18:34:42 +00:00
|
|
|
bool quitting() {
|
|
|
|
return _launchState != Launched;
|
|
|
|
}
|
|
|
|
|
2016-06-07 19:59:39 +00:00
|
|
|
void allDraftsSaved() {
|
|
|
|
if (quitting()) {
|
|
|
|
Application::quit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-02 18:34:42 +00:00
|
|
|
LaunchState launchState() {
|
|
|
|
return _launchState;
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2016-03-02 18:34:42 +00:00
|
|
|
void setLaunchState(LaunchState state) {
|
|
|
|
_launchState = state;
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2016-10-28 12:44:28 +00:00
|
|
|
void restart() {
|
|
|
|
#ifndef TDESKTOP_DISABLE_AUTOUPDATE
|
|
|
|
bool updateReady = (Sandbox::updatingState() == Application::UpdatingReady);
|
|
|
|
#else // !TDESKTOP_DISABLE_AUTOUPDATE
|
|
|
|
bool updateReady = false;
|
|
|
|
#endif // else for !TDESKTOP_DISABLE_AUTOUPDATE
|
|
|
|
if (updateReady) {
|
|
|
|
cSetRestartingUpdate(true);
|
|
|
|
} else {
|
|
|
|
cSetRestarting(true);
|
|
|
|
cSetRestartingToSettings(true);
|
|
|
|
}
|
|
|
|
App::quit();
|
|
|
|
}
|
|
|
|
|
2014-12-22 23:11:37 +00:00
|
|
|
QImage readImage(QByteArray data, QByteArray *format, bool opaque, bool *animated) {
|
2014-05-30 08:53:19 +00:00
|
|
|
QByteArray tmpFormat;
|
|
|
|
QImage result;
|
|
|
|
QBuffer buffer(&data);
|
|
|
|
if (!format) {
|
|
|
|
format = &tmpFormat;
|
|
|
|
}
|
2015-12-23 11:13:08 +00:00
|
|
|
{
|
|
|
|
QImageReader reader(&buffer, *format);
|
2016-08-30 05:24:16 +00:00
|
|
|
#ifndef OS_MAC_OLD
|
2015-12-23 11:13:08 +00:00
|
|
|
reader.setAutoTransform(true);
|
2016-08-30 05:24:16 +00:00
|
|
|
#endif // OS_MAC_OLD
|
2015-12-23 11:13:08 +00:00
|
|
|
if (animated) *animated = reader.supportsAnimation() && reader.imageCount() > 1;
|
|
|
|
QByteArray fmt = reader.format();
|
|
|
|
if (!fmt.isEmpty()) *format = fmt;
|
|
|
|
if (!reader.read(&result)) {
|
|
|
|
return QImage();
|
|
|
|
}
|
|
|
|
fmt = reader.format();
|
|
|
|
if (!fmt.isEmpty()) *format = fmt;
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
buffer.seek(0);
|
2016-12-08 14:08:54 +00:00
|
|
|
auto fmt = QString::fromUtf8(*format).toLower();
|
2014-05-30 08:53:19 +00:00
|
|
|
if (fmt == "jpg" || fmt == "jpeg") {
|
2016-08-30 05:24:16 +00:00
|
|
|
#ifdef OS_MAC_OLD
|
2016-12-08 14:08:54 +00:00
|
|
|
if (auto exifData = exif_data_new_from_data((const uchar*)(data.constData()), data.size())) {
|
|
|
|
auto byteOrder = exif_data_get_byte_order(exifData);
|
|
|
|
if (auto exifEntry = exif_data_get_entry(exifData, EXIF_TAG_ORIENTATION)) {
|
|
|
|
auto orientationFix = [exifEntry, byteOrder] {
|
|
|
|
auto orientation = exif_get_short(exifEntry->data, byteOrder);
|
|
|
|
switch (orientation) {
|
|
|
|
case 2: return QTransform(-1, 0, 0, 1, 0, 0);
|
|
|
|
case 3: return QTransform(-1, 0, 0, -1, 0, 0);
|
|
|
|
case 4: return QTransform(1, 0, 0, -1, 0, 0);
|
|
|
|
case 5: return QTransform(0, -1, -1, 0, 0, 0);
|
|
|
|
case 6: return QTransform(0, 1, -1, 0, 0, 0);
|
|
|
|
case 7: return QTransform(0, 1, 1, 0, 0, 0);
|
|
|
|
case 8: return QTransform(0, -1, 1, 0, 0, 0);
|
|
|
|
}
|
|
|
|
return QTransform();
|
|
|
|
};
|
|
|
|
result = result.transformed(orientationFix());
|
2015-12-23 11:13:08 +00:00
|
|
|
}
|
|
|
|
exif_data_free(exifData);
|
|
|
|
}
|
2016-08-30 05:24:16 +00:00
|
|
|
#endif // OS_MAC_OLD
|
2016-11-28 15:45:07 +00:00
|
|
|
} else if (opaque) {
|
|
|
|
result = Images::prepareOpaque(std_::move(result));
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2015-01-02 14:55:24 +00:00
|
|
|
QImage readImage(const QString &file, QByteArray *format, bool opaque, bool *animated, QByteArray *content) {
|
2014-05-30 08:53:19 +00:00
|
|
|
QFile f(file);
|
2016-11-28 15:45:07 +00:00
|
|
|
if (f.size() > kImageSizeLimit || !f.open(QIODevice::ReadOnly)) {
|
2014-12-22 23:11:37 +00:00
|
|
|
if (animated) *animated = false;
|
2014-05-30 08:53:19 +00:00
|
|
|
return QImage();
|
|
|
|
}
|
2016-12-08 14:08:54 +00:00
|
|
|
auto imageBytes = f.readAll();
|
|
|
|
auto result = readImage(imageBytes, format, opaque, animated);
|
|
|
|
if (content && !result.isNull()) {
|
|
|
|
*content = imageBytes;
|
|
|
|
}
|
2015-01-02 14:55:24 +00:00
|
|
|
return result;
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2016-05-27 10:57:11 +00:00
|
|
|
QPixmap pixmapFromImageInPlace(QImage &&image) {
|
2016-11-28 15:45:07 +00:00
|
|
|
return QPixmap::fromImage(std_::move(image), Qt::ColorOnly);
|
2016-05-27 10:57:11 +00:00
|
|
|
}
|
|
|
|
|
2015-12-25 13:09:14 +00:00
|
|
|
void regPhotoItem(PhotoData *data, HistoryItem *item) {
|
2016-09-27 13:37:18 +00:00
|
|
|
::photoItems[data].insert(item);
|
2015-12-25 13:09:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void unregPhotoItem(PhotoData *data, HistoryItem *item) {
|
|
|
|
::photoItems[data].remove(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
const PhotoItems &photoItems() {
|
|
|
|
return ::photoItems;
|
|
|
|
}
|
|
|
|
|
2015-12-27 21:37:48 +00:00
|
|
|
const PhotosData &photosData() {
|
|
|
|
return ::photosData;
|
|
|
|
}
|
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
void regDocumentItem(DocumentData *data, HistoryItem *item) {
|
2016-09-27 13:37:18 +00:00
|
|
|
::documentItems[data].insert(item);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void unregDocumentItem(DocumentData *data, HistoryItem *item) {
|
|
|
|
::documentItems[data].remove(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
const DocumentItems &documentItems() {
|
|
|
|
return ::documentItems;
|
|
|
|
}
|
|
|
|
|
2015-12-27 21:37:48 +00:00
|
|
|
const DocumentsData &documentsData() {
|
|
|
|
return ::documentsData;
|
|
|
|
}
|
|
|
|
|
2015-04-04 20:01:34 +00:00
|
|
|
void regWebPageItem(WebPageData *data, HistoryItem *item) {
|
2016-09-27 13:37:18 +00:00
|
|
|
::webPageItems[data].insert(item);
|
2015-04-04 20:01:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void unregWebPageItem(WebPageData *data, HistoryItem *item) {
|
|
|
|
::webPageItems[data].remove(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
const WebPageItems &webPageItems() {
|
|
|
|
return ::webPageItems;
|
|
|
|
}
|
|
|
|
|
2016-09-27 13:37:18 +00:00
|
|
|
void regGameItem(GameData *data, HistoryItem *item) {
|
|
|
|
::gameItems[data].insert(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
void unregGameItem(GameData *data, HistoryItem *item) {
|
|
|
|
::gameItems[data].remove(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
const GameItems &gameItems() {
|
|
|
|
return ::gameItems;
|
|
|
|
}
|
|
|
|
|
2015-12-12 22:29:33 +00:00
|
|
|
void regSharedContactItem(int32 userId, HistoryItem *item) {
|
2016-05-27 15:45:35 +00:00
|
|
|
auto user = App::userLoaded(userId);
|
|
|
|
auto canShareThisContact = user ? user->canShareThisContact() : false;
|
2016-09-27 13:37:18 +00:00
|
|
|
::sharedContactItems[userId].insert(item);
|
2016-05-27 15:45:35 +00:00
|
|
|
if (canShareThisContact != (user ? user->canShareThisContact() : false)) {
|
2016-06-01 20:05:37 +00:00
|
|
|
Notify::peerUpdatedDelayed(user, Notify::PeerUpdate::Flag::UserCanShareContact);
|
2016-05-27 15:45:35 +00:00
|
|
|
}
|
2015-12-12 22:29:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void unregSharedContactItem(int32 userId, HistoryItem *item) {
|
2016-05-27 15:45:35 +00:00
|
|
|
auto user = App::userLoaded(userId);
|
|
|
|
auto canShareThisContact = user ? user->canShareThisContact() : false;
|
2015-12-12 22:29:33 +00:00
|
|
|
::sharedContactItems[userId].remove(item);
|
2016-05-27 15:45:35 +00:00
|
|
|
if (canShareThisContact != (user ? user->canShareThisContact() : false)) {
|
2016-06-01 20:05:37 +00:00
|
|
|
Notify::peerUpdatedDelayed(user, Notify::PeerUpdate::Flag::UserCanShareContact);
|
2016-05-27 15:45:35 +00:00
|
|
|
}
|
2015-12-12 22:29:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const SharedContactItems &sharedContactItems() {
|
|
|
|
return ::sharedContactItems;
|
2015-09-02 10:20:33 +00:00
|
|
|
}
|
|
|
|
|
2016-06-24 10:37:29 +00:00
|
|
|
void regGifItem(Media::Clip::Reader *reader, HistoryItem *item) {
|
2015-12-15 14:50:51 +00:00
|
|
|
::gifItems.insert(reader, item);
|
|
|
|
}
|
|
|
|
|
2016-06-24 10:37:29 +00:00
|
|
|
void unregGifItem(Media::Clip::Reader *reader) {
|
2015-12-15 14:50:51 +00:00
|
|
|
::gifItems.remove(reader);
|
|
|
|
}
|
|
|
|
|
2015-12-16 13:35:15 +00:00
|
|
|
void stopGifItems() {
|
2015-12-16 14:39:26 +00:00
|
|
|
if (!::gifItems.isEmpty()) {
|
2015-12-27 21:37:48 +00:00
|
|
|
GifItems gifs = ::gifItems;
|
|
|
|
for (GifItems::const_iterator i = gifs.cbegin(), e = gifs.cend(); i != e; ++i) {
|
|
|
|
if (HistoryMedia *media = i.value()->getMedia()) {
|
2016-04-10 14:53:01 +00:00
|
|
|
media->stopInline();
|
2015-12-16 13:35:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-02 10:20:33 +00:00
|
|
|
QString phoneFromSharedContact(int32 userId) {
|
2016-09-27 13:37:18 +00:00
|
|
|
auto i = ::sharedContactItems.constFind(userId);
|
2016-02-14 15:58:39 +00:00
|
|
|
if (i != ::sharedContactItems.cend() && !i->isEmpty()) {
|
2016-09-27 13:37:18 +00:00
|
|
|
if (auto media = (*i->cbegin())->getMedia()) {
|
|
|
|
if (media->type() == MediaTypeContact) {
|
|
|
|
return static_cast<HistoryContact*>(media)->phone();
|
|
|
|
}
|
2015-12-12 22:29:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return QString();
|
2015-09-02 10:20:33 +00:00
|
|
|
}
|
|
|
|
|
2015-04-30 13:53:36 +00:00
|
|
|
void regMuted(PeerData *peer, int32 changeIn) {
|
|
|
|
::mutedPeers.insert(peer, true);
|
|
|
|
if (App::main()) App::main()->updateMutedIn(changeIn);
|
|
|
|
}
|
|
|
|
|
|
|
|
void unregMuted(PeerData *peer) {
|
|
|
|
::mutedPeers.remove(peer);
|
|
|
|
}
|
|
|
|
|
|
|
|
void updateMuted() {
|
|
|
|
int32 changeInMin = 0;
|
|
|
|
for (MutedPeers::iterator i = ::mutedPeers.begin(); i != ::mutedPeers.end();) {
|
|
|
|
int32 changeIn = 0;
|
|
|
|
History *h = App::history(i.key()->id);
|
|
|
|
if (isNotifyMuted(i.key()->notify, &changeIn)) {
|
|
|
|
h->setMute(true);
|
|
|
|
if (changeIn && (!changeInMin || changeIn < changeInMin)) {
|
|
|
|
changeInMin = changeIn;
|
|
|
|
}
|
|
|
|
++i;
|
|
|
|
} else {
|
|
|
|
h->setMute(false);
|
|
|
|
i = ::mutedPeers.erase(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (changeInMin) App::main()->updateMutedIn(changeInMin);
|
|
|
|
}
|
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
void setProxySettings(QNetworkAccessManager &manager) {
|
2016-03-20 08:16:35 +00:00
|
|
|
#ifndef TDESKTOP_DISABLE_NETWORK_PROXY
|
2015-12-30 19:09:20 +00:00
|
|
|
manager.setProxy(getHttpProxySettings());
|
2016-10-18 07:56:38 +00:00
|
|
|
#endif // !TDESKTOP_DISABLE_NETWORK_PROXY
|
2015-12-30 19:09:20 +00:00
|
|
|
}
|
|
|
|
|
2016-03-20 08:16:35 +00:00
|
|
|
#ifndef TDESKTOP_DISABLE_NETWORK_PROXY
|
2015-12-30 19:09:20 +00:00
|
|
|
QNetworkProxy getHttpProxySettings() {
|
2016-08-27 04:49:18 +00:00
|
|
|
const ProxyData *proxy = nullptr;
|
2016-02-08 14:54:55 +00:00
|
|
|
if (Global::started()) {
|
2016-08-27 04:49:18 +00:00
|
|
|
proxy = (Global::ConnectionType() == dbictHttpProxy) ? (&Global::ConnectionProxy()) : nullptr;
|
2016-01-30 16:31:10 +00:00
|
|
|
} else {
|
2016-08-27 04:49:18 +00:00
|
|
|
proxy = Sandbox::PreLaunchProxy().host.isEmpty() ? nullptr : (&Sandbox::PreLaunchProxy());
|
2016-01-30 16:31:10 +00:00
|
|
|
}
|
|
|
|
if (proxy) {
|
|
|
|
return QNetworkProxy(QNetworkProxy::HttpProxy, proxy->host, proxy->port, proxy->user, proxy->password);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
2015-12-30 19:09:20 +00:00
|
|
|
return QNetworkProxy(QNetworkProxy::DefaultProxy);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
2016-10-18 07:56:38 +00:00
|
|
|
#endif // !TDESKTOP_DISABLE_NETWORK_PROXY
|
2014-05-30 08:53:19 +00:00
|
|
|
|
|
|
|
void setProxySettings(QTcpSocket &socket) {
|
2016-03-20 08:16:35 +00:00
|
|
|
#ifndef TDESKTOP_DISABLE_NETWORK_PROXY
|
2016-08-27 04:49:18 +00:00
|
|
|
if (Global::ConnectionType() == dbictTcpProxy) {
|
|
|
|
auto &p = Global::ConnectionProxy();
|
2014-05-30 08:53:19 +00:00
|
|
|
socket.setProxy(QNetworkProxy(QNetworkProxy::Socks5Proxy, p.host, p.port, p.user, p.password));
|
|
|
|
} else {
|
|
|
|
socket.setProxy(QNetworkProxy(QNetworkProxy::NoProxy));
|
|
|
|
}
|
2016-10-18 07:56:38 +00:00
|
|
|
#endif // !TDESKTOP_DISABLE_NETWORK_PROXY
|
2016-01-03 01:43:42 +00:00
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2016-11-21 20:26:54 +00:00
|
|
|
void complexAdjustRect(ImageRoundCorners corners, QRect &rect, RectParts &parts) {
|
|
|
|
if (corners & ImageRoundCorner::TopLeft) {
|
|
|
|
if (!(corners & ImageRoundCorner::BottomLeft)) {
|
|
|
|
parts = RectPart::NoTopBottom | RectPart::TopFull;
|
|
|
|
rect.setHeight(rect.height() + msgRadius());
|
|
|
|
}
|
|
|
|
} else if (corners & ImageRoundCorner::BottomLeft) {
|
|
|
|
parts = RectPart::NoTopBottom | RectPart::BottomFull;
|
|
|
|
rect.setTop(rect.y() - msgRadius());
|
|
|
|
} else {
|
|
|
|
parts = RectPart::NoTopBottom;
|
|
|
|
rect.setTop(rect.y() - msgRadius());
|
|
|
|
rect.setHeight(rect.height() + msgRadius());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void complexOverlayRect(Painter &p, QRect rect, ImageRoundRadius radius, ImageRoundCorners corners) {
|
|
|
|
auto overlayCorners = (radius == ImageRoundRadius::Small) ? SelectedOverlaySmallCorners : SelectedOverlayLargeCorners;
|
|
|
|
auto overlayParts = RectPart::Full | RectPart::None;
|
|
|
|
if (radius == ImageRoundRadius::Large) {
|
|
|
|
complexAdjustRect(corners, rect, overlayParts);
|
|
|
|
}
|
2016-12-23 13:21:01 +00:00
|
|
|
roundRect(p, rect, p.textPalette().selectOverlay, overlayCorners, nullptr, overlayParts);
|
2016-11-21 20:26:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void complexLocationRect(Painter &p, QRect rect, ImageRoundRadius radius, ImageRoundCorners corners) {
|
|
|
|
auto parts = RectPart::Full | RectPart::None;
|
|
|
|
complexAdjustRect(corners, rect, parts);
|
|
|
|
roundRect(p, rect, st::msgInBg, MessageInCorners, nullptr, parts);
|
|
|
|
}
|
|
|
|
|
2016-07-07 12:35:14 +00:00
|
|
|
QImage **cornersMask(ImageRoundRadius radius) {
|
|
|
|
switch (radius) {
|
|
|
|
case ImageRoundRadius::Large: return ::cornersMaskLarge;
|
|
|
|
case ImageRoundRadius::Small:
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
return ::cornersMaskSmall;
|
2015-05-20 19:28:24 +00:00
|
|
|
}
|
2016-12-23 13:21:01 +00:00
|
|
|
|
|
|
|
void roundRect(Painter &p, int32 x, int32 y, int32 w, int32 h, style::color bg, const CornersPixmaps &corner, const style::color *shadow, RectParts parts) {
|
2016-11-12 15:02:19 +00:00
|
|
|
auto cornerWidth = corner.p[0]->width() / cIntRetinaFactor();
|
|
|
|
auto cornerHeight = corner.p[0]->height() / cIntRetinaFactor();
|
|
|
|
if (w < 2 * cornerWidth || h < 2 * cornerHeight) return;
|
|
|
|
if (w > 2 * cornerWidth) {
|
|
|
|
if (parts & RectPart::Top) {
|
|
|
|
p.fillRect(x + cornerWidth, y, w - 2 * cornerWidth, cornerHeight, bg);
|
|
|
|
}
|
|
|
|
if (parts & RectPart::Bottom) {
|
|
|
|
p.fillRect(x + cornerWidth, y + h - cornerHeight, w - 2 * cornerWidth, cornerHeight, bg);
|
|
|
|
if (shadow) {
|
|
|
|
p.fillRect(x + cornerWidth, y + h, w - 2 * cornerWidth, st::msgShadow, *shadow);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (h > 2 * cornerHeight) {
|
|
|
|
if ((parts & RectPart::NoTopBottom) == qFlags(RectPart::NoTopBottom)) {
|
|
|
|
p.fillRect(x, y + cornerHeight, w, h - 2 * cornerHeight, bg);
|
|
|
|
} else {
|
|
|
|
if (parts & RectPart::Left) {
|
|
|
|
p.fillRect(x, y + cornerHeight, cornerWidth, h - 2 * cornerHeight, bg);
|
|
|
|
}
|
|
|
|
if ((parts & RectPart::Center) && w > 2 * cornerWidth) {
|
|
|
|
p.fillRect(x + cornerWidth, y + cornerHeight, w - 2 * cornerWidth, h - 2 * cornerHeight, bg);
|
|
|
|
}
|
|
|
|
if (parts & RectPart::Right) {
|
|
|
|
p.fillRect(x + w - cornerWidth, y + cornerHeight, cornerWidth, h - 2 * cornerHeight, bg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (parts & RectPart::TopLeft) {
|
|
|
|
p.drawPixmap(x, y, *corner.p[0]);
|
|
|
|
}
|
|
|
|
if (parts & RectPart::TopRight) {
|
|
|
|
p.drawPixmap(x + w - cornerWidth, y, *corner.p[1]);
|
|
|
|
}
|
|
|
|
if (parts & RectPart::BottomLeft) {
|
|
|
|
p.drawPixmap(x, y + h - cornerHeight, *corner.p[2]);
|
2015-05-20 19:28:24 +00:00
|
|
|
}
|
2016-11-12 15:02:19 +00:00
|
|
|
if (parts & RectPart::BottomRight) {
|
|
|
|
p.drawPixmap(x + w - cornerWidth, y + h - cornerHeight, *corner.p[3]);
|
2015-05-20 19:28:24 +00:00
|
|
|
}
|
2015-10-03 10:09:09 +00:00
|
|
|
}
|
|
|
|
|
2016-12-23 13:21:01 +00:00
|
|
|
void roundRect(Painter &p, int32 x, int32 y, int32 w, int32 h, style::color bg, RoundCorners index, const style::color *shadow, RectParts parts) {
|
2016-11-12 15:02:19 +00:00
|
|
|
roundRect(p, x, y, w, h, bg, ::corners[index], shadow, parts);
|
2015-05-20 19:28:24 +00:00
|
|
|
}
|
|
|
|
|
2016-12-23 13:21:01 +00:00
|
|
|
void roundShadow(Painter &p, int32 x, int32 y, int32 w, int32 h, style::color shadow, RoundCorners index, RectParts parts) {
|
2016-11-12 15:02:19 +00:00
|
|
|
auto &corner = ::corners[index];
|
|
|
|
auto cornerWidth = corner.p[0]->width() / cIntRetinaFactor();
|
|
|
|
auto cornerHeight = corner.p[0]->height() / cIntRetinaFactor();
|
|
|
|
if (parts & RectPart::Bottom) {
|
|
|
|
p.fillRect(x + cornerWidth, y + h, w - 2 * cornerWidth, st::msgShadow, shadow);
|
|
|
|
}
|
|
|
|
if (parts & RectPart::BottomLeft) {
|
|
|
|
p.fillRect(x, y + h - cornerHeight, cornerWidth, st::msgShadow, shadow);
|
|
|
|
p.drawPixmap(x, y + h - cornerHeight + st::msgShadow, *corner.p[2]);
|
|
|
|
}
|
|
|
|
if (parts & RectPart::BottomRight) {
|
|
|
|
p.fillRect(x + w - cornerWidth, y + h - cornerHeight, cornerWidth, st::msgShadow, shadow);
|
|
|
|
p.drawPixmap(x + w - cornerWidth, y + h - cornerHeight + st::msgShadow, *corner.p[3]);
|
|
|
|
}
|
2015-10-03 10:09:09 +00:00
|
|
|
}
|
|
|
|
|
2016-12-23 13:21:01 +00:00
|
|
|
void roundRect(Painter &p, int32 x, int32 y, int32 w, int32 h, style::color bg, ImageRoundRadius radius, RectParts parts) {
|
2016-11-12 15:02:19 +00:00
|
|
|
auto colorKey = ((uint32(bg->c.alpha()) & 0xFF) << 24) | ((uint32(bg->c.red()) & 0xFF) << 16) | ((uint32(bg->c.green()) & 0xFF) << 8) | ((uint32(bg->c.blue()) & 0xFF) << 24);
|
|
|
|
auto i = cornersMap.find(colorKey);
|
2015-10-03 10:09:09 +00:00
|
|
|
if (i == cornersMap.cend()) {
|
|
|
|
QImage images[4];
|
2016-07-07 12:35:14 +00:00
|
|
|
switch (radius) {
|
2016-07-13 17:34:57 +00:00
|
|
|
case ImageRoundRadius::Small: prepareCorners(SmallMaskCorners, st::buttonRadius, bg, nullptr, images); break;
|
2016-08-14 19:56:26 +00:00
|
|
|
case ImageRoundRadius::Large: prepareCorners(LargeMaskCorners, msgRadius(), bg, nullptr, images); break;
|
2016-07-19 10:54:43 +00:00
|
|
|
default: p.fillRect(x, y, w, h, bg); return;
|
2016-07-07 12:35:14 +00:00
|
|
|
}
|
2015-10-03 10:09:09 +00:00
|
|
|
|
|
|
|
CornersPixmaps pixmaps;
|
|
|
|
for (int j = 0; j < 4; ++j) {
|
2016-07-13 17:34:57 +00:00
|
|
|
pixmaps.p[j] = new QPixmap(pixmapFromImageInPlace(std_::move(images[j])));
|
2015-10-03 10:09:09 +00:00
|
|
|
pixmaps.p[j]->setDevicePixelRatio(cRetinaFactor());
|
|
|
|
}
|
|
|
|
i = cornersMap.insert(colorKey, pixmaps);
|
|
|
|
}
|
2016-11-12 15:02:19 +00:00
|
|
|
roundRect(p, x, y, w, h, bg, i.value(), nullptr, parts);
|
2015-05-22 11:14:52 +00:00
|
|
|
}
|
|
|
|
|
2015-02-03 15:02:46 +00:00
|
|
|
WallPapers gServerBackgrounds;
|
|
|
|
|
2015-11-20 13:34:37 +00:00
|
|
|
}
|