2
0
mirror of https://github.com/kotatogram/kotatogram-desktop synced 2025-08-27 04:47:10 +00:00

83 lines
2.3 KiB
C++
Raw Normal View History

2020-04-21 08:56:15 +03:00
/*
This file is part of Kotatogram Desktop,
the unofficial app based on Telegram Desktop.
For license and copyright information please follow this link:
https://github.com/kotatogram/kotatogram-desktop/blob/dev/LEGAL
*/
2021-08-25 01:09:37 +03:00
#include "kotato/boxes/kotato_unpin_box.h"
2020-04-21 08:56:15 +03:00
2021-08-24 14:01:27 +03:00
#include "kotato/kotato_lang.h"
2020-04-21 08:56:15 +03:00
#include "lang/lang_keys.h"
#include "apiwrap.h"
#include "history/history_widget.h"
#include "ui/widgets/labels.h"
#include "data/data_channel.h"
#include "data/data_chat.h"
#include "data/data_changes.h"
2020-04-21 08:56:15 +03:00
#include "data/data_user.h"
#include "main/main_session.h"
#include "styles/style_layers.h"
#include "styles/style_boxes.h"
UnpinMessageBox::UnpinMessageBox(
QWidget*,
2020-11-09 05:04:24 +03:00
not_null<PeerData*> peer,
MsgId msgId)
2020-04-21 08:56:15 +03:00
: _peer(peer)
, _api(&peer->session().mtp())
2020-11-09 05:04:24 +03:00
, _msgId(msgId)
2020-04-21 08:56:15 +03:00
, _text(this, tr::lng_pinned_unpin_sure(tr::now), st::boxLabel) {
}
void UnpinMessageBox::prepare() {
2021-08-24 14:01:27 +03:00
addLeftButton(rktr("ktg_hide_pinned_message"), [this] { hideMessage(); });
2020-04-21 08:56:15 +03:00
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;
//auto flags = MTPmessages_UpdatePinnedMessage::Flags(0);
_requestId = _api.request(MTPmessages_UpdatePinnedMessage(
2020-11-09 05:04:24 +03:00
MTP_flags(MTPmessages_UpdatePinnedMessage::Flag::f_unpin),
_peer->input,
2020-11-09 05:04:24 +03:00
MTP_int(_msgId)
)).done([=](const MTPUpdates &result) {
_peer->session().api().applyUpdates(result);
Ui::hideLayer();
}).fail([=](const MTP::Error &error) {
Ui::hideLayer();
}).send();
2020-04-21 08:56:15 +03:00
}
void UnpinMessageBox::hideMessage() {
if (_requestId) return;
auto hidden = HistoryWidget::switchPinnedHidden(_peer, true);
2020-12-29 05:14:15 +03:00
if (hidden) {
_peer->session().changes().peerUpdated(_peer, Data::PeerUpdate::Flag::PinnedMessages);
}
2020-04-21 08:56:15 +03:00
Ui::hideLayer();
}