2
0
mirror of https://github.com/kotatogram/kotatogram-desktop synced 2025-08-31 06:35:14 +00:00

Merge branch 'game_media' into player

Conflicts:
	Telegram/Resources/basic.style
	Telegram/SourceFiles/media/player/media_player_list.cpp
	Telegram/SourceFiles/title.cpp
This commit is contained in:
John Preston
2016-09-30 20:07:56 +03:00
110 changed files with 712 additions and 541 deletions

View File

@@ -32,6 +32,7 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org
#include "apiwrap.h"
#include "observer_peer.h"
#include "styles/style_boxes.h"
#include "styles/style_dialogs.h"
AddContactBox::AddContactBox(QString fname, QString lname, QString phone) : AbstractBox(st::boxWidth)
, _save(this, lang(lng_add_contact), st::defaultBoxButton)
@@ -1451,8 +1452,9 @@ void RevokePublicLinkBox::paintChat(Painter &p, const ChatRow &row, bool selecte
int32 namex = st::contactsPadding.left() + st::contactsPhotoSize + st::contactsPadding.left();
int32 namew = width() - namex - st::contactsPadding.right() - (_revokeWidth + st::contactsCheckPosition.x() * 2);
if (peer->isVerified()) {
namew -= st::verifiedCheck.pxWidth() + st::verifiedCheckPos.x();
p.drawSpriteLeft(namex + qMin(row.name.maxWidth(), namew) + st::verifiedCheckPos.x(), st::contactsPadding.top() + st::contactsNameTop + st::verifiedCheckPos.y(), width(), st::verifiedCheck);
auto icon = &st::dialogsVerifiedIcon;
namew -= icon->width();
icon->paint(p, namex + qMin(row.name.maxWidth(), namew), st::contactsPadding.top() + st::contactsNameTop, width());
}
row.name.drawLeftElided(p, namex, st::contactsPadding.top() + st::contactsNameTop, namew, width());

View File

@@ -80,9 +80,7 @@ shareCheckBorder: windowBg;
shareCheckBg: windowActiveBg;
shareCheckRadius: 10px;
shareCheckSmallRadius: 3px;
shareCheckIcon: icon {
{ "default_checkbox_check", windowBg, point(3px, 6px) },
};
shareCheckIcon: icon {{ "default_checkbox_check", windowBg, point(3px, 6px) }};
shareNameFont: font(11px);
shareNameFg: windowTextFg;
shareNameActiveFg: btnYesColor;

View File

@@ -22,6 +22,7 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org
#include "boxes/contactsbox.h"
#include "dialogs/dialogs_indexed_list.h"
#include "styles/style_dialogs.h"
#include "lang.h"
#include "boxes/addcontactbox.h"
#include "mainwidget.h"
@@ -435,8 +436,9 @@ void ContactsInner::paintDialog(Painter &p, PeerData *peer, ContactData *data, b
int32 iconw = (_chat || _creating != CreatingGroupNone) ? (st::contactsCheckPosition.x() * 2 + st::contactsCheckIcon.pxWidth()) : 0;
int32 namew = width() - namex - st::contactsPadding.right() - iconw;
if (peer->isVerified()) {
namew -= st::verifiedCheck.pxWidth() + st::verifiedCheckPos.x();
p.drawSpriteLeft(namex + qMin(data->name.maxWidth(), namew) + st::verifiedCheckPos.x(), st::contactsPadding.top() + st::contactsNameTop + st::verifiedCheckPos.y(), width(), st::verifiedCheck);
auto icon = &st::dialogsVerifiedIcon;
namew -= icon->width();
icon->paint(p, namex + qMin(data->name.maxWidth(), namew), st::contactsPadding.top() + st::contactsNameTop, width());
}
data->name.drawLeftElided(p, namex, st::contactsPadding.top() + st::contactsNameTop, namew, width());
@@ -1942,8 +1944,9 @@ void MembersInner::paintDialog(Painter &p, PeerData *peer, MemberData *data, boo
int32 namex = st::contactsPadding.left() + st::contactsPhotoSize + st::contactsPadding.left();
int32 namew = width() - namex - st::contactsPadding.right() - (data->canKick ? (_kickWidth + st::contactsCheckPosition.x() * 2) : 0);
if (peer->isVerified()) {
namew -= st::verifiedCheck.pxWidth() + st::verifiedCheckPos.x();
p.drawSpriteLeft(namex + qMin(data->name.maxWidth(), namew) + st::verifiedCheckPos.x(), st::contactsPadding.top() + st::contactsNameTop + st::verifiedCheckPos.y(), width(), st::verifiedCheck);
auto icon = &st::dialogsVerifiedIcon;
namew -= icon->width();
icon->paint(p, namex + qMin(data->name.maxWidth(), namew), st::contactsPadding.top() + st::contactsNameTop, width());
}
data->name.drawLeftElided(p, namex, st::contactsPadding.top() + st::contactsNameTop, namew, width());

View File

@@ -26,6 +26,7 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org
#include "mainwidget.h"
#include "photosendbox.h"
#include "history/history_media_types.h"
#include "styles/style_history.h"
PhotoSendBox::PhotoSendBox(const FileLoadResultPtr &file) : AbstractBox(st::boxWideWidth)
, _file(file)
@@ -233,7 +234,8 @@ void PhotoSendBox::paintEvent(QPaintEvent *e) {
p.drawEllipse(inner);
p.setRenderHint(QPainter::HighQualityAntialiasing, false);
p.drawSpriteCenter(inner, st::msgFileInPlay);
auto icon = &st::historyFileInPlay;
icon->paintInCenter(p, inner);
}
} else {
int32 w = width() - st::boxPhotoPadding.left() - st::boxPhotoPadding.right();
@@ -272,7 +274,8 @@ void PhotoSendBox::paintEvent(QPaintEvent *e) {
p.drawEllipse(inner);
p.setRenderHint(QPainter::HighQualityAntialiasing, false);
p.drawSpriteCenter(inner, _isImage ? st::msgFileOutImage : st::msgFileOutFile);
auto icon = &(_isImage ? st::historyFileOutImage : st::historyFileOutDocument);
icon->paintInCenter(p, inner);
} else {
p.drawPixmapLeft(x + st::msgFilePadding.left(), y + st::msgFilePadding.top(), width(), userDefPhoto(1)->pixCircled(st::msgFileSize));
}
@@ -553,7 +556,8 @@ void EditCaptionBox::paintEvent(QPaintEvent *e) {
p.drawEllipse(inner);
p.setRenderHint(QPainter::HighQualityAntialiasing, false);
p.drawSpriteCenter(inner, st::msgFileInPlay);
auto icon = &st::historyFileInPlay;
icon->paintInCenter(p, inner);
}
} else if (_doc) {
int32 w = width() - st::boxPhotoPadding.left() - st::boxPhotoPadding.right();
@@ -591,7 +595,8 @@ void EditCaptionBox::paintEvent(QPaintEvent *e) {
p.drawEllipse(inner);
p.setRenderHint(QPainter::HighQualityAntialiasing, false);
p.drawSpriteCenter(inner, _isImage ? st::msgFileInImage : st::msgFileInFile);
auto icon = &(_isImage ? st::historyFileInImage : st::historyFileInDocument);
icon->paintInCenter(p, inner);
}
p.setFont(st::semiboldFont);
p.setPen(st::black);

View File

@@ -913,15 +913,24 @@ QVector<PeerData*> ShareInner::selected() const {
QString appendShareGameScoreUrl(const QString &url, const FullMsgId &fullId) {
auto shareHashData = QByteArray(0x10, Qt::Uninitialized);
auto ints = reinterpret_cast<int32*>(shareHashData.data());
ints[0] = MTP::authedId();
ints[1] = fullId.channel;
ints[2] = fullId.msg;
ints[3] = 0;
auto shareHashDataInts = reinterpret_cast<int32*>(shareHashData.data());
auto channel = fullId.channel ? App::channelLoaded(fullId.channel) : static_cast<ChannelData*>(nullptr);
auto channelAccessHash = channel ? channel->access : 0ULL;
auto channelAccessHashInts = reinterpret_cast<int32*>(&channelAccessHash);
shareHashDataInts[0] = MTP::authedId();
shareHashDataInts[1] = fullId.channel;
shareHashDataInts[2] = fullId.msg;
shareHashDataInts[3] = channelAccessHashInts[0];
// Count SHA1() of data.
auto key128Size = 0x10;
auto shareHashEncrypted = QByteArray(key128Size + shareHashData.size(), Qt::Uninitialized);
hashSha1(shareHashData.constData(), shareHashData.size(), shareHashEncrypted.data());
// Mix in channel access hash to the first 64 bits of SHA1 of data.
*reinterpret_cast<uint64*>(shareHashEncrypted.data()) ^= *reinterpret_cast<uint64*>(channelAccessHashInts);
// Encrypt data.
if (!Local::encrypt(shareHashData.constData(), shareHashEncrypted.data() + key128Size, shareHashData.size(), shareHashEncrypted.constData())) {
return url;
}
@@ -1031,29 +1040,51 @@ void shareGameScoreByHash(const QString &hash) {
return;
}
// Decrypt data.
auto hashData = QByteArray(hashEncrypted.size() - key128Size, Qt::Uninitialized);
if (!Local::decrypt(hashEncrypted.constData() + key128Size, hashData.data(), hashEncrypted.size() - key128Size, hashEncrypted.constData())) {
return;
}
char checkSha1[20] = { 0 };
if (memcmp(hashSha1(hashData.constData(), hashData.size(), checkSha1), hashEncrypted.constData(), key128Size) != 0) {
Ui::showLayer(new InformBox(lang(lng_share_wrong_user)));
return;
}
auto ints = reinterpret_cast<int32*>(hashData.data());
if (ints[0] != MTP::authedId()) {
// Count SHA1() of data.
char dataSha1[20] = { 0 };
hashSha1(hashData.constData(), hashData.size(), dataSha1);
// Mix out channel access hash from the first 64 bits of SHA1 of data.
auto channelAccessHash = *reinterpret_cast<uint64*>(hashEncrypted.data()) ^ *reinterpret_cast<uint64*>(dataSha1);
// Check next 64 bits of SHA1() of data.
auto skipSha1Part = sizeof(channelAccessHash);
if (memcmp(dataSha1 + skipSha1Part, hashEncrypted.constData() + skipSha1Part, key128Size - skipSha1Part) != 0) {
Ui::showLayer(new InformBox(lang(lng_share_wrong_user)));
return;
}
auto hashDataInts = reinterpret_cast<int32*>(hashData.data());
if (hashDataInts[0] != MTP::authedId()) {
Ui::showLayer(new InformBox(lang(lng_share_wrong_user)));
return;
}
// Check first 32 bits of channel access hash.
auto channelAccessHashInts = reinterpret_cast<int32*>(&channelAccessHash);
if (channelAccessHashInts[0] != hashDataInts[3]) {
Ui::showLayer(new InformBox(lang(lng_share_wrong_user)));
return;
}
auto channelId = hashDataInts[1];
auto msgId = hashDataInts[2];
if (!channelId && channelAccessHash) {
// If there is no channel id, there should be no channel access_hash.
Ui::showLayer(new InformBox(lang(lng_share_wrong_user)));
return;
}
auto channelId = ints[1];
auto msgId = ints[2];
if (auto item = App::histItemById(channelId, msgId)) {
shareGameScoreFromItem(item);
} else if (App::api()) {
auto channel = channelId ? App::channelLoaded(channelId) : nullptr;
if (channel || !channelId) {
auto resolveMessageAndShareScore = [msgId](ChannelData *channel) {
App::api()->requestMessageData(channel, msgId, [](ChannelData *channel, MsgId msgId) {
if (auto item = App::histItemById(channel, msgId)) {
shareGameScoreFromItem(item);
@@ -1061,6 +1092,22 @@ void shareGameScoreByHash(const QString &hash) {
Ui::showLayer(new InformBox(lang(lng_edit_deleted)));
}
});
};
auto channel = channelId ? App::channelLoaded(channelId) : nullptr;
if (channel || !channelId) {
resolveMessageAndShareScore(channel);
} else {
auto requestChannelIds = MTP_vector<MTPInputChannel>(1, MTP_inputChannel(MTP_int(channelId), MTP_long(channelAccessHash)));
auto requestChannel = MTPchannels_GetChannels(requestChannelIds);
MTP::send(requestChannel, rpcDone([channelId, resolveMessageAndShareScore](const MTPmessages_Chats &result) {
if (result.type() == mtpc_messages_chats) {
App::feedChats(result.c_messages_chats().vchats);
}
if (auto channel = App::channelLoaded(channelId)) {
resolveMessageAndShareScore(channel);
}
}));
}
}
}