mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 22:54:01 +02:00
feat: rework sendReadMessages
fix: send read packet manually fix: send read packet after sending media
This commit is contained in:
parent
bde3caded7
commit
084967354b
9 changed files with 69 additions and 44 deletions
|
@ -21,7 +21,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "main/main_session.h"
|
#include "main/main_session.h"
|
||||||
|
|
||||||
// AyuGram includes
|
// AyuGram includes
|
||||||
#include "ayu/ayu_state.h"
|
#include "ayu/ayu_settings.h"
|
||||||
|
#include "ayu/utils/telegram_helpers.h"
|
||||||
|
|
||||||
|
|
||||||
namespace Api {
|
namespace Api {
|
||||||
|
@ -156,8 +157,7 @@ void Polls::sendVotes(
|
||||||
const auto settings = &AyuSettings::getInstance();
|
const auto settings = &AyuSettings::getInstance();
|
||||||
if (!settings->sendReadMessages && settings->markReadAfterPoll && item)
|
if (!settings->sendReadMessages && settings->markReadAfterPoll && item)
|
||||||
{
|
{
|
||||||
AyuState::setAllowSendReadPacket(true);
|
readHistory(item);
|
||||||
item->history()->session().data().histories().readInboxOnNewMessage(item);
|
|
||||||
}
|
}
|
||||||
}).fail([=] {
|
}).fail([=] {
|
||||||
_pollVotesRequestIds.erase(itemId);
|
_pollVotesRequestIds.erase(itemId);
|
||||||
|
|
|
@ -8,17 +8,4 @@
|
||||||
|
|
||||||
namespace AyuState
|
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,8 +41,4 @@ bool processVariable(AyuStateVariable &variable)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void setAllowSendReadPacket(bool val, int resetAfter = 1);
|
|
||||||
|
|
||||||
bool getAllowSendPacket();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
#include "ui/widgets/popup_menu.h"
|
#include "ui/widgets/popup_menu.h"
|
||||||
|
|
||||||
#include "ayu/ui/sections/edited/edited_log_section.h"
|
#include "ayu/ui/sections/edited/edited_log_section.h"
|
||||||
|
#include "ayu/utils/telegram_helpers.h"
|
||||||
|
|
||||||
|
|
||||||
namespace AyuUi
|
namespace AyuUi
|
||||||
|
@ -53,11 +54,9 @@ void AddReadUntilAction(not_null<Ui::PopupMenu *> menu, HistoryItem *item)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto history = item->history();
|
|
||||||
menu->addAction(tr::ayu_ReadUntilMenuText(tr::now), [=]()
|
menu->addAction(tr::ayu_ReadUntilMenuText(tr::now), [=]()
|
||||||
{
|
{
|
||||||
AyuState::setAllowSendReadPacket(true);
|
readHistory(item);
|
||||||
history->session().data().histories().readInboxOnNewMessage(item);
|
|
||||||
}, &st::menuIconShowInChat);
|
}, &st::menuIconShowInChat);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
|
|
||||||
#include "api/api_text_entities.h"
|
#include "api/api_text_entities.h"
|
||||||
|
|
||||||
|
#include "data/data_channel.h"
|
||||||
#include "lang_auto.h"
|
#include "lang_auto.h"
|
||||||
#include "apiwrap.h"
|
#include "apiwrap.h"
|
||||||
#include "data/data_forum.h"
|
#include "data/data_forum.h"
|
||||||
|
@ -23,6 +24,7 @@
|
||||||
#include "history/history.h"
|
#include "history/history.h"
|
||||||
#include "history/history_item.h"
|
#include "history/history_item.h"
|
||||||
#include "history/history_unread_things.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
|
// https://github.com/AyuGram/AyuGram4AX/blob/rewrite/TMessagesProj/src/main/java/com/radolyn/ayugram/AyuConstants.java
|
||||||
std::unordered_set<ID> ayugram_channels = {
|
std::unordered_set<ID> ayugram_channels = {
|
||||||
|
@ -32,6 +34,7 @@ std::unordered_set<ID> ayugram_channels = {
|
||||||
1947958814, // @ayugramfun
|
1947958814, // @ayugramfun
|
||||||
1815864846, // @ayugramfcm
|
1815864846, // @ayugramfcm
|
||||||
};
|
};
|
||||||
|
|
||||||
std::unordered_set<ID> ayugram_devs = {
|
std::unordered_set<ID> ayugram_devs = {
|
||||||
139303278, // @alexeyzavar
|
139303278, // @alexeyzavar
|
||||||
778327202, // @sharapagorg
|
778327202, // @sharapagorg
|
||||||
|
@ -53,6 +56,7 @@ std::unordered_set<ID> extera_channels = {
|
||||||
1516526055, // @moexci
|
1516526055, // @moexci
|
||||||
1622008530, // @moe_chat
|
1622008530, // @moe_chat
|
||||||
};
|
};
|
||||||
|
|
||||||
std::unordered_set<ID> extera_devs = {
|
std::unordered_set<ID> extera_devs = {
|
||||||
963080346,
|
963080346,
|
||||||
1282540315,
|
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()));
|
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)
|
return peerIsUser(peer->id)
|
||||||
? peerToUser(peer->id).bare
|
? peerToUser(peer->id).bare
|
||||||
: peerIsChat(peer->id)
|
: 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) {
|
if (time == 0x7FFFFFFF) {
|
||||||
return QString("👀 %1").arg(tr::ayu_OneViewTTL(tr::now));
|
return QString("👀 %1").arg(tr::ayu_OneViewTTL(tr::now));
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,4 +29,6 @@ bool isExteraRelated(ID peerId);
|
||||||
void MarkAsReadChatList(not_null<Dialogs::MainList *> list);
|
void MarkAsReadChatList(not_null<Dialogs::MainList *> list);
|
||||||
void MarkAsReadThread(not_null<Data::Thread *> thread);
|
void MarkAsReadThread(not_null<Data::Thread *> thread);
|
||||||
|
|
||||||
|
void readHistory(not_null<HistoryItem *> message);
|
||||||
|
|
||||||
QString formatTTL(int time);
|
QString formatTTL(int time);
|
||||||
|
|
|
@ -249,16 +249,6 @@ void Histories::readInboxTill(
|
||||||
|
|
||||||
AyuSync::getInstance().syncRead(history, tillId);
|
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);
|
const auto needsRequest = history->readInboxTillNeedsRequest(tillId);
|
||||||
if (!needsRequest && !force) {
|
if (!needsRequest && !force) {
|
||||||
DEBUG_LOG(("Reading: readInboxTill finish 1."));
|
DEBUG_LOG(("Reading: readInboxTill finish 1."));
|
||||||
|
@ -280,9 +270,8 @@ void Histories::readInboxTill(
|
||||||
sendPendingReadInbox(history);
|
sendPendingReadInbox(history);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
} else if (!needsRequest && (allow != reallyAllow && !force)
|
} else if (!needsRequest
|
||||||
&& (!maybeState || !maybeState->willReadTill))
|
&& (!maybeState || !maybeState->willReadTill)) {
|
||||||
{
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const auto stillUnread = history->countStillUnreadLocal(tillId);
|
const auto stillUnread = history->countStillUnreadLocal(tillId);
|
||||||
|
@ -587,6 +576,16 @@ void Histories::sendPendingReadInbox(not_null<History*> history) {
|
||||||
|
|
||||||
void Histories::sendReadRequests() {
|
void Histories::sendReadRequests() {
|
||||||
DEBUG_LOG(("Reading: send requests with count %1.").arg(_states.size()));
|
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()) {
|
if (_states.empty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "styles/style_chat.h"
|
#include "styles/style_chat.h"
|
||||||
|
|
||||||
// AyuGram includes
|
// AyuGram includes
|
||||||
#include "ayu/ayu_state.h"
|
#include "ayu/ayu_settings.h"
|
||||||
|
#include "ayu/utils/telegram_helpers.h"
|
||||||
|
|
||||||
|
|
||||||
namespace Data {
|
namespace Data {
|
||||||
|
@ -838,8 +839,7 @@ void Reactions::send(not_null<HistoryItem*> item, bool addToRecent) {
|
||||||
const auto settings = &AyuSettings::getInstance();
|
const auto settings = &AyuSettings::getInstance();
|
||||||
if (!settings->sendReadMessages && settings->markReadAfterReaction && item)
|
if (!settings->sendReadMessages && settings->markReadAfterReaction && item)
|
||||||
{
|
{
|
||||||
AyuState::setAllowSendReadPacket(true);
|
readHistory(item);
|
||||||
item->history()->session().data().histories().readInboxOnNewMessage(item);
|
|
||||||
}
|
}
|
||||||
}).fail([=](const MTP::Error &error) {
|
}).fail([=](const MTP::Error &error) {
|
||||||
_sentRequests.remove(id);
|
_sentRequests.remove(id);
|
||||||
|
|
|
@ -170,7 +170,7 @@ 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/utils/telegram_helpers.h"
|
||||||
|
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
@ -1067,6 +1067,15 @@ void HistoryWidget::initTabbedSelector() {
|
||||||
Data::InsertCustomEmoji(_field.data(), data.document);
|
Data::InsertCustomEmoji(_field.data(), data.document);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
const auto settings = &AyuSettings::getInstance();
|
||||||
|
if (!settings->sendReadMessages && settings->markReadAfterSend) {
|
||||||
|
const auto lastMessage = history()->lastMessage();
|
||||||
|
|
||||||
|
if (lastMessage) {
|
||||||
|
readHistory(lastMessage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
controller()->sendingAnimation().appendSending(
|
controller()->sendingAnimation().appendSending(
|
||||||
data.messageSendingFrom);
|
data.messageSendingFrom);
|
||||||
const auto localId = data.messageSendingFrom.localId;
|
const auto localId = data.messageSendingFrom.localId;
|
||||||
|
@ -3969,8 +3978,7 @@ void HistoryWidget::send(Api::SendOptions options) {
|
||||||
auto lastMessage = _history->lastMessage();
|
auto lastMessage = _history->lastMessage();
|
||||||
if (!settings->sendReadMessages && settings->markReadAfterSend && lastMessage)
|
if (!settings->sendReadMessages && settings->markReadAfterSend && lastMessage)
|
||||||
{
|
{
|
||||||
AyuState::setAllowSendReadPacket(true);
|
readHistory(lastMessage);
|
||||||
_history->session().data().histories().readInboxOnNewMessage(lastMessage);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!_history) {
|
if (!_history) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue