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

View File

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

View File

@ -190,7 +190,10 @@ public:
void noHider(HistoryHider *destroyed); void noHider(HistoryHider *destroyed);
bool setForwardDraft(PeerId peer, ForwardWhatMessages what); bool setForwardDraft(PeerId peer, ForwardWhatMessages what);
bool setForwardDraft(PeerId peer, const SelectedItemSet &items); 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); bool onInlineSwitchChosen(const PeerId &peer, const QString &botAndQuery);
void onShareContact(const PeerId &peer, UserData *contact); void onShareContact(const PeerId &peer, UserData *contact);
bool onSendPaths(const PeerId &peer); 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 "auth_session.h"
#include "apiwrap.h" #include "apiwrap.h"
#include "mainwidget.h" #include "mainwidget.h"
#include "mainwindow.h"
#include "observer_peer.h" #include "observer_peer.h"
#include "styles/style_boxes.h" #include "styles/style_boxes.h"
#include "window/window_controller.h" #include "window/window_controller.h"