mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
feat: burn ttl message & display expired status
This commit is contained in:
parent
7c940a0480
commit
ccf8d91f01
6 changed files with 124 additions and 51 deletions
|
@ -34,6 +34,7 @@
|
||||||
#include "data/data_session.h"
|
#include "data/data_session.h"
|
||||||
#include "history/view/history_view_context_menu.h"
|
#include "history/view/history_view_context_menu.h"
|
||||||
#include "history/view/history_view_element.h"
|
#include "history/view/history_view_element.h"
|
||||||
|
#include "window/window_controller.h"
|
||||||
#include "window/window_session_controller.h"
|
#include "window/window_session_controller.h"
|
||||||
|
|
||||||
namespace AyuUi {
|
namespace AyuUi {
|
||||||
|
@ -58,13 +59,14 @@ void AddDeletedMessagesActions(PeerData *peerData,
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
addCallback(tr::ayu_ViewDeletedMenuText(tr::now),
|
addCallback(
|
||||||
[=]
|
tr::ayu_ViewDeletedMenuText(tr::now),
|
||||||
{
|
[=]
|
||||||
sessionController->session().tryResolveWindow()
|
{
|
||||||
->showSection(std::make_shared<MessageHistory::SectionMemento>(peerData, nullptr, topicId));
|
sessionController->session().tryResolveWindow()
|
||||||
},
|
->showSection(std::make_shared<MessageHistory::SectionMemento>(peerData, nullptr, topicId));
|
||||||
&st::menuIconArchive);
|
},
|
||||||
|
&st::menuIconArchive);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AddJumpToBeginningAction(PeerData *peerData,
|
void AddJumpToBeginningAction(PeerData *peerData,
|
||||||
|
@ -149,14 +151,15 @@ void AddJumpToBeginningAction(PeerData *peerData,
|
||||||
|
|
||||||
void AddHistoryAction(not_null<Ui::PopupMenu*> menu, HistoryItem *item) {
|
void AddHistoryAction(not_null<Ui::PopupMenu*> menu, HistoryItem *item) {
|
||||||
if (AyuMessages::hasRevisions(item)) {
|
if (AyuMessages::hasRevisions(item)) {
|
||||||
menu->addAction(tr::ayu_EditsHistoryMenuText(tr::now),
|
menu->addAction(
|
||||||
[=]
|
tr::ayu_EditsHistoryMenuText(tr::now),
|
||||||
{
|
[=]
|
||||||
item->history()->session().tryResolveWindow()
|
{
|
||||||
->showSection(
|
item->history()->session().tryResolveWindow()
|
||||||
std::make_shared<MessageHistory::SectionMemento>(item->history()->peer, item, 0));
|
->showSection(
|
||||||
},
|
std::make_shared<MessageHistory::SectionMemento>(item->history()->peer, item, 0));
|
||||||
&st::ayuEditsHistoryIcon);
|
},
|
||||||
|
&st::ayuEditsHistoryIcon);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -171,15 +174,16 @@ void AddHideMessageAction(not_null<Ui::PopupMenu*> menu, HistoryItem *item) {
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto history = item->history();
|
const auto history = item->history();
|
||||||
menu->addAction(tr::ayu_ContextHideMessage(tr::now),
|
menu->addAction(
|
||||||
[=]()
|
tr::ayu_ContextHideMessage(tr::now),
|
||||||
{
|
[=]()
|
||||||
item->destroy();
|
{
|
||||||
history->requestChatListMessage();
|
item->destroy();
|
||||||
|
history->requestChatListMessage();
|
||||||
|
|
||||||
AyuState::hide(item);
|
AyuState::hide(item);
|
||||||
},
|
},
|
||||||
&st::menuIconClear);
|
&st::menuIconClear);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AddUserMessagesAction(not_null<Ui::PopupMenu*> menu, HistoryItem *item) {
|
void AddUserMessagesAction(not_null<Ui::PopupMenu*> menu, HistoryItem *item) {
|
||||||
|
@ -432,31 +436,77 @@ void AddReadUntilAction(not_null<Ui::PopupMenu*> menu, HistoryItem *item) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
menu->addAction(tr::ayu_ReadUntilMenuText(tr::now),
|
menu->addAction(
|
||||||
[=]()
|
tr::ayu_ReadUntilMenuText(tr::now),
|
||||||
|
[=]()
|
||||||
|
{
|
||||||
|
readHistory(item);
|
||||||
|
if (item->media() && item->media()->ttlSeconds() <= 0 && item->unsupportedTTL() <= 0 && !item->out() && item
|
||||||
|
->isUnreadMedia()) {
|
||||||
|
const auto ids = MTP_vector<MTPint>(1, MTP_int(item->id));
|
||||||
|
if (const auto channel = item->history()->peer->asChannel()) {
|
||||||
|
item->history()->session().api().request(MTPchannels_ReadMessageContents(
|
||||||
|
channel->inputChannel,
|
||||||
|
ids
|
||||||
|
)).send();
|
||||||
|
} else {
|
||||||
|
item->history()->session().api().request(MTPmessages_ReadMessageContents(
|
||||||
|
ids
|
||||||
|
)).done([=](const MTPmessages_AffectedMessages &result)
|
||||||
{
|
{
|
||||||
readHistory(item);
|
item->history()->session().api().applyAffectedMessages(
|
||||||
if (item->media() && !item->media()->ttlSeconds()) {
|
item->history()->peer,
|
||||||
const auto ids = MTP_vector<MTPint>(1, MTP_int(item->id));
|
result);
|
||||||
if (const auto channel = item->history()->peer->asChannel()) {
|
}).send();
|
||||||
item->history()->session().api().request(MTPchannels_ReadMessageContents(
|
}
|
||||||
channel->inputChannel,
|
item->markContentsRead();
|
||||||
ids
|
}
|
||||||
)).send();
|
},
|
||||||
} else {
|
&st::menuIconShowInChat);
|
||||||
item->history()->session().api().request(MTPmessages_ReadMessageContents(
|
}
|
||||||
ids
|
|
||||||
)).done([=](const MTPmessages_AffectedMessages &result)
|
void AddBurnAction(not_null<Ui::PopupMenu*> menu, HistoryItem *item) {
|
||||||
{
|
if (!item->media() || item->media()->ttlSeconds() <= 0 && item->unsupportedTTL() <= 0 || item->out() ||
|
||||||
item->history()->session().api().applyAffectedMessages(
|
!item->isUnreadMedia()) {
|
||||||
item->history()->peer,
|
return;
|
||||||
result);
|
}
|
||||||
}).send();
|
|
||||||
}
|
menu->addAction(
|
||||||
item->markContentsRead();
|
tr::ayu_ExpireMediaContextMenuText(tr::now),
|
||||||
}
|
[=]()
|
||||||
},
|
{
|
||||||
&st::menuIconShowInChat);
|
const auto ids = MTP_vector<MTPint>(1, MTP_int(item->id));
|
||||||
|
const auto callback = [=]()
|
||||||
|
{
|
||||||
|
if (const auto window = Core::App().activeWindow()) {
|
||||||
|
if (const auto controller = window->sessionController()) {
|
||||||
|
controller->showToast(tr::lng_box_ok(tr::now));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if (const auto channel = item->history()->peer->asChannel()) {
|
||||||
|
item->history()->session().api().request(MTPchannels_ReadMessageContents(
|
||||||
|
channel->inputChannel,
|
||||||
|
ids
|
||||||
|
)).done([=]()
|
||||||
|
{
|
||||||
|
callback();
|
||||||
|
}).send();
|
||||||
|
} else {
|
||||||
|
item->history()->session().api().request(MTPmessages_ReadMessageContents(
|
||||||
|
ids
|
||||||
|
)).done([=](const MTPmessages_AffectedMessages &result)
|
||||||
|
{
|
||||||
|
item->history()->session().api().applyAffectedMessages(
|
||||||
|
item->history()->peer,
|
||||||
|
result);
|
||||||
|
callback();
|
||||||
|
}).send();
|
||||||
|
}
|
||||||
|
item->markContentsRead();
|
||||||
|
},
|
||||||
|
&st::menuIconTTLAny);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace AyuUi
|
} // namespace AyuUi
|
||||||
|
|
|
@ -30,5 +30,6 @@ void AddHideMessageAction(not_null<Ui::PopupMenu*> menu, HistoryItem *item);
|
||||||
void AddUserMessagesAction(not_null<Ui::PopupMenu*> menu, HistoryItem *item);
|
void AddUserMessagesAction(not_null<Ui::PopupMenu*> menu, HistoryItem *item);
|
||||||
void AddMessageDetailsAction(not_null<Ui::PopupMenu*> menu, HistoryItem *item);
|
void AddMessageDetailsAction(not_null<Ui::PopupMenu*> menu, HistoryItem *item);
|
||||||
void AddReadUntilAction(not_null<Ui::PopupMenu*> menu, HistoryItem *item);
|
void AddReadUntilAction(not_null<Ui::PopupMenu*> menu, HistoryItem *item);
|
||||||
|
void AddBurnAction(not_null<Ui::PopupMenu*> menu, HistoryItem *item);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2608,6 +2608,7 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) {
|
||||||
}
|
}
|
||||||
|
|
||||||
AyuUi::AddReadUntilAction(_menu, item);
|
AyuUi::AddReadUntilAction(_menu, item);
|
||||||
|
AyuUi::AddBurnAction(_menu, item);
|
||||||
};
|
};
|
||||||
|
|
||||||
const auto addReplyAction = [&](HistoryItem *item) {
|
const auto addReplyAction = [&](HistoryItem *item) {
|
||||||
|
|
|
@ -276,7 +276,7 @@ std::unique_ptr<Data::Media> HistoryItem::CreateMedia(
|
||||||
});
|
});
|
||||||
}, [&](const MTPDmessageMediaPhoto &media) -> Result {
|
}, [&](const MTPDmessageMediaPhoto &media) -> Result {
|
||||||
const auto photo = media.vphoto();
|
const auto photo = media.vphoto();
|
||||||
if (media.vttl_seconds() && false) { // AyuGram: show expiring messages
|
if (false) { // AyuGram: show expiring messages
|
||||||
LOG(("App Error: "
|
LOG(("App Error: "
|
||||||
"Unexpected MTPMessageMediaPhoto "
|
"Unexpected MTPMessageMediaPhoto "
|
||||||
"with ttl_seconds in CreateMedia."));
|
"with ttl_seconds in CreateMedia."));
|
||||||
|
@ -438,6 +438,7 @@ HistoryItem::HistoryItem(
|
||||||
createServiceFromMtp(data);
|
createServiceFromMtp(data);
|
||||||
applyTTL(data);
|
applyTTL(data);
|
||||||
} else {
|
} else {
|
||||||
|
auto skipSetText = false;
|
||||||
createComponents(data);
|
createComponents(data);
|
||||||
if (media) {
|
if (media) {
|
||||||
setMedia(*media);
|
setMedia(*media);
|
||||||
|
@ -445,13 +446,25 @@ HistoryItem::HistoryItem(
|
||||||
media->match(
|
media->match(
|
||||||
[&](const MTPDmessageMediaPhoto &media)
|
[&](const MTPDmessageMediaPhoto &media)
|
||||||
{
|
{
|
||||||
auto time = media.vttl_seconds()->v;
|
if (!data.is_media_unread()) {
|
||||||
|
createServiceFromMtp(data);
|
||||||
|
skipSetText = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto time = media.vttl_seconds()->v;
|
||||||
setAyuHint(formatTTL(time));
|
setAyuHint(formatTTL(time));
|
||||||
|
_unsupportedTTL = time;
|
||||||
},
|
},
|
||||||
[&](const MTPDmessageMediaDocument &media)
|
[&](const MTPDmessageMediaDocument &media)
|
||||||
{
|
{
|
||||||
auto time = media.vttl_seconds()->v;
|
if (!data.is_media_unread()) {
|
||||||
|
createServiceFromMtp(data);
|
||||||
|
skipSetText = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto time = media.vttl_seconds()->v;
|
||||||
setAyuHint(formatTTL(time));
|
setAyuHint(formatTTL(time));
|
||||||
|
_unsupportedTTL = time;
|
||||||
},
|
},
|
||||||
[&](const MTPDmessageMediaWebPage &media)
|
[&](const MTPDmessageMediaWebPage &media)
|
||||||
{
|
{
|
||||||
|
@ -482,7 +495,9 @@ HistoryItem::HistoryItem(
|
||||||
&history->session(),
|
&history->session(),
|
||||||
data.ventities().value_or_empty())
|
data.ventities().value_or_empty())
|
||||||
};
|
};
|
||||||
setText(_media ? textWithEntities : EnsureNonEmpty(textWithEntities));
|
if (!skipSetText) {
|
||||||
|
setText(_media ? textWithEntities : EnsureNonEmpty(textWithEntities));
|
||||||
|
}
|
||||||
if (const auto groupedId = data.vgrouped_id()) {
|
if (const auto groupedId = data.vgrouped_id()) {
|
||||||
setGroupId(
|
setGroupId(
|
||||||
MessageGroupId::FromRaw(
|
MessageGroupId::FromRaw(
|
||||||
|
|
|
@ -566,6 +566,10 @@ public:
|
||||||
[[nodiscard]] bool canUpdateDate() const;
|
[[nodiscard]] bool canUpdateDate() const;
|
||||||
void customEmojiRepaint();
|
void customEmojiRepaint();
|
||||||
|
|
||||||
|
[[nodiscard]] int unsupportedTTL() const {
|
||||||
|
return _unsupportedTTL;
|
||||||
|
}
|
||||||
|
|
||||||
[[nodiscard]] bool needsUpdateForVideoQualities(const MTPMessage &data);
|
[[nodiscard]] bool needsUpdateForVideoQualities(const MTPMessage &data);
|
||||||
|
|
||||||
[[nodiscard]] TimeId ttlDestroyAt() const {
|
[[nodiscard]] TimeId ttlDestroyAt() const {
|
||||||
|
@ -687,6 +691,7 @@ private:
|
||||||
crl::time _reactionsLastRefreshed = 0;
|
crl::time _reactionsLastRefreshed = 0;
|
||||||
|
|
||||||
bool _deleted = false;
|
bool _deleted = false;
|
||||||
|
int _unsupportedTTL = 0;
|
||||||
|
|
||||||
TimeId _date = 0;
|
TimeId _date = 0;
|
||||||
TimeId _ttlDestroyAt = 0;
|
TimeId _ttlDestroyAt = 0;
|
||||||
|
|
|
@ -1044,6 +1044,7 @@ void AddMessageActions(
|
||||||
|
|
||||||
if (request.item) {
|
if (request.item) {
|
||||||
AyuUi::AddReadUntilAction(menu, request.item);
|
AyuUi::AddReadUntilAction(menu, request.item);
|
||||||
|
AyuUi::AddBurnAction(menu, request.item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue