2015-04-04 20:01:34 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
|
|
|
the official desktop version of Telegram messaging app, see https://telegram.org
|
|
|
|
|
|
|
|
Telegram Desktop is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
It is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
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.
|
|
|
|
|
2015-04-04 20:01:34 +00:00
|
|
|
Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE
|
2016-02-08 10:56:18 +00:00
|
|
|
Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org
|
2015-04-04 20:01:34 +00:00
|
|
|
*/
|
|
|
|
#include "stdafx.h"
|
2016-04-10 18:18:26 +00:00
|
|
|
#include "structs.h"
|
|
|
|
|
2016-04-07 18:05:28 +00:00
|
|
|
#include "ui/style.h"
|
2015-04-04 20:01:34 +00:00
|
|
|
#include "lang.h"
|
2016-04-10 18:18:26 +00:00
|
|
|
#include "inline_bots/inline_bot_layout_item.h"
|
2015-04-04 20:01:34 +00:00
|
|
|
#include "history.h"
|
|
|
|
#include "mainwidget.h"
|
|
|
|
#include "application.h"
|
|
|
|
#include "fileuploader.h"
|
2016-04-12 21:31:28 +00:00
|
|
|
#include "mainwindow.h"
|
2016-04-07 18:05:28 +00:00
|
|
|
#include "ui/filedialog.h"
|
2016-04-12 21:31:28 +00:00
|
|
|
#include "apiwrap.h"
|
2015-09-21 20:57:42 +00:00
|
|
|
#include "boxes/confirmbox.h"
|
2015-04-04 20:01:34 +00:00
|
|
|
#include "audio.h"
|
|
|
|
#include "localstorage.h"
|
|
|
|
|
|
|
|
namespace {
|
2016-03-25 11:29:45 +00:00
|
|
|
int peerColorIndex(const PeerId &peer) {
|
|
|
|
UserId myId(MTP::authedId()), peerId(peerToBareInt(peer));
|
2015-04-04 20:01:34 +00:00
|
|
|
QByteArray both(qsl("%1%2").arg(peerId).arg(myId).toUtf8());
|
|
|
|
if (both.size() > 15) {
|
|
|
|
both = both.mid(0, 15);
|
|
|
|
}
|
|
|
|
uchar md5[16];
|
|
|
|
hashMd5(both.constData(), both.size(), md5);
|
2015-09-03 10:48:40 +00:00
|
|
|
return (md5[peerId & 0x0F] & (peerIsUser(peer) ? 0x07 : 0x03));
|
2015-04-04 20:01:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-25 11:29:45 +00:00
|
|
|
style::color peerColor(int index) {
|
2015-04-04 20:01:34 +00:00
|
|
|
static const style::color peerColors[8] = {
|
|
|
|
style::color(st::color1),
|
|
|
|
style::color(st::color2),
|
|
|
|
style::color(st::color3),
|
|
|
|
style::color(st::color4),
|
|
|
|
style::color(st::color5),
|
|
|
|
style::color(st::color6),
|
|
|
|
style::color(st::color7),
|
|
|
|
style::color(st::color8)
|
|
|
|
};
|
|
|
|
return peerColors[index];
|
|
|
|
}
|
|
|
|
|
2016-03-25 11:29:45 +00:00
|
|
|
ImagePtr userDefPhoto(int index) {
|
2015-12-12 22:29:33 +00:00
|
|
|
static const ImagePtr userDefPhotos[UserColorsCount] = {
|
2015-04-04 20:01:34 +00:00
|
|
|
ImagePtr(qsl(":/ava/art/usercolor1.png"), "PNG"),
|
|
|
|
ImagePtr(qsl(":/ava/art/usercolor2.png"), "PNG"),
|
|
|
|
ImagePtr(qsl(":/ava/art/usercolor3.png"), "PNG"),
|
|
|
|
ImagePtr(qsl(":/ava/art/usercolor4.png"), "PNG"),
|
|
|
|
ImagePtr(qsl(":/ava/art/usercolor5.png"), "PNG"),
|
|
|
|
ImagePtr(qsl(":/ava/art/usercolor6.png"), "PNG"),
|
|
|
|
ImagePtr(qsl(":/ava/art/usercolor7.png"), "PNG"),
|
|
|
|
ImagePtr(qsl(":/ava/art/usercolor8.png"), "PNG"),
|
|
|
|
};
|
|
|
|
return userDefPhotos[index];
|
|
|
|
}
|
|
|
|
|
2016-03-25 11:29:45 +00:00
|
|
|
ImagePtr chatDefPhoto(int index) {
|
2015-04-04 20:01:34 +00:00
|
|
|
static const ImagePtr chatDefPhotos[4] = {
|
|
|
|
ImagePtr(qsl(":/ava/art/chatcolor1.png"), "PNG"),
|
|
|
|
ImagePtr(qsl(":/ava/art/chatcolor2.png"), "PNG"),
|
|
|
|
ImagePtr(qsl(":/ava/art/chatcolor3.png"), "PNG"),
|
|
|
|
ImagePtr(qsl(":/ava/art/chatcolor4.png"), "PNG"),
|
|
|
|
};
|
|
|
|
return chatDefPhotos[index];
|
|
|
|
}
|
|
|
|
|
2016-03-25 11:29:45 +00:00
|
|
|
ImagePtr channelDefPhoto(int index) {
|
2015-09-22 10:26:39 +00:00
|
|
|
static const ImagePtr channelDefPhotos[4] = {
|
|
|
|
ImagePtr(qsl(":/ava/art/channelcolor1.png"), "PNG"),
|
|
|
|
ImagePtr(qsl(":/ava/art/channelcolor2.png"), "PNG"),
|
|
|
|
ImagePtr(qsl(":/ava/art/channelcolor3.png"), "PNG"),
|
|
|
|
ImagePtr(qsl(":/ava/art/channelcolor4.png"), "PNG"),
|
|
|
|
};
|
|
|
|
return channelDefPhotos[index];
|
|
|
|
}
|
|
|
|
|
2015-04-04 20:01:34 +00:00
|
|
|
NotifySettings globalNotifyAll, globalNotifyUsers, globalNotifyChats;
|
|
|
|
NotifySettingsPtr globalNotifyAllPtr = UnknownNotifySettings, globalNotifyUsersPtr = UnknownNotifySettings, globalNotifyChatsPtr = UnknownNotifySettings;
|
|
|
|
|
2016-02-18 16:36:33 +00:00
|
|
|
PeerData::PeerData(const PeerId &id) : id(id)
|
2016-03-25 11:29:45 +00:00
|
|
|
, loadedStatus(NotLoaded)
|
2015-04-04 20:01:34 +00:00
|
|
|
, colorIndex(peerColorIndex(id))
|
|
|
|
, color(peerColor(colorIndex))
|
2015-08-07 12:11:50 +00:00
|
|
|
, photoId(UnknownPeerPhotoId)
|
2015-04-04 20:01:34 +00:00
|
|
|
, nameVersion(0)
|
2016-03-18 10:18:30 +00:00
|
|
|
, notify(UnknownNotifySettings)
|
|
|
|
, _userpic(isUser() ? userDefPhoto(colorIndex) : ((isChat() || isMegagroup()) ? chatDefPhoto(colorIndex) : channelDefPhoto(colorIndex))) {
|
2015-09-06 10:17:09 +00:00
|
|
|
if (!peerIsUser(id) && !peerIsChannel(id)) updateName(QString(), QString(), QString());
|
2015-04-04 20:01:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PeerData::updateName(const QString &newName, const QString &newNameOrPhone, const QString &newUsername) {
|
2015-09-16 13:04:08 +00:00
|
|
|
if (name == newName && nameVersion > 0) {
|
|
|
|
if (isUser()) {
|
|
|
|
if (asUser()->nameOrPhone == newNameOrPhone && asUser()->username == newUsername) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else if (isChannel()) {
|
|
|
|
if (asChannel()->username == newUsername) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else if (isChat()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2015-04-04 20:01:34 +00:00
|
|
|
|
|
|
|
++nameVersion;
|
|
|
|
name = newName;
|
2015-09-04 13:01:31 +00:00
|
|
|
nameText.setText(st::msgNameFont, name, _textNameOptions);
|
|
|
|
if (isUser()) {
|
|
|
|
asUser()->username = newUsername;
|
|
|
|
asUser()->setNameOrPhone(newNameOrPhone);
|
2015-09-13 19:15:45 +00:00
|
|
|
} else if (isChannel()) {
|
2015-09-23 17:43:08 +00:00
|
|
|
if (asChannel()->username != newUsername) {
|
|
|
|
asChannel()->username = newUsername;
|
|
|
|
if (newUsername.isEmpty()) {
|
2016-03-19 16:55:15 +00:00
|
|
|
asChannel()->flags &= ~MTPDchannel::Flag::f_username;
|
2015-09-23 17:43:08 +00:00
|
|
|
} else {
|
2016-03-19 16:55:15 +00:00
|
|
|
asChannel()->flags |= MTPDchannel::Flag::f_username;
|
2015-09-23 17:43:08 +00:00
|
|
|
}
|
|
|
|
if (App::main()) {
|
|
|
|
App::main()->peerUsernameChanged(this);
|
|
|
|
}
|
|
|
|
}
|
2015-09-04 13:01:31 +00:00
|
|
|
}
|
2015-09-03 10:48:40 +00:00
|
|
|
|
2015-04-04 20:01:34 +00:00
|
|
|
Names oldNames = names;
|
|
|
|
NameFirstChars oldChars = chars;
|
|
|
|
fillNames();
|
2015-09-04 13:01:31 +00:00
|
|
|
|
2015-04-04 20:01:34 +00:00
|
|
|
if (App::main()) {
|
|
|
|
emit App::main()->peerNameChanged(this, oldNames, oldChars);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-18 10:18:30 +00:00
|
|
|
void PeerData::setUserpic(ImagePtr userpic) {
|
|
|
|
_userpic = userpic;
|
|
|
|
}
|
|
|
|
|
|
|
|
ImagePtr PeerData::currentUserpic() const {
|
|
|
|
if (_userpic->loaded()) {
|
|
|
|
return _userpic;
|
2016-03-21 18:40:00 +00:00
|
|
|
}
|
|
|
|
_userpic->load();
|
|
|
|
|
|
|
|
if (isUser()) {
|
2016-03-18 10:18:30 +00:00
|
|
|
return userDefPhoto(colorIndex);
|
|
|
|
} else if (isMegagroup() || isChat()) {
|
|
|
|
return chatDefPhoto(colorIndex);
|
|
|
|
}
|
|
|
|
return channelDefPhoto(colorIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PeerData::paintUserpic(Painter &p, int size, int x, int y) const {
|
|
|
|
p.drawPixmap(x, y, currentUserpic()->pixCircled(size, size));
|
|
|
|
}
|
|
|
|
|
|
|
|
StorageKey PeerData::userpicUniqueKey() const {
|
|
|
|
if (photoLoc.isNull() || !_userpic->loaded()) {
|
|
|
|
return StorageKey(0, (isUser() ? 0x1000 : ((isChat() || isMegagroup()) ? 0x2000 : 0x3000)) | colorIndex);
|
|
|
|
}
|
|
|
|
return storageKey(photoLoc);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PeerData::saveUserpic(const QString &path) const {
|
|
|
|
currentUserpic()->pixCircled().save(path, "PNG");
|
|
|
|
}
|
|
|
|
|
2016-03-21 18:57:03 +00:00
|
|
|
QPixmap PeerData::genUserpic(int size) const {
|
|
|
|
return currentUserpic()->pixCircled(size, size);
|
|
|
|
}
|
|
|
|
|
2015-12-20 14:05:07 +00:00
|
|
|
const Text &BotCommand::descriptionText() const {
|
|
|
|
if (_descriptionText.isEmpty() && !_description.isEmpty()) {
|
|
|
|
_descriptionText.setText(st::mentionFont, _description, _textNameOptions);
|
|
|
|
}
|
|
|
|
return _descriptionText;
|
|
|
|
}
|
|
|
|
|
2015-08-07 12:11:50 +00:00
|
|
|
void UserData::setPhoto(const MTPUserProfilePhoto &p) { // see Local::readPeer as well
|
2015-06-29 22:09:23 +00:00
|
|
|
PhotoId newPhotoId = photoId;
|
2016-03-18 10:18:30 +00:00
|
|
|
ImagePtr newPhoto = _userpic;
|
2015-08-07 12:11:50 +00:00
|
|
|
StorageImageLocation newPhotoLoc = photoLoc;
|
2015-04-04 20:01:34 +00:00
|
|
|
switch (p.type()) {
|
|
|
|
case mtpc_userProfilePhoto: {
|
2016-04-08 10:44:35 +00:00
|
|
|
const auto &d(p.c_userProfilePhoto());
|
2015-06-29 22:09:23 +00:00
|
|
|
newPhotoId = d.vphoto_id.v;
|
2015-08-07 12:11:50 +00:00
|
|
|
newPhotoLoc = App::imageLocation(160, 160, d.vphoto_small);
|
|
|
|
newPhoto = newPhotoLoc.isNull() ? userDefPhoto(colorIndex) : ImagePtr(newPhotoLoc);
|
2015-09-03 10:48:40 +00:00
|
|
|
//App::feedPhoto(App::photoFromUserPhoto(peerToUser(id), MTP_int(unixtime()), p));
|
2015-04-04 20:01:34 +00:00
|
|
|
} break;
|
|
|
|
default: {
|
2015-06-29 22:09:23 +00:00
|
|
|
newPhotoId = 0;
|
2015-04-04 20:01:34 +00:00
|
|
|
if (id == ServiceUserId) {
|
2016-04-11 07:43:40 +00:00
|
|
|
if (_userpic.v() == userDefPhoto(colorIndex).v()) {
|
2015-06-29 22:09:23 +00:00
|
|
|
newPhoto = ImagePtr(QPixmap::fromImage(App::wnd()->iconLarge().scaledToWidth(160, Qt::SmoothTransformation), Qt::ColorOnly), "PNG");
|
|
|
|
}
|
2015-04-04 20:01:34 +00:00
|
|
|
} else {
|
2015-06-29 22:09:23 +00:00
|
|
|
newPhoto = userDefPhoto(colorIndex);
|
2015-04-04 20:01:34 +00:00
|
|
|
}
|
2015-08-07 12:11:50 +00:00
|
|
|
newPhotoLoc = StorageImageLocation();
|
2015-04-04 20:01:34 +00:00
|
|
|
} break;
|
|
|
|
}
|
2016-03-18 10:18:30 +00:00
|
|
|
if (newPhotoId != photoId || newPhoto.v() != _userpic.v() || newPhotoLoc != photoLoc) {
|
2015-06-29 22:09:23 +00:00
|
|
|
photoId = newPhotoId;
|
2016-03-18 10:18:30 +00:00
|
|
|
setUserpic(newPhoto);
|
2015-08-07 12:11:50 +00:00
|
|
|
photoLoc = newPhotoLoc;
|
2016-02-14 15:58:39 +00:00
|
|
|
if (App::main()) {
|
|
|
|
emit App::main()->peerPhotoChanged(this);
|
|
|
|
}
|
2015-06-29 22:09:23 +00:00
|
|
|
}
|
2015-04-04 20:01:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PeerData::fillNames() {
|
|
|
|
names.clear();
|
|
|
|
chars.clear();
|
|
|
|
QString toIndex = textAccentFold(name);
|
2016-02-16 11:21:39 +00:00
|
|
|
if (cRussianLetters().match(toIndex).hasMatch()) {
|
|
|
|
toIndex += ' ' + translitRusEng(toIndex);
|
|
|
|
}
|
2015-09-03 10:48:40 +00:00
|
|
|
if (isUser()) {
|
2015-09-04 13:01:31 +00:00
|
|
|
if (!asUser()->nameOrPhone.isEmpty() && asUser()->nameOrPhone != name) toIndex += ' ' + textAccentFold(asUser()->nameOrPhone);
|
|
|
|
if (!asUser()->username.isEmpty()) toIndex += ' ' + textAccentFold(asUser()->username);
|
2015-09-13 19:15:45 +00:00
|
|
|
} else if (isChannel()) {
|
|
|
|
if (!asChannel()->username.isEmpty()) toIndex += ' ' + textAccentFold(asChannel()->username);
|
2015-04-04 20:01:34 +00:00
|
|
|
}
|
|
|
|
toIndex += ' ' + rusKeyboardLayoutSwitch(toIndex);
|
|
|
|
|
|
|
|
QStringList namesList = toIndex.toLower().split(cWordSplit(), QString::SkipEmptyParts);
|
|
|
|
for (QStringList::const_iterator i = namesList.cbegin(), e = namesList.cend(); i != e; ++i) {
|
|
|
|
names.insert(*i);
|
|
|
|
chars.insert(i->at(0));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void UserData::setName(const QString &first, const QString &last, const QString &phoneName, const QString &usern) {
|
|
|
|
bool updName = !first.isEmpty() || !last.isEmpty(), updUsername = (username != usern);
|
|
|
|
|
|
|
|
if (updName && first.trimmed().isEmpty()) {
|
|
|
|
firstName = last;
|
|
|
|
lastName = QString();
|
|
|
|
updateName(firstName, phoneName, usern);
|
|
|
|
} else {
|
|
|
|
if (updName) {
|
|
|
|
firstName = first;
|
|
|
|
lastName = last;
|
|
|
|
}
|
2015-09-23 17:43:08 +00:00
|
|
|
updateName(lastName.isEmpty() ? firstName : lng_full_name(lt_first_name, firstName, lt_last_name, lastName), phoneName, usern);
|
2015-04-04 20:01:34 +00:00
|
|
|
}
|
|
|
|
if (updUsername) {
|
|
|
|
if (App::main()) {
|
|
|
|
App::main()->peerUsernameChanged(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void UserData::setPhone(const QString &newPhone) {
|
|
|
|
phone = newPhone;
|
|
|
|
}
|
|
|
|
|
2016-03-25 11:29:45 +00:00
|
|
|
void UserData::setBotInfoVersion(int version) {
|
2015-06-15 17:19:24 +00:00
|
|
|
if (version < 0) {
|
2015-11-20 13:34:37 +00:00
|
|
|
if (botInfo) {
|
|
|
|
if (!botInfo->commands.isEmpty()) {
|
|
|
|
botInfo->commands.clear();
|
|
|
|
Notify::botCommandsChanged(this);
|
|
|
|
}
|
|
|
|
delete botInfo;
|
|
|
|
botInfo = 0;
|
|
|
|
Notify::userIsBotChanged(this);
|
|
|
|
}
|
2015-06-15 17:19:24 +00:00
|
|
|
} else if (!botInfo) {
|
2015-06-10 12:48:26 +00:00
|
|
|
botInfo = new BotInfo();
|
|
|
|
botInfo->version = version;
|
2015-11-20 13:34:37 +00:00
|
|
|
Notify::userIsBotChanged(this);
|
2015-06-10 12:48:26 +00:00
|
|
|
} else if (botInfo->version < version) {
|
2015-07-03 15:55:22 +00:00
|
|
|
if (!botInfo->commands.isEmpty()) {
|
|
|
|
botInfo->commands.clear();
|
2015-11-20 13:34:37 +00:00
|
|
|
Notify::botCommandsChanged(this);
|
2015-07-03 15:55:22 +00:00
|
|
|
}
|
2015-06-10 12:48:26 +00:00
|
|
|
botInfo->description.clear();
|
|
|
|
botInfo->version = version;
|
2015-06-10 15:54:24 +00:00
|
|
|
botInfo->inited = false;
|
2015-06-10 12:48:26 +00:00
|
|
|
}
|
|
|
|
}
|
2015-08-07 12:11:50 +00:00
|
|
|
|
2015-06-10 12:48:26 +00:00
|
|
|
void UserData::setBotInfo(const MTPBotInfo &info) {
|
|
|
|
switch (info.type()) {
|
|
|
|
case mtpc_botInfo: {
|
2016-04-08 10:44:35 +00:00
|
|
|
const auto &d(info.c_botInfo());
|
2016-03-04 15:34:46 +00:00
|
|
|
if (peerFromUser(d.vuser_id.v) != id || !botInfo) return;
|
2015-06-10 15:54:24 +00:00
|
|
|
|
2015-06-15 17:19:24 +00:00
|
|
|
QString desc = qs(d.vdescription);
|
2015-06-10 15:54:24 +00:00
|
|
|
if (botInfo->description != desc) {
|
|
|
|
botInfo->description = desc;
|
2015-06-15 17:19:24 +00:00
|
|
|
botInfo->text = Text(st::msgMinWidth);
|
2015-06-10 15:54:24 +00:00
|
|
|
}
|
2015-12-31 15:27:21 +00:00
|
|
|
|
2016-04-08 10:44:35 +00:00
|
|
|
const auto &v(d.vcommands.c_vector().v);
|
2015-06-10 12:48:26 +00:00
|
|
|
botInfo->commands.reserve(v.size());
|
2015-07-03 15:55:22 +00:00
|
|
|
bool changedCommands = false;
|
|
|
|
int32 j = 0;
|
2015-06-10 12:48:26 +00:00
|
|
|
for (int32 i = 0, l = v.size(); i < l; ++i) {
|
2015-07-03 15:55:22 +00:00
|
|
|
if (v.at(i).type() != mtpc_botCommand) continue;
|
|
|
|
|
|
|
|
QString cmd = qs(v.at(i).c_botCommand().vcommand), desc = qs(v.at(i).c_botCommand().vdescription);
|
|
|
|
if (botInfo->commands.size() <= j) {
|
|
|
|
botInfo->commands.push_back(BotCommand(cmd, desc));
|
|
|
|
changedCommands = true;
|
|
|
|
} else {
|
|
|
|
if (botInfo->commands[j].command != cmd) {
|
|
|
|
botInfo->commands[j].command = cmd;
|
|
|
|
changedCommands = true;
|
|
|
|
}
|
|
|
|
if (botInfo->commands[j].setDescription(desc)) {
|
|
|
|
changedCommands = true;
|
|
|
|
}
|
2015-06-10 12:48:26 +00:00
|
|
|
}
|
2015-07-03 15:55:22 +00:00
|
|
|
++j;
|
|
|
|
}
|
|
|
|
while (j < botInfo->commands.size()) {
|
|
|
|
botInfo->commands.pop_back();
|
|
|
|
changedCommands = true;
|
2015-06-10 12:48:26 +00:00
|
|
|
}
|
2015-06-10 15:54:24 +00:00
|
|
|
|
|
|
|
botInfo->inited = true;
|
2015-07-03 15:55:22 +00:00
|
|
|
|
2015-11-20 13:34:37 +00:00
|
|
|
if (changedCommands) {
|
|
|
|
Notify::botCommandsChanged(this);
|
2015-07-03 15:55:22 +00:00
|
|
|
}
|
2015-06-10 12:48:26 +00:00
|
|
|
} break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-04 13:01:31 +00:00
|
|
|
void UserData::setNameOrPhone(const QString &newNameOrPhone) {
|
|
|
|
if (nameOrPhone != newNameOrPhone) {
|
|
|
|
nameOrPhone = newNameOrPhone;
|
|
|
|
phoneText.setText(st::msgNameFont, nameOrPhone, _textNameOptions);
|
|
|
|
}
|
2015-04-04 20:01:34 +00:00
|
|
|
}
|
|
|
|
|
2015-06-10 12:48:26 +00:00
|
|
|
void UserData::madeAction() {
|
2015-06-24 17:24:48 +00:00
|
|
|
if (botInfo || isServiceUser(id)) return;
|
|
|
|
|
2015-06-10 12:48:26 +00:00
|
|
|
int32 t = unixtime();
|
|
|
|
if (onlineTill <= 0 && -onlineTill < t) {
|
|
|
|
onlineTill = -t - SetOnlineAfterActivity;
|
2015-06-29 22:09:23 +00:00
|
|
|
App::markPeerUpdated(this);
|
2015-06-10 12:48:26 +00:00
|
|
|
} else if (onlineTill > 0 && onlineTill < t + 1) {
|
|
|
|
onlineTill = t + SetOnlineAfterActivity;
|
2015-06-29 22:09:23 +00:00
|
|
|
App::markPeerUpdated(this);
|
2015-06-10 12:48:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-07 12:11:50 +00:00
|
|
|
void ChatData::setPhoto(const MTPChatPhoto &p, const PhotoId &phId) { // see Local::readPeer as well
|
|
|
|
PhotoId newPhotoId = photoId;
|
2016-03-18 10:18:30 +00:00
|
|
|
ImagePtr newPhoto = _userpic;
|
2015-08-07 12:11:50 +00:00
|
|
|
StorageImageLocation newPhotoLoc = photoLoc;
|
2015-04-04 20:01:34 +00:00
|
|
|
switch (p.type()) {
|
|
|
|
case mtpc_chatPhoto: {
|
2016-04-08 10:44:35 +00:00
|
|
|
const auto &d(p.c_chatPhoto());
|
2015-06-29 22:09:23 +00:00
|
|
|
if (phId != UnknownPeerPhotoId) {
|
2015-08-07 12:11:50 +00:00
|
|
|
newPhotoId = phId;
|
2015-04-04 20:01:34 +00:00
|
|
|
}
|
2015-08-07 12:11:50 +00:00
|
|
|
newPhotoLoc = App::imageLocation(160, 160, d.vphoto_small);
|
|
|
|
newPhoto = newPhotoLoc.isNull() ? chatDefPhoto(colorIndex) : ImagePtr(newPhotoLoc);
|
|
|
|
// photoFull = ImagePtr(640, 640, d.vphoto_big, chatDefPhoto(colorIndex));
|
2015-04-04 20:01:34 +00:00
|
|
|
} break;
|
|
|
|
default: {
|
2015-08-07 12:11:50 +00:00
|
|
|
newPhotoId = 0;
|
|
|
|
newPhotoLoc = StorageImageLocation();
|
|
|
|
newPhoto = chatDefPhoto(colorIndex);
|
|
|
|
// photoFull = ImagePtr();
|
2015-04-04 20:01:34 +00:00
|
|
|
} break;
|
|
|
|
}
|
2016-03-18 10:18:30 +00:00
|
|
|
if (newPhotoId != photoId || newPhoto.v() != _userpic.v() || newPhotoLoc != photoLoc) {
|
2015-08-07 12:11:50 +00:00
|
|
|
photoId = newPhotoId;
|
2016-03-18 10:18:30 +00:00
|
|
|
setUserpic(newPhoto);
|
2015-08-07 12:11:50 +00:00
|
|
|
photoLoc = newPhotoLoc;
|
|
|
|
emit App::main()->peerPhotoChanged(this);
|
|
|
|
}
|
2015-04-04 20:01:34 +00:00
|
|
|
}
|
|
|
|
|
2015-09-03 10:48:40 +00:00
|
|
|
void ChannelData::setPhoto(const MTPChatPhoto &p, const PhotoId &phId) { // see Local::readPeer as well
|
|
|
|
PhotoId newPhotoId = photoId;
|
2016-03-18 10:18:30 +00:00
|
|
|
ImagePtr newPhoto = _userpic;
|
2015-09-03 10:48:40 +00:00
|
|
|
StorageImageLocation newPhotoLoc = photoLoc;
|
|
|
|
switch (p.type()) {
|
|
|
|
case mtpc_chatPhoto: {
|
2016-04-08 10:44:35 +00:00
|
|
|
const auto &d(p.c_chatPhoto());
|
2015-09-03 10:48:40 +00:00
|
|
|
if (phId != UnknownPeerPhotoId) {
|
|
|
|
newPhotoId = phId;
|
|
|
|
}
|
|
|
|
newPhotoLoc = App::imageLocation(160, 160, d.vphoto_small);
|
2015-11-06 17:48:49 +00:00
|
|
|
newPhoto = newPhotoLoc.isNull() ? (isMegagroup() ? chatDefPhoto(colorIndex) : channelDefPhoto(colorIndex)) : ImagePtr(newPhotoLoc);
|
|
|
|
// photoFull = ImagePtr(640, 640, d.vphoto_big, (isMegagroup() ? chatDefPhoto(colorIndex) : channelDefPhoto(colorIndex)));
|
2015-09-03 10:48:40 +00:00
|
|
|
} break;
|
|
|
|
default: {
|
|
|
|
newPhotoId = 0;
|
|
|
|
newPhotoLoc = StorageImageLocation();
|
2015-11-06 17:48:49 +00:00
|
|
|
newPhoto = (isMegagroup() ? chatDefPhoto(colorIndex) : channelDefPhoto(colorIndex));
|
2015-09-03 10:48:40 +00:00
|
|
|
// photoFull = ImagePtr();
|
|
|
|
} break;
|
|
|
|
}
|
2016-03-18 10:18:30 +00:00
|
|
|
if (newPhotoId != photoId || newPhoto.v() != _userpic.v() || newPhotoLoc != photoLoc) {
|
2015-09-03 10:48:40 +00:00
|
|
|
photoId = newPhotoId;
|
2016-03-18 10:18:30 +00:00
|
|
|
setUserpic(newPhoto);
|
2015-09-03 10:48:40 +00:00
|
|
|
photoLoc = newPhotoLoc;
|
2015-10-03 11:33:51 +00:00
|
|
|
if (App::main()) emit App::main()->peerPhotoChanged(this);
|
2015-09-03 10:48:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-06 10:17:09 +00:00
|
|
|
void ChannelData::setName(const QString &newName, const QString &usern) {
|
|
|
|
bool updName = !newName.isEmpty(), updUsername = (username != usern);
|
|
|
|
|
|
|
|
updateName(newName.isEmpty() ? name : newName, QString(), usern);
|
|
|
|
}
|
|
|
|
|
2015-09-23 17:43:08 +00:00
|
|
|
void ChannelData::updateFull(bool force) {
|
|
|
|
if (!_lastFullUpdate || force || getms(true) > _lastFullUpdate + UpdateFullChannelTimeout) {
|
2015-10-03 11:33:51 +00:00
|
|
|
if (App::api()) {
|
|
|
|
App::api()->requestFullPeer(this);
|
|
|
|
if (!amCreator() && !inviter) App::api()->requestSelfParticipant(this);
|
|
|
|
}
|
2015-09-21 20:57:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ChannelData::fullUpdated() {
|
|
|
|
_lastFullUpdate = getms(true);
|
|
|
|
}
|
|
|
|
|
2015-11-13 15:14:33 +00:00
|
|
|
void ChannelData::flagsUpdated() {
|
|
|
|
if (isMegagroup()) {
|
|
|
|
if (!mgInfo) {
|
|
|
|
mgInfo = new MegagroupInfo();
|
|
|
|
}
|
|
|
|
if (History *h = App::historyLoaded(id)) {
|
|
|
|
if (h->asChannelHistory()->onlyImportant()) {
|
|
|
|
MsgId fixInScrollMsgId = 0;
|
|
|
|
int32 fixInScrollMsgTop = 0;
|
|
|
|
h->asChannelHistory()->getSwitchReadyFor(SwitchAtTopMsgId, fixInScrollMsgId, fixInScrollMsgTop);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (mgInfo) {
|
|
|
|
delete mgInfo;
|
|
|
|
mgInfo = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-06 17:48:49 +00:00
|
|
|
ChannelData::~ChannelData() {
|
|
|
|
delete mgInfo;
|
|
|
|
}
|
|
|
|
|
2015-09-13 08:41:27 +00:00
|
|
|
uint64 PtsWaiter::ptsKey(PtsSkippedQueue queue) {
|
|
|
|
return _queue.insert(uint64(uint32(_last)) << 32 | uint64(uint32(_count)), queue).key();
|
|
|
|
}
|
|
|
|
|
2015-09-20 09:54:22 +00:00
|
|
|
void PtsWaiter::setWaitingForSkipped(ChannelData *channel, int32 ms) {
|
|
|
|
if (ms >= 0) {
|
|
|
|
if (App::main()) {
|
|
|
|
App::main()->ptsWaiterStartTimerFor(channel, ms);
|
|
|
|
}
|
|
|
|
_waitingForSkipped = true;
|
|
|
|
} else {
|
|
|
|
_waitingForSkipped = false;
|
|
|
|
checkForWaiting(channel);
|
|
|
|
}
|
2015-09-20 08:55:41 +00:00
|
|
|
}
|
|
|
|
|
2015-09-20 09:54:22 +00:00
|
|
|
void PtsWaiter::setWaitingForShortPoll(ChannelData *channel, int32 ms) {
|
|
|
|
if (ms >= 0) {
|
|
|
|
if (App::main()) {
|
|
|
|
App::main()->ptsWaiterStartTimerFor(channel, ms);
|
|
|
|
}
|
|
|
|
_waitingForShortPoll = true;
|
|
|
|
} else {
|
|
|
|
_waitingForShortPoll = false;
|
|
|
|
checkForWaiting(channel);
|
|
|
|
}
|
2015-09-20 08:55:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PtsWaiter::checkForWaiting(ChannelData *channel) {
|
|
|
|
if (!_waitingForSkipped && !_waitingForShortPoll && App::main()) {
|
|
|
|
App::main()->ptsWaiterStartTimerFor(channel, -1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-13 08:41:27 +00:00
|
|
|
void PtsWaiter::applySkippedUpdates(ChannelData *channel) {
|
2015-09-20 09:54:22 +00:00
|
|
|
if (!_waitingForSkipped) return;
|
|
|
|
|
|
|
|
setWaitingForSkipped(channel, -1);
|
2015-09-20 08:55:41 +00:00
|
|
|
|
|
|
|
if (!App::main() || _queue.isEmpty()) return;
|
2015-09-13 08:41:27 +00:00
|
|
|
|
|
|
|
++_applySkippedLevel;
|
|
|
|
for (QMap<uint64, PtsSkippedQueue>::const_iterator i = _queue.cbegin(), e = _queue.cend(); i != e; ++i) {
|
|
|
|
switch (i.value()) {
|
|
|
|
case SkippedUpdate: App::main()->feedUpdate(_updateQueue.value(i.key())); break;
|
2015-09-21 20:57:42 +00:00
|
|
|
case SkippedUpdates: App::main()->feedUpdates(_updatesQueue.value(i.key())); break;
|
2015-09-13 08:41:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
--_applySkippedLevel;
|
|
|
|
clearSkippedUpdates();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PtsWaiter::clearSkippedUpdates() {
|
|
|
|
_queue.clear();
|
|
|
|
_updateQueue.clear();
|
|
|
|
_updatesQueue.clear();
|
|
|
|
_applySkippedLevel = 0;
|
|
|
|
}
|
|
|
|
|
2015-09-21 20:57:42 +00:00
|
|
|
bool PtsWaiter::updated(ChannelData *channel, int32 pts, int32 count) {
|
|
|
|
if (_requesting || _applySkippedLevel) {
|
|
|
|
return true;
|
2015-09-28 14:19:37 +00:00
|
|
|
} else if (pts <= _good && count > 0) {
|
2015-09-21 20:57:42 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return check(channel, pts, count);
|
|
|
|
}
|
|
|
|
|
2015-09-28 14:19:37 +00:00
|
|
|
bool PtsWaiter::updated(ChannelData *channel, int32 pts, int32 count, const MTPUpdates &updates) {
|
2015-09-21 20:57:42 +00:00
|
|
|
if (_requesting || _applySkippedLevel) {
|
|
|
|
return true;
|
2015-09-28 14:19:37 +00:00
|
|
|
} else if (pts <= _good && count > 0) {
|
2015-09-21 20:57:42 +00:00
|
|
|
return false;
|
2015-09-28 14:19:37 +00:00
|
|
|
} else if (check(channel, pts, count)) {
|
2015-09-21 20:57:42 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
_updatesQueue.insert(ptsKey(SkippedUpdates), updates);
|
|
|
|
return false;
|
|
|
|
}
|
2015-09-13 08:41:27 +00:00
|
|
|
|
2015-09-28 14:19:37 +00:00
|
|
|
bool PtsWaiter::updated(ChannelData *channel, int32 pts, int32 count, const MTPUpdate &update) {
|
2015-09-21 20:57:42 +00:00
|
|
|
if (_requesting || _applySkippedLevel) {
|
|
|
|
return true;
|
2015-09-28 14:19:37 +00:00
|
|
|
} else if (pts <= _good && count > 0) {
|
2015-09-21 20:57:42 +00:00
|
|
|
return false;
|
2015-09-28 14:19:37 +00:00
|
|
|
} else if (check(channel, pts, count)) {
|
2015-09-21 20:57:42 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
_updateQueue.insert(ptsKey(SkippedUpdate), update);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool PtsWaiter::check(ChannelData *channel, int32 pts, int32 count) { // return false if need to save that update and apply later
|
2015-09-13 08:41:27 +00:00
|
|
|
if (!inited()) {
|
|
|
|
init(pts);
|
|
|
|
return true;
|
|
|
|
}
|
2015-09-21 20:57:42 +00:00
|
|
|
|
2015-09-13 08:41:27 +00:00
|
|
|
_last = qMax(_last, pts);
|
|
|
|
_count += count;
|
|
|
|
if (_last == _count) {
|
|
|
|
_good = _last;
|
|
|
|
return true;
|
|
|
|
} else if (_last < _count) {
|
2015-09-20 09:54:22 +00:00
|
|
|
setWaitingForSkipped(channel, 1);
|
2015-09-13 08:41:27 +00:00
|
|
|
} else {
|
2015-09-20 09:54:22 +00:00
|
|
|
setWaitingForSkipped(channel, WaitForSkippedTimeout);
|
2015-09-13 08:41:27 +00:00
|
|
|
}
|
|
|
|
return !count;
|
|
|
|
}
|
|
|
|
|
2015-12-24 19:26:28 +00:00
|
|
|
PhotoData::PhotoData(const PhotoId &id, const uint64 &access, int32 date, const ImagePtr &thumb, const ImagePtr &medium, const ImagePtr &full)
|
|
|
|
: id(id)
|
|
|
|
, access(access)
|
|
|
|
, date(date)
|
|
|
|
, thumb(thumb)
|
|
|
|
, medium(medium)
|
|
|
|
, full(full)
|
|
|
|
, peer(0)
|
|
|
|
, uploadingData(0) {
|
|
|
|
}
|
|
|
|
|
|
|
|
void PhotoData::automaticLoad(const HistoryItem *item) {
|
|
|
|
full->automaticLoad(item);
|
|
|
|
}
|
|
|
|
|
2015-12-27 21:37:48 +00:00
|
|
|
void PhotoData::automaticLoadSettingsChanged() {
|
|
|
|
full->automaticLoadSettingsChanged();
|
|
|
|
}
|
|
|
|
|
2015-12-25 13:09:14 +00:00
|
|
|
void PhotoData::download() {
|
|
|
|
full->loadEvenCancelled();
|
|
|
|
notifyLayoutChanged();
|
|
|
|
}
|
|
|
|
|
2015-12-24 19:26:28 +00:00
|
|
|
bool PhotoData::loaded() const {
|
2015-12-25 13:09:14 +00:00
|
|
|
bool wasLoading = loading();
|
|
|
|
if (full->loaded()) {
|
|
|
|
if (wasLoading) {
|
|
|
|
notifyLayoutChanged();
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2015-12-24 19:26:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool PhotoData::loading() const {
|
|
|
|
return full->loading();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool PhotoData::displayLoading() const {
|
|
|
|
return full->loading() ? full->displayLoading() : uploading();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PhotoData::cancel() {
|
|
|
|
full->cancel();
|
2015-12-25 13:09:14 +00:00
|
|
|
notifyLayoutChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PhotoData::notifyLayoutChanged() const {
|
|
|
|
const PhotoItems &items(App::photoItems());
|
|
|
|
PhotoItems::const_iterator i = items.constFind(const_cast<PhotoData*>(this));
|
|
|
|
if (i != items.cend()) {
|
|
|
|
for (HistoryItemsMap::const_iterator j = i->cbegin(), e = i->cend(); j != e; ++j) {
|
|
|
|
Notify::historyItemLayoutChanged(j.key());
|
|
|
|
}
|
|
|
|
}
|
2015-12-24 19:26:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
float64 PhotoData::progress() const {
|
2015-12-25 13:09:14 +00:00
|
|
|
if (uploading()) {
|
|
|
|
if (uploadingData->size > 0) {
|
|
|
|
return float64(uploadingData->offset) / uploadingData->size;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return full->progress();
|
2015-12-24 19:26:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int32 PhotoData::loadOffset() const {
|
|
|
|
return full->loadOffset();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool PhotoData::uploading() const {
|
|
|
|
return uploadingData;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PhotoData::forget() {
|
|
|
|
thumb->forget();
|
|
|
|
replyPreview->forget();
|
|
|
|
medium->forget();
|
|
|
|
full->forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
ImagePtr PhotoData::makeReplyPreview() {
|
|
|
|
if (replyPreview->isNull() && !thumb->isNull()) {
|
|
|
|
if (thumb->loaded()) {
|
|
|
|
int w = thumb->width(), h = thumb->height();
|
|
|
|
if (w <= 0) w = 1;
|
|
|
|
if (h <= 0) h = 1;
|
|
|
|
replyPreview = ImagePtr(w > h ? thumb->pix(w * st::msgReplyBarSize.height() / h, st::msgReplyBarSize.height()) : thumb->pix(st::msgReplyBarSize.height()), "PNG");
|
|
|
|
} else {
|
|
|
|
thumb->load();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return replyPreview;
|
|
|
|
}
|
|
|
|
|
|
|
|
PhotoData::~PhotoData() {
|
2015-12-28 21:20:04 +00:00
|
|
|
deleteAndMark(uploadingData);
|
2015-12-24 19:26:28 +00:00
|
|
|
}
|
|
|
|
|
2016-03-29 17:17:00 +00:00
|
|
|
void PhotoOpenClickHandler::onClickImpl() const {
|
|
|
|
App::wnd()->showPhoto(this, App::hoveredLinkItem() ? App::hoveredLinkItem() : App::contextItem());
|
2015-12-24 19:26:28 +00:00
|
|
|
}
|
|
|
|
|
2016-03-29 17:17:00 +00:00
|
|
|
void PhotoSaveClickHandler::onClickImpl() const {
|
2015-12-25 13:09:14 +00:00
|
|
|
PhotoData *data = photo();
|
|
|
|
if (!data->date) return;
|
|
|
|
|
|
|
|
data->download();
|
|
|
|
}
|
|
|
|
|
2016-03-29 17:17:00 +00:00
|
|
|
void PhotoCancelClickHandler::onClickImpl() const {
|
2015-12-24 19:26:28 +00:00
|
|
|
PhotoData *data = photo();
|
|
|
|
if (!data->date) return;
|
|
|
|
|
|
|
|
if (data->uploading()) {
|
2016-02-17 16:37:21 +00:00
|
|
|
if (HistoryItem *item = App::hoveredLinkItem() ? App::hoveredLinkItem() : (App::contextItem() ? App::contextItem() : 0)) {
|
|
|
|
if (HistoryMessage *msg = item->toHistoryMessage()) {
|
|
|
|
if (msg->getMedia() && msg->getMedia()->type() == MediaTypePhoto && static_cast<HistoryPhoto*>(msg->getMedia())->photo() == data) {
|
|
|
|
App::contextItem(item);
|
|
|
|
App::main()->deleteLayer(-2);
|
|
|
|
}
|
2015-12-24 19:26:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
data->cancel();
|
2015-04-04 20:01:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-19 10:29:19 +00:00
|
|
|
QString saveFileName(const QString &title, const QString &filter, const QString &prefix, QString name, bool savingAs, const QDir &dir) {
|
2015-04-04 20:01:34 +00:00
|
|
|
#ifdef Q_OS_WIN
|
|
|
|
name = name.replace(QRegularExpression(qsl("[\\\\\\/\\:\\*\\?\\\"\\<\\>\\|]")), qsl("_"));
|
|
|
|
#elif defined Q_OS_MAC
|
|
|
|
name = name.replace(QRegularExpression(qsl("[\\:]")), qsl("_"));
|
|
|
|
#elif defined Q_OS_LINUX
|
|
|
|
name = name.replace(QRegularExpression(qsl("[\\/]")), qsl("_"));
|
|
|
|
#endif
|
|
|
|
if (cAskDownloadPath() || savingAs) {
|
|
|
|
if (!name.isEmpty() && name.at(0) == QChar::fromLatin1('.')) {
|
|
|
|
name = filedialogDefaultName(prefix, name);
|
|
|
|
} else if (dir.path() != qsl(".")) {
|
|
|
|
QString path = dir.absolutePath();
|
|
|
|
if (path != cDialogLastPath()) {
|
|
|
|
cSetDialogLastPath(path);
|
|
|
|
Local::writeUserSettings();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-18 11:38:00 +00:00
|
|
|
// check if extension of filename is present in filter
|
|
|
|
// it should be in first filter section on the first place
|
|
|
|
// place it there, if it is not
|
|
|
|
QString ext = QFileInfo(name).suffix(), fil = filter, sep = qsl(";;");
|
|
|
|
if (!ext.isEmpty()) {
|
|
|
|
if (QRegularExpression(qsl("^[a-zA-Z_0-9]+$")).match(ext).hasMatch()) {
|
|
|
|
QStringList filters = filter.split(sep);
|
|
|
|
if (filters.size() > 1) {
|
|
|
|
QString first = filters.at(0);
|
|
|
|
int32 start = first.indexOf(qsl("(*."));
|
|
|
|
if (start >= 0) {
|
|
|
|
if (!QRegularExpression(qsl("\\(\\*\\.") + ext + qsl("[\\)\\s]"), QRegularExpression::CaseInsensitiveOption).match(first).hasMatch()) {
|
|
|
|
QRegularExpressionMatch m = QRegularExpression(qsl(" \\*\\.") + ext + qsl("[\\)\\s]"), QRegularExpression::CaseInsensitiveOption).match(first);
|
|
|
|
if (m.hasMatch() && m.capturedStart() > start + 3) {
|
|
|
|
int32 oldpos = m.capturedStart(), oldend = m.capturedEnd();
|
|
|
|
fil = first.mid(0, start + 3) + ext + qsl(" *.") + first.mid(start + 3, oldpos - start - 3) + first.mid(oldend - 1) + sep + filters.mid(1).join(sep);
|
|
|
|
} else {
|
|
|
|
fil = first.mid(0, start + 3) + ext + qsl(" *.") + first.mid(start + 3) + sep + filters.mid(1).join(sep);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
fil = QString();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
fil = QString();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
fil = QString();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return filedialogGetSaveFile(name, title, fil, name) ? name : QString();
|
2015-04-04 20:01:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QString path;
|
|
|
|
if (cDownloadPath().isEmpty()) {
|
|
|
|
path = psDownloadPath();
|
|
|
|
} else if (cDownloadPath() == qsl("tmp")) {
|
|
|
|
path = cTempDir();
|
|
|
|
} else {
|
|
|
|
path = cDownloadPath();
|
|
|
|
}
|
|
|
|
if (name.isEmpty()) name = qsl(".unknown");
|
|
|
|
if (name.at(0) == QChar::fromLatin1('.')) {
|
|
|
|
if (!QDir().exists(path)) QDir().mkpath(path);
|
|
|
|
return filedialogDefaultName(prefix, name, path);
|
|
|
|
}
|
|
|
|
if (dir.path() != qsl(".")) {
|
|
|
|
path = dir.absolutePath() + '/';
|
|
|
|
}
|
|
|
|
|
|
|
|
QString nameStart, extension;
|
|
|
|
int32 extPos = name.lastIndexOf('.');
|
|
|
|
if (extPos >= 0) {
|
|
|
|
nameStart = name.mid(0, extPos);
|
|
|
|
extension = name.mid(extPos);
|
|
|
|
} else {
|
|
|
|
nameStart = name;
|
|
|
|
}
|
|
|
|
QString nameBase = path + nameStart;
|
|
|
|
name = nameBase + extension;
|
|
|
|
for (int i = 0; QFileInfo(name).exists(); ++i) {
|
|
|
|
name = nameBase + QString(" (%1)").arg(i + 2) + extension;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!QDir().exists(path)) QDir().mkpath(path);
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
2015-06-19 21:58:01 +00:00
|
|
|
bool StickerData::setInstalled() const {
|
|
|
|
switch (set.type()) {
|
|
|
|
case mtpc_inputStickerSetID: {
|
2016-03-19 16:55:15 +00:00
|
|
|
auto it = Global::StickerSets().constFind(set.c_inputStickerSetID().vid.v);
|
|
|
|
return (it != Global::StickerSets().cend()) && !(it->flags & MTPDstickerSet::Flag::f_disabled);
|
2015-06-19 21:58:01 +00:00
|
|
|
} break;
|
|
|
|
case mtpc_inputStickerSetShortName: {
|
|
|
|
QString name = qs(set.c_inputStickerSetShortName().vshort_name).toLower();
|
2016-03-19 16:55:15 +00:00
|
|
|
for (auto it = Global::StickerSets().cbegin(), e = Global::StickerSets().cend(); it != e; ++it) {
|
2015-12-02 17:17:53 +00:00
|
|
|
if (it->shortName.toLower() == name) {
|
2016-03-19 16:55:15 +00:00
|
|
|
return !(it->flags & MTPDstickerSet::Flag::f_disabled);
|
2015-12-02 17:17:53 +00:00
|
|
|
}
|
2015-06-19 21:58:01 +00:00
|
|
|
}
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-03-16 11:54:37 +00:00
|
|
|
QString documentSaveFilename(const DocumentData *data, bool forceSavingAs = false, const QString already = QString(), const QDir &dir = QDir()) {
|
2016-02-12 18:18:32 +00:00
|
|
|
QString name, filter, caption, prefix;
|
|
|
|
MimeType mimeType = mimeTypeForName(data->mime);
|
|
|
|
QStringList p = mimeType.globPatterns();
|
|
|
|
QString pattern = p.isEmpty() ? QString() : p.front();
|
|
|
|
if (data->voice()) {
|
|
|
|
bool mp3 = (data->mime == qstr("audio/mp3"));
|
|
|
|
name = already.isEmpty() ? (mp3 ? qsl(".mp3") : qsl(".ogg")) : already;
|
|
|
|
filter = mp3 ? qsl("MP3 Audio (*.mp3);;All files (*.*)") : qsl("OGG Opus Audio (*.ogg);;All files (*.*)");
|
|
|
|
caption = lang(lng_save_audio);
|
|
|
|
prefix = qsl("audio");
|
|
|
|
} else if (data->isVideo()) {
|
|
|
|
name = already.isEmpty() ? qsl(".mov") : already;
|
|
|
|
filter = qsl("MOV Video (*.mov);;All files (*.*)");
|
|
|
|
caption = lang(lng_save_video);
|
|
|
|
prefix = qsl("video");
|
2015-12-24 19:26:28 +00:00
|
|
|
} else {
|
2016-02-12 18:18:32 +00:00
|
|
|
name = already.isEmpty() ? data->name : already;
|
|
|
|
if (name.isEmpty()) {
|
|
|
|
name = pattern.isEmpty() ? qsl(".unknown") : pattern.replace('*', QString());
|
2015-12-24 19:26:28 +00:00
|
|
|
}
|
2016-02-12 18:18:32 +00:00
|
|
|
if (pattern.isEmpty()) {
|
|
|
|
filter = QString();
|
2015-12-24 19:26:28 +00:00
|
|
|
} else {
|
2016-02-12 18:18:32 +00:00
|
|
|
filter = mimeType.filterString() + qsl(";;All files (*.*)");
|
2015-12-12 22:29:33 +00:00
|
|
|
}
|
2016-03-25 11:29:45 +00:00
|
|
|
caption = lang(data->song() ? lng_save_audio_file : lng_save_file);
|
2016-02-12 18:18:32 +00:00
|
|
|
prefix = qsl("doc");
|
2015-12-12 22:29:33 +00:00
|
|
|
}
|
2015-04-04 20:01:34 +00:00
|
|
|
|
2016-02-12 18:18:32 +00:00
|
|
|
return saveFileName(caption, filter, prefix, name, forceSavingAs, dir);
|
2015-12-24 19:26:28 +00:00
|
|
|
}
|
|
|
|
|
2016-03-29 17:17:00 +00:00
|
|
|
void DocumentOpenClickHandler::doOpen(DocumentData *data, ActionOnLoad action) {
|
2015-07-03 08:47:16 +00:00
|
|
|
if (!data->date) return;
|
2015-04-04 20:01:34 +00:00
|
|
|
|
2016-04-10 18:18:26 +00:00
|
|
|
HistoryItem *item = App::hoveredLinkItem() ? App::hoveredLinkItem() : (App::contextItem() ? App::contextItem() : nullptr);
|
|
|
|
FullMsgId msgId;
|
|
|
|
if (item) {
|
|
|
|
msgId = item->fullId();
|
|
|
|
}
|
|
|
|
bool playVoice = data->voice() && audioPlayer();
|
|
|
|
bool playMusic = data->song() && audioPlayer();
|
2015-12-24 19:26:28 +00:00
|
|
|
bool playAnimation = data->isAnimation() && item && item->getMedia();
|
2015-11-26 17:34:52 +00:00
|
|
|
const FileLocation &location(data->location(true));
|
2016-02-12 16:35:06 +00:00
|
|
|
if (!location.isEmpty() || (!data->data().isEmpty() && (playVoice || playMusic || playAnimation))) {
|
|
|
|
if (playVoice) {
|
|
|
|
AudioMsgId playing;
|
|
|
|
AudioPlayerState playingState = AudioPlayerStopped;
|
|
|
|
audioPlayer()->currentState(&playing, &playingState);
|
2016-04-10 18:18:26 +00:00
|
|
|
if (playing == AudioMsgId(data, msgId) && !(playingState & AudioPlayerStoppedMask) && playingState != AudioPlayerFinishing) {
|
2016-02-12 16:35:06 +00:00
|
|
|
audioPlayer()->pauseresume(OverviewVoiceFiles);
|
|
|
|
} else {
|
2016-04-10 18:18:26 +00:00
|
|
|
AudioMsgId audio(data, msgId);
|
2016-02-12 16:35:06 +00:00
|
|
|
audioPlayer()->play(audio);
|
|
|
|
if (App::main()) {
|
|
|
|
App::main()->audioPlayProgress(audio);
|
2016-02-12 18:18:32 +00:00
|
|
|
App::main()->mediaMarkRead(data);
|
2016-02-12 16:35:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (playMusic) {
|
2015-06-30 21:07:05 +00:00
|
|
|
SongMsgId playing;
|
|
|
|
AudioPlayerState playingState = AudioPlayerStopped;
|
|
|
|
audioPlayer()->currentState(&playing, &playingState);
|
2016-04-10 18:18:26 +00:00
|
|
|
if (playing == SongMsgId(data, msgId) && !(playingState & AudioPlayerStoppedMask) && playingState != AudioPlayerFinishing) {
|
2016-02-12 16:35:06 +00:00
|
|
|
audioPlayer()->pauseresume(OverviewFiles);
|
2015-06-30 21:07:05 +00:00
|
|
|
} else {
|
2016-04-10 18:18:26 +00:00
|
|
|
SongMsgId song(data, msgId);
|
2015-07-03 08:47:16 +00:00
|
|
|
audioPlayer()->play(song);
|
|
|
|
if (App::main()) App::main()->documentPlayProgress(song);
|
2015-06-30 21:07:05 +00:00
|
|
|
}
|
2016-02-12 18:18:32 +00:00
|
|
|
} else if (data->voice() || data->isVideo()) {
|
2016-02-12 16:35:06 +00:00
|
|
|
psOpenFile(location.name());
|
2016-02-12 18:18:32 +00:00
|
|
|
if (App::main()) App::main()->mediaMarkRead(data);
|
2015-12-23 19:23:14 +00:00
|
|
|
} else if (data->size < MediaViewImageSizeLimit) {
|
2015-12-24 19:26:28 +00:00
|
|
|
if (!data->data().isEmpty() && playAnimation) {
|
2016-03-14 09:58:43 +00:00
|
|
|
if (action == ActionOnLoadPlayInline && item->getMedia()) {
|
2015-12-24 19:26:28 +00:00
|
|
|
item->getMedia()->playInline(item);
|
2015-12-23 19:23:14 +00:00
|
|
|
} else {
|
2015-12-24 19:26:28 +00:00
|
|
|
App::wnd()->showDocument(data, item);
|
2015-12-23 19:23:14 +00:00
|
|
|
}
|
|
|
|
} else if (location.accessEnable()) {
|
2016-04-10 18:18:26 +00:00
|
|
|
if (data->isAnimation() || QImageReader(location.name()).canRead()) {
|
|
|
|
if (action == ActionOnLoadPlayInline && item && item->getMedia()) {
|
2016-01-02 01:28:11 +00:00
|
|
|
item->getMedia()->playInline(item);
|
|
|
|
} else {
|
|
|
|
App::wnd()->showDocument(data, item);
|
|
|
|
}
|
2015-12-23 19:23:14 +00:00
|
|
|
} else {
|
|
|
|
psOpenFile(location.name());
|
|
|
|
}
|
|
|
|
location.accessDisable();
|
2015-12-21 13:14:29 +00:00
|
|
|
} else {
|
|
|
|
psOpenFile(location.name());
|
2015-04-04 20:01:34 +00:00
|
|
|
}
|
|
|
|
} else {
|
2015-11-26 17:34:52 +00:00
|
|
|
psOpenFile(location.name());
|
2015-04-04 20:01:34 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (data->status != FileReady) return;
|
|
|
|
|
2015-12-24 19:26:28 +00:00
|
|
|
QString filename;
|
|
|
|
if (!data->saveToCache()) {
|
2016-02-12 18:18:32 +00:00
|
|
|
filename = documentSaveFilename(data);
|
2015-12-24 19:26:28 +00:00
|
|
|
if (filename.isEmpty()) return;
|
2015-04-04 20:01:34 +00:00
|
|
|
}
|
|
|
|
|
2016-04-10 18:18:26 +00:00
|
|
|
data->save(filename, action, msgId);
|
2015-04-04 20:01:34 +00:00
|
|
|
}
|
|
|
|
|
2016-03-29 17:17:00 +00:00
|
|
|
void DocumentOpenClickHandler::onClickImpl() const {
|
2016-02-12 16:35:06 +00:00
|
|
|
doOpen(document(), document()->voice() ? ActionOnLoadNone : ActionOnLoadOpen);
|
2015-07-03 08:47:16 +00:00
|
|
|
}
|
|
|
|
|
2016-03-29 17:17:00 +00:00
|
|
|
void GifOpenClickHandler::onClickImpl() const {
|
2016-02-12 16:35:06 +00:00
|
|
|
doOpen(document(), ActionOnLoadPlayInline);
|
2015-12-21 13:14:29 +00:00
|
|
|
}
|
|
|
|
|
2016-03-29 17:17:00 +00:00
|
|
|
void DocumentSaveClickHandler::doSave(DocumentData *data, bool forceSavingAs) {
|
2015-04-04 20:01:34 +00:00
|
|
|
if (!data->date) return;
|
|
|
|
|
2016-03-26 08:13:57 +00:00
|
|
|
QString filepath = data->filepath(DocumentData::FilePathResolveSaveFromDataSilent, forceSavingAs);
|
2016-03-16 11:54:37 +00:00
|
|
|
if (!filepath.isEmpty() && !forceSavingAs) {
|
2015-04-04 20:01:34 +00:00
|
|
|
QPoint pos(QCursor::pos());
|
2016-03-16 11:54:37 +00:00
|
|
|
if (!psShowOpenWithMenu(pos.x(), pos.y(), filepath)) {
|
|
|
|
psOpenFile(filepath, true);
|
2015-04-04 20:01:34 +00:00
|
|
|
}
|
|
|
|
} else {
|
2016-03-16 11:54:37 +00:00
|
|
|
QFileInfo fileinfo(filepath);
|
|
|
|
QDir filedir(filepath.isEmpty() ? QDir() : fileinfo.dir());
|
|
|
|
QString filename(filepath.isEmpty() ? QString() : fileinfo.fileName());
|
|
|
|
QString newfname = documentSaveFilename(data, forceSavingAs, filename, filedir);
|
|
|
|
if (!newfname.isEmpty()) {
|
|
|
|
ActionOnLoad action = filename.isEmpty() ? ActionOnLoadNone : ActionOnLoadOpenWith;
|
2015-12-24 19:26:28 +00:00
|
|
|
FullMsgId actionMsgId = App::hoveredLinkItem() ? App::hoveredLinkItem()->fullId() : (App::contextItem() ? App::contextItem()->fullId() : FullMsgId());
|
2016-03-16 11:54:37 +00:00
|
|
|
data->save(newfname, action, actionMsgId);
|
2015-04-04 20:01:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-29 17:17:00 +00:00
|
|
|
void DocumentSaveClickHandler::onClickImpl() const {
|
2015-04-19 10:29:19 +00:00
|
|
|
doSave(document());
|
2015-04-04 20:01:34 +00:00
|
|
|
}
|
|
|
|
|
2016-03-29 17:17:00 +00:00
|
|
|
void DocumentCancelClickHandler::onClickImpl() const {
|
2015-04-04 20:01:34 +00:00
|
|
|
DocumentData *data = document();
|
2015-12-24 19:26:28 +00:00
|
|
|
if (!data->date) return;
|
2015-04-04 20:01:34 +00:00
|
|
|
|
2015-12-24 19:26:28 +00:00
|
|
|
if (data->uploading()) {
|
2016-02-17 16:37:21 +00:00
|
|
|
if (HistoryItem *item = App::hoveredLinkItem() ? App::hoveredLinkItem() : (App::contextItem() ? App::contextItem() : 0)) {
|
|
|
|
if (HistoryMessage *msg = item->toHistoryMessage()) {
|
|
|
|
if (msg->getMedia() && msg->getMedia()->getDocument() == data) {
|
|
|
|
App::contextItem(item);
|
|
|
|
App::main()->deleteLayer(-2);
|
|
|
|
}
|
2015-12-24 19:26:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
data->cancel();
|
|
|
|
}
|
2015-04-04 20:01:34 +00:00
|
|
|
}
|
|
|
|
|
2016-02-12 16:35:06 +00:00
|
|
|
VoiceData::~VoiceData() {
|
2016-02-14 19:46:01 +00:00
|
|
|
if (!waveform.isEmpty() && waveform.at(0) == -1 && waveform.size() > int32(sizeof(TaskId))) {
|
2016-02-12 16:35:06 +00:00
|
|
|
TaskId taskId = 0;
|
|
|
|
memcpy(&taskId, waveform.constData() + 1, sizeof(taskId));
|
|
|
|
Local::cancelTask(taskId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-09 05:57:55 +00:00
|
|
|
DocumentAdditionalData::~DocumentAdditionalData() {
|
|
|
|
}
|
|
|
|
|
|
|
|
DocumentData::DocumentData(DocumentId id, int32 dc, uint64 accessHash, const QString &url, const QVector<MTPDocumentAttribute> &attributes)
|
|
|
|
: id(id)
|
|
|
|
, _dc(dc)
|
|
|
|
, _access(accessHash)
|
|
|
|
, _url(url) {
|
2015-12-23 16:48:44 +00:00
|
|
|
setattributes(attributes);
|
2016-04-09 05:57:55 +00:00
|
|
|
if (_dc && _access) {
|
|
|
|
_location = Local::readFileLocation(mediaKey());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DocumentData *DocumentData::create(DocumentId id) {
|
|
|
|
return new DocumentData(id, 0, 0, QString(), QVector<MTPDocumentAttribute>());
|
|
|
|
}
|
|
|
|
|
|
|
|
DocumentData *DocumentData::create(DocumentId id, int32 dc, uint64 accessHash, const QVector<MTPDocumentAttribute> &attributes) {
|
|
|
|
return new DocumentData(id, dc, accessHash, QString(), attributes);
|
|
|
|
}
|
|
|
|
|
|
|
|
DocumentData *DocumentData::create(DocumentId id, const QString &url, const QVector<MTPDocumentAttribute> &attributes) {
|
|
|
|
return new DocumentData(id, 0, 0, url, attributes);
|
2015-04-04 20:01:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DocumentData::setattributes(const QVector<MTPDocumentAttribute> &attributes) {
|
|
|
|
for (int32 i = 0, l = attributes.size(); i < l; ++i) {
|
|
|
|
switch (attributes[i].type()) {
|
|
|
|
case mtpc_documentAttributeImageSize: {
|
2016-04-08 10:44:35 +00:00
|
|
|
const auto &d(attributes[i].c_documentAttributeImageSize());
|
2015-04-04 20:01:34 +00:00
|
|
|
dimensions = QSize(d.vw.v, d.vh.v);
|
|
|
|
} break;
|
2015-12-17 17:31:28 +00:00
|
|
|
case mtpc_documentAttributeAnimated: if (type == FileDocument || type == StickerDocument || type == VideoDocument) {
|
2015-06-30 21:07:05 +00:00
|
|
|
type = AnimatedDocument;
|
2016-04-10 19:20:48 +00:00
|
|
|
_additional = nullptr;
|
2015-06-30 21:07:05 +00:00
|
|
|
} break;
|
2015-04-04 20:01:34 +00:00
|
|
|
case mtpc_documentAttributeSticker: {
|
2016-04-08 10:44:35 +00:00
|
|
|
const auto &d(attributes[i].c_documentAttributeSticker());
|
2015-06-30 21:07:05 +00:00
|
|
|
if (type == FileDocument) {
|
|
|
|
type = StickerDocument;
|
2016-04-10 19:20:48 +00:00
|
|
|
_additional = std_::make_unique<StickerData>();
|
2015-12-31 05:34:43 +00:00
|
|
|
}
|
|
|
|
if (sticker()) {
|
|
|
|
sticker()->alt = qs(d.valt);
|
|
|
|
sticker()->set = d.vstickerset;
|
2015-05-11 12:44:27 +00:00
|
|
|
}
|
2015-04-04 20:01:34 +00:00
|
|
|
} break;
|
|
|
|
case mtpc_documentAttributeVideo: {
|
2016-04-08 10:44:35 +00:00
|
|
|
const auto &d(attributes[i].c_documentAttributeVideo());
|
2015-12-17 17:31:28 +00:00
|
|
|
if (type == FileDocument) {
|
|
|
|
type = VideoDocument;
|
|
|
|
}
|
2015-12-28 15:34:45 +00:00
|
|
|
_duration = d.vduration.v;
|
2015-04-04 20:01:34 +00:00
|
|
|
dimensions = QSize(d.vw.v, d.vh.v);
|
|
|
|
} break;
|
|
|
|
case mtpc_documentAttributeAudio: {
|
2016-04-08 10:44:35 +00:00
|
|
|
const auto &d(attributes[i].c_documentAttributeAudio());
|
2015-12-31 05:34:43 +00:00
|
|
|
if (type == FileDocument) {
|
2016-02-12 16:35:06 +00:00
|
|
|
if (d.is_voice()) {
|
|
|
|
type = VoiceDocument;
|
2016-04-10 19:20:48 +00:00
|
|
|
_additional = std_::make_unique<VoiceData>();
|
2016-02-12 16:35:06 +00:00
|
|
|
} else {
|
|
|
|
type = SongDocument;
|
2016-04-10 19:20:48 +00:00
|
|
|
_additional = std_::make_unique<SongData>();
|
2016-02-12 16:35:06 +00:00
|
|
|
}
|
2015-12-31 05:34:43 +00:00
|
|
|
}
|
2016-02-12 16:35:06 +00:00
|
|
|
if (voice()) {
|
|
|
|
voice()->duration = d.vduration.v;
|
|
|
|
VoiceWaveform waveform = documentWaveformDecode(qba(d.vwaveform));
|
|
|
|
uchar wavemax = 0;
|
|
|
|
for (int32 i = 0, l = waveform.size(); i < l; ++i) {
|
|
|
|
uchar waveat = waveform.at(i);
|
|
|
|
if (wavemax < waveat) wavemax = waveat;
|
|
|
|
}
|
|
|
|
voice()->waveform = waveform;
|
|
|
|
voice()->wavemax = wavemax;
|
|
|
|
} else if (song()) {
|
2015-12-31 05:34:43 +00:00
|
|
|
song()->duration = d.vduration.v;
|
|
|
|
song()->title = qs(d.vtitle);
|
|
|
|
song()->performer = qs(d.vperformer);
|
|
|
|
}
|
2015-04-04 20:01:34 +00:00
|
|
|
} break;
|
|
|
|
case mtpc_documentAttributeFilename: name = qs(attributes[i].c_documentAttributeFilename().vfile_name); break;
|
|
|
|
}
|
|
|
|
}
|
2015-06-30 21:07:05 +00:00
|
|
|
if (type == StickerDocument) {
|
|
|
|
if (dimensions.width() <= 0 || dimensions.height() <= 0 || dimensions.width() > StickerMaxSize || dimensions.height() > StickerMaxSize || size > StickerInMemory) {
|
|
|
|
type = FileDocument;
|
2016-04-10 19:20:48 +00:00
|
|
|
_additional = nullptr;
|
2015-12-23 16:48:44 +00:00
|
|
|
}
|
2015-12-23 21:19:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-24 19:26:28 +00:00
|
|
|
bool DocumentData::saveToCache() const {
|
2016-02-12 16:35:06 +00:00
|
|
|
return (type == StickerDocument) || (isAnimation() && size < AnimationInMemory) || (voice() && size < AudioVoiceMsgInMemory);
|
2015-12-24 19:26:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DocumentData::forget() {
|
|
|
|
thumb->forget();
|
|
|
|
if (sticker()) sticker()->img->forget();
|
|
|
|
replyPreview->forget();
|
|
|
|
_data.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DocumentData::automaticLoad(const HistoryItem *item) {
|
|
|
|
if (loaded() || status != FileReady) return;
|
|
|
|
|
2015-12-30 19:09:20 +00:00
|
|
|
if (saveToCache() && _loader != CancelledMtpFileLoader) {
|
2015-12-23 21:19:57 +00:00
|
|
|
if (type == StickerDocument) {
|
2015-12-24 19:26:28 +00:00
|
|
|
save(QString(), _actionOnLoad, _actionOnLoadMsgId);
|
2015-12-27 21:37:48 +00:00
|
|
|
} else if (isAnimation()) {
|
2015-12-24 19:26:28 +00:00
|
|
|
bool loadFromCloud = false;
|
2015-12-27 21:37:48 +00:00
|
|
|
if (item) {
|
|
|
|
if (item->history()->peer->isUser()) {
|
|
|
|
loadFromCloud = !(cAutoDownloadGif() & dbiadNoPrivate);
|
|
|
|
} else {
|
|
|
|
loadFromCloud = !(cAutoDownloadGif() & dbiadNoGroups);
|
|
|
|
}
|
|
|
|
} else { // if load at least anywhere
|
|
|
|
loadFromCloud = !(cAutoDownloadGif() & dbiadNoPrivate) || !(cAutoDownloadGif() & dbiadNoGroups);
|
2015-12-24 19:26:28 +00:00
|
|
|
}
|
|
|
|
save(QString(), _actionOnLoad, _actionOnLoadMsgId, loadFromCloud ? LoadFromCloudOrLocal : LoadFromLocalOnly, true);
|
2016-02-12 16:35:06 +00:00
|
|
|
} else if (voice()) {
|
|
|
|
if (item) {
|
|
|
|
bool loadFromCloud = false;
|
|
|
|
if (item->history()->peer->isUser()) {
|
|
|
|
loadFromCloud = !(cAutoDownloadAudio() & dbiadNoPrivate);
|
|
|
|
} else {
|
|
|
|
loadFromCloud = !(cAutoDownloadAudio() & dbiadNoGroups);
|
|
|
|
}
|
|
|
|
save(QString(), _actionOnLoad, _actionOnLoadMsgId, loadFromCloud ? LoadFromCloudOrLocal : LoadFromLocalOnly, true);
|
|
|
|
}
|
2015-12-24 19:26:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-27 21:37:48 +00:00
|
|
|
void DocumentData::automaticLoadSettingsChanged() {
|
2016-02-12 16:35:06 +00:00
|
|
|
if (loaded() || status != FileReady || (!isAnimation() && !voice()) || !saveToCache() || _loader != CancelledMtpFileLoader) return;
|
2015-12-27 21:37:48 +00:00
|
|
|
_loader = 0;
|
|
|
|
}
|
|
|
|
|
2015-12-24 19:26:28 +00:00
|
|
|
void DocumentData::performActionOnLoad() {
|
|
|
|
if (_actionOnLoad == ActionOnLoadNone) return;
|
|
|
|
|
|
|
|
const FileLocation &loc(location(true));
|
|
|
|
QString already = loc.name();
|
2016-04-10 18:18:26 +00:00
|
|
|
HistoryItem *item = _actionOnLoadMsgId.msg ? App::histItemById(_actionOnLoadMsgId) : nullptr;
|
|
|
|
bool showImage = !isVideo() && (size < MediaViewImageSizeLimit);
|
|
|
|
bool playVoice = voice() && audioPlayer() && (_actionOnLoad == ActionOnLoadPlayInline || _actionOnLoad == ActionOnLoadOpen);
|
|
|
|
bool playMusic = song() && audioPlayer() && (_actionOnLoad == ActionOnLoadPlayInline || _actionOnLoad == ActionOnLoadOpen);
|
|
|
|
bool playAnimation = isAnimation() && (_actionOnLoad == ActionOnLoadPlayInline || _actionOnLoad == ActionOnLoadOpen) && showImage && item && item->getMedia();
|
2016-02-12 16:35:06 +00:00
|
|
|
if (playVoice) {
|
|
|
|
if (loaded()) {
|
|
|
|
AudioMsgId playing;
|
|
|
|
AudioPlayerState state = AudioPlayerStopped;
|
|
|
|
audioPlayer()->currentState(&playing, &state);
|
2016-04-10 18:18:26 +00:00
|
|
|
if (playing == AudioMsgId(this, _actionOnLoadMsgId) && !(state & AudioPlayerStoppedMask) && state != AudioPlayerFinishing) {
|
2016-02-12 16:35:06 +00:00
|
|
|
audioPlayer()->pauseresume(OverviewVoiceFiles);
|
|
|
|
} else {
|
|
|
|
audioPlayer()->play(AudioMsgId(this, _actionOnLoadMsgId));
|
2016-02-12 18:18:32 +00:00
|
|
|
if (App::main()) App::main()->mediaMarkRead(this);
|
2016-02-12 16:35:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (playMusic) {
|
2015-12-24 19:26:28 +00:00
|
|
|
if (loaded()) {
|
|
|
|
SongMsgId playing;
|
|
|
|
AudioPlayerState playingState = AudioPlayerStopped;
|
|
|
|
audioPlayer()->currentState(&playing, &playingState);
|
2016-04-10 18:18:26 +00:00
|
|
|
if (playing == SongMsgId(this, _actionOnLoadMsgId) && !(playingState & AudioPlayerStoppedMask) && playingState != AudioPlayerFinishing) {
|
2016-02-12 16:35:06 +00:00
|
|
|
audioPlayer()->pauseresume(OverviewFiles);
|
2015-12-24 19:26:28 +00:00
|
|
|
} else {
|
2016-04-10 18:18:26 +00:00
|
|
|
SongMsgId song(this, _actionOnLoadMsgId);
|
2015-12-24 19:26:28 +00:00
|
|
|
audioPlayer()->play(song);
|
|
|
|
if (App::main()) App::main()->documentPlayProgress(song);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (playAnimation) {
|
|
|
|
if (loaded()) {
|
2016-03-14 09:58:43 +00:00
|
|
|
if (_actionOnLoad == ActionOnLoadPlayInline && item->getMedia()) {
|
2015-12-24 19:26:28 +00:00
|
|
|
item->getMedia()->playInline(item);
|
|
|
|
} else {
|
|
|
|
App::wnd()->showDocument(this, item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (already.isEmpty()) return;
|
|
|
|
|
|
|
|
if (_actionOnLoad == ActionOnLoadOpenWith) {
|
|
|
|
QPoint pos(QCursor::pos());
|
|
|
|
if (!psShowOpenWithMenu(pos.x(), pos.y(), already)) {
|
|
|
|
psOpenFile(already, true);
|
|
|
|
}
|
|
|
|
} else if (_actionOnLoad == ActionOnLoadOpen || _actionOnLoad == ActionOnLoadPlayInline) {
|
2016-02-12 18:18:32 +00:00
|
|
|
if (voice() || isVideo()) {
|
2016-02-12 16:35:06 +00:00
|
|
|
psOpenFile(already);
|
2016-02-12 18:18:32 +00:00
|
|
|
if (App::main()) App::main()->mediaMarkRead(this);
|
2016-02-12 16:35:06 +00:00
|
|
|
} else if (loc.accessEnable()) {
|
2015-12-24 19:26:28 +00:00
|
|
|
if (showImage && QImageReader(loc.name()).canRead()) {
|
2016-04-10 18:18:26 +00:00
|
|
|
if (_actionOnLoad == ActionOnLoadPlayInline && item && item->getMedia()) {
|
2016-01-02 01:28:11 +00:00
|
|
|
item->getMedia()->playInline(item);
|
|
|
|
} else {
|
|
|
|
App::wnd()->showDocument(this, item);
|
|
|
|
}
|
2015-12-23 21:19:57 +00:00
|
|
|
} else {
|
2015-12-24 19:26:28 +00:00
|
|
|
psOpenFile(already);
|
2015-12-23 21:19:57 +00:00
|
|
|
}
|
2015-12-24 19:26:28 +00:00
|
|
|
loc.accessDisable();
|
|
|
|
} else {
|
|
|
|
psOpenFile(already);
|
2015-12-23 21:19:57 +00:00
|
|
|
}
|
2015-12-24 19:26:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
_actionOnLoad = ActionOnLoadNone;
|
|
|
|
}
|
|
|
|
|
2016-03-16 11:54:37 +00:00
|
|
|
bool DocumentData::loaded(FilePathResolveType type) const {
|
2015-12-24 19:26:28 +00:00
|
|
|
if (loading() && _loader->done()) {
|
|
|
|
if (_loader->fileType() == mtpc_storage_fileUnknown) {
|
|
|
|
_loader->deleteLater();
|
2016-04-09 05:57:55 +00:00
|
|
|
_loader->stop();
|
2015-12-30 19:09:20 +00:00
|
|
|
_loader = CancelledMtpFileLoader;
|
2015-12-24 19:26:28 +00:00
|
|
|
} else {
|
|
|
|
DocumentData *that = const_cast<DocumentData*>(this);
|
|
|
|
that->_location = FileLocation(mtpToStorageType(_loader->fileType()), _loader->fileName());
|
|
|
|
that->_data = _loader->bytes();
|
|
|
|
if (that->sticker() && !_loader->imagePixmap().isNull()) {
|
|
|
|
that->sticker()->img = ImagePtr(_data, _loader->imageFormat(), _loader->imagePixmap());
|
2015-12-23 21:19:57 +00:00
|
|
|
}
|
2015-12-24 19:26:28 +00:00
|
|
|
|
|
|
|
_loader->deleteLater();
|
2016-04-09 05:57:55 +00:00
|
|
|
_loader->stop();
|
|
|
|
_loader = nullptr;
|
2015-06-30 21:07:05 +00:00
|
|
|
}
|
2015-12-24 19:26:28 +00:00
|
|
|
notifyLayoutChanged();
|
2015-06-30 21:07:05 +00:00
|
|
|
}
|
2016-03-16 11:54:37 +00:00
|
|
|
return !data().isEmpty() || !filepath(type).isEmpty();
|
2015-04-04 20:01:34 +00:00
|
|
|
}
|
|
|
|
|
2015-12-24 19:26:28 +00:00
|
|
|
bool DocumentData::loading() const {
|
2015-12-30 19:09:20 +00:00
|
|
|
return _loader && _loader != CancelledMtpFileLoader;
|
2015-12-24 19:26:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool DocumentData::displayLoading() const {
|
|
|
|
return loading() ? (!_loader->loadingLocal() || !_loader->autoLoading()) : uploading();
|
|
|
|
}
|
|
|
|
|
|
|
|
float64 DocumentData::progress() const {
|
2015-12-25 13:09:14 +00:00
|
|
|
if (uploading()) {
|
|
|
|
if (size > 0) {
|
|
|
|
return float64(uploadOffset) / size;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return loading() ? _loader->currentProgress() : (loaded() ? 1 : 0);
|
2015-12-24 19:26:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int32 DocumentData::loadOffset() const {
|
|
|
|
return loading() ? _loader->currentOffset() : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DocumentData::uploading() const {
|
|
|
|
return status == FileUploading;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DocumentData::save(const QString &toFile, ActionOnLoad action, const FullMsgId &actionMsgId, LoadFromCloudSetting fromCloud, bool autoLoading) {
|
2016-03-16 11:54:37 +00:00
|
|
|
_actionOnLoad = action;
|
|
|
|
_actionOnLoadMsgId = actionMsgId;
|
|
|
|
|
|
|
|
if (loaded(FilePathResolveChecked)) {
|
2015-12-24 19:26:28 +00:00
|
|
|
const FileLocation &l(location(true));
|
|
|
|
if (!toFile.isEmpty()) {
|
|
|
|
if (!_data.isEmpty()) {
|
|
|
|
QFile f(toFile);
|
|
|
|
f.open(QIODevice::WriteOnly);
|
|
|
|
f.write(_data);
|
2016-03-16 11:54:37 +00:00
|
|
|
f.close();
|
|
|
|
|
|
|
|
setLocation(FileLocation(StorageFilePartial, toFile));
|
|
|
|
Local::writeFileLocation(mediaKey(), FileLocation(mtpToStorageType(mtpc_storage_filePartial), toFile));
|
2015-12-24 19:26:28 +00:00
|
|
|
} else if (l.accessEnable()) {
|
|
|
|
QFile(l.name()).copy(toFile);
|
|
|
|
l.accessDisable();
|
|
|
|
}
|
|
|
|
}
|
2016-03-16 11:54:37 +00:00
|
|
|
performActionOnLoad();
|
2015-12-24 19:26:28 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-12-30 19:09:20 +00:00
|
|
|
if (_loader == CancelledMtpFileLoader) _loader = 0;
|
2015-12-24 19:26:28 +00:00
|
|
|
if (_loader) {
|
|
|
|
if (!_loader->setFileName(toFile)) {
|
|
|
|
cancel();
|
|
|
|
_loader = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_loader) {
|
|
|
|
if (fromCloud == LoadFromCloudOrLocal) _loader->permitLoadFromCloud();
|
|
|
|
} else {
|
|
|
|
status = FileReady;
|
2016-04-09 05:57:55 +00:00
|
|
|
if (!_access && !_url.isEmpty()) {
|
|
|
|
_loader = new webFileLoader(_url, toFile, fromCloud, autoLoading);
|
|
|
|
} else {
|
|
|
|
_loader = new mtpFileLoader(_dc, id, _access, locationType(), toFile, size, (saveToCache() ? LoadToCacheAsWell : LoadToFileOnly), fromCloud, autoLoading);
|
|
|
|
}
|
2015-12-30 19:09:20 +00:00
|
|
|
_loader->connect(_loader, SIGNAL(progress(FileLoader*)), App::main(), SLOT(documentLoadProgress(FileLoader*)));
|
|
|
|
_loader->connect(_loader, SIGNAL(failed(FileLoader*,bool)), App::main(), SLOT(documentLoadFailed(FileLoader*,bool)));
|
2015-12-24 19:26:28 +00:00
|
|
|
_loader->start();
|
2015-12-23 16:48:44 +00:00
|
|
|
}
|
2015-12-12 22:29:33 +00:00
|
|
|
notifyLayoutChanged();
|
|
|
|
}
|
|
|
|
|
2015-12-24 19:26:28 +00:00
|
|
|
void DocumentData::cancel() {
|
|
|
|
if (!loading()) return;
|
|
|
|
|
2016-04-09 05:57:55 +00:00
|
|
|
FileLoader *l = _loader;
|
2015-12-30 19:09:20 +00:00
|
|
|
_loader = CancelledMtpFileLoader;
|
2015-12-24 19:26:28 +00:00
|
|
|
if (l) {
|
|
|
|
l->cancel();
|
|
|
|
l->deleteLater();
|
2016-04-09 05:57:55 +00:00
|
|
|
l->stop();
|
2015-12-24 19:26:28 +00:00
|
|
|
|
|
|
|
notifyLayoutChanged();
|
|
|
|
}
|
|
|
|
_actionOnLoad = ActionOnLoadNone;
|
|
|
|
}
|
|
|
|
|
2015-12-12 22:29:33 +00:00
|
|
|
void DocumentData::notifyLayoutChanged() const {
|
|
|
|
const DocumentItems &items(App::documentItems());
|
|
|
|
DocumentItems::const_iterator i = items.constFind(const_cast<DocumentData*>(this));
|
|
|
|
if (i != items.cend()) {
|
|
|
|
for (HistoryItemsMap::const_iterator j = i->cbegin(), e = i->cend(); j != e; ++j) {
|
|
|
|
Notify::historyItemLayoutChanged(j.key());
|
|
|
|
}
|
|
|
|
}
|
2016-04-10 18:18:26 +00:00
|
|
|
|
|
|
|
if (auto items = InlineBots::Layout::documentItems()) {
|
|
|
|
for (auto item : items->value(const_cast<DocumentData*>(this))) {
|
|
|
|
Notify::inlineItemLayoutChanged(item);
|
|
|
|
}
|
|
|
|
}
|
2015-04-04 20:01:34 +00:00
|
|
|
}
|
|
|
|
|
2016-02-12 16:35:06 +00:00
|
|
|
VoiceWaveform documentWaveformDecode(const QByteArray &encoded5bit) {
|
|
|
|
VoiceWaveform result((encoded5bit.size() * 8) / 5, 0);
|
|
|
|
for (int32 i = 0, l = result.size(); i < l; ++i) { // read each 5 bit of encoded5bit as 0-31 unsigned char
|
|
|
|
int32 byte = (i * 5) / 8, shift = (i * 5) % 8;
|
|
|
|
result[i] = (((*(uint16*)(encoded5bit.constData() + byte)) >> shift) & 0x1F);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
QByteArray documentWaveformEncode5bit(const VoiceWaveform &waveform) {
|
|
|
|
QByteArray result((waveform.size() * 5 + 7) / 8, 0);
|
|
|
|
for (int32 i = 0, l = waveform.size(); i < l; ++i) { // write each 0-31 unsigned char as 5 bit to result
|
|
|
|
int32 byte = (i * 5) / 8, shift = (i * 5) % 8;
|
|
|
|
(*(uint16*)(result.data() + byte)) |= (uint16(waveform.at(i) & 0x1F) << shift);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2015-12-24 19:26:28 +00:00
|
|
|
QByteArray DocumentData::data() const {
|
|
|
|
return _data;
|
|
|
|
}
|
|
|
|
|
|
|
|
const FileLocation &DocumentData::location(bool check) const {
|
|
|
|
if (check && !_location.check()) {
|
2016-02-12 18:18:32 +00:00
|
|
|
const_cast<DocumentData*>(this)->_location = Local::readFileLocation(mediaKey());
|
2015-12-24 19:26:28 +00:00
|
|
|
}
|
2015-11-26 17:34:52 +00:00
|
|
|
return _location;
|
2015-04-04 20:01:34 +00:00
|
|
|
}
|
|
|
|
|
2015-12-24 19:26:28 +00:00
|
|
|
void DocumentData::setLocation(const FileLocation &loc) {
|
|
|
|
if (loc.check()) {
|
|
|
|
_location = loc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-16 11:54:37 +00:00
|
|
|
QString DocumentData::filepath(FilePathResolveType type, bool forceSavingAs) const {
|
|
|
|
bool check = (type != FilePathResolveCached);
|
|
|
|
QString result = (check && _location.name().isEmpty()) ? QString() : location(check).name();
|
|
|
|
bool saveFromData = result.isEmpty() && !data().isEmpty();
|
|
|
|
if (saveFromData) {
|
|
|
|
if (type != FilePathResolveSaveFromData && type != FilePathResolveSaveFromDataSilent) {
|
|
|
|
saveFromData = false;
|
2016-03-26 08:13:57 +00:00
|
|
|
} else if (type == FilePathResolveSaveFromDataSilent && (cAskDownloadPath() || forceSavingAs)) {
|
2016-03-16 11:54:37 +00:00
|
|
|
saveFromData = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (saveFromData) {
|
|
|
|
QString filename = documentSaveFilename(this, forceSavingAs);
|
|
|
|
if (!filename.isEmpty()) {
|
|
|
|
QFile f(filename);
|
|
|
|
if (f.open(QIODevice::WriteOnly)) {
|
|
|
|
if (f.write(data()) == data().size()) {
|
|
|
|
f.close();
|
|
|
|
const_cast<DocumentData*>(this)->_location = FileLocation(StorageFilePartial, filename);
|
|
|
|
Local::writeFileLocation(mediaKey(), _location);
|
|
|
|
result = filename;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2015-12-24 19:26:28 +00:00
|
|
|
ImagePtr DocumentData::makeReplyPreview() {
|
|
|
|
if (replyPreview->isNull() && !thumb->isNull()) {
|
|
|
|
if (thumb->loaded()) {
|
|
|
|
int w = thumb->width(), h = thumb->height();
|
|
|
|
if (w <= 0) w = 1;
|
|
|
|
if (h <= 0) h = 1;
|
|
|
|
replyPreview = ImagePtr(w > h ? thumb->pix(w * st::msgReplyBarSize.height() / h, st::msgReplyBarSize.height()) : thumb->pix(st::msgReplyBarSize.height()), "PNG");
|
|
|
|
} else {
|
|
|
|
thumb->load();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return replyPreview;
|
|
|
|
}
|
|
|
|
|
2015-12-19 14:37:28 +00:00
|
|
|
bool fileIsImage(const QString &name, const QString &mime) {
|
2015-12-10 13:37:45 +00:00
|
|
|
QString lowermime = mime.toLower(), namelower = name.toLower();
|
|
|
|
if (lowermime.startsWith(qstr("image/"))) {
|
2015-12-19 14:37:28 +00:00
|
|
|
return true;
|
2015-12-10 13:37:45 +00:00
|
|
|
} else if (namelower.endsWith(qstr(".bmp"))
|
|
|
|
|| namelower.endsWith(qstr(".jpg"))
|
|
|
|
|| namelower.endsWith(qstr(".jpeg"))
|
|
|
|
|| namelower.endsWith(qstr(".gif"))
|
|
|
|
|| namelower.endsWith(qstr(".webp"))
|
|
|
|
|| namelower.endsWith(qstr(".tga"))
|
|
|
|
|| namelower.endsWith(qstr(".tiff"))
|
|
|
|
|| namelower.endsWith(qstr(".tif"))
|
|
|
|
|| namelower.endsWith(qstr(".psd"))
|
|
|
|
|| namelower.endsWith(qstr(".png"))) {
|
2015-12-19 14:37:28 +00:00
|
|
|
return true;
|
2015-12-10 13:37:45 +00:00
|
|
|
}
|
2015-12-19 14:37:28 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DocumentData::recountIsImage() {
|
2016-02-12 18:18:32 +00:00
|
|
|
if (isAnimation() || isVideo()) return;
|
2015-12-28 15:34:45 +00:00
|
|
|
_duration = fileIsImage(name, mime) ? 1 : -1; // hack
|
2015-12-10 13:37:45 +00:00
|
|
|
}
|
|
|
|
|
2016-04-09 05:57:55 +00:00
|
|
|
void DocumentData::setRemoteLocation(int32 dc, uint64 access) {
|
|
|
|
_dc = dc;
|
|
|
|
_access = access;
|
|
|
|
if (isValid()) {
|
|
|
|
if (_location.check()) {
|
|
|
|
Local::writeFileLocation(mediaKey(), _location);
|
|
|
|
} else {
|
|
|
|
_location = Local::readFileLocation(mediaKey());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-03-01 19:41:06 +00:00
|
|
|
|
2016-04-09 05:57:55 +00:00
|
|
|
void DocumentData::setContentUrl(const QString &url) {
|
|
|
|
_url = url;
|
|
|
|
}
|
|
|
|
|
2016-04-10 14:53:01 +00:00
|
|
|
void DocumentData::collectLocalData(DocumentData *local) {
|
|
|
|
if (local == this) return;
|
|
|
|
|
|
|
|
if (!local->_data.isEmpty()) {
|
|
|
|
_data = local->_data;
|
|
|
|
if (voice()) {
|
|
|
|
if (!Local::copyAudio(local->mediaKey(), mediaKey())) {
|
|
|
|
Local::writeAudio(mediaKey(), _data);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!Local::copyStickerImage(local->mediaKey(), mediaKey())) {
|
|
|
|
Local::writeStickerImage(mediaKey(), _data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!local->_location.isEmpty()) {
|
|
|
|
_location = local->_location;
|
|
|
|
Local::writeFileLocation(mediaKey(), _location);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-09 05:57:55 +00:00
|
|
|
DocumentData::~DocumentData() {
|
2016-03-01 19:41:06 +00:00
|
|
|
if (loading()) {
|
|
|
|
_loader->deleteLater();
|
|
|
|
_loader->stop();
|
2016-04-09 05:57:55 +00:00
|
|
|
_loader = nullptr;
|
2016-03-01 19:41:06 +00:00
|
|
|
}
|
2015-12-24 19:26:28 +00:00
|
|
|
}
|
|
|
|
|
2016-04-08 09:20:10 +00:00
|
|
|
WebPageData::WebPageData(const WebPageId &id, WebPageType type, const QString &url, const QString &displayUrl, const QString &siteName, const QString &title, const QString &description, DocumentData *document, PhotoData *photo, int32 duration, const QString &author, int32 pendingTill) : id(id)
|
2015-12-10 13:37:45 +00:00
|
|
|
, type(type)
|
|
|
|
, url(url)
|
|
|
|
, displayUrl(displayUrl)
|
|
|
|
, siteName(siteName)
|
|
|
|
, title(title)
|
|
|
|
, description(description)
|
|
|
|
, duration(duration)
|
|
|
|
, author(author)
|
|
|
|
, photo(photo)
|
2016-04-08 09:20:10 +00:00
|
|
|
, document(document)
|
2015-12-10 13:37:45 +00:00
|
|
|
, pendingTill(pendingTill) {
|
2015-04-04 20:01:34 +00:00
|
|
|
}
|
|
|
|
|
2016-03-29 17:17:00 +00:00
|
|
|
void PeerOpenClickHandler::onClickImpl() const {
|
|
|
|
if (App::main()) {
|
2015-09-13 17:27:29 +00:00
|
|
|
if (peer() && peer()->isChannel() && App::main()->historyPeer() != peer()) {
|
2015-09-23 17:43:08 +00:00
|
|
|
if (!peer()->asChannel()->isPublic() && !peer()->asChannel()->amIn()) {
|
2015-12-07 18:09:05 +00:00
|
|
|
Ui::showLayer(new InformBox(lang((peer()->isMegagroup()) ? lng_group_not_accessible : lng_channel_not_accessible)));
|
2015-09-21 20:57:42 +00:00
|
|
|
} else {
|
2015-12-13 11:36:08 +00:00
|
|
|
Ui::showPeerHistory(peer(), ShowAtUnreadMsgId);
|
2015-09-21 20:57:42 +00:00
|
|
|
}
|
2015-09-13 17:27:29 +00:00
|
|
|
} else {
|
|
|
|
App::main()->showPeerProfile(peer());
|
|
|
|
}
|
2015-04-04 20:01:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
MsgId clientMsgId() {
|
2015-11-09 09:51:22 +00:00
|
|
|
static MsgId currentClientMsgId = StartClientMsgId;
|
|
|
|
Q_ASSERT(currentClientMsgId < EndClientMsgId);
|
|
|
|
return currentClientMsgId++;
|
2015-04-04 20:01:34 +00:00
|
|
|
}
|