Fix t.me/share links.

Regression was introduced in ffc20e4492.

Fixes #4099.
This commit is contained in:
John Preston 2017-11-30 21:45:36 +04:00
parent 43570d1613
commit 2bbf17b672
4 changed files with 27 additions and 15 deletions

View File

@ -331,7 +331,7 @@ void HistoryHider::forward() {
} else if (_sendPath) {
parent()->onSendPaths(_offered->id);
} else if (!_shareUrl.isEmpty()) {
parent()->onShareUrl(_offered->id, _shareUrl, _shareText);
parent()->shareUrl(_offered, _shareUrl, _shareText);
} else if (!_botAndQuery.isEmpty()) {
parent()->onInlineSwitchChosen(_offered->id, _botAndQuery);
} else {
@ -402,9 +402,8 @@ bool HistoryHider::offerPeer(PeerId peer) {
}
return false;
} else if (!_shareUrl.isEmpty()) {
auto toId = _offered->id;
_offered = nullptr;
if (parent()->onShareUrl(toId, _shareUrl, _shareText)) {
auto offered = base::take(_offered);
if (parent()->shareUrl(offered, _shareUrl, _shareText)) {
startHide();
}
return false;

View File

@ -662,19 +662,28 @@ bool MainWidget::setForwardDraft(PeerId peerId, const SelectedItemSet &items) {
return true;
}
bool MainWidget::onShareUrl(const PeerId &peer, const QString &url, const QString &text) {
PeerData *p = App::peer(peer);
if (!peer || p->canWrite()) {
bool MainWidget::shareUrl(
not_null<PeerData*> peer,
const QString &url,
const QString &text) {
if (!peer->canWrite()) {
Ui::show(Box<InformBox>(lang(lng_share_cant)));
return false;
}
History *h = App::history(peer);
TextWithTags textWithTags = { url + '\n' + text, TextWithTags::Tags() };
MessageCursor cursor = { url.size() + 1, url.size() + 1 + text.size(), QFIXED_MAX };
h->setLocalDraft(std::make_unique<Data::Draft>(textWithTags, 0, cursor, false));
h->clearEditDraft();
bool opened = _history->peer() && (_history->peer()->id == peer);
if (opened) {
TextWithTags textWithTags = {
url + '\n' + text,
TextWithTags::Tags()
};
MessageCursor cursor = {
url.size() + 1,
url.size() + 1 + text.size(),
QFIXED_MAX
};
auto history = App::history(peer->id);
history->setLocalDraft(
std::make_unique<Data::Draft>(textWithTags, 0, cursor, false));
history->clearEditDraft();
if (_history->peer() == peer) {
_history->applyDraft();
} else {
Ui::showPeerHistory(peer, ShowAtUnreadMsgId);

View File

@ -190,7 +190,10 @@ public:
void noHider(HistoryHider *destroyed);
bool setForwardDraft(PeerId peer, ForwardWhatMessages what);
bool setForwardDraft(PeerId peer, const SelectedItemSet &items);
bool onShareUrl(const PeerId &peer, const QString &url, const QString &text);
bool shareUrl(
not_null<PeerData*> peer,
const QString &url,
const QString &text);
bool onInlineSwitchChosen(const PeerId &peer, const QString &botAndQuery);
void onShareContact(const PeerId &peer, UserData *contact);
bool onSendPaths(const PeerId &peer);

View File

@ -31,6 +31,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
#include "auth_session.h"
#include "apiwrap.h"
#include "mainwidget.h"
#include "mainwindow.h"
#include "observer_peer.h"
#include "styles/style_boxes.h"
#include "window/window_controller.h"