mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Added bot button to bar of pinned messages.
This commit is contained in:
parent
1710890886
commit
31cd841b75
5 changed files with 108 additions and 18 deletions
|
@ -6389,23 +6389,27 @@ void HistoryWidget::checkPinnedBarState() {
|
||||||
&session(),
|
&session(),
|
||||||
_pinnedTracker->shownMessageId());
|
_pinnedTracker->shownMessageId());
|
||||||
_pinnedBar = std::make_unique<Ui::PinnedBar>(this);
|
_pinnedBar = std::make_unique<Ui::PinnedBar>(this);
|
||||||
_pinnedBar->setContent(std::move(barContent));
|
rpl::combine(
|
||||||
Info::Profile::SharedMediaCountValue(
|
Info::Profile::SharedMediaCountValue(
|
||||||
_peer,
|
_peer,
|
||||||
nullptr,
|
nullptr,
|
||||||
Storage::SharedMediaType::Pinned
|
Storage::SharedMediaType::Pinned
|
||||||
) | rpl::distinct_until_changed(
|
) | rpl::distinct_until_changed(
|
||||||
) | rpl::map([=](int count) {
|
) | rpl::map([=](int count) {
|
||||||
if (_pinnedClickedId) {
|
if (_pinnedClickedId) {
|
||||||
_pinnedClickedId = FullMsgId();
|
_pinnedClickedId = FullMsgId();
|
||||||
_minPinnedId = std::nullopt;
|
_minPinnedId = std::nullopt;
|
||||||
updatePinnedViewer();
|
updatePinnedViewer();
|
||||||
}
|
}
|
||||||
return (count > 1);
|
return (count > 1);
|
||||||
}) | rpl::distinct_until_changed(
|
}) | rpl::distinct_until_changed(),
|
||||||
) | rpl::start_with_next([=](bool many) {
|
HistoryView::PinnedBarItemWithReplyMarkup(
|
||||||
refreshPinnedBarButton(many);
|
&session(),
|
||||||
|
_pinnedTracker->shownMessageId())
|
||||||
|
) | rpl::start_with_next([=](bool many, HistoryItem *item) {
|
||||||
|
refreshPinnedBarButton(many, item);
|
||||||
}, _pinnedBar->lifetime());
|
}, _pinnedBar->lifetime());
|
||||||
|
_pinnedBar->setContent(std::move(barContent));
|
||||||
|
|
||||||
controller()->adaptive().oneColumnValue(
|
controller()->adaptive().oneColumnValue(
|
||||||
) | rpl::start_with_next([=](bool one) {
|
) | rpl::start_with_next([=](bool one) {
|
||||||
|
@ -6492,7 +6496,30 @@ void HistoryWidget::setChooseReportMessagesDetails(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void HistoryWidget::refreshPinnedBarButton(bool many) {
|
void HistoryWidget::refreshPinnedBarButton(bool many, HistoryItem *item) {
|
||||||
|
if (const auto replyMarkup = item ? item->inlineReplyMarkup() : nullptr) {
|
||||||
|
const auto &rows = replyMarkup->data.rows;
|
||||||
|
if ((rows.size() == 1) && (rows.front().size() == 1)) {
|
||||||
|
const auto text = rows.front().front().text;
|
||||||
|
if (!text.isEmpty()) {
|
||||||
|
auto button = object_ptr<Ui::RoundButton>(
|
||||||
|
this,
|
||||||
|
rpl::single(text),
|
||||||
|
st::historyPinnedBotButton);
|
||||||
|
button->setTextTransform(
|
||||||
|
Ui::RoundButton::TextTransform::NoTransform);
|
||||||
|
button->setFullRadius(true);
|
||||||
|
button->setClickedCallback([=] {
|
||||||
|
App::activateBotCommand(controller(), item, 0, 0);
|
||||||
|
});
|
||||||
|
if (button->width() > st::historyPinnedBotButtonMaxWidth) {
|
||||||
|
button->setFullWidth(st::historyPinnedBotButtonMaxWidth);
|
||||||
|
}
|
||||||
|
_pinnedBar->setRightButton(std::move(button));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
const auto close = !many;
|
const auto close = !many;
|
||||||
auto button = object_ptr<Ui::IconButton>(
|
auto button = object_ptr<Ui::IconButton>(
|
||||||
this,
|
this,
|
||||||
|
|
|
@ -512,7 +512,7 @@ private:
|
||||||
void updatePinnedViewer();
|
void updatePinnedViewer();
|
||||||
void setupPinnedTracker();
|
void setupPinnedTracker();
|
||||||
void checkPinnedBarState();
|
void checkPinnedBarState();
|
||||||
void refreshPinnedBarButton(bool many);
|
void refreshPinnedBarButton(bool many, HistoryItem *item);
|
||||||
void checkLastPinnedClickedIdReset(
|
void checkLastPinnedClickedIdReset(
|
||||||
int wasScrollTop,
|
int wasScrollTop,
|
||||||
int nowScrollTop);
|
int nowScrollTop);
|
||||||
|
|
|
@ -154,4 +154,56 @@ rpl::producer<Ui::MessageBarContent> PinnedBarContent(
|
||||||
}) | rpl::flatten_latest();
|
}) | rpl::flatten_latest();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rpl::producer<HistoryItem*> PinnedBarItemWithReplyMarkup(
|
||||||
|
not_null<Main::Session*> session,
|
||||||
|
rpl::producer<PinnedId> id) {
|
||||||
|
return rpl::make_producer<HistoryItem*>([=,
|
||||||
|
id = std::move(id)](auto consumer) {
|
||||||
|
auto lifetime = rpl::lifetime();
|
||||||
|
consumer.put_next(nullptr);
|
||||||
|
|
||||||
|
struct State {
|
||||||
|
HistoryMessageReplyMarkup *previousReplyMarkup = nullptr;
|
||||||
|
rpl::lifetime lifetime;
|
||||||
|
};
|
||||||
|
const auto state = lifetime.make_state<State>();
|
||||||
|
|
||||||
|
const auto pushUnique = [=](not_null<HistoryItem*> item) {
|
||||||
|
const auto replyMarkup = item->inlineReplyMarkup();
|
||||||
|
if (state->previousReplyMarkup == replyMarkup) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
consumer.put_next(item.get());
|
||||||
|
state->previousReplyMarkup = replyMarkup;
|
||||||
|
};
|
||||||
|
|
||||||
|
rpl::duplicate(
|
||||||
|
id
|
||||||
|
) | rpl::start_with_next([=](PinnedId current) {
|
||||||
|
const auto fullId = current.message;
|
||||||
|
if (!fullId) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const auto messageFlag = [=](not_null<HistoryItem*> item) {
|
||||||
|
using Update = Data::MessageUpdate;
|
||||||
|
session->changes().messageFlagsValue(
|
||||||
|
item,
|
||||||
|
Update::Flag::ReplyMarkup
|
||||||
|
) | rpl::start_with_next([=](const Update &update) {
|
||||||
|
pushUnique(update.item);
|
||||||
|
}, state->lifetime);
|
||||||
|
};
|
||||||
|
if (const auto item = session->data().message(fullId)) {
|
||||||
|
messageFlag(item);
|
||||||
|
} else {
|
||||||
|
session->api().requestMessageData(
|
||||||
|
session->data().peer(fullId.peer),
|
||||||
|
fullId.msg,
|
||||||
|
[=] { messageFlag(session->data().message(fullId)); });
|
||||||
|
}
|
||||||
|
}, lifetime);
|
||||||
|
return lifetime;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace HistoryView
|
} // namespace HistoryView
|
||||||
|
|
|
@ -49,4 +49,8 @@ struct PinnedId {
|
||||||
not_null<Main::Session*> session,
|
not_null<Main::Session*> session,
|
||||||
rpl::producer<PinnedId> id);
|
rpl::producer<PinnedId> id);
|
||||||
|
|
||||||
|
[[nodiscard]] rpl::producer<HistoryItem*> PinnedBarItemWithReplyMarkup(
|
||||||
|
not_null<Main::Session*> session,
|
||||||
|
rpl::producer<PinnedId> id);
|
||||||
|
|
||||||
} // namespace HistoryView
|
} // namespace HistoryView
|
||||||
|
|
|
@ -477,6 +477,13 @@ historyPinnedShowAll: IconButton(historyReplyCancel) {
|
||||||
icon: icon {{ "pinned_show_all", historyReplyCancelFg }};
|
icon: icon {{ "pinned_show_all", historyReplyCancelFg }};
|
||||||
iconOver: icon {{ "pinned_show_all", historyReplyCancelFgOver }};
|
iconOver: icon {{ "pinned_show_all", historyReplyCancelFgOver }};
|
||||||
}
|
}
|
||||||
|
historyPinnedBotButton: RoundButton(defaultActiveButton) {
|
||||||
|
width: -34px;
|
||||||
|
height: 30px;
|
||||||
|
textTop: 6px;
|
||||||
|
padding: margins(2px, 10px, 10px, 9px);
|
||||||
|
}
|
||||||
|
historyPinnedBotButtonMaxWidth: 150px;
|
||||||
|
|
||||||
msgBotKbDuration: 200;
|
msgBotKbDuration: 200;
|
||||||
msgBotKbFont: semiboldFont;
|
msgBotKbFont: semiboldFont;
|
||||||
|
|
Loading…
Add table
Reference in a new issue