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
|
|
|
|
*/
|
2020-05-16 20:07:05 +03:00
|
|
|
#include "kotato/customboxes/unpin_box.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"
|
2020-07-01 05:43:07 +03:00
|
|
|
#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)
|
2020-07-01 05:43:07 +03:00
|
|
|
, _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() {
|
|
|
|
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;
|
|
|
|
|
2020-07-01 05:43:07 +03:00
|
|
|
//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),
|
2020-07-01 05:43:07 +03:00
|
|
|
_peer->input,
|
2020-11-09 05:04:24 +03:00
|
|
|
MTP_int(_msgId)
|
2020-07-01 05:43:07 +03:00
|
|
|
)).done([=](const MTPUpdates &result) {
|
|
|
|
_peer->session().api().applyUpdates(result);
|
|
|
|
Ui::hideLayer();
|
|
|
|
}).fail([=](const RPCError &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();
|
|
|
|
}
|