mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Removed App::wnd() from HistoryView::Message.
This commit is contained in:
parent
ca83b8a8c6
commit
65aecf16a6
1 changed files with 120 additions and 79 deletions
|
@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
*/
|
*/
|
||||||
#include "history/view/history_view_message.h"
|
#include "history/view/history_view_message.h"
|
||||||
|
|
||||||
|
#include "core/click_handler_types.h" // ClickHandlerContext
|
||||||
#include "history/view/history_view_cursor_state.h"
|
#include "history/view/history_view_cursor_state.h"
|
||||||
#include "history/history_item_components.h"
|
#include "history/history_item_components.h"
|
||||||
#include "history/history_message.h"
|
#include "history/history_message.h"
|
||||||
|
@ -25,12 +26,11 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "data/data_channel.h"
|
#include "data/data_channel.h"
|
||||||
#include "lang/lang_keys.h"
|
#include "lang/lang_keys.h"
|
||||||
#include "mainwidget.h"
|
#include "mainwidget.h"
|
||||||
#include "mainwindow.h"
|
|
||||||
#include "main/main_session.h"
|
#include "main/main_session.h"
|
||||||
#include "window/window_session_controller.h"
|
#include "window/window_session_controller.h"
|
||||||
#include "apiwrap.h"
|
#include "apiwrap.h"
|
||||||
#include "layout/layout_selection.h"
|
#include "layout/layout_selection.h"
|
||||||
#include "facades.h"
|
|
||||||
#include "styles/style_widgets.h"
|
#include "styles/style_widgets.h"
|
||||||
#include "styles/style_chat.h"
|
#include "styles/style_chat.h"
|
||||||
#include "styles/style_dialogs.h"
|
#include "styles/style_dialogs.h"
|
||||||
|
@ -40,6 +40,15 @@ namespace {
|
||||||
|
|
||||||
const auto kPsaTooltipPrefix = "cloud_lng_tooltip_psa_";
|
const auto kPsaTooltipPrefix = "cloud_lng_tooltip_psa_";
|
||||||
|
|
||||||
|
std::optional<Window::SessionController*> ExtractController(
|
||||||
|
const ClickContext &context) {
|
||||||
|
const auto my = context.other.value<ClickHandlerContext>();
|
||||||
|
if (const auto controller = my.sessionWindow.get()) {
|
||||||
|
return controller;
|
||||||
|
}
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
|
||||||
class KeyboardStyle : public ReplyKeyboard::Style {
|
class KeyboardStyle : public ReplyKeyboard::Style {
|
||||||
public:
|
public:
|
||||||
using ReplyKeyboard::Style::Style;
|
using ReplyKeyboard::Style::Style;
|
||||||
|
@ -1380,21 +1389,25 @@ bool Message::getStateCommentsButton(
|
||||||
|
|
||||||
ClickHandlerPtr Message::createGoToCommentsLink() const {
|
ClickHandlerPtr Message::createGoToCommentsLink() const {
|
||||||
const auto fullId = data()->fullId();
|
const auto fullId = data()->fullId();
|
||||||
return std::make_shared<LambdaClickHandler>([=] {
|
const auto sessionId = data()->history()->session().uniqueId();
|
||||||
if (const auto window = App::wnd()) {
|
return std::make_shared<LambdaClickHandler>([=](ClickContext context) {
|
||||||
if (const auto controller = window->sessionController()) {
|
const auto controller = ExtractController(context).value_or(nullptr);
|
||||||
if (const auto item = controller->session().data().message(fullId)) {
|
if (!controller) {
|
||||||
const auto history = item->history();
|
return;
|
||||||
if (const auto channel = history->peer->asChannel()) {
|
}
|
||||||
if (channel->invitePeekExpires()) {
|
if (controller->session().uniqueId() != sessionId) {
|
||||||
Ui::Toast::Show(
|
return;
|
||||||
tr::lng_channel_invite_private(tr::now));
|
}
|
||||||
return;
|
if (const auto item = controller->session().data().message(fullId)) {
|
||||||
}
|
const auto history = item->history();
|
||||||
}
|
if (const auto channel = history->peer->asChannel()) {
|
||||||
controller->showRepliesForMessage(history, item->id);
|
if (channel->invitePeekExpires()) {
|
||||||
|
Ui::Toast::Show(
|
||||||
|
tr::lng_channel_invite_private(tr::now));
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
controller->showRepliesForMessage(history, item->id);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -2318,80 +2331,108 @@ void Message::drawRightAction(
|
||||||
}
|
}
|
||||||
|
|
||||||
ClickHandlerPtr Message::rightActionLink() const {
|
ClickHandlerPtr Message::rightActionLink() const {
|
||||||
if (!_rightActionLink) {
|
if (_rightActionLink) {
|
||||||
if (isPinnedContext()) {
|
return _rightActionLink;
|
||||||
_rightActionLink = goToMessageClickHandler(data());
|
}
|
||||||
return _rightActionLink;
|
if (isPinnedContext()) {
|
||||||
} else if (displayRightActionComments()) {
|
_rightActionLink = goToMessageClickHandler(data());
|
||||||
_rightActionLink = createGoToCommentsLink();
|
return _rightActionLink;
|
||||||
return _rightActionLink;
|
} else if (displayRightActionComments()) {
|
||||||
}
|
_rightActionLink = createGoToCommentsLink();
|
||||||
const auto owner = &data()->history()->owner();
|
return _rightActionLink;
|
||||||
const auto itemId = data()->fullId();
|
}
|
||||||
const auto forwarded = data()->Get<HistoryMessageForwarded>();
|
const auto sessionId = data()->history()->session().uniqueId();
|
||||||
const auto savedFromPeer = forwarded ? forwarded->savedFromPeer : nullptr;
|
const auto owner = &data()->history()->owner();
|
||||||
const auto savedFromMsgId = forwarded ? forwarded->savedFromMsgId : 0;
|
const auto itemId = data()->fullId();
|
||||||
const auto showByThread = std::make_shared<FnMut<void()>>();
|
const auto forwarded = data()->Get<HistoryMessageForwarded>();
|
||||||
const auto showByThreadWeak = std::weak_ptr<FnMut<void()>>(showByThread);
|
const auto savedFromPeer = forwarded ? forwarded->savedFromPeer : nullptr;
|
||||||
if (data()->externalReply()) {
|
const auto savedFromMsgId = forwarded ? forwarded->savedFromMsgId : 0;
|
||||||
*showByThread = [=, requested = 0]() mutable {
|
|
||||||
const auto original = savedFromPeer->owner().message(savedFromPeer->asChannel(), savedFromMsgId);
|
using Callback = FnMut<void(not_null<Window::SessionController*>)>;
|
||||||
if (original && original->replyToTop()) {
|
const auto showByThread = std::make_shared<Callback>();
|
||||||
App::wnd()->sessionController()->showRepliesForMessage(
|
const auto showByThreadWeak = std::weak_ptr<Callback>(showByThread);
|
||||||
original->history(),
|
if (data()->externalReply()) {
|
||||||
original->replyToTop(),
|
*showByThread = [=, requested = 0](
|
||||||
original->id,
|
not_null<Window::SessionController*> controller) mutable {
|
||||||
Window::SectionShow::Way::Forward);
|
const auto original = savedFromPeer->owner().message(
|
||||||
} else if (!requested) {
|
savedFromPeer->asChannel(),
|
||||||
const auto channel = savedFromPeer->asChannel();
|
savedFromMsgId);
|
||||||
const auto prequested = &requested;
|
if (original && original->replyToTop()) {
|
||||||
requested = 1;
|
controller->showRepliesForMessage(
|
||||||
channel->session().api().requestMessageData(channel, savedFromMsgId, [=](ChannelData *gotChannel, MsgId gotId) {
|
original->history(),
|
||||||
|
original->replyToTop(),
|
||||||
|
original->id,
|
||||||
|
Window::SectionShow::Way::Forward);
|
||||||
|
} else if (!requested) {
|
||||||
|
const auto channel = savedFromPeer->asChannel();
|
||||||
|
const auto prequested = &requested;
|
||||||
|
requested = 1;
|
||||||
|
channel->session().api().requestMessageData(
|
||||||
|
channel,
|
||||||
|
savedFromMsgId,
|
||||||
|
[=, weak = base::make_weak(controller.get())](
|
||||||
|
ChannelData *gotChannel, MsgId gotId) {
|
||||||
if (const auto strong = showByThreadWeak.lock()) {
|
if (const auto strong = showByThreadWeak.lock()) {
|
||||||
*prequested = 2;
|
if (const auto strongController = weak.get()) {
|
||||||
(*strong)();
|
*prequested = 2;
|
||||||
|
(*strong)(strongController);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else if (requested == 2) {
|
} else if (requested == 2) {
|
||||||
App::wnd()->sessionController()->showPeerHistory(
|
controller->showPeerHistory(
|
||||||
savedFromPeer,
|
savedFromPeer,
|
||||||
Window::SectionShow::Way::Forward,
|
Window::SectionShow::Way::Forward,
|
||||||
savedFromMsgId);
|
savedFromMsgId);
|
||||||
}
|
|
||||||
};
|
|
||||||
};
|
|
||||||
_rightActionLink = std::make_shared<LambdaClickHandler>([=] {
|
|
||||||
if (const auto item = owner->message(itemId)) {
|
|
||||||
if (*showByThread) {
|
|
||||||
(*showByThread)();
|
|
||||||
} else if (savedFromPeer && savedFromMsgId) {
|
|
||||||
App::wnd()->sessionController()->showPeerHistory(
|
|
||||||
savedFromPeer,
|
|
||||||
Window::SectionShow::Way::Forward,
|
|
||||||
savedFromMsgId);
|
|
||||||
} else {
|
|
||||||
FastShareMessage(item);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
}
|
};
|
||||||
|
_rightActionLink = std::make_shared<LambdaClickHandler>([=](
|
||||||
|
ClickContext context) {
|
||||||
|
const auto controller = ExtractController(context).value_or(nullptr);
|
||||||
|
if (!controller) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (controller->session().uniqueId() != sessionId) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (const auto item = owner->message(itemId)) {
|
||||||
|
if (*showByThread) {
|
||||||
|
(*showByThread)(controller);
|
||||||
|
} else if (savedFromPeer && savedFromMsgId) {
|
||||||
|
controller->showPeerHistory(
|
||||||
|
savedFromPeer,
|
||||||
|
Window::SectionShow::Way::Forward,
|
||||||
|
savedFromMsgId);
|
||||||
|
} else {
|
||||||
|
FastShareMessage(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
return _rightActionLink;
|
return _rightActionLink;
|
||||||
}
|
}
|
||||||
|
|
||||||
ClickHandlerPtr Message::fastReplyLink() const {
|
ClickHandlerPtr Message::fastReplyLink() const {
|
||||||
if (!_fastReplyLink) {
|
if (_fastReplyLink) {
|
||||||
const auto owner = &data()->history()->owner();
|
return _fastReplyLink;
|
||||||
const auto itemId = data()->fullId();
|
}
|
||||||
_fastReplyLink = std::make_shared<LambdaClickHandler>([=] {
|
const auto owner = &data()->history()->owner();
|
||||||
if (const auto item = owner->message(itemId)) {
|
const auto itemId = data()->fullId();
|
||||||
if (const auto main = App::main()) { // multi good
|
_fastReplyLink = std::make_shared<LambdaClickHandler>([=](
|
||||||
if (&main->session() == &owner->session()) {
|
ClickContext context) {
|
||||||
main->replyToItem(item);
|
const auto controller = ExtractController(context).value_or(nullptr);
|
||||||
}
|
if (!controller) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (const auto item = owner->message(itemId)) {
|
||||||
|
if (const auto main = controller->content()) {
|
||||||
|
if (&main->session() == &owner->session()) {
|
||||||
|
main->replyToItem(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
}
|
});
|
||||||
return _fastReplyLink;
|
return _fastReplyLink;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue