mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-02-22 16:26:52 +00:00
Move peer photo update from Messenger to ApiWrap.
This commit is contained in:
parent
e2207e33ef
commit
8c1cc51c2e
@ -43,6 +43,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "ui/text_options.h"
|
||||
#include "storage/localimageloader.h"
|
||||
#include "storage/file_download.h"
|
||||
#include "storage/file_upload.h"
|
||||
#include "storage/storage_facade.h"
|
||||
#include "storage/storage_shared_media.h"
|
||||
#include "storage/storage_user_photos.h"
|
||||
@ -154,6 +155,12 @@ ApiWrap::ApiWrap(not_null<AuthSession*> session)
|
||||
, _feedReadTimer([=] { readFeeds(); })
|
||||
, _proxyPromotionTimer([=] { refreshProxyPromotion(); })
|
||||
, _updateNotifySettingsTimer([=] { sendNotifySettingsUpdates(); }) {
|
||||
crl::on_main([=] {
|
||||
_session->uploader().photoReady(
|
||||
) | rpl::start_with_next([=](const Storage::UploadedPhoto &data) {
|
||||
photoUploadReady(data.fullId, data.file);
|
||||
}, _session->lifetime());
|
||||
});
|
||||
}
|
||||
|
||||
void ApiWrap::requestChangelog(
|
||||
@ -4345,7 +4352,7 @@ void ApiWrap::sendInlineResult(
|
||||
not_null<UserData*> bot,
|
||||
not_null<InlineBots::Result*> data,
|
||||
const SendOptions &options) {
|
||||
Auth().api().sendAction(options);
|
||||
sendAction(options);
|
||||
|
||||
const auto history = options.history;
|
||||
const auto peer = history->peer;
|
||||
@ -4376,9 +4383,9 @@ void ApiWrap::sendInlineResult(
|
||||
flags |= MTPDmessage::Flag::f_via_bot_id;
|
||||
}
|
||||
|
||||
auto messageFromId = channelPost ? 0 : Auth().userId();
|
||||
auto messageFromId = channelPost ? 0 : _session->userId();
|
||||
auto messagePostAuthor = channelPost
|
||||
? App::peerName(Auth().user())
|
||||
? App::peerName(_session->user())
|
||||
: QString();
|
||||
MTPint messageDate = MTP_int(unixtime());
|
||||
UserId messageViaBotId = bot ? peerToUser(bot->id) : 0;
|
||||
@ -4425,7 +4432,7 @@ void ApiWrap::sendExistingDocument(
|
||||
Data::FileOrigin origin,
|
||||
TextWithEntities caption,
|
||||
const SendOptions &options) {
|
||||
Auth().api().sendAction(options);
|
||||
sendAction(options);
|
||||
|
||||
const auto history = options.history;
|
||||
const auto peer = history->peer;
|
||||
@ -4439,7 +4446,8 @@ void ApiWrap::sendExistingDocument(
|
||||
sendFlags |= MTPmessages_SendMedia::Flag::f_reply_to_msg_id;
|
||||
}
|
||||
bool channelPost = peer->isChannel() && !peer->isMegagroup();
|
||||
bool silentPost = channelPost && Auth().data().notifySilentPosts(peer);
|
||||
bool silentPost = channelPost
|
||||
&& _session->data().notifySilentPosts(peer);
|
||||
if (channelPost) {
|
||||
flags |= MTPDmessage::Flag::f_views;
|
||||
flags |= MTPDmessage::Flag::f_post;
|
||||
@ -4452,9 +4460,10 @@ void ApiWrap::sendExistingDocument(
|
||||
if (silentPost) {
|
||||
sendFlags |= MTPmessages_SendMedia::Flag::f_silent;
|
||||
}
|
||||
auto messageFromId = channelPost ? 0 : Auth().userId();
|
||||
auto messageFromId = channelPost ? 0 : _session->userId();
|
||||
auto messagePostAuthor = channelPost
|
||||
? App::peerName(Auth().user()) : QString();
|
||||
? App::peerName(_session->user())
|
||||
: QString();
|
||||
|
||||
TextUtilities::Trim(caption);
|
||||
auto sentEntities = TextUtilities::EntitiesToMTP(
|
||||
@ -4793,6 +4802,93 @@ void ApiWrap::requestSupportContact(FnMut<void(const MTPUser &)> callback) {
|
||||
}).send();
|
||||
}
|
||||
|
||||
void ApiWrap::uploadPeerPhoto(not_null<PeerData*> peer, QImage &&image) {
|
||||
const auto ready = PreparePeerPhoto(peer->id, std::move(image));
|
||||
|
||||
const auto fakeId = FullMsgId(peerToChannel(peer->id), clientMsgId());
|
||||
const auto already = ranges::find(
|
||||
_peerPhotoUploads,
|
||||
peer,
|
||||
[](const auto &pair) { return pair.second; });
|
||||
if (already != end(_peerPhotoUploads)) {
|
||||
_session->uploader().cancel(already->first);
|
||||
_peerPhotoUploads.erase(already);
|
||||
}
|
||||
_peerPhotoUploads.emplace(fakeId, peer);
|
||||
_session->uploader().uploadMedia(fakeId, ready);
|
||||
}
|
||||
|
||||
void ApiWrap::photoUploadReady(
|
||||
const FullMsgId &msgId,
|
||||
const MTPInputFile &file) {
|
||||
if (const auto maybePeer = _peerPhotoUploads.take(msgId)) {
|
||||
const auto peer = *maybePeer;
|
||||
const auto applier = [=](const MTPUpdates &result) {
|
||||
applyUpdates(result);
|
||||
};
|
||||
if (peer->isSelf()) {
|
||||
request(MTPphotos_UploadProfilePhoto(
|
||||
file
|
||||
)).done([=](const MTPphotos_Photo &result) {
|
||||
result.match([&](const MTPDphotos_photo &data) {
|
||||
_session->data().photo(data.vphoto);
|
||||
App::feedUsers(data.vusers);
|
||||
});
|
||||
}).send();
|
||||
} else if (const auto chat = peer->asChat()) {
|
||||
const auto history = App::history(chat);
|
||||
history->sendRequestId = request(MTPmessages_EditChatPhoto(
|
||||
chat->inputChat,
|
||||
MTP_inputChatUploadedPhoto(file)
|
||||
)).done(applier).afterRequest(history->sendRequestId).send();
|
||||
} else if (const auto channel = peer->asChannel()) {
|
||||
const auto history = App::history(channel);
|
||||
history->sendRequestId = request(MTPchannels_EditPhoto(
|
||||
channel->inputChannel,
|
||||
MTP_inputChatUploadedPhoto(file)
|
||||
)).done(applier).afterRequest(history->sendRequestId).send();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void ApiWrap::clearPeerPhoto(not_null<PhotoData*> photo) {
|
||||
const auto self = App::self();
|
||||
if (!self) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (self->userpicPhotoId() == photo->id) {
|
||||
request(MTPphotos_UpdateProfilePhoto(
|
||||
MTP_inputPhotoEmpty()
|
||||
)).done([=](const MTPUserProfilePhoto &result) {
|
||||
self->setPhoto(result);
|
||||
}).send();
|
||||
} else if (photo->peer && photo->peer->userpicPhotoId() == photo->id) {
|
||||
const auto applier = [=](const MTPUpdates &result) {
|
||||
applyUpdates(result);
|
||||
};
|
||||
if (const auto chat = photo->peer->asChat()) {
|
||||
request(MTPmessages_EditChatPhoto(
|
||||
chat->inputChat,
|
||||
MTP_inputChatPhotoEmpty()
|
||||
)).done(applier).send();
|
||||
} else if (const auto channel = photo->peer->asChannel()) {
|
||||
request(MTPchannels_EditPhoto(
|
||||
channel->inputChannel,
|
||||
MTP_inputChatPhotoEmpty()
|
||||
)).done(applier).send();
|
||||
}
|
||||
} else {
|
||||
request(MTPphotos_DeletePhotos(
|
||||
MTP_vector<MTPInputPhoto>(1, photo->mtpInput())
|
||||
)).send();
|
||||
_session->storage().remove(Storage::UserPhotosRemoveOne(
|
||||
self->bareId(),
|
||||
photo->id));
|
||||
}
|
||||
}
|
||||
|
||||
void ApiWrap::readServerHistory(not_null<History*> history) {
|
||||
if (history->unreadCount()) {
|
||||
readServerHistoryForce(history);
|
||||
|
@ -324,6 +324,9 @@ public:
|
||||
|
||||
void requestSupportContact(FnMut<void(const MTPUser&)> callback);
|
||||
|
||||
void uploadPeerPhoto(not_null<PeerData*> peer, QImage &&image);
|
||||
void clearPeerPhoto(not_null<PhotoData*> photo);
|
||||
|
||||
~ApiWrap();
|
||||
|
||||
private:
|
||||
@ -505,6 +508,8 @@ private:
|
||||
FileReferencesHandler &&handler,
|
||||
Request &&data);
|
||||
|
||||
void photoUploadReady(const FullMsgId &msgId, const MTPInputFile &file);
|
||||
|
||||
not_null<AuthSession*> _session;
|
||||
|
||||
MessageDataRequests _messageDataRequests;
|
||||
@ -652,4 +657,6 @@ private:
|
||||
|
||||
std::vector<FnMut<void(const MTPUser &)>> _supportContactCallbacks;
|
||||
|
||||
base::flat_map<FullMsgId, not_null<PeerData*>> _peerPhotoUploads;
|
||||
|
||||
};
|
||||
|
@ -237,6 +237,10 @@ public:
|
||||
void checkAutoLock();
|
||||
void checkAutoLockIn(TimeMs time);
|
||||
|
||||
rpl::lifetime &lifetime() {
|
||||
return _lifetime;
|
||||
}
|
||||
|
||||
base::Observable<DocumentData*> documentUpdated;
|
||||
base::Observable<std::pair<not_null<HistoryItem*>, MsgId>> messageIdChanging;
|
||||
|
||||
|
@ -426,9 +426,7 @@ void GroupInfoBox::createGroup(not_null<PeerListBox*> selectUsersBox, const QStr
|
||||
| [this](not_null<ChatData*> chat) {
|
||||
auto image = _photo->takeResultImage();
|
||||
if (!image.isNull()) {
|
||||
Messenger::Instance().uploadProfilePhoto(
|
||||
std::move(image),
|
||||
chat->id);
|
||||
Auth().api().uploadPeerPhoto(chat, std::move(image));
|
||||
}
|
||||
Ui::showPeerHistory(chat, ShowAtUnreadMsgId);
|
||||
};
|
||||
@ -531,9 +529,7 @@ void GroupInfoBox::createChannel(const QString &title, const QString &descriptio
|
||||
| [this](not_null<ChannelData*> channel) {
|
||||
auto image = _photo->takeResultImage();
|
||||
if (!image.isNull()) {
|
||||
Messenger::Instance().uploadProfilePhoto(
|
||||
std::move(image),
|
||||
channel->id);
|
||||
Auth().api().uploadPeerPhoto(channel, std::move(image));
|
||||
}
|
||||
_createdChannel = channel;
|
||||
_creationRequestId = request(
|
||||
|
@ -1391,9 +1391,7 @@ void Controller::savePhoto() {
|
||||
? _controls.photo->takeResultImage()
|
||||
: QImage();
|
||||
if (!image.isNull()) {
|
||||
Messenger::Instance().uploadProfilePhoto(
|
||||
std::move(image),
|
||||
_peer->id);
|
||||
Auth().api().uploadPeerPhoto(_peer, std::move(image));
|
||||
}
|
||||
_box->closeBox();
|
||||
}
|
||||
|
@ -615,13 +615,11 @@ void Widget::Step::finish(const MTPUser &user, QImage &&photo) {
|
||||
App::wnd()->setupMain(&user);
|
||||
|
||||
// "this" is already deleted here by creating the main widget.
|
||||
if (auto user = App::self()) {
|
||||
if (const auto user = App::self()) {
|
||||
Auth().api().requestFullPeer(user);
|
||||
}
|
||||
if (!photo.isNull()) {
|
||||
Messenger::Instance().uploadProfilePhoto(
|
||||
std::move(photo),
|
||||
Auth().userId());
|
||||
if (!photo.isNull()) {
|
||||
Auth().api().uploadPeerPhoto(user, std::move(photo));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -960,22 +960,8 @@ void MainWidget::cancelUploadLayer(not_null<HistoryItem*> item) {
|
||||
void MainWidget::deletePhotoLayer(PhotoData *photo) {
|
||||
if (!photo) return;
|
||||
Ui::show(Box<ConfirmBox>(lang(lng_delete_photo_sure), lang(lng_box_delete), crl::guard(this, [=] {
|
||||
Auth().api().clearPeerPhoto(photo);
|
||||
Ui::hideLayer();
|
||||
|
||||
auto me = App::self();
|
||||
if (!me) return;
|
||||
|
||||
if (me->userpicPhotoId() == photo->id) {
|
||||
Messenger::Instance().peerClearPhoto(me->id);
|
||||
} else if (photo->peer && !photo->peer->isUser() && photo->peer->userpicPhotoId() == photo->id) {
|
||||
Messenger::Instance().peerClearPhoto(photo->peer->id);
|
||||
} else {
|
||||
MTP::send(MTPphotos_DeletePhotos(
|
||||
MTP_vector<MTPInputPhoto>(1, photo->mtpInput())));
|
||||
Auth().storage().remove(Storage::UserPhotosRemoveOne(
|
||||
me->bareId(),
|
||||
photo->id));
|
||||
}
|
||||
})));
|
||||
}
|
||||
|
||||
|
@ -29,7 +29,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "core/update_checker.h"
|
||||
#include "passport/passport_form_controller.h"
|
||||
#include "observer_peer.h"
|
||||
#include "storage/file_upload.h"
|
||||
#include "storage/storage_databases.h"
|
||||
#include "mainwidget.h"
|
||||
#include "mediaview.h"
|
||||
@ -560,83 +559,6 @@ void Messenger::startLocalStorage() {
|
||||
});
|
||||
}
|
||||
|
||||
void Messenger::regPhotoUpdate(const PeerId &peer, const FullMsgId &msgId) {
|
||||
photoUpdates.insert(msgId, peer);
|
||||
}
|
||||
|
||||
bool Messenger::isPhotoUpdating(const PeerId &peer) {
|
||||
for (QMap<FullMsgId, PeerId>::iterator i = photoUpdates.begin(), e = photoUpdates.end(); i != e; ++i) {
|
||||
if (i.value() == peer) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void Messenger::cancelPhotoUpdate(const PeerId &peer) {
|
||||
for (QMap<FullMsgId, PeerId>::iterator i = photoUpdates.begin(), e = photoUpdates.end(); i != e;) {
|
||||
if (i.value() == peer) {
|
||||
i = photoUpdates.erase(i);
|
||||
} else {
|
||||
++i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Messenger::selfPhotoCleared(const MTPUserProfilePhoto &result) {
|
||||
if (!App::self()) return;
|
||||
App::self()->setPhoto(result);
|
||||
emit peerPhotoDone(App::self()->id);
|
||||
}
|
||||
|
||||
void Messenger::chatPhotoCleared(PeerId peer, const MTPUpdates &updates) {
|
||||
if (App::main()) {
|
||||
App::main()->sentUpdatesReceived(updates);
|
||||
}
|
||||
cancelPhotoUpdate(peer);
|
||||
emit peerPhotoDone(peer);
|
||||
}
|
||||
|
||||
void Messenger::selfPhotoDone(const MTPphotos_Photo &result) {
|
||||
if (!App::self()) return;
|
||||
const auto &photo = result.c_photos_photo();
|
||||
Auth().data().photo(photo.vphoto);
|
||||
App::feedUsers(photo.vusers);
|
||||
cancelPhotoUpdate(App::self()->id);
|
||||
emit peerPhotoDone(App::self()->id);
|
||||
}
|
||||
|
||||
void Messenger::chatPhotoDone(PeerId peer, const MTPUpdates &updates) {
|
||||
if (App::main()) {
|
||||
App::main()->sentUpdatesReceived(updates);
|
||||
}
|
||||
cancelPhotoUpdate(peer);
|
||||
emit peerPhotoDone(peer);
|
||||
}
|
||||
|
||||
bool Messenger::peerPhotoFailed(PeerId peer, const RPCError &error) {
|
||||
if (MTP::isDefaultHandledError(error)) return false;
|
||||
|
||||
LOG(("Application Error: update photo failed %1: %2").arg(error.type()).arg(error.description()));
|
||||
cancelPhotoUpdate(peer);
|
||||
emit peerPhotoFail(peer);
|
||||
return true;
|
||||
}
|
||||
|
||||
void Messenger::peerClearPhoto(PeerId id) {
|
||||
if (!AuthSession::Exists()) return;
|
||||
|
||||
if (id == Auth().userPeerId()) {
|
||||
MTP::send(MTPphotos_UpdateProfilePhoto(MTP_inputPhotoEmpty()), rpcDone(&Messenger::selfPhotoCleared), rpcFail(&Messenger::peerPhotoFailed, id));
|
||||
} else if (peerIsChat(id)) {
|
||||
MTP::send(MTPmessages_EditChatPhoto(peerToBareMTPInt(id), MTP_inputChatPhotoEmpty()), rpcDone(&Messenger::chatPhotoCleared, id), rpcFail(&Messenger::peerPhotoFailed, id));
|
||||
} else if (peerIsChannel(id)) {
|
||||
if (auto channel = App::channelLoaded(id)) {
|
||||
MTP::send(MTPchannels_EditPhoto(channel->inputChannel, MTP_inputChatPhotoEmpty()), rpcDone(&Messenger::chatPhotoCleared, id), rpcFail(&Messenger::peerPhotoFailed, id));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Messenger::killDownloadSessionsStart(MTP::DcId dcId) {
|
||||
if (killDownloadSessionTimes.constFind(dcId) == killDownloadSessionTimes.cend()) {
|
||||
killDownloadSessionTimes.insert(dcId, getms() + MTPAckSendWaiting + MTPKillFileSessionTimeout);
|
||||
@ -728,24 +650,6 @@ void Messenger::killDownloadSessions() {
|
||||
}
|
||||
}
|
||||
|
||||
void Messenger::photoUpdated(const FullMsgId &msgId, const MTPInputFile &file) {
|
||||
Expects(AuthSession::Exists());
|
||||
|
||||
auto i = photoUpdates.find(msgId);
|
||||
if (i != photoUpdates.end()) {
|
||||
auto id = i.value();
|
||||
if (id == Auth().userPeerId()) {
|
||||
MTP::send(MTPphotos_UploadProfilePhoto(file), rpcDone(&Messenger::selfPhotoDone), rpcFail(&Messenger::peerPhotoFailed, id));
|
||||
} else if (peerIsChat(id)) {
|
||||
auto history = App::history(id);
|
||||
history->sendRequestId = MTP::send(MTPmessages_EditChatPhoto(history->peer->asChat()->inputChat, MTP_inputChatUploadedPhoto(file)), rpcDone(&Messenger::chatPhotoDone, id), rpcFail(&Messenger::peerPhotoFailed, id), 0, 0, history->sendRequestId);
|
||||
} else if (peerIsChannel(id)) {
|
||||
auto history = App::history(id);
|
||||
history->sendRequestId = MTP::send(MTPchannels_EditPhoto(history->peer->asChannel()->inputChannel, MTP_inputChatUploadedPhoto(file)), rpcDone(&Messenger::chatPhotoDone, id), rpcFail(&Messenger::peerPhotoFailed, id), 0, 0, history->sendRequestId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Messenger::onSwitchDebugMode() {
|
||||
if (Logs::DebugEnabled()) {
|
||||
QFile(cWorkingDir() + qsl("tdata/withdebug")).remove();
|
||||
@ -795,7 +699,6 @@ void Messenger::authSessionCreate(UserId userId) {
|
||||
void Messenger::authSessionDestroy() {
|
||||
unlockTerms();
|
||||
|
||||
_uploaderSubscription = rpl::lifetime();
|
||||
_authSession.reset();
|
||||
_private->storedAuthSession.reset();
|
||||
_private->authSessionUserId = 0;
|
||||
@ -998,54 +901,6 @@ bool Messenger::openLocalUrl(const QString &url, QVariant context) {
|
||||
return false;
|
||||
}
|
||||
|
||||
void Messenger::uploadProfilePhoto(QImage &&tosend, const PeerId &peerId) {
|
||||
PreparedPhotoThumbs photoThumbs;
|
||||
QVector<MTPPhotoSize> photoSizes;
|
||||
|
||||
auto thumb = App::pixmapFromImageInPlace(tosend.scaled(160, 160, Qt::KeepAspectRatio, Qt::SmoothTransformation));
|
||||
photoThumbs.insert('a', thumb);
|
||||
photoSizes.push_back(MTP_photoSize(MTP_string("a"), MTP_fileLocationUnavailable(MTP_long(0), MTP_int(0), MTP_long(0)), MTP_int(thumb.width()), MTP_int(thumb.height()), MTP_int(0)));
|
||||
|
||||
auto medium = App::pixmapFromImageInPlace(tosend.scaled(320, 320, Qt::KeepAspectRatio, Qt::SmoothTransformation));
|
||||
photoThumbs.insert('b', medium);
|
||||
photoSizes.push_back(MTP_photoSize(MTP_string("b"), MTP_fileLocationUnavailable(MTP_long(0), MTP_int(0), MTP_long(0)), MTP_int(medium.width()), MTP_int(medium.height()), MTP_int(0)));
|
||||
|
||||
auto full = QPixmap::fromImage(tosend, Qt::ColorOnly);
|
||||
photoThumbs.insert('c', full);
|
||||
photoSizes.push_back(MTP_photoSize(MTP_string("c"), MTP_fileLocationUnavailable(MTP_long(0), MTP_int(0), MTP_long(0)), MTP_int(full.width()), MTP_int(full.height()), MTP_int(0)));
|
||||
|
||||
QByteArray jpeg;
|
||||
QBuffer jpegBuffer(&jpeg);
|
||||
full.save(&jpegBuffer, "JPG", 87);
|
||||
|
||||
PhotoId id = rand_value<PhotoId>();
|
||||
|
||||
auto photo = MTP_photo(
|
||||
MTP_flags(0),
|
||||
MTP_long(id),
|
||||
MTP_long(0),
|
||||
MTP_bytes(QByteArray()),
|
||||
MTP_int(unixtime()),
|
||||
MTP_vector<MTPPhotoSize>(photoSizes));
|
||||
|
||||
QString file, filename;
|
||||
int32 filesize = 0;
|
||||
QByteArray data;
|
||||
|
||||
SendMediaReady ready(SendMediaType::Photo, file, filename, filesize, data, id, id, qsl("jpg"), peerId, photo, photoThumbs, MTP_documentEmpty(MTP_long(0)), jpeg, 0);
|
||||
|
||||
if (!_uploaderSubscription) {
|
||||
_uploaderSubscription = Auth().uploader().photoReady(
|
||||
) | rpl::start_with_next([=](const Storage::UploadedPhoto &data) {
|
||||
photoUpdated(data.fullId, data.file);
|
||||
});
|
||||
}
|
||||
|
||||
FullMsgId newId(peerToChannel(peerId), clientMsgId());
|
||||
regPhotoUpdate(peerId, newId);
|
||||
Auth().uploader().uploadMedia(newId, ready);
|
||||
}
|
||||
|
||||
void Messenger::lockByPasscode() {
|
||||
_passcodeLock = true;
|
||||
_window->setupPasscodeLock();
|
||||
|
@ -162,20 +162,6 @@ public:
|
||||
void checkStartUrl();
|
||||
bool openLocalUrl(const QString &url, QVariant context);
|
||||
|
||||
void uploadProfilePhoto(QImage &&tosend, const PeerId &peerId);
|
||||
void regPhotoUpdate(const PeerId &peer, const FullMsgId &msgId);
|
||||
bool isPhotoUpdating(const PeerId &peer);
|
||||
void cancelPhotoUpdate(const PeerId &peer);
|
||||
|
||||
void selfPhotoCleared(const MTPUserProfilePhoto &result);
|
||||
void chatPhotoCleared(PeerId peer, const MTPUpdates &updates);
|
||||
void selfPhotoDone(const MTPphotos_Photo &result);
|
||||
void chatPhotoDone(PeerId peerId, const MTPUpdates &updates);
|
||||
bool peerPhotoFailed(PeerId peerId, const RPCError &e);
|
||||
void peerClearPhoto(PeerId peer);
|
||||
|
||||
void writeUserConfigIn(TimeMs ms);
|
||||
|
||||
void killDownloadSessionsStart(MTP::DcId dcId);
|
||||
void killDownloadSessionsStop(MTP::DcId dcId);
|
||||
|
||||
@ -217,10 +203,6 @@ public:
|
||||
protected:
|
||||
bool eventFilter(QObject *object, QEvent *event) override;
|
||||
|
||||
signals:
|
||||
void peerPhotoDone(PeerId peer);
|
||||
void peerPhotoFail(PeerId peer);
|
||||
|
||||
public slots:
|
||||
void onAllKeysDestroyed();
|
||||
|
||||
@ -239,7 +221,6 @@ private:
|
||||
static void QuitAttempt();
|
||||
void quitDelayed();
|
||||
|
||||
void photoUpdated(const FullMsgId &msgId, const MTPInputFile &file);
|
||||
void resetAuthorizationKeys();
|
||||
void authSessionDestroy();
|
||||
void clearPasscodeLock();
|
||||
@ -247,8 +228,6 @@ private:
|
||||
|
||||
not_null<Core::Launcher*> _launcher;
|
||||
|
||||
QMap<FullMsgId, PeerId> photoUpdates;
|
||||
|
||||
QMap<MTP::DcId, TimeMs> killDownloadSessionTimes;
|
||||
SingleTimer killDownloadSessionsTimer;
|
||||
|
||||
@ -272,9 +251,6 @@ private:
|
||||
base::Observable<void> _passcodedChanged;
|
||||
QPointer<BoxContent> _badProxyDisableBox;
|
||||
|
||||
// While profile photo uploading is not moved to apiwrap.
|
||||
rpl::lifetime _uploaderSubscription;
|
||||
|
||||
std::unique_ptr<Media::Audio::Instance> _audio;
|
||||
QImage _logo;
|
||||
QImage _logoNoMargin;
|
||||
|
@ -61,17 +61,6 @@ CoverWidget::CoverWidget(QWidget *parent, UserData *self)
|
||||
notifyPeerUpdated(update);
|
||||
}));
|
||||
|
||||
connect(
|
||||
&Messenger::Instance(),
|
||||
&Messenger::peerPhotoDone,
|
||||
this,
|
||||
&CoverWidget::onPhotoUploadStatusChanged);
|
||||
connect(
|
||||
&Messenger::Instance(),
|
||||
&Messenger::peerPhotoFail,
|
||||
this,
|
||||
&CoverWidget::onPhotoUploadStatusChanged);
|
||||
|
||||
_userpicButton->addClickHandler([this] { showPhoto(); });
|
||||
validatePhoto();
|
||||
|
||||
@ -102,7 +91,6 @@ void CoverWidget::showPhoto() {
|
||||
}
|
||||
|
||||
void CoverWidget::cancelPhotoUpload() {
|
||||
Messenger::Instance().cancelPhotoUpdate(_self->id);
|
||||
refreshStatusText();
|
||||
}
|
||||
|
||||
@ -309,7 +297,7 @@ void CoverWidget::refreshNameText() {
|
||||
}
|
||||
|
||||
void CoverWidget::refreshStatusText() {
|
||||
if (Messenger::Instance().isPhotoUpdating(_self->id)) {
|
||||
if (false) {
|
||||
_statusText = lang(lng_settings_uploading_photo);
|
||||
_statusTextIsOnline = false;
|
||||
if (!_cancelPhotoUpload) {
|
||||
@ -378,9 +366,7 @@ void CoverWidget::showSetPhotoBox(const QImage &img) {
|
||||
auto box = Ui::show(Box<PhotoCropBox>(img, peer));
|
||||
box->ready(
|
||||
) | rpl::start_with_next([=](QImage &&image) {
|
||||
Messenger::Instance().uploadProfilePhoto(
|
||||
std::move(image),
|
||||
peer->id);
|
||||
Auth().api().uploadPeerPhoto(peer, std::move(image));
|
||||
}, box->lifetime());
|
||||
box->boxClosing() | rpl::start_with_next([=] {
|
||||
onPhotoUploadStatusChanged();
|
||||
|
@ -22,6 +22,66 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
|
||||
using Storage::ValidateThumbDimensions;
|
||||
|
||||
SendMediaReady PreparePeerPhoto(PeerId peerId, QImage &&image) {
|
||||
PreparedPhotoThumbs photoThumbs;
|
||||
QVector<MTPPhotoSize> photoSizes;
|
||||
|
||||
QByteArray jpeg;
|
||||
QBuffer jpegBuffer(&jpeg);
|
||||
image.save(&jpegBuffer, "JPG", 87);
|
||||
|
||||
const auto scaled = [&](int size) {
|
||||
return App::pixmapFromImageInPlace(image.scaled(
|
||||
size,
|
||||
size,
|
||||
Qt::KeepAspectRatio,
|
||||
Qt::SmoothTransformation));
|
||||
};
|
||||
const auto push = [&](const char *type, QPixmap &&pixmap) {
|
||||
photoSizes.push_back(MTP_photoSize(
|
||||
MTP_string(type),
|
||||
MTP_fileLocationUnavailable(
|
||||
MTP_long(0),
|
||||
MTP_int(0),
|
||||
MTP_long(0)),
|
||||
MTP_int(pixmap.width()),
|
||||
MTP_int(pixmap.height()), MTP_int(0)));
|
||||
photoThumbs.insert(type[0], std::move(pixmap));
|
||||
};
|
||||
push("a", scaled(160));
|
||||
push("b", scaled(320));
|
||||
push("c", App::pixmapFromImageInPlace(std::move(image)));
|
||||
|
||||
const auto id = rand_value<PhotoId>();
|
||||
const auto photo = MTP_photo(
|
||||
MTP_flags(0),
|
||||
MTP_long(id),
|
||||
MTP_long(0),
|
||||
MTP_bytes(QByteArray()),
|
||||
MTP_int(unixtime()),
|
||||
MTP_vector<MTPPhotoSize>(photoSizes));
|
||||
|
||||
QString file, filename;
|
||||
int32 filesize = 0;
|
||||
QByteArray data;
|
||||
|
||||
return SendMediaReady(
|
||||
SendMediaType::Photo,
|
||||
file,
|
||||
filename,
|
||||
filesize,
|
||||
data,
|
||||
id,
|
||||
id,
|
||||
qsl("jpg"),
|
||||
peerId,
|
||||
photo,
|
||||
photoThumbs,
|
||||
MTP_documentEmpty(MTP_long(0)),
|
||||
jpeg,
|
||||
0);
|
||||
}
|
||||
|
||||
TaskQueue::TaskQueue(TimeMs stopTimeoutMs) {
|
||||
if (stopTimeoutMs > 0) {
|
||||
_stopTimer = new QTimer(this);
|
||||
|
@ -89,6 +89,8 @@ struct SendMediaReady {
|
||||
|
||||
};
|
||||
|
||||
SendMediaReady PreparePeerPhoto(PeerId peerId, QImage &&image);
|
||||
|
||||
using TaskId = void*; // no interface, just id
|
||||
|
||||
class Task {
|
||||
|
@ -23,6 +23,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "window/window_controller.h"
|
||||
#include "lang/lang_keys.h"
|
||||
#include "auth_session.h"
|
||||
#include "apiwrap.h"
|
||||
#include "mainwidget.h"
|
||||
#include "messenger.h"
|
||||
#include "observer_peer.h"
|
||||
@ -478,14 +479,9 @@ void UserpicButton::changePhotoLazy() {
|
||||
}
|
||||
|
||||
void UserpicButton::uploadNewPeerPhoto() {
|
||||
auto callback = crl::guard(
|
||||
this,
|
||||
[this](QImage &&image) {
|
||||
Messenger::Instance().uploadProfilePhoto(
|
||||
std::move(image),
|
||||
_peer->id
|
||||
);
|
||||
});
|
||||
auto callback = crl::guard(this, [=](QImage &&image) {
|
||||
Auth().api().uploadPeerPhoto(_peer, std::move(image));
|
||||
});
|
||||
ShowChoosePhotoBox(this, _peerForCrop, std::move(callback));
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user