Skip to content

Commit

Permalink
Fix t.me/share links.
Browse files Browse the repository at this point in the history
Regression was introduced in ffc20e4.

Fixes #4099.
  • Loading branch information
john-preston committed Nov 30, 2017
1 parent 43570d1 commit 2bbf17b
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 15 deletions.
7 changes: 3 additions & 4 deletions Telegram/SourceFiles/history/history_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
Expand Down
29 changes: 19 additions & 10 deletions Telegram/SourceFiles/mainwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 4 additions & 1 deletion Telegram/SourceFiles/mainwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,10 @@ class MainWidget : public Ui::RpWidget, public RPCSender, private base::Subscrib
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);
Expand Down
1 change: 1 addition & 0 deletions Telegram/SourceFiles/window/window_peer_menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 2bbf17b

Please sign in to comment.