feat: rework sendReadMessages

fix: send read packet manually
fix: send read packet after sending media
This commit is contained in:
ZavaruKitsu 2023-12-01 20:58:00 +03:00
parent bde3caded7
commit 084967354b
9 changed files with 69 additions and 44 deletions

View file

@ -21,7 +21,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "main/main_session.h"
// AyuGram includes
#include "ayu/ayu_state.h"
#include "ayu/ayu_settings.h"
#include "ayu/utils/telegram_helpers.h"
namespace Api {
@ -156,8 +157,7 @@ void Polls::sendVotes(
const auto settings = &AyuSettings::getInstance();
if (!settings->sendReadMessages && settings->markReadAfterPoll && item)
{
AyuState::setAllowSendReadPacket(true);
item->history()->session().data().histories().readInboxOnNewMessage(item);
readHistory(item);
}
}).fail([=] {
_pollVotesRequestIds.erase(itemId);

View file

@ -8,17 +8,4 @@
namespace AyuState
{
void setAllowSendReadPacket(bool val, int resetAfter)
{
allowSendReadPacket.val = val;
allowSendReadPacket.resetAfter = resetAfter;
}
bool getAllowSendPacket()
{
auto settings = &AyuSettings::getInstance();
return settings->sendReadMessages || processVariable(allowSendReadPacket);
}
}

View file

@ -41,8 +41,4 @@ bool processVariable(AyuStateVariable &variable)
}
void setAllowSendReadPacket(bool val, int resetAfter = 1);
bool getAllowSendPacket();
}

View file

@ -16,6 +16,7 @@
#include "ui/widgets/popup_menu.h"
#include "ayu/ui/sections/edited/edited_log_section.h"
#include "ayu/utils/telegram_helpers.h"
namespace AyuUi
@ -53,11 +54,9 @@ void AddReadUntilAction(not_null<Ui::PopupMenu *> menu, HistoryItem *item)
return;
}
const auto history = item->history();
menu->addAction(tr::ayu_ReadUntilMenuText(tr::now), [=]()
{
AyuState::setAllowSendReadPacket(true);
history->session().data().histories().readInboxOnNewMessage(item);
readHistory(item);
}, &st::menuIconShowInChat);
}

View file

@ -10,6 +10,7 @@
#include "api/api_text_entities.h"
#include "data/data_channel.h"
#include "lang_auto.h"
#include "apiwrap.h"
#include "data/data_forum.h"
@ -23,6 +24,7 @@
#include "history/history.h"
#include "history/history_item.h"
#include "history/history_unread_things.h"
#include "data/data_histories.h"
// https://github.com/AyuGram/AyuGram4AX/blob/rewrite/TMessagesProj/src/main/java/com/radolyn/ayugram/AyuConstants.java
std::unordered_set<ID> ayugram_channels = {
@ -32,6 +34,7 @@ std::unordered_set<ID> ayugram_channels = {
1947958814, // @ayugramfun
1815864846, // @ayugramfcm
};
std::unordered_set<ID> ayugram_devs = {
139303278, // @alexeyzavar
778327202, // @sharapagorg
@ -53,6 +56,7 @@ std::unordered_set<ID> extera_channels = {
1516526055, // @moexci
1622008530, // @moe_chat
};
std::unordered_set<ID> extera_devs = {
963080346,
1282540315,
@ -153,7 +157,8 @@ std::pair<std::string, std::string> serializeTextWithEntities(not_null<HistoryIt
return std::make_pair(text, std::string(reinterpret_cast<char *>(buff.data()), buff.size()));
}
ID getBareID(not_null<PeerData *> peer) {
ID getBareID(not_null<PeerData *> peer)
{
return peerIsUser(peer->id)
? peerToUser(peer->id).bare
: peerIsChat(peer->id)
@ -288,7 +293,36 @@ void MarkAsReadThread(not_null<Data::Thread *> thread)
}
}
QString formatTTL(int time) {
void readHistory(not_null<HistoryItem *> message)
{
const auto history = message->history();
const auto tillId = message->id;
history->session().data().histories()
.sendRequest(history, Data::Histories::RequestType::ReadInbox, [=](Fn<void()> finish)
{
if (const auto channel = history->peer->asChannel()) {
return history->session().api().request(MTPchannels_ReadHistory(
channel->inputChannel,
MTP_int(tillId)
)).send();
}
else {
return history->session().api().request(MTPmessages_ReadHistory(
history->peer->input,
MTP_int(tillId)
)).done([=](const MTPmessages_AffectedMessages &result)
{
history->session().api().applyAffectedMessages(history->peer, result);
}).fail([=]
{
}).send();
}
});
}
QString formatTTL(int time)
{
if (time == 0x7FFFFFFF) {
return QString("👀 %1").arg(tr::ayu_OneViewTTL(tr::now));
}

View file

@ -29,4 +29,6 @@ bool isExteraRelated(ID peerId);
void MarkAsReadChatList(not_null<Dialogs::MainList *> list);
void MarkAsReadThread(not_null<Data::Thread *> thread);
void readHistory(not_null<HistoryItem *> message);
QString formatTTL(int time);

View file

@ -249,16 +249,6 @@ void Histories::readInboxTill(
AyuSync::getInstance().syncRead(history, tillId);
// AyuGram sendReadMessages
const auto settings = &AyuSettings::getInstance();
auto allow = settings->sendReadMessages;
auto reallyAllow = AyuState::getAllowSendPacket(); // will return true if `allow`
if (!reallyAllow)
{
DEBUG_LOG(("[AyuGram] Don't read messages"));
return;
}
const auto needsRequest = history->readInboxTillNeedsRequest(tillId);
if (!needsRequest && !force) {
DEBUG_LOG(("Reading: readInboxTill finish 1."));
@ -280,9 +270,8 @@ void Histories::readInboxTill(
sendPendingReadInbox(history);
}
return;
} else if (!needsRequest && (allow != reallyAllow && !force)
&& (!maybeState || !maybeState->willReadTill))
{
} else if (!needsRequest
&& (!maybeState || !maybeState->willReadTill)) {
return;
}
const auto stillUnread = history->countStillUnreadLocal(tillId);
@ -587,6 +576,16 @@ void Histories::sendPendingReadInbox(not_null<History*> history) {
void Histories::sendReadRequests() {
DEBUG_LOG(("Reading: send requests with count %1.").arg(_states.size()));
// AyuGram sendReadMessages
const auto settings = &AyuSettings::getInstance();
if (!settings->sendReadMessages)
{
DEBUG_LOG(("[AyuGram] Don't read messages"));
_states.clear();
return;
}
if (_states.empty()) {
return;
}

View file

@ -31,7 +31,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "styles/style_chat.h"
// AyuGram includes
#include "ayu/ayu_state.h"
#include "ayu/ayu_settings.h"
#include "ayu/utils/telegram_helpers.h"
namespace Data {
@ -838,8 +839,7 @@ void Reactions::send(not_null<HistoryItem*> item, bool addToRecent) {
const auto settings = &AyuSettings::getInstance();
if (!settings->sendReadMessages && settings->markReadAfterReaction && item)
{
AyuState::setAllowSendReadPacket(true);
item->history()->session().data().histories().readInboxOnNewMessage(item);
readHistory(item);
}
}).fail([=](const MTP::Error &error) {
_sentRequests.remove(id);

View file

@ -170,7 +170,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
// AyuGram includes
#include "ayu/ayu_settings.h"
#include "ayu/ayu_state.h"
#include "ayu/utils/telegram_helpers.h"
namespace {
@ -1067,6 +1067,15 @@ void HistoryWidget::initTabbedSelector() {
Data::InsertCustomEmoji(_field.data(), data.document);
}
} else {
const auto settings = &AyuSettings::getInstance();
if (!settings->sendReadMessages && settings->markReadAfterSend) {
const auto lastMessage = history()->lastMessage();
if (lastMessage) {
readHistory(lastMessage);
}
}
controller()->sendingAnimation().appendSending(
data.messageSendingFrom);
const auto localId = data.messageSendingFrom.localId;
@ -3969,8 +3978,7 @@ void HistoryWidget::send(Api::SendOptions options) {
auto lastMessage = _history->lastMessage();
if (!settings->sendReadMessages && settings->markReadAfterSend && lastMessage)
{
AyuState::setAllowSendReadPacket(true);
_history->session().data().histories().readInboxOnNewMessage(lastMessage);
readHistory(lastMessage);
}
if (!_history) {