mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
fix: reduce CPU usage for TTL messages & refactor
This commit is contained in:
parent
3243f57fd5
commit
4327fd4c58
7 changed files with 38 additions and 31 deletions
|
@ -44,6 +44,8 @@ void map(not_null<HistoryItem*> item, AyuMessageBase &message) {
|
||||||
message.fromId = item->from()->id.value & PeerId::kChatTypeMask;
|
message.fromId = item->from()->id.value & PeerId::kChatTypeMask;
|
||||||
if (item->topic()) {
|
if (item->topic()) {
|
||||||
message.topicId = item->topicRootId().bare;
|
message.topicId = item->topicRootId().bare;
|
||||||
|
} else {
|
||||||
|
message.topicId = 0;
|
||||||
}
|
}
|
||||||
message.messageId = item->id.bare;
|
message.messageId = item->id.bare;
|
||||||
message.date = item->date();
|
message.date = item->date();
|
||||||
|
|
|
@ -702,7 +702,7 @@ void InnerWidget::addMessages(Direction direction, const std::vector<AyuMessageB
|
||||||
? message.fakeId // viewing edited history
|
? message.fakeId // viewing edited history
|
||||||
: message.messageId; // viewing deleted messages
|
: message.messageId; // viewing deleted messages
|
||||||
if (_messageIds.find(id) != _messageIds.end()) {
|
if (_messageIds.find(id) != _messageIds.end()) {
|
||||||
return;
|
continue;
|
||||||
}
|
}
|
||||||
auto count = 0;
|
auto count = 0;
|
||||||
const auto addOne = [&](
|
const auto addOne = [&](
|
||||||
|
|
|
@ -36,6 +36,7 @@
|
||||||
|
|
||||||
#include "ayu/ayu_settings.h"
|
#include "ayu/ayu_settings.h"
|
||||||
#include "ayu/ayu_state.h"
|
#include "ayu/ayu_state.h"
|
||||||
|
#include "ayu/data/messages_storage.h"
|
||||||
|
|
||||||
Main::Session *getSession(ID userId) {
|
Main::Session *getSession(ID userId) {
|
||||||
for (const auto &[index, account] : Core::App().domain().accounts()) {
|
for (const auto &[index, account] : Core::App().domain().accounts()) {
|
||||||
|
@ -503,6 +504,28 @@ int getScheduleTime(int64 sumSize) {
|
||||||
return time;
|
return time;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool isMessageSavable(const not_null<HistoryItem *> item) {
|
||||||
|
const auto settings = &AyuSettings::getInstance();
|
||||||
|
|
||||||
|
if (!settings->saveDeletedMessages) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (const auto possiblyBot = item->history()->peer->asUser()) {
|
||||||
|
return !possiblyBot->isBot() || (settings->saveForBots && possiblyBot->isBot());
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void processMessageDelete(not_null<HistoryItem*> item) {
|
||||||
|
if (!isMessageSavable(item)) {
|
||||||
|
item->destroy();
|
||||||
|
} else {
|
||||||
|
item->setDeleted();
|
||||||
|
AyuMessages::addDeletedMessage(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void resolveUser(ID userId, const QString &username, Main::Session *session, const Callback &callback) {
|
void resolveUser(ID userId, const QString &username, Main::Session *session, const Callback &callback) {
|
||||||
auto normalized = username.trimmed().toLower();
|
auto normalized = username.trimmed().toLower();
|
||||||
if (normalized.isEmpty()) {
|
if (normalized.isEmpty()) {
|
||||||
|
|
|
@ -48,6 +48,9 @@ QString getPeerDC(not_null<PeerData*> peer);
|
||||||
|
|
||||||
int getScheduleTime(int64 sumSize);
|
int getScheduleTime(int64 sumSize);
|
||||||
|
|
||||||
|
bool isMessageSavable(not_null<HistoryItem *> item);
|
||||||
|
void processMessageDelete(not_null<HistoryItem *> item);
|
||||||
|
|
||||||
void searchById(ID userId, Main::Session *session, bool retry, const Callback &callback);
|
void searchById(ID userId, Main::Session *session, bool retry, const Callback &callback);
|
||||||
void searchById(ID userId, Main::Session *session, const Callback &callback);
|
void searchById(ID userId, Main::Session *session, const Callback &callback);
|
||||||
|
|
||||||
|
|
|
@ -83,8 +83,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
|
|
||||||
// AyuGram includes
|
// AyuGram includes
|
||||||
#include "ayu/ayu_settings.h"
|
#include "ayu/ayu_settings.h"
|
||||||
#include "ayu/ayu_state.h"
|
|
||||||
#include "ayu/data/messages_storage.h"
|
#include "ayu/data/messages_storage.h"
|
||||||
|
#include "ayu/utils/telegram_helpers.h"
|
||||||
|
|
||||||
|
|
||||||
namespace Data {
|
namespace Data {
|
||||||
|
@ -215,19 +215,6 @@ void CheckForSwitchInlineButton(not_null<HistoryItem*> item) {
|
||||||
double(std::numeric_limits<int>::max())));
|
double(std::numeric_limits<int>::max())));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NeedSaveMessage(not_null<HistoryItem *> item) {
|
|
||||||
const auto settings = &AyuSettings::getInstance();
|
|
||||||
|
|
||||||
if (!settings->saveDeletedMessages) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (const auto possiblyBot = item->history()->peer->asUser()) {
|
|
||||||
return !possiblyBot->isBot() || (settings->saveForBots && possiblyBot->isBot());
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
Session::Session(not_null<Main::Session*> session)
|
Session::Session(not_null<Main::Session*> session)
|
||||||
|
@ -2566,7 +2553,10 @@ void Session::checkTTLs() {
|
||||||
return pair.second;
|
return pair.second;
|
||||||
}) | ranges::views::join;
|
}) | ranges::views::join;
|
||||||
for (auto &item : toBeRemoved) {
|
for (auto &item : toBeRemoved) {
|
||||||
item->setDeleted();
|
// remove message from `_ttlMessages` to avoid calling this method infinitely
|
||||||
|
item->applyTTL(0);
|
||||||
|
|
||||||
|
processMessageDelete(item);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
while (!_ttlMessages.empty() && _ttlMessages.begin()->first <= now) {
|
while (!_ttlMessages.empty() && _ttlMessages.begin()->first <= now) {
|
||||||
|
@ -2591,12 +2581,7 @@ void Session::processMessagesDeleted(
|
||||||
if (list && i != list->end()) {
|
if (list && i != list->end()) {
|
||||||
const auto history = i->second->history();
|
const auto history = i->second->history();
|
||||||
|
|
||||||
if (!NeedSaveMessage(i->second)) {
|
processMessageDelete(i->second);
|
||||||
i->second->destroy();
|
|
||||||
} else {
|
|
||||||
i->second->setDeleted();
|
|
||||||
AyuMessages::addDeletedMessage(i->second);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!history->chatListMessageKnown()) {
|
if (!history->chatListMessageKnown()) {
|
||||||
historiesToCheck.emplace(history);
|
historiesToCheck.emplace(history);
|
||||||
|
@ -2616,12 +2601,7 @@ void Session::processNonChannelMessagesDeleted(const QVector<MTPint> &data) {
|
||||||
if (const auto item = nonChannelMessage(messageId.v)) {
|
if (const auto item = nonChannelMessage(messageId.v)) {
|
||||||
const auto history = item->history();
|
const auto history = item->history();
|
||||||
|
|
||||||
if (!NeedSaveMessage(item)) {
|
processMessageDelete(item);
|
||||||
item->destroy();
|
|
||||||
} else {
|
|
||||||
item->setDeleted();
|
|
||||||
AyuMessages::addDeletedMessage(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!history->chatListMessageKnown()) {
|
if (!history->chatListMessageKnown()) {
|
||||||
historiesToCheck.emplace(history);
|
historiesToCheck.emplace(history);
|
||||||
|
|
|
@ -3093,7 +3093,7 @@ bool HistoryItem::isDeleted() const {
|
||||||
|
|
||||||
void HistoryItem::setAyuHint(const QString &hint) {
|
void HistoryItem::setAyuHint(const QString &hint) {
|
||||||
try {
|
try {
|
||||||
if (isService()) {
|
if (isService() && !_text.empty()) {
|
||||||
const auto data = Get<HistoryServiceData>();
|
const auto data = Get<HistoryServiceData>();
|
||||||
const auto postfix = QString(" (%1)").arg(hint);
|
const auto postfix = QString(" (%1)").arg(hint);
|
||||||
if (!_text.text.endsWith(postfix)) { // fix stacking for TTL messages
|
if (!_text.text.endsWith(postfix)) { // fix stacking for TTL messages
|
||||||
|
|
|
@ -420,6 +420,7 @@ public:
|
||||||
void setPostAuthor(const QString &author);
|
void setPostAuthor(const QString &author);
|
||||||
void setDeleted();
|
void setDeleted();
|
||||||
bool isDeleted() const;
|
bool isDeleted() const;
|
||||||
|
void applyTTL(TimeId destroyAt);
|
||||||
void setAyuHint(const QString &hint);
|
void setAyuHint(const QString &hint);
|
||||||
void setRealId(MsgId newId);
|
void setRealId(MsgId newId);
|
||||||
void incrementReplyToTopCounter();
|
void incrementReplyToTopCounter();
|
||||||
|
@ -652,8 +653,6 @@ private:
|
||||||
void applyTTL(const MTPDmessage &data);
|
void applyTTL(const MTPDmessage &data);
|
||||||
void applyTTL(const MTPDmessageService &data);
|
void applyTTL(const MTPDmessageService &data);
|
||||||
|
|
||||||
void applyTTL(TimeId destroyAt);
|
|
||||||
|
|
||||||
// For an invoice button we replace the button text with a "Receipt" key.
|
// For an invoice button we replace the button text with a "Receipt" key.
|
||||||
// It should show the receipt for the payed invoice. Still let mobile apps do that.
|
// It should show the receipt for the payed invoice. Still let mobile apps do that.
|
||||||
void replaceBuyWithReceiptInMarkup();
|
void replaceBuyWithReceiptInMarkup();
|
||||||
|
|
Loading…
Add table
Reference in a new issue