2014-05-30 08:53:19 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 10:23:14 +00:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2018-01-03 10:23:14 +00:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2014-05-30 08:53:19 +00:00
|
|
|
*/
|
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"
|
2017-04-06 14:38:10 +00:00
|
|
|
#include "styles/style_chat_helpers.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"
|
2017-04-13 08:27:10 +00:00
|
|
|
#include "lang/lang_keys.h"
|
2018-06-20 17:30:57 +00:00
|
|
|
#include "boxes/confirm_box.h"
|
2016-06-09 11:51:24 +00:00
|
|
|
#include "data/data_abstract_structure.h"
|
2018-01-14 16:02:25 +00:00
|
|
|
#include "data/data_media_types.h"
|
2018-01-04 10:22:53 +00:00
|
|
|
#include "data/data_session.h"
|
2018-01-13 12:45:11 +00:00
|
|
|
#include "history/history.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"
|
2017-12-18 15:44:50 +00:00
|
|
|
#include "history/history_item_components.h"
|
2018-01-09 17:08:31 +00:00
|
|
|
#include "history/view/history_view_service_message.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"
|
2017-02-23 10:59:19 +00:00
|
|
|
#include "messenger.h"
|
2014-05-30 08:53:19 +00:00
|
|
|
#include "application.h"
|
2017-03-04 10:23:56 +00:00
|
|
|
#include "storage/file_upload.h"
|
2017-02-23 10:59:19 +00:00
|
|
|
#include "mainwindow.h"
|
2014-05-30 08:53:19 +00:00
|
|
|
#include "mainwidget.h"
|
2017-03-04 10:23:56 +00:00
|
|
|
#include "storage/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"
|
2017-02-23 09:32:28 +00:00
|
|
|
#include "auth_session.h"
|
2017-12-11 14:45:29 +00:00
|
|
|
#include "core/crash_reports.h"
|
2018-04-26 16:14:21 +00:00
|
|
|
#include "core/update_checker.h"
|
2017-08-27 11:59:08 +00:00
|
|
|
#include "storage/storage_facade.h"
|
|
|
|
#include "storage/storage_shared_media.h"
|
2017-02-03 20:07:26 +00:00
|
|
|
#include "window/themes/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
|
|
|
|
2018-06-09 08:52:37 +00:00
|
|
|
std::unordered_map<PeerId, std::unique_ptr<PeerData>> peersData;
|
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 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
|
|
|
|
2018-01-11 19:33:26 +00:00
|
|
|
HistoryView::Element *hoveredItem = nullptr,
|
2016-06-14 16:26:41 +00:00
|
|
|
*pressedItem = nullptr,
|
|
|
|
*hoveredLinkItem = nullptr,
|
|
|
|
*pressedLinkItem = 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 {
|
2017-07-13 14:42:46 +00:00
|
|
|
QPixmap p[4];
|
2015-10-03 10:09:09 +00:00
|
|
|
};
|
2017-07-13 14:42:46 +00:00
|
|
|
QVector<CornersPixmaps> corners;
|
2016-09-27 13:37:18 +00:00
|
|
|
using CornersMap = QMap<uint32, CornersPixmaps>;
|
2015-10-03 10:09:09 +00:00
|
|
|
CornersMap cornersMap;
|
2017-07-13 14:42:46 +00:00
|
|
|
QImage cornersMaskLarge[4], cornersMaskSmall[4];
|
2015-05-20 19:28:24 +00:00
|
|
|
|
2017-02-15 08:50:11 +00:00
|
|
|
using EmojiImagesMap = QMap<int, QPixmap>;
|
|
|
|
EmojiImagesMap MainEmojiMap;
|
|
|
|
QMap<int, EmojiImagesMap> OtherEmojiMap;
|
2014-05-30 08:53:19 +00:00
|
|
|
|
|
|
|
int32 serviceImageCacheSize = 0;
|
|
|
|
|
2017-12-17 08:13:26 +00:00
|
|
|
} // namespace
|
2014-05-30 08:53:19 +00:00
|
|
|
|
|
|
|
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-04-12 21:31:28 +00:00
|
|
|
MainWindow *wnd() {
|
2017-08-04 14:54:32 +00:00
|
|
|
if (auto instance = Messenger::InstancePointer()) {
|
2017-08-08 09:31:48 +00:00
|
|
|
return instance->getActiveWindow();
|
2017-02-23 10:59:19 +00:00
|
|
|
}
|
|
|
|
return nullptr;
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
MainWidget *main() {
|
2017-02-23 10:59:19 +00:00
|
|
|
if (auto window = wnd()) {
|
|
|
|
return window->mainWidget();
|
2016-04-12 21:31:28 +00:00
|
|
|
}
|
|
|
|
return nullptr;
|
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-07-08 16:59:46 +00:00
|
|
|
UserData *feedUser(const MTPUser &user) {
|
|
|
|
UserData *data = nullptr;
|
2018-01-04 09:21:06 +00:00
|
|
|
bool minimal = false;
|
2016-07-08 16:59:46 +00:00
|
|
|
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();
|
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-09-26 13:53:51 +00:00
|
|
|
//data->setFlags(MTPDuser_ClientFlag::f_inaccessible | 0);
|
|
|
|
data->setFlags(MTPDuser::Flag::f_deleted);
|
2018-01-04 09:21:06 +00:00
|
|
|
if (!data->phone().isEmpty()) {
|
|
|
|
data->setPhone(QString());
|
|
|
|
update.flags |= UpdateFlag::UserPhoneChanged;
|
|
|
|
}
|
2016-07-08 16:59:46 +00:00
|
|
|
data->setBotInfoVersion(-1);
|
|
|
|
status = &emptyStatus;
|
2018-01-04 09:21:06 +00:00
|
|
|
data->setContactStatus(UserData::ContactStatus::PhoneUnknown);
|
2016-07-08 16:59:46 +00:00
|
|
|
|
2018-01-04 09:21:06 +00:00
|
|
|
if (canShareThisContact != data->canShareThisContactFast()) {
|
|
|
|
update.flags |= UpdateFlag::UserCanShareContact;
|
|
|
|
}
|
2016-07-08 16:59:46 +00:00
|
|
|
} 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();
|
2017-09-26 11:49:16 +00:00
|
|
|
if (minimal) {
|
|
|
|
auto mask = 0
|
2017-09-26 13:53:51 +00:00
|
|
|
//| MTPDuser_ClientFlag::f_inaccessible
|
|
|
|
| MTPDuser::Flag::f_deleted;
|
2017-09-26 11:49:16 +00:00
|
|
|
data->setFlags((data->flags() & ~mask) | (d.vflags.v & mask));
|
|
|
|
} else {
|
|
|
|
data->setFlags(d.vflags.v);
|
2016-07-08 16:59:46 +00:00
|
|
|
if (d.is_self()) {
|
|
|
|
data->input = MTP_inputPeerSelf();
|
|
|
|
data->inputUser = MTP_inputUserSelf();
|
|
|
|
} else if (!d.has_access_hash()) {
|
2017-09-26 11:49:16 +00:00
|
|
|
data->input = MTP_inputPeerUser(d.vid, MTP_long(data->accessHash()));
|
|
|
|
data->inputUser = MTP_inputUser(d.vid, MTP_long(data->accessHash()));
|
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());
|
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();
|
2017-07-06 11:37:42 +00:00
|
|
|
QString fname = (!minimal || noLocalName) ? (d.has_first_name() ? TextUtilities::SingleLine(qs(d.vfirst_name)) : QString()) : data->firstName;
|
|
|
|
QString lname = (!minimal || noLocalName) ? (d.has_last_name() ? TextUtilities::SingleLine(qs(d.vlast_name)) : QString()) : data->lastName;
|
2016-07-08 16:59:46 +00:00
|
|
|
|
|
|
|
QString phone = minimal ? data->phone() : (d.has_phone() ? qs(d.vphone) : QString());
|
2017-07-06 11:37:42 +00:00
|
|
|
QString uname = minimal ? data->username : (d.has_username() ? TextUtilities::SingleLine(qs(d.vusername)) : QString());
|
2016-07-08 16:59:46 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
2018-01-04 09:21:06 +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->contactStatus() == UserData::ContactStatus::Contact)
|
|
|
|
|| (!showPhone
|
|
|
|
&& data->contactStatus() == UserData::ContactStatus::CanAdd));
|
2016-07-08 16:59:46 +00:00
|
|
|
if (minimal) {
|
|
|
|
showPhoneChanged = false;
|
2018-01-04 09:21:06 +00:00
|
|
|
showPhone = !isServiceUser(data->id)
|
|
|
|
&& (data->id != Auth().userPeerId())
|
|
|
|
&& (data->contactStatus() == UserData::ContactStatus::CanAdd);
|
2016-07-08 16:59:46 +00:00
|
|
|
}
|
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
|
|
|
|
2018-01-04 09:21:06 +00:00
|
|
|
const auto 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) {
|
2017-12-11 14:45:29 +00:00
|
|
|
CrashReports::SetAnnotation("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());
|
|
|
|
}
|
2017-09-26 11:49:16 +00:00
|
|
|
if (d.has_access_hash()) {
|
|
|
|
data->setAccessHash(d.vaccess_hash.v);
|
|
|
|
}
|
2016-07-08 16:59:46 +00:00
|
|
|
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);
|
|
|
|
}
|
2018-01-04 09:21:06 +00:00
|
|
|
data->setContactStatus((d.is_contact() || d.is_mutual_contact())
|
|
|
|
? UserData::ContactStatus::Contact
|
|
|
|
: data->phone().isEmpty()
|
|
|
|
? UserData::ContactStatus::PhoneUnknown
|
|
|
|
: UserData::ContactStatus::CanAdd);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2018-01-04 09:21:06 +00:00
|
|
|
if (canShareThisContact != data->canShareThisContactFast()) {
|
|
|
|
update.flags |= UpdateFlag::UserCanShareContact;
|
|
|
|
}
|
2016-07-08 16:59:46 +00:00
|
|
|
} 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
|
|
|
}
|
2018-09-11 14:36:09 +00:00
|
|
|
} else if (data->loadedStatus != PeerData::FullLoaded
|
|
|
|
&& (!data->isSelf() || !data->phone().isEmpty())) {
|
2016-07-08 16:59:46 +00:00
|
|
|
data->loadedStatus = PeerData::FullLoaded;
|
|
|
|
}
|
|
|
|
|
2017-03-17 17:19:46 +00:00
|
|
|
if (status && !minimal) {
|
2018-09-11 12:50:40 +00:00
|
|
|
const auto oldOnlineTill = data->onlineTill;
|
|
|
|
const auto newOnlineTill = ApiWrap::OnlineTillFromStatus(
|
|
|
|
*status,
|
|
|
|
oldOnlineTill);
|
2017-03-17 17:19:46 +00:00
|
|
|
if (oldOnlineTill != newOnlineTill) {
|
|
|
|
data->onlineTill = newOnlineTill;
|
|
|
|
update.flags |= UpdateFlag::UserOnlineChanged;
|
|
|
|
}
|
2016-07-08 16:59:46 +00:00
|
|
|
}
|
|
|
|
|
2018-01-04 09:21:06 +00:00
|
|
|
if (data->contactStatus() == UserData::ContactStatus::PhoneUnknown
|
|
|
|
&& !data->phone().isEmpty()
|
2018-09-11 12:50:40 +00:00
|
|
|
&& !data->isSelf()) {
|
2018-01-04 09:21:06 +00:00
|
|
|
data->setContactStatus(UserData::ContactStatus::CanAdd);
|
2016-07-08 16:59:46 +00:00
|
|
|
}
|
|
|
|
if (App::main()) {
|
|
|
|
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;
|
2017-03-10 19:46:28 +00:00
|
|
|
for_const (auto &user, users.v) {
|
2016-07-08 16:59:46 +00:00
|
|
|
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) {
|
2017-09-26 11:49:16 +00:00
|
|
|
auto &c = d.vmigrated_to.c_inputChannel();
|
|
|
|
auto channel = App::channel(peerFromChannel(c.vchannel_id));
|
|
|
|
channel->addFlags(MTPDchannel::Flag::f_megagroup);
|
2016-07-08 16:59:46 +00:00
|
|
|
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;
|
2017-10-30 19:24:20 +00:00
|
|
|
if (auto h = App::historyLoaded(cdata->id)) {
|
|
|
|
if (auto hto = App::historyLoaded(channel->id)) {
|
2016-07-08 16:59:46 +00:00
|
|
|
if (!h->isEmpty()) {
|
2018-01-31 17:10:29 +00:00
|
|
|
h->unloadBlocks();
|
2016-07-08 16:59:46 +00:00
|
|
|
}
|
|
|
|
if (hto->inChatList(Dialogs::Mode::All) && h->inChatList(Dialogs::Mode::All)) {
|
2018-01-04 17:15:04 +00:00
|
|
|
App::main()->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
|
|
|
|
2017-09-26 11:49:16 +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
|
|
|
}
|
2017-09-26 11:49:16 +00:00
|
|
|
cdata->setFlags(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;
|
|
|
|
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();
|
2017-09-26 11:49:16 +00:00
|
|
|
cdata->setFlags(MTPDchat_ClientFlag::f_forbidden | 0);
|
2016-07-08 16:59:46 +00:00
|
|
|
if (canEdit != cdata->canEdit()) {
|
|
|
|
update.flags |= UpdateFlag::ChatCanEdit;
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case mtpc_channel: {
|
2017-12-26 13:32:44 +00:00
|
|
|
const auto &d = chat.c_channel();
|
2016-05-24 16:13:07 +00:00
|
|
|
|
2017-12-26 13:32:44 +00:00
|
|
|
const auto peerId = peerFromChannel(d.vid.v);
|
2016-07-08 16:59:46 +00:00
|
|
|
minimal = d.is_min();
|
|
|
|
if (minimal) {
|
|
|
|
data = App::channelLoaded(peerId);
|
|
|
|
if (!data) {
|
2017-12-26 13:32:44 +00:00
|
|
|
// Can't apply minimal to a not loaded channel.
|
|
|
|
// Need to make getDifference.
|
|
|
|
return nullptr;
|
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);
|
2017-12-26 13:32:44 +00:00
|
|
|
const auto accessHash = d.has_access_hash()
|
|
|
|
? d.vaccess_hash
|
|
|
|
: MTP_long(0);
|
|
|
|
data->input = MTP_inputPeerChannel(d.vid, accessHash);
|
2016-07-08 16:59:46 +00:00
|
|
|
}
|
2015-09-13 19:15:45 +00:00
|
|
|
|
2017-12-26 13:32:44 +00:00
|
|
|
const auto cdata = data->asChannel();
|
|
|
|
const auto wasInChannel = cdata->amIn();
|
|
|
|
const auto canViewAdmins = cdata->canViewAdmins();
|
|
|
|
const auto canViewMembers = cdata->canViewMembers();
|
|
|
|
const auto canAddMembers = cdata->canAddMembers();
|
2016-05-24 16:13:07 +00:00
|
|
|
|
2017-12-26 13:32:44 +00:00
|
|
|
if (d.has_participants_count()) {
|
|
|
|
cdata->setMembersCount(d.vparticipants_count.v);
|
|
|
|
}
|
2016-07-08 16:59:46 +00:00
|
|
|
if (minimal) {
|
2017-09-26 11:49:16 +00:00
|
|
|
auto mask = 0
|
|
|
|
| MTPDchannel::Flag::f_broadcast
|
|
|
|
| MTPDchannel::Flag::f_verified
|
|
|
|
| MTPDchannel::Flag::f_megagroup
|
|
|
|
| MTPDchannel::Flag::f_democracy
|
|
|
|
| MTPDchannel_ClientFlag::f_forbidden;
|
|
|
|
cdata->setFlags((cdata->flags() & ~mask) | (d.vflags.v & mask));
|
2016-07-08 16:59:46 +00:00
|
|
|
} else {
|
2017-06-17 19:52:18 +00:00
|
|
|
if (d.has_admin_rights()) {
|
|
|
|
cdata->setAdminRights(d.vadmin_rights);
|
|
|
|
} else if (cdata->hasAdminRights()) {
|
|
|
|
cdata->setAdminRights(MTP_channelAdminRights(MTP_flags(0)));
|
2017-06-04 11:09:29 +00:00
|
|
|
}
|
2017-06-17 19:52:18 +00:00
|
|
|
if (d.has_banned_rights()) {
|
|
|
|
cdata->setRestrictedRights(d.vbanned_rights);
|
2017-09-26 13:53:51 +00:00
|
|
|
} else if (cdata->hasRestrictions()) {
|
2017-06-17 19:52:18 +00:00
|
|
|
cdata->setRestrictedRights(MTP_channelBannedRights(MTP_flags(0), MTP_int(0)));
|
2017-06-04 11:09:29 +00:00
|
|
|
}
|
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());
|
|
|
|
}
|
2017-09-26 11:49:16 +00:00
|
|
|
cdata->setFlags(d.vflags.v);
|
2018-03-06 17:07:42 +00:00
|
|
|
//if (d.has_feed_id()) { // #feed
|
|
|
|
// cdata->setFeed(Auth().data().feed(d.vfeed_id.v));
|
|
|
|
//} else {
|
|
|
|
// cdata->clearFeed();
|
|
|
|
//}
|
2016-07-08 16:59:46 +00:00
|
|
|
}
|
2015-09-13 19:15:45 +00:00
|
|
|
|
2017-07-06 11:37:42 +00:00
|
|
|
QString uname = d.has_username() ? TextUtilities::SingleLine(qs(d.vusername)) : QString();
|
2016-07-08 16:59:46 +00:00
|
|
|
cdata->setName(qs(d.vtitle), uname);
|
2016-06-03 12:45:33 +00:00
|
|
|
|
2016-07-08 16:59:46 +00:00
|
|
|
cdata->setPhoto(d.vphoto);
|
2015-09-13 19:15:45 +00:00
|
|
|
|
2018-02-08 09:20:14 +00:00
|
|
|
if (wasInChannel != cdata->amIn()) {
|
|
|
|
update.flags |= UpdateFlag::ChannelAmIn;
|
|
|
|
}
|
2017-06-09 16:12:02 +00:00
|
|
|
if (canViewAdmins != cdata->canViewAdmins()
|
|
|
|
|| canViewMembers != cdata->canViewMembers()
|
2018-02-08 09:20:14 +00:00
|
|
|
|| canAddMembers != cdata->canAddMembers()) {
|
|
|
|
update.flags |= UpdateFlag::ChannelRightsChanged;
|
|
|
|
}
|
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 canViewAdmins = cdata->canViewAdmins();
|
|
|
|
auto canViewMembers = cdata->canViewMembers();
|
|
|
|
auto canAddMembers = cdata->canAddMembers();
|
|
|
|
|
|
|
|
cdata->inputChannel = MTP_inputChannel(d.vid, d.vaccess_hash);
|
|
|
|
|
|
|
|
auto mask = mtpCastFlags(MTPDchannelForbidden::Flag::f_broadcast | MTPDchannelForbidden::Flag::f_megagroup);
|
2017-09-26 11:49:16 +00:00
|
|
|
cdata->setFlags((cdata->flags() & ~mask) | (mtpCastFlags(d.vflags) & mask) | MTPDchannel_ClientFlag::f_forbidden);
|
2016-07-08 16:59:46 +00:00
|
|
|
|
2017-06-04 11:09:29 +00:00
|
|
|
if (cdata->hasAdminRights()) {
|
|
|
|
cdata->setAdminRights(MTP_channelAdminRights(MTP_flags(0)));
|
|
|
|
}
|
2017-09-26 13:53:51 +00:00
|
|
|
if (cdata->hasRestrictions()) {
|
2017-06-09 16:12:02 +00:00
|
|
|
cdata->setRestrictedRights(MTP_channelBannedRights(MTP_flags(0), MTP_int(0)));
|
2017-06-04 11:09:29 +00:00
|
|
|
}
|
|
|
|
|
2016-07-08 16:59:46 +00:00
|
|
|
cdata->setName(qs(d.vtitle), QString());
|
|
|
|
|
|
|
|
cdata->access = d.vaccess_hash.v;
|
|
|
|
cdata->setPhoto(MTP_chatPhotoEmpty());
|
|
|
|
cdata->date = 0;
|
|
|
|
cdata->setMembersCount(0);
|
|
|
|
|
2018-02-08 09:20:14 +00:00
|
|
|
if (wasInChannel != cdata->amIn()) {
|
|
|
|
update.flags |= UpdateFlag::ChannelAmIn;
|
|
|
|
}
|
2017-06-09 16:12:02 +00:00
|
|
|
if (canViewAdmins != cdata->canViewAdmins()
|
|
|
|
|| canViewMembers != cdata->canViewMembers()
|
2018-02-08 09:20:14 +00:00
|
|
|
|| canAddMembers != cdata->canAddMembers()) {
|
|
|
|
update.flags |= UpdateFlag::ChannelRightsChanged;
|
|
|
|
}
|
2016-07-08 16:59:46 +00:00
|
|
|
} 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;
|
|
|
|
}
|
2017-08-11 10:42:52 +00:00
|
|
|
if (update.flags) {
|
|
|
|
update.peer = data;
|
|
|
|
Notify::peerUpdatedDelayed(update);
|
2016-07-08 16:59:46 +00:00
|
|
|
}
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
PeerData *feedChats(const MTPVector<MTPChat> &chats) {
|
|
|
|
PeerData *result = nullptr;
|
2017-03-10 19:46:28 +00:00
|
|
|
for_const (auto &chat, chats.v) {
|
2016-07-08 16:59:46 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2017-08-11 10:42:52 +00:00
|
|
|
void feedParticipants(const MTPChatParticipants &p, bool requestBotInfos) {
|
2015-06-29 22:09:23 +00:00
|
|
|
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;
|
2017-03-10 19:46:28 +00:00
|
|
|
auto &v = d.vparticipants.v;
|
2014-05-30 08:53:19 +00:00
|
|
|
chat->count = v.size();
|
2017-12-01 18:38:44 +00:00
|
|
|
int32 pversion = chat->participants.empty()
|
|
|
|
? 1
|
|
|
|
: (chat->participants.begin()->second + 1);
|
2017-06-09 16:12:02 +00:00
|
|
|
chat->invitedByMe.clear();
|
|
|
|
chat->admins.clear();
|
2017-09-26 11:49:16 +00:00
|
|
|
chat->removeFlags(MTPDchat::Flag::f_admin);
|
2017-06-09 16:12:02 +00:00
|
|
|
for (auto 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;
|
2017-08-04 14:54:32 +00:00
|
|
|
if (inviter == Auth().userId()) {
|
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()) {
|
2017-09-26 11:49:16 +00:00
|
|
|
chat->addFlags(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;
|
|
|
|
}
|
|
|
|
}
|
2017-12-01 18:38:44 +00:00
|
|
|
if (!chat->participants.empty()) {
|
|
|
|
auto h = App::historyLoaded(chat->id);
|
2015-06-18 17:24:54 +00:00
|
|
|
bool found = !h || !h->lastKeyboardFrom;
|
2017-12-01 18:38:44 +00:00
|
|
|
auto botStatus = -1;
|
2018-06-04 19:48:17 +00:00
|
|
|
for (auto i = chat->participants.begin(); i != chat->participants.end();) {
|
2017-12-01 18:38:44 +00:00
|
|
|
auto [user, version] = *i;
|
|
|
|
if (version < pversion) {
|
2014-05-30 08:53:19 +00:00
|
|
|
i = chat->participants.erase(i);
|
|
|
|
} else {
|
2017-12-01 18:38:44 +00:00
|
|
|
if (user->botInfo) {
|
|
|
|
botStatus = 2;// (botStatus > 0/* || !user->botInfo->readsAllHistory*/) ? 2 : 1;
|
|
|
|
if (requestBotInfos && !user->botInfo->inited) {
|
|
|
|
Auth().api().requestFullPeer(user);
|
2017-08-04 14:54:32 +00:00
|
|
|
}
|
2015-06-15 17:19:24 +00:00
|
|
|
}
|
2017-12-01 18:38:44 +00:00
|
|
|
if (!found && user->id == h->lastKeyboardFrom) {
|
2015-06-18 17:24:54 +00:00
|
|
|
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);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2017-08-11 10:42:52 +00:00
|
|
|
void feedParticipantAdd(const MTPDupdateChatParticipantAdd &d) {
|
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();
|
2017-08-04 14:54:32 +00:00
|
|
|
Auth().api().requestPeer(chat);
|
2015-10-29 19:10:49 +00:00
|
|
|
} 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) {
|
2017-12-01 18:38:44 +00:00
|
|
|
if (chat->participants.empty() && chat->count) {
|
2014-05-30 08:53:19 +00:00
|
|
|
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()) {
|
2017-12-01 18:38:44 +00:00
|
|
|
chat->participants[user] = (chat->participants.empty() ? 1 : chat->participants.begin()->second);
|
2017-08-04 14:54:32 +00:00
|
|
|
if (d.vinviter_id.v == Auth().userId()) {
|
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;
|
2017-08-04 14:54:32 +00:00
|
|
|
if (!user->botInfo->inited) {
|
|
|
|
Auth().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);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-11 10:42:52 +00:00
|
|
|
void feedParticipantDelete(const MTPDupdateChatParticipantDelete &d) {
|
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();
|
2017-08-04 14:54:32 +00:00
|
|
|
Auth().api().requestPeer(chat);
|
2015-10-29 19:10:49 +00:00
|
|
|
} 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();
|
2018-06-09 08:52:37 +00:00
|
|
|
const auto user = App::userLoaded(d.vuser_id.v);
|
2014-05-30 08:53:19 +00:00
|
|
|
if (user) {
|
2017-12-01 18:38:44 +00:00
|
|
|
if (chat->participants.empty()) {
|
2015-11-02 02:28:24 +00:00
|
|
|
if (chat->count > 0) {
|
|
|
|
chat->count--;
|
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
} else {
|
2017-06-09 16:12:02 +00:00
|
|
|
auto i = chat->participants.find(user);
|
2014-05-30 08:53:19 +00:00
|
|
|
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()) {
|
2017-09-26 11:49:16 +00:00
|
|
|
chat->removeFlags(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;
|
2017-12-01 18:38:44 +00:00
|
|
|
for (auto [participant, v] : chat->participants) {
|
|
|
|
if (participant->botInfo) {
|
|
|
|
if (true || botStatus > 0/* || !participant->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-10-29 19:10:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-11 10:42:52 +00:00
|
|
|
void feedChatAdmins(const MTPDupdateChatAdmins &d) {
|
2017-09-25 16:06:53 +00:00
|
|
|
auto chat = App::chat(d.vchat_id.v);
|
2015-10-29 19:10:49 +00:00
|
|
|
if (chat->version <= d.vversion.v) {
|
2017-09-25 16:06:53 +00:00
|
|
|
auto wasCanEdit = chat->canEdit();
|
|
|
|
auto badVersion = (chat->version + 1 < d.vversion.v);
|
2015-10-29 19:10:49 +00:00
|
|
|
chat->version = d.vversion.v;
|
|
|
|
if (mtpIsTrue(d.venabled)) {
|
2017-09-26 11:49:16 +00:00
|
|
|
chat->addFlags(MTPDchat::Flag::f_admins_enabled);
|
2015-10-29 19:10:49 +00:00
|
|
|
} else {
|
2017-09-26 11:49:16 +00:00
|
|
|
chat->removeFlags(MTPDchat::Flag::f_admins_enabled);
|
2015-10-29 19:10:49 +00:00
|
|
|
}
|
2017-09-25 16:06:53 +00:00
|
|
|
if (badVersion || mtpIsTrue(d.venabled)) {
|
|
|
|
chat->invalidateParticipants();
|
|
|
|
Auth().api().requestPeer(chat);
|
|
|
|
}
|
|
|
|
if (wasCanEdit != chat->canEdit()) {
|
|
|
|
Notify::peerUpdatedDelayed(
|
|
|
|
chat,
|
|
|
|
Notify::PeerUpdate::Flag::ChatCanEdit);
|
|
|
|
}
|
|
|
|
Notify::peerUpdatedDelayed(
|
|
|
|
chat,
|
|
|
|
Notify::PeerUpdate::Flag::AdminsChanged);
|
2015-10-29 19:10:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-11 10:42:52 +00:00
|
|
|
void feedParticipantAdmin(const MTPDupdateChatParticipantAdmin &d) {
|
2015-10-29 19:10:49 +00:00
|
|
|
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();
|
2017-08-04 14:54:32 +00:00
|
|
|
Auth().api().requestPeer(chat);
|
2015-10-29 19:10:49 +00:00
|
|
|
} 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()) {
|
2017-09-26 11:49:16 +00:00
|
|
|
chat->addFlags(MTPDchat::Flag::f_admin);
|
2015-11-02 05:49:25 +00:00
|
|
|
}
|
2015-11-02 02:28:24 +00:00
|
|
|
if (chat->noParticipantInfo()) {
|
2017-08-04 14:54:32 +00:00
|
|
|
Auth().api().requestFullPeer(chat);
|
2015-11-02 02:28:24 +00:00
|
|
|
} 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()) {
|
2017-09-26 11:49:16 +00:00
|
|
|
chat->removeFlags(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);
|
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);
|
2017-08-04 14:54:32 +00:00
|
|
|
if (m.has_from_id() && peerId == Auth().userPeerId()) {
|
2015-09-03 10:48:40 +00:00
|
|
|
peerId = peerFromUser(m.vfrom_id);
|
|
|
|
}
|
2017-12-21 12:11:33 +00:00
|
|
|
if (const auto existing = App::histItemById(peerToChannel(peerId), m.vid.v)) {
|
2016-05-06 17:33:48 +00:00
|
|
|
auto text = qs(m.vmessage);
|
2017-12-21 12:11:33 +00:00
|
|
|
auto entities = m.has_entities()
|
|
|
|
? TextUtilities::EntitiesFromMTP(m.ventities.v)
|
|
|
|
: EntitiesInText();
|
2018-01-17 16:21:01 +00:00
|
|
|
const auto media = m.has_media() ? &m.vmedia : nullptr;
|
2016-05-06 17:33:48 +00:00
|
|
|
existing->setText({ text, entities });
|
2018-01-17 16:21:01 +00:00
|
|
|
existing->updateSentMedia(m.has_media() ? &m.vmedia : nullptr);
|
2017-12-21 12:11:33 +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);
|
2017-12-21 12:11:33 +00:00
|
|
|
existing->indexAsNewItem();
|
2018-03-13 10:19:06 +00:00
|
|
|
Auth().data().requestItemTextRefresh(existing);
|
2018-01-11 13:07:29 +00:00
|
|
|
if (existing->mainView()) {
|
2015-12-27 21:37:48 +00:00
|
|
|
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
|
|
|
void updateEditedMessage(const MTPMessage &m) {
|
2017-11-21 16:38:17 +00:00
|
|
|
auto apply = [](const auto &data) {
|
|
|
|
auto peerId = peerFromMTP(data.vto_id);
|
|
|
|
if (data.has_from_id() && peerId == Auth().userPeerId()) {
|
|
|
|
peerId = peerFromUser(data.vfrom_id);
|
|
|
|
}
|
|
|
|
if (auto existing = App::histItemById(peerToChannel(peerId), data.vid.v)) {
|
|
|
|
existing->applyEdition(data);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-09-23 18:26:53 +00:00
|
|
|
if (m.type() == mtpc_message) { // apply message edit
|
2017-11-21 16:38:17 +00:00
|
|
|
apply(m.c_message());
|
2016-09-23 18:26:53 +00:00
|
|
|
} else if (m.type() == mtpc_messageService) {
|
2017-11-21 16:38:17 +00:00
|
|
|
apply(m.c_messageService());
|
2016-06-13 18:42:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-27 21:37:48 +00:00
|
|
|
void addSavedGif(DocumentData *doc) {
|
2017-11-05 17:07:27 +00:00
|
|
|
auto &saved = Auth().data().savedGifsRef();
|
2015-12-27 21:37:48 +00:00
|
|
|
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();
|
|
|
|
|
2018-01-17 18:20:55 +00:00
|
|
|
Auth().data().notifySavedGifsUpdated();
|
2017-11-05 17:07:27 +00:00
|
|
|
Auth().data().setLastSavedGifsUpdate(0);
|
2017-08-04 14:54:32 +00:00
|
|
|
Auth().api().updateStickers();
|
2015-12-27 21:37:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void checkSavedGif(HistoryItem *item) {
|
2018-09-11 12:50:40 +00:00
|
|
|
if (!item->Has<HistoryMessageForwarded>() && (item->out() || item->history()->peer == Auth().user())) {
|
2018-01-14 16:02:25 +00:00
|
|
|
if (const auto media = item->media()) {
|
|
|
|
if (const auto document = media->document()) {
|
|
|
|
if (document->isGifv()) {
|
|
|
|
addSavedGif(document);
|
2015-12-27 21:37:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-18 14:59:17 +00:00
|
|
|
void feedMsgs(const QVector<MTPMessage> &msgs, NewMessageType type) {
|
2017-12-13 18:10:48 +00:00
|
|
|
auto indices = base::flat_map<uint64, int>();
|
|
|
|
for (int i = 0, l = msgs.size(); i != l; ++i) {
|
|
|
|
const auto &msg = msgs[i];
|
|
|
|
if (msg.type() == mtpc_message) {
|
|
|
|
const auto &data = msg.c_message();
|
2015-09-20 08:55:41 +00:00
|
|
|
if (type == NewMessageUnread) { // new message, index my forwarded messages to links overview
|
2017-12-13 18:10:48 +00:00
|
|
|
if (checkEntitiesAndViewsUpdate(data)) { // already in blocks
|
2015-10-15 00:15:28 +00:00
|
|
|
LOG(("Skipping message, because it is already in blocks!"));
|
2017-12-13 18:10:48 +00:00
|
|
|
continue;
|
2015-10-15 00:15:28 +00:00
|
|
|
}
|
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
2017-12-13 18:10:48 +00:00
|
|
|
const auto msgId = idFromMessage(msg);
|
|
|
|
indices.emplace((uint64(uint32(msgId)) << 32) | uint64(i), i);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
2017-12-13 18:10:48 +00:00
|
|
|
for (const auto [position, index] : indices) {
|
|
|
|
histories().addNewMessage(msgs[index], 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) {
|
2017-03-10 19:46:28 +00:00
|
|
|
return feedMsgs(msgs.v, type);
|
2015-11-18 14:59:17 +00:00
|
|
|
}
|
|
|
|
|
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();
|
2018-07-13 16:49:46 +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,
|
|
|
|
l.vfile_reference.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);
|
2018-07-13 16:49:46 +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,
|
|
|
|
l.vfile_reference.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);
|
2018-07-13 16:49:46 +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-09-03 10:48:40 +00:00
|
|
|
void feedInboxRead(const PeerId &peer, MsgId upTo) {
|
2018-01-31 17:10:29 +00:00
|
|
|
if (const auto history = App::historyLoaded(peer)) {
|
2016-06-09 19:28:58 +00:00
|
|
|
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);
|
2018-01-31 17:10:29 +00:00
|
|
|
if (const auto user = history->peer->asUser()) {
|
|
|
|
user->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);
|
|
|
|
}
|
|
|
|
|
2018-01-31 17:10:29 +00:00
|
|
|
void feedWereDeleted(
|
|
|
|
ChannelId channelId,
|
|
|
|
const QVector<MTPint> &msgsIds) {
|
2018-01-03 09:06:02 +00:00
|
|
|
const auto data = fetchMsgsData(channelId, false);
|
2015-09-03 10:48:40 +00:00
|
|
|
if (!data) return;
|
|
|
|
|
2018-01-31 17:10:29 +00:00
|
|
|
const auto affectedHistory = (channelId != NoChannel)
|
|
|
|
? App::history(peerFromChannel(channelId)).get()
|
2018-01-03 09:06:02 +00:00
|
|
|
: nullptr;
|
2015-09-19 09:13:21 +00:00
|
|
|
|
2018-01-31 17:10:29 +00:00
|
|
|
auto historiesToCheck = base::flat_set<not_null<History*>>();
|
2018-01-03 09:06:02 +00:00
|
|
|
for (const auto msgId : msgsIds) {
|
|
|
|
auto j = data->constFind(msgId.v);
|
2015-09-03 10:48:40 +00:00
|
|
|
if (j != data->cend()) {
|
2018-01-31 17:10:29 +00:00
|
|
|
const auto history = (*j)->history();
|
2015-09-19 09:13:21 +00:00
|
|
|
(*j)->destroy();
|
2018-01-31 17:10:29 +00:00
|
|
|
if (!history->lastMessageKnown()) {
|
|
|
|
historiesToCheck.emplace(history);
|
2015-11-20 18:24:44 +00:00
|
|
|
}
|
2018-01-31 17:10:29 +00:00
|
|
|
} else if (affectedHistory) {
|
|
|
|
affectedHistory->unknownMessageDeleted(msgId.v);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
}
|
2018-01-31 17:10:29 +00:00
|
|
|
for (const auto history : historiesToCheck) {
|
|
|
|
Auth().api().requestDialogEntry(history);
|
2015-09-19 09:13:21 +00:00
|
|
|
}
|
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) {
|
2018-01-04 09:21:06 +00:00
|
|
|
if (const auto user = userLoaded(userId.v)) {
|
|
|
|
const auto wasShowPhone = (user->contactStatus() == UserData::ContactStatus::CanAdd);
|
2014-05-30 08:53:19 +00:00
|
|
|
switch (myLink.type()) {
|
2015-03-13 13:01:25 +00:00
|
|
|
case mtpc_contactLinkContact:
|
2018-01-04 09:21:06 +00:00
|
|
|
user->setContactStatus(UserData::ContactStatus::Contact);
|
2014-05-30 08:53:19 +00:00
|
|
|
break;
|
2015-03-13 13:01:25 +00:00
|
|
|
case mtpc_contactLinkHasPhone:
|
2018-01-04 09:21:06 +00:00
|
|
|
user->setContactStatus(UserData::ContactStatus::CanAdd);
|
2015-03-13 13:01:25 +00:00
|
|
|
break;
|
|
|
|
case mtpc_contactLinkNone:
|
|
|
|
case mtpc_contactLinkUnknown:
|
2018-01-04 09:21:06 +00:00
|
|
|
user->setContactStatus(UserData::ContactStatus::PhoneUnknown);
|
2014-05-30 08:53:19 +00:00
|
|
|
break;
|
|
|
|
}
|
2018-01-04 09:21:06 +00:00
|
|
|
if (user->contactStatus() == UserData::ContactStatus::PhoneUnknown
|
|
|
|
&& !user->phone().isEmpty()
|
|
|
|
&& user->id != Auth().userPeerId()) {
|
|
|
|
user->setContactStatus(UserData::ContactStatus::CanAdd);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
2015-07-21 14:55:23 +00:00
|
|
|
|
2018-01-04 09:21:06 +00:00
|
|
|
const auto showPhone = !isServiceUser(user->id)
|
|
|
|
&& !user->isSelf()
|
|
|
|
&& user->contactStatus() == UserData::ContactStatus::CanAdd;
|
|
|
|
const auto showPhoneChanged = !isServiceUser(user->id)
|
|
|
|
&& !user->isSelf()
|
|
|
|
&& (showPhone != wasShowPhone);
|
2015-07-21 14:55:23 +00:00
|
|
|
if (showPhoneChanged) {
|
2018-01-04 09:21:06 +00:00
|
|
|
user->setName(
|
|
|
|
TextUtilities::SingleLine(user->firstName),
|
|
|
|
TextUtilities::SingleLine(user->lastName),
|
|
|
|
showPhone
|
|
|
|
? App::formatPhone(user->phone())
|
|
|
|
: QString(),
|
|
|
|
TextUtilities::SingleLine(user->username));
|
2015-06-29 22:09:23 +00:00
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-25 11:29:45 +00:00
|
|
|
PeerData *peer(const PeerId &id, PeerData::LoadedStatus restriction) {
|
2018-06-09 08:52:37 +00:00
|
|
|
if (!id) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2016-03-25 11:29:45 +00:00
|
|
|
|
2018-06-09 08:52:37 +00:00
|
|
|
auto i = peersData.find(id);
|
2014-05-30 08:53:19 +00:00
|
|
|
if (i == peersData.cend()) {
|
2018-06-09 08:52:37 +00:00
|
|
|
auto newData = [&]() -> std::unique_ptr<PeerData> {
|
|
|
|
if (peerIsUser(id)) {
|
|
|
|
return std::make_unique<UserData>(id);
|
|
|
|
} else if (peerIsChat(id)) {
|
|
|
|
return std::make_unique<ChatData>(id);
|
|
|
|
} else if (peerIsChannel(id)) {
|
|
|
|
return std::make_unique<ChannelData>(id);
|
|
|
|
}
|
|
|
|
Unexpected("Peer id type.");
|
|
|
|
}();
|
2015-09-03 10:48:40 +00:00
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
newData->input = MTPinputPeer(MTP_inputPeerEmpty());
|
2018-06-09 08:52:37 +00:00
|
|
|
i = peersData.emplace(id, std::move(newData)).first;
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
2016-03-25 11:29:45 +00:00
|
|
|
switch (restriction) {
|
|
|
|
case PeerData::MinimalLoaded: {
|
2018-06-09 08:52:37 +00:00
|
|
|
if (i->second->loadedStatus == PeerData::NotLoaded) {
|
2016-03-25 11:29:45 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case PeerData::FullLoaded: {
|
2018-06-09 08:52:37 +00:00
|
|
|
if (i->second->loadedStatus != PeerData::FullLoaded) {
|
2016-03-25 11:29:45 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
}
|
2018-06-09 08:52:37 +00:00
|
|
|
return i->second.get();
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2018-06-04 15:35:11 +00:00
|
|
|
void enumerateUsers(Fn<void(not_null<UserData*>)> action) {
|
2018-06-09 08:52:37 +00:00
|
|
|
for (const auto &[peerId, peer] : peersData) {
|
2018-04-09 17:48:29 +00:00
|
|
|
if (const auto user = peer->asUser()) {
|
2017-03-17 17:19:46 +00:00
|
|
|
action(user);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-09 17:48:29 +00:00
|
|
|
void enumerateChatsChannels(
|
2018-06-04 15:35:11 +00:00
|
|
|
Fn<void(not_null<PeerData*>)> action) {
|
2018-06-09 08:52:37 +00:00
|
|
|
for (const auto &[peerId, peer] : peersData) {
|
2018-04-09 17:48:29 +00:00
|
|
|
if (!peer->isUser()) {
|
2018-06-09 08:52:37 +00:00
|
|
|
action(peer.get());
|
2018-04-09 17:48:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-28 22:06:27 +00:00
|
|
|
PeerData *peerByName(const QString &username) {
|
2018-06-09 08:52:37 +00:00
|
|
|
const auto uname = username.trimmed();
|
|
|
|
for (const auto &[peerId, peer] : peersData) {
|
2016-03-31 14:06:40 +00:00
|
|
|
if (!peer->userName().compare(uname, Qt::CaseInsensitive)) {
|
2018-06-09 08:52:37 +00:00
|
|
|
return peer.get();
|
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
|
|
|
}
|
|
|
|
|
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() {
|
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
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2017-08-31 17:53:03 +00:00
|
|
|
not_null<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
|
|
|
}
|
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
History *historyLoaded(const PeerId &peer) {
|
2018-01-21 19:21:08 +00:00
|
|
|
if (!peer) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2018-01-19 17:10:58 +00:00
|
|
|
void historyRegItem(not_null<HistoryItem*> item) {
|
|
|
|
const auto data = fetchMsgsData(item->channelId());
|
|
|
|
const auto i = data->constFind(item->id);
|
2015-09-03 10:48:40 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2018-01-19 17:10:58 +00:00
|
|
|
void historyUnregItem(not_null<HistoryItem*> item) {
|
|
|
|
const auto data = fetchMsgsData(item->channelId(), false);
|
2015-09-03 10:48:40 +00:00
|
|
|
if (!data) return;
|
|
|
|
|
2018-01-19 17:10:58 +00:00
|
|
|
const 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
|
|
|
}
|
|
|
|
}
|
2018-01-19 17:10:58 +00:00
|
|
|
const 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
|
|
|
}
|
|
|
|
}
|
2017-08-04 14:54:32 +00:00
|
|
|
Auth().notifications().clearFromItem(item);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2018-01-19 17:10:58 +00:00
|
|
|
void historyUpdateDependent(not_null<HistoryItem*> item) {
|
|
|
|
const auto j = ::dependentItems.find(item);
|
2016-03-11 12:20:58 +00:00
|
|
|
if (j != ::dependentItems.cend()) {
|
2018-01-19 17:10:58 +00:00
|
|
|
for_const (const auto dependent, j.value()) {
|
2016-03-25 15:20:34 +00:00
|
|
|
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
|
|
|
|
2018-06-09 08:52:37 +00:00
|
|
|
const auto oldData = base::take(msgsData);
|
|
|
|
const auto oldChannelData = base::take(channelMsgsData);
|
|
|
|
for (const auto item : oldData) {
|
|
|
|
delete item;
|
2014-07-04 11:12:54 +00:00
|
|
|
}
|
2018-06-09 08:52:37 +00:00
|
|
|
for (const auto &data : oldChannelData) {
|
|
|
|
for (const auto item : data) {
|
|
|
|
delete item;
|
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-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
|
|
|
|
2018-06-09 08:52:37 +00:00
|
|
|
peersData.clear();
|
2016-09-29 11:37:16 +00:00
|
|
|
|
2017-08-04 14:54:32 +00:00
|
|
|
if (AuthSession::Exists()) {
|
|
|
|
Auth().api().clearWebPageRequests();
|
|
|
|
}
|
2015-01-02 16:09:05 +00:00
|
|
|
cSetRecentStickers(RecentStickerPack());
|
2015-09-09 08:19:25 +00:00
|
|
|
cSetReportSpamStatuses(ReportSpamStatuses());
|
2016-02-15 11:11:07 +00:00
|
|
|
cSetAutoDownloadPhoto(0);
|
|
|
|
cSetAutoDownloadAudio(0);
|
|
|
|
cSetAutoDownloadGif(0);
|
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) {
|
2017-07-13 14:42:46 +00:00
|
|
|
Expects(::corners.size() > index);
|
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) {
|
2017-07-13 14:42:46 +00:00
|
|
|
::corners[index].p[i] = pixmapFromImageInPlace(std::move(cors[i]));
|
|
|
|
::corners[index].p[i].setDevicePixelRatio(cRetinaFactor());
|
2015-10-03 10:09:09 +00:00
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-13 14:42:46 +00:00
|
|
|
void createMaskCorners() {
|
2015-05-20 19:28:24 +00:00
|
|
|
QImage mask[4];
|
2017-07-13 14:42:46 +00:00
|
|
|
prepareCorners(SmallMaskCorners, st::buttonRadius, QColor(255, 255, 255), nullptr, mask);
|
2015-05-20 19:28:24 +00:00
|
|
|
for (int i = 0; i < 4; ++i) {
|
2017-07-13 14:42:46 +00:00
|
|
|
::cornersMaskSmall[i] = mask[i].convertToFormat(QImage::Format_ARGB32_Premultiplied);
|
|
|
|
::cornersMaskSmall[i].setDevicePixelRatio(cRetinaFactor());
|
2016-07-07 12:35:14 +00:00
|
|
|
}
|
2017-12-25 19:26:08 +00:00
|
|
|
prepareCorners(LargeMaskCorners, st::historyMessageRadius, QColor(255, 255, 255), nullptr, mask);
|
2016-07-07 12:35:14 +00:00
|
|
|
for (int i = 0; i < 4; ++i) {
|
2017-07-13 14:42:46 +00:00
|
|
|
::cornersMaskLarge[i] = mask[i].convertToFormat(QImage::Format_ARGB32_Premultiplied);
|
|
|
|
::cornersMaskLarge[i].setDevicePixelRatio(cRetinaFactor());
|
2016-07-07 12:35:14 +00:00
|
|
|
}
|
2017-07-13 14:42:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void createPaletteCorners() {
|
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);
|
2017-12-25 19:26:08 +00:00
|
|
|
prepareCorners(SelectedOverlayLargeCorners, st::historyMessageRadius, st::msgSelectOverlay);
|
2016-07-08 10:06:41 +00:00
|
|
|
prepareCorners(DateCorners, st::dateRadius, st::msgDateImgBg);
|
|
|
|
prepareCorners(DateSelectedCorners, st::dateRadius, st::msgDateImgBgSelected);
|
2017-12-25 19:26:08 +00:00
|
|
|
prepareCorners(InShadowCorners, st::historyMessageRadius, st::msgInShadow);
|
|
|
|
prepareCorners(InSelectedShadowCorners, st::historyMessageRadius, st::msgInShadowSelected);
|
|
|
|
prepareCorners(ForwardCorners, st::historyMessageRadius, st::historyForwardChooseBg);
|
2016-12-21 15:05:58 +00:00
|
|
|
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(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
|
|
|
|
2017-12-25 19:26:08 +00:00
|
|
|
prepareCorners(MessageInCorners, st::historyMessageRadius, st::msgInBg, &st::msgInShadow);
|
|
|
|
prepareCorners(MessageInSelectedCorners, st::historyMessageRadius, st::msgInBgSelected, &st::msgInShadowSelected);
|
|
|
|
prepareCorners(MessageOutCorners, st::historyMessageRadius, st::msgOutBg, &st::msgOutShadow);
|
|
|
|
prepareCorners(MessageOutSelectedCorners, st::historyMessageRadius, st::msgOutBgSelected, &st::msgOutShadowSelected);
|
2016-12-20 13:03:51 +00:00
|
|
|
}
|
2016-11-03 10:33:57 +00:00
|
|
|
|
2017-07-13 14:42:46 +00:00
|
|
|
void createCorners() {
|
|
|
|
::corners.resize(RoundCornersCount);
|
|
|
|
createMaskCorners();
|
|
|
|
createPaletteCorners();
|
|
|
|
}
|
|
|
|
|
2016-12-20 13:03:51 +00:00
|
|
|
void clearCorners() {
|
2017-07-13 14:42:46 +00:00
|
|
|
::corners.clear();
|
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);
|
|
|
|
}
|
2017-02-15 08:50:11 +00:00
|
|
|
Ui::Emoji::Init();
|
2016-12-20 13:03:51 +00:00
|
|
|
if (!::emoji) {
|
2017-02-15 08:50:11 +00:00
|
|
|
::emoji = new QPixmap(Ui::Emoji::Filename(Ui::Emoji::Index()));
|
2016-12-20 13:03:51 +00:00
|
|
|
if (cRetina()) ::emoji->setDevicePixelRatio(cRetinaFactor());
|
|
|
|
}
|
|
|
|
if (!::emojiLarge) {
|
2017-02-15 08:50:11 +00:00
|
|
|
::emojiLarge = new QPixmap(Ui::Emoji::Filename(Ui::Emoji::Index() + 1));
|
2016-12-20 13:03:51 +00:00
|
|
|
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()) {
|
2017-07-13 14:42:46 +00:00
|
|
|
createPaletteCorners();
|
2016-12-20 13:03:51 +00:00
|
|
|
|
|
|
|
if (App::main()) {
|
|
|
|
App::main()->updateScrollColors();
|
|
|
|
}
|
2018-01-09 17:08:31 +00:00
|
|
|
HistoryView::serviceColorsUpdated();
|
2016-12-20 13:03:51 +00:00
|
|
|
} else if (update.type == Update::Type::New) {
|
|
|
|
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();
|
|
|
|
}
|
2018-01-09 17:08:31 +00:00
|
|
|
HistoryView::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
|
|
|
|
2017-03-12 08:49:44 +00:00
|
|
|
if (AuthSession::Exists()) {
|
|
|
|
// Clear notifications to prevent any showNotification() calls while destroying items.
|
2017-08-04 14:54:32 +00:00
|
|
|
Auth().notifications().clearAllFast();
|
2017-03-12 08:49:44 +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();
|
|
|
|
|
2017-02-15 08:50:11 +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
|
|
|
}
|
|
|
|
|
2018-01-11 19:33:26 +00:00
|
|
|
void hoveredItem(HistoryView::Element *item) {
|
2014-05-30 08:53:19 +00:00
|
|
|
::hoveredItem = item;
|
|
|
|
}
|
|
|
|
|
2018-01-11 19:33:26 +00:00
|
|
|
HistoryView::Element *hoveredItem() {
|
2014-05-30 08:53:19 +00:00
|
|
|
return ::hoveredItem;
|
|
|
|
}
|
|
|
|
|
2018-01-11 19:33:26 +00:00
|
|
|
void pressedItem(HistoryView::Element *item) {
|
2014-05-30 08:53:19 +00:00
|
|
|
::pressedItem = item;
|
|
|
|
}
|
|
|
|
|
2018-01-11 19:33:26 +00:00
|
|
|
HistoryView::Element *pressedItem() {
|
2014-05-30 08:53:19 +00:00
|
|
|
return ::pressedItem;
|
|
|
|
}
|
2016-01-03 01:43:42 +00:00
|
|
|
|
2018-01-11 19:33:26 +00:00
|
|
|
void hoveredLinkItem(HistoryView::Element *item) {
|
2014-05-30 08:53:19 +00:00
|
|
|
::hoveredLinkItem = item;
|
|
|
|
}
|
|
|
|
|
2018-01-11 19:33:26 +00:00
|
|
|
HistoryView::Element *hoveredLinkItem() {
|
2014-05-30 08:53:19 +00:00
|
|
|
return ::hoveredLinkItem;
|
|
|
|
}
|
|
|
|
|
2018-01-11 19:33:26 +00:00
|
|
|
void pressedLinkItem(HistoryView::Element *item) {
|
2014-05-30 08:53:19 +00:00
|
|
|
::pressedLinkItem = item;
|
|
|
|
}
|
|
|
|
|
2018-01-11 19:33:26 +00:00
|
|
|
HistoryView::Element *pressedLinkItem() {
|
2014-05-30 08:53:19 +00:00
|
|
|
return ::pressedLinkItem;
|
|
|
|
}
|
2016-01-03 01:43:42 +00:00
|
|
|
|
2018-01-11 19:33:26 +00:00
|
|
|
void mousedItem(HistoryView::Element *item) {
|
2014-05-30 08:53:19 +00:00
|
|
|
::mousedItem = item;
|
|
|
|
}
|
|
|
|
|
2018-01-11 19:33:26 +00:00
|
|
|
HistoryView::Element *mousedItem() {
|
2014-05-30 08:53:19 +00:00
|
|
|
return ::mousedItem;
|
|
|
|
}
|
|
|
|
|
2016-06-14 16:26:41 +00:00
|
|
|
void clearMousedItems() {
|
|
|
|
hoveredItem(nullptr);
|
|
|
|
pressedItem(nullptr);
|
|
|
|
hoveredLinkItem(nullptr);
|
|
|
|
pressedLinkItem(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) {
|
2017-02-15 08:50:11 +00:00
|
|
|
auto &map = (fontHeight == st::msgFont->height) ? MainEmojiMap : OtherEmojiMap[fontHeight];
|
|
|
|
auto i = map.constFind(emoji->index());
|
|
|
|
if (i == map.cend()) {
|
|
|
|
auto image = QImage(Ui::Emoji::Size() + st::emojiPadding * cIntRetinaFactor() * 2, fontHeight * cIntRetinaFactor(), QImage::Format_ARGB32_Premultiplied);
|
|
|
|
if (cRetina()) image.setDevicePixelRatio(cRetinaFactor());
|
|
|
|
image.fill(Qt::transparent);
|
2014-05-30 08:53:19 +00:00
|
|
|
{
|
2017-02-15 08:50:11 +00:00
|
|
|
QPainter p(&image);
|
|
|
|
emojiDraw(p, emoji, st::emojiPadding * cIntRetinaFactor(), (fontHeight * cIntRetinaFactor() - Ui::Emoji::Size()) / 2);
|
|
|
|
}
|
2017-02-21 13:45:56 +00:00
|
|
|
i = map.insert(emoji->index(), App::pixmapFromImageInPlace(std::move(image)));
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
return i.value();
|
|
|
|
}
|
|
|
|
|
|
|
|
void checkImageCacheSize() {
|
|
|
|
int64 nowImageCacheSize = imageCacheSize();
|
|
|
|
if (nowImageCacheSize > serviceImageCacheSize + MemoryForImageCache) {
|
2014-11-12 20:18:00 +00:00
|
|
|
App::forgetMedia();
|
2018-04-07 07:01:32 +00:00
|
|
|
Auth().data().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() {
|
2018-06-20 17:30:57 +00:00
|
|
|
if (quitting()) {
|
|
|
|
return;
|
|
|
|
} else if (AuthSession::Exists()
|
|
|
|
&& Auth().data().exportInProgress()) {
|
|
|
|
Auth().data().stopExportWithConfirmation([] { App::quit(); });
|
|
|
|
return;
|
|
|
|
}
|
2016-03-02 18:34:42 +00:00
|
|
|
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();
|
|
|
|
}
|
2017-04-29 20:06:32 +00:00
|
|
|
Messenger::QuitAttempt();
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2016-03-02 18:34:42 +00:00
|
|
|
bool quitting() {
|
|
|
|
return _launchState != Launched;
|
|
|
|
}
|
|
|
|
|
|
|
|
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() {
|
2018-07-11 22:14:44 +00:00
|
|
|
using namespace Core;
|
|
|
|
const auto updateReady = !UpdaterDisabled()
|
|
|
|
&& (UpdateChecker().state() == UpdateChecker::State::Ready);
|
2016-10-28 12:44:28 +00:00
|
|
|
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) {
|
2017-02-21 13:45:56 +00:00
|
|
|
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) {
|
2017-02-21 13:45:56 +00:00
|
|
|
return QPixmap::fromImage(std::move(image), Qt::ColorOnly);
|
2016-05-27 10:57:11 +00:00
|
|
|
}
|
|
|
|
|
2017-12-21 16:15:37 +00:00
|
|
|
void rectWithCorners(Painter &p, QRect rect, const style::color &bg, RoundCorners index, RectParts corners) {
|
|
|
|
auto parts = RectPart::Top
|
|
|
|
| RectPart::NoTopBottom
|
|
|
|
| RectPart::Bottom
|
|
|
|
| corners;
|
|
|
|
roundRect(p, rect, bg, index, nullptr, parts);
|
|
|
|
if ((corners & RectPart::AllCorners) != RectPart::AllCorners) {
|
|
|
|
const auto size = ::corners[index].p[0].width() / cIntRetinaFactor();
|
|
|
|
if (!(corners & RectPart::TopLeft)) {
|
|
|
|
p.fillRect(rect.x(), rect.y(), size, size, bg);
|
|
|
|
}
|
|
|
|
if (!(corners & RectPart::TopRight)) {
|
|
|
|
p.fillRect(rect.x() + rect.width() - size, rect.y(), size, size, bg);
|
|
|
|
}
|
2017-12-18 17:50:25 +00:00
|
|
|
if (!(corners & RectPart::BottomLeft)) {
|
2017-12-21 16:15:37 +00:00
|
|
|
p.fillRect(rect.x(), rect.y() + rect.height() - size, size, size, bg);
|
|
|
|
}
|
|
|
|
if (!(corners & RectPart::BottomRight)) {
|
|
|
|
p.fillRect(rect.x() + rect.width() - size, rect.y() + rect.height() - size, size, size, bg);
|
2016-11-21 20:26:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-18 17:50:25 +00:00
|
|
|
void complexOverlayRect(Painter &p, QRect rect, ImageRoundRadius radius, RectParts corners) {
|
2017-04-02 11:30:03 +00:00
|
|
|
if (radius == ImageRoundRadius::Ellipse) {
|
|
|
|
PainterHighQualityEnabler hq(p);
|
|
|
|
p.setPen(Qt::NoPen);
|
|
|
|
p.setBrush(p.textPalette().selectOverlay);
|
|
|
|
p.drawEllipse(rect);
|
|
|
|
} else {
|
2017-12-13 18:10:48 +00:00
|
|
|
auto overlayCorners = (radius == ImageRoundRadius::Small)
|
|
|
|
? SelectedOverlaySmallCorners
|
|
|
|
: SelectedOverlayLargeCorners;
|
2017-12-21 16:15:37 +00:00
|
|
|
const auto bg = p.textPalette().selectOverlay;
|
|
|
|
rectWithCorners(p, rect, bg, overlayCorners, corners);
|
2016-11-21 20:26:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-18 17:50:25 +00:00
|
|
|
void complexLocationRect(Painter &p, QRect rect, ImageRoundRadius radius, RectParts corners) {
|
2017-12-21 16:15:37 +00:00
|
|
|
rectWithCorners(p, rect, st::msgInBg, MessageInCorners, corners);
|
2016-11-21 20:26:54 +00:00
|
|
|
}
|
|
|
|
|
2017-07-13 14:42:46 +00:00
|
|
|
QImage *cornersMask(ImageRoundRadius radius) {
|
2016-07-07 12:35:14 +00:00
|
|
|
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) {
|
2017-07-13 14:42:46 +00:00
|
|
|
auto cornerWidth = corner.p[0].width() / cIntRetinaFactor();
|
|
|
|
auto cornerHeight = corner.p[0].height() / cIntRetinaFactor();
|
2016-11-12 15:02:19 +00:00
|
|
|
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) {
|
2017-08-31 16:28:58 +00:00
|
|
|
if ((parts & RectPart::NoTopBottom) == RectPart::NoTopBottom) {
|
2016-11-12 15:02:19 +00:00
|
|
|
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) {
|
2017-07-13 14:42:46 +00:00
|
|
|
p.drawPixmap(x, y, corner.p[0]);
|
2016-11-12 15:02:19 +00:00
|
|
|
}
|
|
|
|
if (parts & RectPart::TopRight) {
|
2017-07-13 14:42:46 +00:00
|
|
|
p.drawPixmap(x + w - cornerWidth, y, corner.p[1]);
|
2016-11-12 15:02:19 +00:00
|
|
|
}
|
|
|
|
if (parts & RectPart::BottomLeft) {
|
2017-07-13 14:42:46 +00:00
|
|
|
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) {
|
2017-07-13 14:42:46 +00:00
|
|
|
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];
|
2017-07-13 14:42:46 +00:00
|
|
|
auto cornerWidth = corner.p[0].width() / cIntRetinaFactor();
|
|
|
|
auto cornerHeight = corner.p[0].height() / cIntRetinaFactor();
|
2016-11-12 15:02:19 +00:00
|
|
|
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);
|
2017-07-13 14:42:46 +00:00
|
|
|
p.drawPixmap(x, y + h - cornerHeight + st::msgShadow, corner.p[2]);
|
2016-11-12 15:02:19 +00:00
|
|
|
}
|
|
|
|
if (parts & RectPart::BottomRight) {
|
|
|
|
p.fillRect(x + w - cornerWidth, y + h - cornerHeight, cornerWidth, st::msgShadow, shadow);
|
2017-07-13 14:42:46 +00:00
|
|
|
p.drawPixmap(x + w - cornerWidth, y + h - cornerHeight + st::msgShadow, corner.p[3]);
|
2016-11-12 15:02:19 +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, 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;
|
2017-12-25 19:26:08 +00:00
|
|
|
case ImageRoundRadius::Large: prepareCorners(LargeMaskCorners, st::historyMessageRadius, 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) {
|
2017-07-13 14:42:46 +00:00
|
|
|
pixmaps.p[j] = pixmapFromImageInPlace(std::move(images[j]));
|
|
|
|
pixmaps.p[j].setDevicePixelRatio(cRetinaFactor());
|
2015-10-03 10:09:09 +00:00
|
|
|
}
|
|
|
|
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
|
|
|
}
|