[Improvement] Hiding and showing pinned messages
This commit is contained in:
parent
c8a1fff6d7
commit
ae26dbe21b
9 changed files with 211 additions and 25 deletions
|
|
@ -849,6 +849,8 @@ PRIVATE
|
||||||
kotato/boxes/kotato_fonts_box.h
|
kotato/boxes/kotato_fonts_box.h
|
||||||
kotato/boxes/kotato_radio_box.cpp
|
kotato/boxes/kotato_radio_box.cpp
|
||||||
kotato/boxes/kotato_radio_box.h
|
kotato/boxes/kotato_radio_box.h
|
||||||
|
kotato/boxes/kotato_unpin_box.cpp
|
||||||
|
kotato/boxes/kotato_unpin_box.h
|
||||||
kotato/kotato_lang.cpp
|
kotato/kotato_lang.cpp
|
||||||
kotato/kotato_lang.h
|
kotato/kotato_lang.h
|
||||||
kotato/kotato_settings.cpp
|
kotato/kotato_settings.cpp
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,8 @@
|
||||||
"ktg_settings_show_json_settings": "Show settings file",
|
"ktg_settings_show_json_settings": "Show settings file",
|
||||||
"ktg_settings_restart": "Restart Kotatogram",
|
"ktg_settings_restart": "Restart Kotatogram",
|
||||||
"ktg_copy_btn_callback": "Copy callback data",
|
"ktg_copy_btn_callback": "Copy callback data",
|
||||||
|
"ktg_pinned_message_show": "Show pinned message",
|
||||||
|
"ktg_pinned_message_hide": "Hide pinned message",
|
||||||
"ktg_settings_chats": "Chats",
|
"ktg_settings_chats": "Chats",
|
||||||
"ktg_settings_sticker_height": "Sticker height: {pixels}px",
|
"ktg_settings_sticker_height": "Sticker height: {pixels}px",
|
||||||
"ktg_settings_sticker_scale_both": "Apply to sticker width",
|
"ktg_settings_sticker_scale_both": "Apply to sticker width",
|
||||||
|
|
@ -97,6 +99,7 @@
|
||||||
"ktg_settings_top_bar_mute": "Mute in profile top bar",
|
"ktg_settings_top_bar_mute": "Mute in profile top bar",
|
||||||
"ktg_settings_messages": "Messages",
|
"ktg_settings_messages": "Messages",
|
||||||
"ktg_settings_filters_hide_all": "Hide \"All chats\" folder",
|
"ktg_settings_filters_hide_all": "Hide \"All chats\" folder",
|
||||||
|
"ktg_hide_pinned_message": "Hide",
|
||||||
"ktg_settings_userpic_rounding": "Profile pictures rounding",
|
"ktg_settings_userpic_rounding": "Profile pictures rounding",
|
||||||
"ktg_settings_userpic_rounding_none": "Square",
|
"ktg_settings_userpic_rounding_none": "Square",
|
||||||
"ktg_settings_userpic_rounding_small": "Small",
|
"ktg_settings_userpic_rounding_small": "Small",
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "mainwidget.h"
|
#include "mainwidget.h"
|
||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
#include "main/main_session.h"
|
#include "main/main_session.h"
|
||||||
|
#include "main/main_session_settings.h"
|
||||||
#include "window/notifications_manager.h"
|
#include "window/notifications_manager.h"
|
||||||
#include "calls/calls_instance.h"
|
#include "calls/calls_instance.h"
|
||||||
#include "storage/localstorage.h"
|
#include "storage/localstorage.h"
|
||||||
|
|
@ -3203,6 +3204,57 @@ void History::setHasPinnedMessages(bool has) {
|
||||||
session().changes().historyUpdated(this, UpdateFlag::PinnedMessages);
|
session().changes().historyUpdated(this, UpdateFlag::PinnedMessages);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool History::hasHiddenPinnedMessage() {
|
||||||
|
auto result = false;
|
||||||
|
const auto migrated = peer->migrateFrom();
|
||||||
|
const auto currentPinnedId = Data::ResolveTopPinnedId(peer, migrated);
|
||||||
|
const auto universalPinnedId = !currentPinnedId
|
||||||
|
? int32(0)
|
||||||
|
: (migrated && !peerIsChannel(currentPinnedId.peer))
|
||||||
|
? (currentPinnedId.msg - ServerMaxMsgId)
|
||||||
|
: currentPinnedId.msg;
|
||||||
|
if (universalPinnedId) {
|
||||||
|
const auto hiddenId = session().settings().hiddenPinnedMessageId(peer->id);
|
||||||
|
if (hiddenId == universalPinnedId) {
|
||||||
|
result = true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
session().api().requestFullPeer(peer);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool History::switchPinnedHidden(bool hidden) {
|
||||||
|
auto result = false;
|
||||||
|
if (hidden) {
|
||||||
|
const auto migrated = peer->migrateFrom();
|
||||||
|
const auto currentPinnedId = Data::ResolveTopPinnedId(peer, migrated);
|
||||||
|
const auto universalPinnedId = !currentPinnedId
|
||||||
|
? int32(0)
|
||||||
|
: (migrated && !peerIsChannel(currentPinnedId.peer))
|
||||||
|
? (currentPinnedId.msg - ServerMaxMsgId)
|
||||||
|
: currentPinnedId.msg;
|
||||||
|
if (universalPinnedId) {
|
||||||
|
session().settings().setHiddenPinnedMessageId(peer->id, universalPinnedId);
|
||||||
|
session().saveSettingsDelayed();
|
||||||
|
result = true;
|
||||||
|
} else {
|
||||||
|
session().api().requestFullPeer(peer);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
const auto hiddenId = session().settings().hiddenPinnedMessageId(peer->id);
|
||||||
|
if (hiddenId != 0) {
|
||||||
|
session().settings().setHiddenPinnedMessageId(peer->id, 0);
|
||||||
|
session().saveSettingsDelayed();
|
||||||
|
result = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (result) {
|
||||||
|
session().changes().historyUpdated(this, UpdateFlag::PinnedMessages);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
History::~History() = default;
|
History::~History() = default;
|
||||||
|
|
||||||
HistoryBlock::HistoryBlock(not_null<History*> history)
|
HistoryBlock::HistoryBlock(not_null<History*> history)
|
||||||
|
|
|
||||||
|
|
@ -464,6 +464,9 @@ public:
|
||||||
[[nodiscard]] bool hasPinnedMessages() const;
|
[[nodiscard]] bool hasPinnedMessages() const;
|
||||||
void setHasPinnedMessages(bool has);
|
void setHasPinnedMessages(bool has);
|
||||||
|
|
||||||
|
bool hasHiddenPinnedMessage();
|
||||||
|
bool switchPinnedHidden(bool hidden);
|
||||||
|
|
||||||
// Still public data.
|
// Still public data.
|
||||||
std::deque<std::unique_ptr<HistoryBlock>> blocks;
|
std::deque<std::unique_ptr<HistoryBlock>> blocks;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6518,9 +6518,7 @@ void HistoryWidget::checkPinnedBarState() {
|
||||||
Expects(_pinnedTracker != nullptr);
|
Expects(_pinnedTracker != nullptr);
|
||||||
Expects(_list != nullptr);
|
Expects(_list != nullptr);
|
||||||
|
|
||||||
const auto hiddenId = _peer->canPinMessages()
|
const auto hiddenId = session().settings().hiddenPinnedMessageId(_peer->id);
|
||||||
? MsgId(0)
|
|
||||||
: session().settings().hiddenPinnedMessageId(_peer->id);
|
|
||||||
const auto currentPinnedId = Data::ResolveTopPinnedId(
|
const auto currentPinnedId = Data::ResolveTopPinnedId(
|
||||||
_peer,
|
_peer,
|
||||||
_migrated ? _migrated->peer.get() : nullptr);
|
_migrated ? _migrated->peer.get() : nullptr);
|
||||||
|
|
@ -6703,7 +6701,11 @@ void HistoryWidget::refreshPinnedBarButton(bool many, HistoryItem *item) {
|
||||||
button->clicks(
|
button->clicks(
|
||||||
) | rpl::start_with_next([=] {
|
) | rpl::start_with_next([=] {
|
||||||
if (close) {
|
if (close) {
|
||||||
hidePinnedMessage();
|
// if (button->clickModifiers() & Qt::ControlModifier) {
|
||||||
|
// hidePinnedMessage(true);
|
||||||
|
// } else {
|
||||||
|
hidePinnedMessage();
|
||||||
|
// }
|
||||||
} else {
|
} else {
|
||||||
const auto id = _pinnedTracker->currentMessageId();
|
const auto id = _pinnedTracker->currentMessageId();
|
||||||
if (id.message) {
|
if (id.message) {
|
||||||
|
|
@ -7090,14 +7092,14 @@ void HistoryWidget::editMessage(not_null<HistoryItem*> item) {
|
||||||
_field->setFocus();
|
_field->setFocus();
|
||||||
}
|
}
|
||||||
|
|
||||||
void HistoryWidget::hidePinnedMessage() {
|
void HistoryWidget::hidePinnedMessage(bool force) {
|
||||||
Expects(_pinnedBar != nullptr);
|
Expects(_pinnedBar != nullptr);
|
||||||
|
|
||||||
const auto id = _pinnedTracker->currentMessageId();
|
const auto id = _pinnedTracker->currentMessageId();
|
||||||
if (!id.message) {
|
if (!id.message) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (_peer->canPinMessages()) {
|
if (_peer->canPinMessages() && !force) {
|
||||||
Window::ToggleMessagePinned(controller(), id.message, false);
|
Window::ToggleMessagePinned(controller(), id.message, false);
|
||||||
} else {
|
} else {
|
||||||
const auto callback = [=] {
|
const auto callback = [=] {
|
||||||
|
|
|
||||||
|
|
@ -397,7 +397,7 @@ private:
|
||||||
void reportSelectedMessages();
|
void reportSelectedMessages();
|
||||||
void toggleKeyboard(bool manual = true);
|
void toggleKeyboard(bool manual = true);
|
||||||
void startBotCommand();
|
void startBotCommand();
|
||||||
void hidePinnedMessage();
|
void hidePinnedMessage(bool force = false);
|
||||||
void cancelFieldAreaState();
|
void cancelFieldAreaState();
|
||||||
void unblockUser();
|
void unblockUser();
|
||||||
void sendBotStartCommand();
|
void sendBotStartCommand();
|
||||||
|
|
|
||||||
80
Telegram/SourceFiles/kotato/boxes/kotato_unpin_box.cpp
Normal file
80
Telegram/SourceFiles/kotato/boxes/kotato_unpin_box.cpp
Normal file
|
|
@ -0,0 +1,80 @@
|
||||||
|
/*
|
||||||
|
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
|
||||||
|
*/
|
||||||
|
#include "kotato/boxes/kotato_unpin_box.h"
|
||||||
|
|
||||||
|
#include "kotato/kotato_lang.h"
|
||||||
|
#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"
|
||||||
|
#include "data/data_user.h"
|
||||||
|
#include "data/data_session.h"
|
||||||
|
#include "main/main_session.h"
|
||||||
|
#include "styles/style_layers.h"
|
||||||
|
#include "styles/style_boxes.h"
|
||||||
|
|
||||||
|
UnpinMessageBox::UnpinMessageBox(
|
||||||
|
QWidget*,
|
||||||
|
not_null<PeerData*> peer,
|
||||||
|
MsgId msgId)
|
||||||
|
: _peer(peer)
|
||||||
|
, _api(&peer->session().mtp())
|
||||||
|
, _msgId(msgId)
|
||||||
|
, _text(this, tr::lng_pinned_unpin_sure(tr::now), st::boxLabel) {
|
||||||
|
}
|
||||||
|
|
||||||
|
void UnpinMessageBox::prepare() {
|
||||||
|
addLeftButton(rktr("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;
|
||||||
|
|
||||||
|
//auto flags = MTPmessages_UpdatePinnedMessage::Flags(0);
|
||||||
|
_requestId = _api.request(MTPmessages_UpdatePinnedMessage(
|
||||||
|
MTP_flags(MTPmessages_UpdatePinnedMessage::Flag::f_unpin),
|
||||||
|
_peer->input,
|
||||||
|
MTP_int(_msgId)
|
||||||
|
)).done([=](const MTPUpdates &result) {
|
||||||
|
_peer->session().api().applyUpdates(result);
|
||||||
|
Ui::hideLayer();
|
||||||
|
}).fail([=](const MTP::Error &error) {
|
||||||
|
Ui::hideLayer();
|
||||||
|
}).send();
|
||||||
|
}
|
||||||
|
|
||||||
|
void UnpinMessageBox::hideMessage() {
|
||||||
|
if (_requestId) return;
|
||||||
|
|
||||||
|
_peer->owner().history(_peer)->switchPinnedHidden(true);
|
||||||
|
Ui::hideLayer();
|
||||||
|
}
|
||||||
39
Telegram/SourceFiles/kotato/boxes/kotato_unpin_box.h
Normal file
39
Telegram/SourceFiles/kotato/boxes/kotato_unpin_box.h
Normal file
|
|
@ -0,0 +1,39 @@
|
||||||
|
/*
|
||||||
|
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
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "boxes/abstract_box.h"
|
||||||
|
#include "mtproto/sender.h"
|
||||||
|
|
||||||
|
namespace Ui {
|
||||||
|
class FlatLabel;
|
||||||
|
} // namespace Ui
|
||||||
|
|
||||||
|
class UnpinMessageBox final : public Ui::BoxContent {
|
||||||
|
public:
|
||||||
|
UnpinMessageBox(QWidget*, not_null<PeerData*> peer, MsgId msgId);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void prepare() override;
|
||||||
|
|
||||||
|
void resizeEvent(QResizeEvent *e) override;
|
||||||
|
void keyPressEvent(QKeyEvent *e) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
void unpinMessage();
|
||||||
|
void hideMessage();
|
||||||
|
|
||||||
|
const not_null<PeerData*> _peer;
|
||||||
|
MTP::Sender _api;
|
||||||
|
MsgId _msgId = 0;
|
||||||
|
|
||||||
|
object_ptr<Ui::FlatLabel> _text;
|
||||||
|
|
||||||
|
mtpRequestId _requestId = 0;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
@ -8,9 +8,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "window/window_peer_menu.h"
|
#include "window/window_peer_menu.h"
|
||||||
|
|
||||||
#include "kotato/kotato_settings.h"
|
#include "kotato/kotato_settings.h"
|
||||||
|
#include "kotato/kotato_lang.h"
|
||||||
#include "api/api_chat_participants.h"
|
#include "api/api_chat_participants.h"
|
||||||
#include "lang/lang_keys.h"
|
#include "lang/lang_keys.h"
|
||||||
#include "ui/boxes/confirm_box.h"
|
|
||||||
#include "base/options.h"
|
#include "base/options.h"
|
||||||
#include "base/unixtime.h"
|
#include "base/unixtime.h"
|
||||||
#include "boxes/delete_messages_box.h"
|
#include "boxes/delete_messages_box.h"
|
||||||
|
|
@ -26,6 +26,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "boxes/peers/add_participants_box.h"
|
#include "boxes/peers/add_participants_box.h"
|
||||||
#include "boxes/peers/edit_contact_box.h"
|
#include "boxes/peers/edit_contact_box.h"
|
||||||
#include "boxes/share_box.h"
|
#include "boxes/share_box.h"
|
||||||
|
#include "kotato/boxes/kotato_unpin_box.h"
|
||||||
|
#include "ui/boxes/confirm_box.h"
|
||||||
#include "ui/boxes/report_box.h"
|
#include "ui/boxes/report_box.h"
|
||||||
#include "ui/toast/toast.h"
|
#include "ui/toast/toast.h"
|
||||||
#include "ui/text/format_values.h"
|
#include "ui/text/format_values.h"
|
||||||
|
|
@ -212,6 +214,7 @@ private:
|
||||||
void addBotToGroup();
|
void addBotToGroup();
|
||||||
void addNewMembers();
|
void addNewMembers();
|
||||||
void addDeleteContact();
|
void addDeleteContact();
|
||||||
|
void addHidePin();
|
||||||
void addTTLSubmenu(bool addSeparator);
|
void addTTLSubmenu(bool addSeparator);
|
||||||
void addGiftPremium();
|
void addGiftPremium();
|
||||||
|
|
||||||
|
|
@ -744,6 +747,23 @@ void Filler::addDeleteContact() {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Filler::addHidePin() {
|
||||||
|
const auto history = _peer->owner().history(_peer);
|
||||||
|
if (history->hasPinnedMessages()) {
|
||||||
|
if (history->hasHiddenPinnedMessage()) {
|
||||||
|
_addAction(
|
||||||
|
ktr("ktg_pinned_message_show"),
|
||||||
|
[=] { history->switchPinnedHidden(false); },
|
||||||
|
&st::menuIconPin);
|
||||||
|
} else {
|
||||||
|
_addAction(
|
||||||
|
ktr("ktg_pinned_message_hide"),
|
||||||
|
[=] { history->switchPinnedHidden(true); },
|
||||||
|
&st::menuIconUnpin);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Filler::addManageChat() {
|
void Filler::addManageChat() {
|
||||||
if (!EditPeerInfoBox::Available(_peer)) {
|
if (!EditPeerInfoBox::Available(_peer)) {
|
||||||
return;
|
return;
|
||||||
|
|
@ -883,6 +903,7 @@ void Filler::fillHistoryActions() {
|
||||||
addToggleMuteSubmenu(true);
|
addToggleMuteSubmenu(true);
|
||||||
addInfo();
|
addInfo();
|
||||||
addSupportInfo();
|
addSupportInfo();
|
||||||
|
addHidePin();
|
||||||
addManageChat();
|
addManageChat();
|
||||||
addCreatePoll();
|
addCreatePoll();
|
||||||
addThemeEdit();
|
addThemeEdit();
|
||||||
|
|
@ -1625,24 +1646,8 @@ void ToggleMessagePinned(
|
||||||
Box(PinMessageBox, item->history()->peer, item->id),
|
Box(PinMessageBox, item->history()->peer, item->id),
|
||||||
Ui::LayerOption::CloseOther);
|
Ui::LayerOption::CloseOther);
|
||||||
} else {
|
} else {
|
||||||
const auto peer = item->history()->peer;
|
|
||||||
const auto session = &peer->session();
|
|
||||||
const auto callback = crl::guard(session, [=](Fn<void()> &&close) {
|
|
||||||
close();
|
|
||||||
session->api().request(MTPmessages_UpdatePinnedMessage(
|
|
||||||
MTP_flags(MTPmessages_UpdatePinnedMessage::Flag::f_unpin),
|
|
||||||
peer->input,
|
|
||||||
MTP_int(itemId.msg)
|
|
||||||
)).done([=](const MTPUpdates &result) {
|
|
||||||
session->api().applyUpdates(result);
|
|
||||||
}).send();
|
|
||||||
});
|
|
||||||
navigation->parentController()->show(
|
navigation->parentController()->show(
|
||||||
Ui::MakeConfirmBox({
|
Box<UnpinMessageBox>(item->history()->peer, item->id),
|
||||||
.text = tr::lng_pinned_unpin_sure(),
|
|
||||||
.confirmed = callback,
|
|
||||||
.confirmText = tr::lng_pinned_unpin(),
|
|
||||||
}),
|
|
||||||
Ui::LayerOption::CloseOther);
|
Ui::LayerOption::CloseOther);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue