Fixed scheduled sending text messages until online when user is online.

This commit is contained in:
23rd 2020-01-26 01:41:02 +03:00 committed by John Preston
parent 03d96a32f2
commit 7cbc5ef902
3 changed files with 64 additions and 4 deletions

View file

@ -14,6 +14,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "main/main_session.h"
#include "history/history.h"
#include "history/history_item_components.h"
#include "history/history_message.h"
#include "apiwrap.h"
namespace Data {
@ -116,6 +117,56 @@ int ScheduledMessages::count(not_null<History*> history) const {
return (i != end(_data)) ? i->second.items.size() : 0;
}
void ScheduledMessages::sendNowSimpleMessage(
const MTPDupdateShortSentMessage &update,
not_null<HistoryItem*> local) {
Expects(local->isSending());
Expects(local->isScheduled());
Expects(local->date() == kScheduledUntilOnlineTimestamp);
// When the user sends a text message scheduled until online
// while the recipient is already online, the server sends
// updateShortSentMessage to the client and the client calls this method.
// Since such messages can only be sent to recipients,
// we know for sure that a message can't have fields such as the author,
// views count, etc.
const auto &history = local->history();
auto flags = NewMessageFlags(history->peer)
| MTPDmessage::Flag::f_entities
| MTPDmessage::Flag::f_from_id
| (local->replyToId()
? MTPDmessage::Flag::f_reply_to_msg_id
: MTPDmessage::Flag(0));
auto clientFlags = NewMessageClientFlags()
| MTPDmessage_ClientFlag::f_local_history_entry;
history->addNewMessage(
MTP_message(
MTP_flags(flags),
update.vid(),
MTP_int(_session->userId()),
peerToMTP(history->peer->id),
MTPMessageFwdHeader(),
MTPint(),
MTP_int(local->replyToId()),
update.vdate(),
MTP_string(local->originalText().text),
MTP_messageMediaEmpty(),
MTPReplyMarkup(),
Api::EntitiesToMTP(local->originalText().entities),
MTP_int(1),
MTPint(),
MTP_string(),
MTPlong(),
//MTPMessageReactions(),
MTPVector<MTPRestrictionReason>()),
clientFlags,
NewMessageType::Unread);
local->destroy();
}
void ScheduledMessages::apply(const MTPDupdateNewScheduledMessage &update) {
const auto &message = update.vmessage();
const auto peer = PeerFromMessage(message);

View file

@ -41,6 +41,10 @@ public:
void appendSending(not_null<HistoryItem*> item);
void removeSending(not_null<HistoryItem*> item);
void sendNowSimpleMessage(
const MTPDupdateShortSentMessage &update,
not_null<HistoryItem*> local);
[[nodiscard]] rpl::producer<> updates(not_null<History*> history);
[[nodiscard]] Data::MessagesSlice list(not_null<History*> history);

View file

@ -3799,14 +3799,19 @@ void MainWidget::feedUpdates(const MTPUpdates &updates, uint64 randomId) {
if (!IsServerMsgId(d.vid().v)) {
LOG(("API Error: Bad msgId got from server: %1").arg(d.vid().v));
} else if (randomId) {
const auto sent = session().data().messageSentData(randomId);
auto &owner = session().data();
const auto sent = owner.messageSentData(randomId);
const auto lookupMessage = [&] {
return sent.peerId
? session().data().message(
peerToChannel(sent.peerId),
d.vid().v)
? owner.message(peerToChannel(sent.peerId), d.vid().v)
: nullptr;
};
if (const auto id = owner.messageIdByRandomId(randomId)) {
if (const auto local = owner.message(id);
local->isScheduled()) {
owner.scheduledMessages().sendNowSimpleMessage(d, local);
}
}
const auto wasAlready = (lookupMessage() != nullptr);
feedUpdate(MTP_updateMessageID(d.vid(), MTP_long(randomId))); // ignore real date
if (const auto item = lookupMessage()) {