Added sending action when choosing sticker.

This commit is contained in:
23rd 2021-08-30 18:05:07 +03:00
parent 0852dbc40f
commit 8c17e3e578
9 changed files with 60 additions and 5 deletions

View file

@ -129,6 +129,7 @@ void SendProgressManager::send(const Key &key, int progress) {
case Type::ChooseContact: return MTP_sendMessageChooseContactAction();
case Type::PlayGame: return MTP_sendMessageGamePlayAction();
case Type::Speaking: return MTP_speakingInGroupCallAction();
case Type::ChooseSticker: return MTP_sendMessageChooseStickerAction();
default: return MTP_sendMessageTypingAction();
}
}();

View file

@ -970,6 +970,11 @@ StickersListWidget::StickersListWidget(
}
refreshRecent();
}, lifetime());
positionValue(
) | rpl::skip(1) | rpl::map_to(
TabbedSelector::Action::Update
) | rpl::start_to_stream(_choosingUpdated, lifetime());
}
Main::Session &StickersListWidget::session() const {
@ -988,6 +993,11 @@ rpl::producer<> StickersListWidget::checkForHide() const {
return _checkForHide.events();
}
auto StickersListWidget::choosingUpdated() const
-> rpl::producer<TabbedSelector::Action> {
return _choosingUpdated.events();
}
object_ptr<TabbedSelector::InnerFooter> StickersListWidget::createFooter() {
Expects(_footer == nullptr);
@ -2361,6 +2371,7 @@ TabbedSelector::InnerFooter *StickersListWidget::getFooter() const {
}
void StickersListWidget::processHideFinished() {
_choosingUpdated.fire(TabbedSelector::Action::Cancel);
clearSelection();
clearHeavyData();
if (_footer) {

View file

@ -55,6 +55,7 @@ public:
rpl::producer<TabbedSelector::FileChosen> chosen() const;
rpl::producer<> scrollUpdated() const;
rpl::producer<> checkForHide() const;
rpl::producer<TabbedSelector::Action> choosingUpdated() const;
void refreshRecent() override;
void preloadImages() override;
@ -392,6 +393,7 @@ private:
rpl::event_stream<TabbedSelector::FileChosen> _chosen;
rpl::event_stream<> _scrollUpdated;
rpl::event_stream<> _checkForHide;
rpl::event_stream<TabbedSelector::Action> _choosingUpdated;
};

View file

@ -479,6 +479,13 @@ auto TabbedSelector::inlineResultChosen() const
return hasGifsTab() ? gifs()->inlineResultChosen() : nullptr;
}
auto TabbedSelector::choosingStickerUpdated() const
-> rpl::producer<TabbedSelector::Action>{
return hasStickersTab()
? stickers()->choosingUpdated()
: rpl::never<Action>();
}
rpl::producer<> TabbedSelector::cancelled() const {
return hasGifsTab() ? gifs()->cancelRequests() : nullptr;
}

View file

@ -67,6 +67,10 @@ public:
EmojiOnly,
MediaEditor,
};
enum class Action {
Update,
Cancel,
};
TabbedSelector(
QWidget *parent,
@ -85,6 +89,7 @@ public:
rpl::producer<> checkForHide() const;
rpl::producer<> slideFinished() const;
rpl::producer<> contextMenuRequested() const;
rpl::producer<Action> choosingStickerUpdated() const;
void setRoundRadius(int radius);
void refreshStickers();

View file

@ -904,6 +904,19 @@ void HistoryWidget::initTabbedSelector() {
) | filter | rpl::start_with_next([=] {
selector->showMenuWithType(sendMenuType());
}, lifetime());
selector->choosingStickerUpdated(
) | rpl::start_with_next([=](const Selector::Action &data) {
if (!_history) {
return;
}
const auto type = Api::SendProgressType::ChooseSticker;
if (data != Selector::Action::Cancel) {
session().sendProgressManager().update(_history, type);
} else {
session().sendProgressManager().cancel(_history, type);
}
}, lifetime());
}
void HistoryWidget::supportInitAutocomplete() {

View file

@ -30,6 +30,7 @@ struct VoiceToSend {
struct SendActionUpdate {
Api::SendProgressType type = Api::SendProgressType();
int progress = 0;
bool cancel = false;
};
struct SetHistoryArgs {

View file

@ -1560,6 +1560,14 @@ void ComposeControls::initTabbedSelector() {
) | rpl::start_with_next([=] {
selector->showMenuWithType(sendMenuType());
}, wrap->lifetime());
selector->choosingStickerUpdated(
) | rpl::start_with_next([=](ChatHelpers::TabbedSelector::Action action) {
_sendActionUpdates.fire({
.type = Api::SendProgressType::ChooseSticker,
.cancel = (action == ChatHelpers::TabbedSelector::Action::Cancel),
});
}, wrap->lifetime());
}
void ComposeControls::initSendButton() {

View file

@ -240,11 +240,18 @@ RepliesWidget::RepliesWidget(
_composeControls->sendActionUpdates(
) | rpl::start_with_next([=](ComposeControls::SendActionUpdate &&data) {
session().sendProgressManager().update(
_history,
_rootId,
data.type,
data.progress);
if (!data.cancel) {
session().sendProgressManager().update(
_history,
_rootId,
data.type,
data.progress);
} else {
session().sendProgressManager().cancel(
_history,
_rootId,
data.type);
}
}, lifetime());
using MessageUpdateFlag = Data::MessageUpdate::Flag;