mirror of
https://github.com/kotatogram/kotatogram-desktop
synced 2025-08-30 22:25:12 +00:00
Remove some more Auth() calls.
This commit is contained in:
@@ -98,7 +98,9 @@ int Style::minButtonWidth(HistoryMessageMarkupButton::Type type) const {
|
||||
|
||||
} // namespace
|
||||
|
||||
BotKeyboard::BotKeyboard(QWidget *parent) : TWidget(parent)
|
||||
BotKeyboard::BotKeyboard(not_null<Main::Session*> session, QWidget *parent)
|
||||
: TWidget(parent)
|
||||
, _session(session)
|
||||
, _st(&st::botKbButton) {
|
||||
setGeometry(0, 0, _st->margin, st::botKbScroll.deltat);
|
||||
_height = st::botKbScroll.deltat;
|
||||
@@ -149,7 +151,7 @@ void BotKeyboard::leaveEventHook(QEvent *e) {
|
||||
}
|
||||
|
||||
bool BotKeyboard::moderateKeyActivate(int key) {
|
||||
if (const auto item = Auth().data().message(_wasForMsgId)) {
|
||||
if (const auto item = _session->data().message(_wasForMsgId)) {
|
||||
if (const auto markup = item->Get<HistoryMessageReplyMarkup>()) {
|
||||
if (key >= Qt::Key_1 && key <= Qt::Key_9) {
|
||||
const auto index = int(key - Qt::Key_1);
|
||||
|
@@ -9,18 +9,22 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
|
||||
#include "ui/widgets/tooltip.h"
|
||||
|
||||
class ReplyKeyboard;
|
||||
|
||||
namespace style {
|
||||
struct BotKeyboardButton;
|
||||
} // namespace style
|
||||
|
||||
class ReplyKeyboard;
|
||||
namespace Main {
|
||||
class Session;
|
||||
} // namespace Main
|
||||
|
||||
class BotKeyboard
|
||||
: public TWidget
|
||||
, public Ui::AbstractTooltipShower
|
||||
, public ClickHandlerHost {
|
||||
public:
|
||||
BotKeyboard(QWidget *parent);
|
||||
BotKeyboard(not_null<Main::Session*> session, QWidget *parent);
|
||||
|
||||
bool moderateKeyActivate(int index);
|
||||
|
||||
@@ -70,6 +74,7 @@ private:
|
||||
void updateStyle(int newWidth);
|
||||
void clearSelection();
|
||||
|
||||
const not_null<Main::Session*> _session;
|
||||
FullMsgId _wasForMsgId;
|
||||
int _height = 0;
|
||||
int _maxOuterHeight = 0;
|
||||
|
@@ -527,7 +527,7 @@ void EmojiKeywords::handleSessionChanges() {
|
||||
void EmojiKeywords::apiChanged(ApiWrap *api) {
|
||||
_api = api;
|
||||
if (_api) {
|
||||
crl::on_main(&Auth(), crl::guard(&_guard, [=] {
|
||||
crl::on_main(&_api->session(), crl::guard(&_guard, [=] {
|
||||
base::ObservableViewer(
|
||||
Lang::CurrentCloudManager().firstLanguageSuggestion()
|
||||
) | rpl::filter([=] {
|
||||
|
@@ -698,7 +698,7 @@ void EmojiListWidget::colorChosen(EmojiPtr emoji) {
|
||||
cRefEmojiVariants().insert(
|
||||
emoji->nonColoredId(),
|
||||
emoji->variantIndex(emoji));
|
||||
Auth().saveSettingsDelayed();
|
||||
controller()->session().saveSettingsDelayed();
|
||||
}
|
||||
if (_pickerSel >= 0) {
|
||||
auto section = (_pickerSel / MatrixRowShift);
|
||||
|
@@ -254,7 +254,7 @@ void FieldAutocomplete::updateFiltered(bool resetScroll) {
|
||||
};
|
||||
mrows.reserve(mrows.size() + (_chat->participants.empty() ? _chat->lastAuthors.size() : _chat->participants.size()));
|
||||
if (_chat->noParticipantInfo()) {
|
||||
Auth().api().requestFullPeer(_chat);
|
||||
_chat->session().api().requestFullPeer(_chat);
|
||||
} else if (!_chat->participants.empty()) {
|
||||
for (const auto user : _chat->participants) {
|
||||
if (user->isInaccessible()) continue;
|
||||
@@ -277,7 +277,7 @@ void FieldAutocomplete::updateFiltered(bool resetScroll) {
|
||||
} else if (_channel && _channel->isMegagroup()) {
|
||||
QMultiMap<int32, UserData*> ordered;
|
||||
if (_channel->lastParticipantsRequestNeeded()) {
|
||||
Auth().api().requestLastParticipants(_channel);
|
||||
_channel->session().api().requestLastParticipants(_channel);
|
||||
} else {
|
||||
mrows.reserve(mrows.size() + _channel->mgInfo->lastParticipants.size());
|
||||
for (const auto user : _channel->mgInfo->lastParticipants) {
|
||||
@@ -600,7 +600,9 @@ FieldAutocompleteInner::FieldAutocompleteInner(
|
||||
, _brows(brows)
|
||||
, _srows(srows)
|
||||
, _previewTimer([=] { showPreview(); }) {
|
||||
subscribe(Auth().downloaderTaskFinished(), [this] { update(); });
|
||||
subscribe(
|
||||
controller->session().downloaderTaskFinished(),
|
||||
[=] { update(); });
|
||||
}
|
||||
|
||||
void FieldAutocompleteInner::paintEvent(QPaintEvent *e) {
|
||||
|
@@ -48,17 +48,13 @@ constexpr auto kParseLinksTimeout = crl::time(1000);
|
||||
// For mention tags save and validate userId, ignore tags for different userId.
|
||||
class FieldTagMimeProcessor : public Ui::InputField::TagMimeProcessor {
|
||||
public:
|
||||
QString tagFromMimeTag(const QString &mimeTag) override {
|
||||
if (TextUtilities::IsMentionLink(mimeTag)) {
|
||||
auto match = QRegularExpression(":(\\d+)$").match(mimeTag);
|
||||
if (!match.hasMatch()
|
||||
|| match.capturedRef(1).toInt() != Auth().userId()) {
|
||||
return QString();
|
||||
}
|
||||
return mimeTag.mid(0, mimeTag.size() - match.capturedLength());
|
||||
}
|
||||
return mimeTag;
|
||||
}
|
||||
explicit FieldTagMimeProcessor(
|
||||
not_null<Window::SessionController*> controller);
|
||||
|
||||
QString tagFromMimeTag(const QString &mimeTag) override;
|
||||
|
||||
private:
|
||||
const not_null<Window::SessionController*> _controller;
|
||||
|
||||
};
|
||||
|
||||
@@ -85,6 +81,24 @@ private:
|
||||
|
||||
};
|
||||
|
||||
FieldTagMimeProcessor::FieldTagMimeProcessor(
|
||||
not_null<Window::SessionController*> controller)
|
||||
: _controller(controller) {
|
||||
}
|
||||
|
||||
QString FieldTagMimeProcessor::tagFromMimeTag(const QString &mimeTag) {
|
||||
if (TextUtilities::IsMentionLink(mimeTag)) {
|
||||
const auto userId = _controller->session().userId();
|
||||
auto match = QRegularExpression(":(\\d+)$").match(mimeTag);
|
||||
if (!match.hasMatch()
|
||||
|| match.capturedRef(1).toInt() != userId) {
|
||||
return QString();
|
||||
}
|
||||
return mimeTag.mid(0, mimeTag.size() - match.capturedLength());
|
||||
}
|
||||
return mimeTag;
|
||||
}
|
||||
|
||||
//bool ValidateUrl(const QString &value) {
|
||||
// const auto match = qthelp::RegExpDomain().match(value);
|
||||
// if (!match.hasMatch() || match.capturedStart() != 0) {
|
||||
@@ -264,7 +278,8 @@ void InitMessageField(
|
||||
field->setMinHeight(st::historySendSize.height() - 2 * st::historySendPadding);
|
||||
field->setMaxHeight(st::historyComposeFieldMaxHeight);
|
||||
|
||||
field->setTagMimeProcessor(std::make_unique<FieldTagMimeProcessor>());
|
||||
field->setTagMimeProcessor(
|
||||
std::make_unique<FieldTagMimeProcessor>(controller));
|
||||
|
||||
field->document()->setDocumentMargin(4.);
|
||||
field->setAdditionalMargin(style::ConvertScale(4) - 4);
|
||||
@@ -307,7 +322,9 @@ bool HasSendText(not_null<const Ui::InputField*> field) {
|
||||
return false;
|
||||
}
|
||||
|
||||
InlineBotQuery ParseInlineBotQuery(not_null<const Ui::InputField*> field) {
|
||||
InlineBotQuery ParseInlineBotQuery(
|
||||
not_null<Main::Session*> session,
|
||||
not_null<const Ui::InputField*> field) {
|
||||
auto result = InlineBotQuery();
|
||||
|
||||
const auto &full = field->getTextWithTags();
|
||||
@@ -345,7 +362,7 @@ InlineBotQuery ParseInlineBotQuery(not_null<const Ui::InputField*> field) {
|
||||
auto username = text.midRef(inlineUsernameStart, inlineUsernameLength);
|
||||
if (username != result.username) {
|
||||
result.username = username.toString();
|
||||
if (const auto peer = Auth().data().peerByUsername(result.username)) {
|
||||
if (const auto peer = session->data().peerByUsername(result.username)) {
|
||||
if (const auto user = peer->asUser()) {
|
||||
result.bot = peer->asUser();
|
||||
} else {
|
||||
|
@@ -52,7 +52,9 @@ struct InlineBotQuery {
|
||||
UserData *bot = nullptr;
|
||||
bool lookingUpBot = false;
|
||||
};
|
||||
InlineBotQuery ParseInlineBotQuery(not_null<const Ui::InputField*> field);
|
||||
InlineBotQuery ParseInlineBotQuery(
|
||||
not_null<Main::Session*> session,
|
||||
not_null<const Ui::InputField*> field);
|
||||
|
||||
struct AutocompleteQuery {
|
||||
QString query;
|
||||
|
Reference in New Issue
Block a user