mirror of
https://github.com/kotatogram/kotatogram-desktop
synced 2025-08-30 06:07:45 +00:00
Suggest to hide pinned message instead of unpin
This commit is contained in:
parent
e719a0e818
commit
b601f3364c
@ -2481,4 +2481,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
|
||||
"ktg_settings_messages" = "Messages";
|
||||
|
||||
"ktg_hide_pinned_message" = "Hide";
|
||||
|
||||
// Keys finished
|
||||
|
@ -108,5 +108,6 @@
|
||||
"ktg_settings_filters_hide_folder_names": "Компактные папки",
|
||||
"ktg_settings_top_bar_mute": "Уведомления вверху профиля",
|
||||
"ktg_settings_messages": "Сообщения",
|
||||
"ktg_settings_filters_hide_all": "Скрыть папку «Все чаты»"
|
||||
"ktg_settings_filters_hide_all": "Скрыть папку «Все чаты»",
|
||||
"ktg_hide_pinned_message": "Скрыть"
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "apiwrap.h"
|
||||
#include "history/history.h"
|
||||
#include "history/history_item.h"
|
||||
#include "history/history_widget.h"
|
||||
#include "ui/widgets/checkbox.h"
|
||||
#include "ui/widgets/buttons.h"
|
||||
#include "ui/widgets/labels.h"
|
||||
@ -493,6 +494,73 @@ bool PinMessageBox::pinFail(const RPCError &error) {
|
||||
return true;
|
||||
}
|
||||
|
||||
UnpinMessageBox::UnpinMessageBox(
|
||||
QWidget*,
|
||||
not_null<PeerData*> peer)
|
||||
: _peer(peer)
|
||||
, _text(this, tr::lng_pinned_unpin_sure(tr::now), st::boxLabel) {
|
||||
}
|
||||
|
||||
void UnpinMessageBox::prepare() {
|
||||
addLeftButton(tr::ktg_hide_pinned_message(), [this] { hideMessage(); });
|
||||
|
||||
addButton(tr::lng_pinned_unpin(), [this] { unpinMessage(); });
|
||||
addButton(tr::lng_cancel(), [this] { closeBox(); });
|
||||
|
||||
auto height = st::boxPadding.top() + _text->height() + st::boxPadding.bottom();
|
||||
setDimensions(st::boxWidth, height);
|
||||
}
|
||||
|
||||
void UnpinMessageBox::resizeEvent(QResizeEvent *e) {
|
||||
BoxContent::resizeEvent(e);
|
||||
_text->moveToLeft(st::boxPadding.left(), st::boxPadding.top());
|
||||
}
|
||||
|
||||
void UnpinMessageBox::keyPressEvent(QKeyEvent *e) {
|
||||
if (e->key() == Qt::Key_Enter || e->key() == Qt::Key_Return) {
|
||||
unpinMessage();
|
||||
} else if (e->key() == Qt::Key_Backspace) {
|
||||
hideMessage();
|
||||
} else {
|
||||
BoxContent::keyPressEvent(e);
|
||||
}
|
||||
}
|
||||
|
||||
void UnpinMessageBox::unpinMessage() {
|
||||
if (_requestId) return;
|
||||
|
||||
_requestId = MTP::send(
|
||||
MTPmessages_UpdatePinnedMessage(
|
||||
MTP_flags(0),
|
||||
_peer->input,
|
||||
MTP_int(0)),
|
||||
rpcDone(&UnpinMessageBox::unpinDone),
|
||||
rpcFail(&UnpinMessageBox::unpinFail));
|
||||
}
|
||||
|
||||
void UnpinMessageBox::hideMessage() {
|
||||
if (_requestId) return;
|
||||
|
||||
auto hidden = HistoryWidget::switchPinnedHidden(_peer, true);
|
||||
if (hidden) {
|
||||
Notify::peerUpdatedDelayed(
|
||||
_peer,
|
||||
Notify::PeerUpdate::Flag::PinnedMessageChanged);
|
||||
}
|
||||
Ui::hideLayer();
|
||||
}
|
||||
|
||||
void UnpinMessageBox::unpinDone(const MTPUpdates &updates) {
|
||||
_peer->session().api().applyUpdates(updates);
|
||||
Ui::hideLayer();
|
||||
}
|
||||
|
||||
bool UnpinMessageBox::unpinFail(const RPCError &error) {
|
||||
if (MTP::isDefaultHandledError(error)) return false;
|
||||
Ui::hideLayer();
|
||||
return true;
|
||||
}
|
||||
|
||||
DeleteMessagesBox::DeleteMessagesBox(
|
||||
QWidget*,
|
||||
not_null<HistoryItem*> item,
|
||||
|
@ -149,6 +149,30 @@ private:
|
||||
|
||||
};
|
||||
|
||||
class UnpinMessageBox : public Ui::BoxContent, public RPCSender {
|
||||
public:
|
||||
UnpinMessageBox(QWidget*, not_null<PeerData*> peer);
|
||||
|
||||
protected:
|
||||
void prepare() override;
|
||||
|
||||
void resizeEvent(QResizeEvent *e) override;
|
||||
void keyPressEvent(QKeyEvent *e) override;
|
||||
|
||||
private:
|
||||
void unpinMessage();
|
||||
void hideMessage();
|
||||
void unpinDone(const MTPUpdates &updates);
|
||||
bool unpinFail(const RPCError &error);
|
||||
|
||||
not_null<PeerData*> _peer;
|
||||
|
||||
object_ptr<Ui::FlatLabel> _text;
|
||||
|
||||
mtpRequestId _requestId = 0;
|
||||
|
||||
};
|
||||
|
||||
class DeleteMessagesBox : public Ui::BoxContent, public RPCSender {
|
||||
public:
|
||||
DeleteMessagesBox(
|
||||
|
@ -6187,21 +6187,7 @@ void HistoryWidget::unpinMessage(FullMsgId itemId) {
|
||||
return;
|
||||
}
|
||||
|
||||
Ui::show(Box<ConfirmBox>(tr::lng_pinned_unpin_sure(tr::now), tr::lng_pinned_unpin(tr::now), crl::guard(this, [=] {
|
||||
peer->clearPinnedMessage();
|
||||
|
||||
Ui::hideLayer();
|
||||
MTP::send(
|
||||
MTPmessages_UpdatePinnedMessage(
|
||||
MTP_flags(0),
|
||||
peer->input,
|
||||
MTP_int(0)),
|
||||
rpcDone(&HistoryWidget::unpinDone));
|
||||
})));
|
||||
}
|
||||
|
||||
void HistoryWidget::unpinDone(const MTPUpdates &updates) {
|
||||
session().api().applyUpdates(updates);
|
||||
Ui::show(Box<UnpinMessageBox>(peer));
|
||||
}
|
||||
|
||||
void HistoryWidget::hidePinnedMessage(bool force) {
|
||||
|
@ -540,7 +540,6 @@ private:
|
||||
void updatePinnedBar(bool force = false);
|
||||
bool pinnedMsgVisibilityUpdated();
|
||||
void destroyPinnedBar();
|
||||
void unpinDone(const MTPUpdates &updates);
|
||||
|
||||
void sendInlineResult(
|
||||
not_null<InlineBots::Result*> result,
|
||||
|
Loading…
x
Reference in New Issue
Block a user