mirror of
https://github.com/ars3niy/tdlib-purple
synced 2025-08-31 14:05:10 +00:00
When got (or failed to get) reply source, check again if message ready
Could later be still not ready due to downloads
This commit is contained in:
@@ -204,6 +204,7 @@ struct IncomingMessage {
|
||||
int32_t selectedPhotoSizeId;
|
||||
unsigned inlineFileSizeLimit;
|
||||
bool standardDownload;
|
||||
bool repliedMessageFailed;
|
||||
};
|
||||
|
||||
class PendingMessageQueue {
|
||||
|
@@ -279,6 +279,7 @@ void makeFullMessage(td::td_api::object_ptr<td::td_api::message> message, Incomi
|
||||
{
|
||||
fullMessage.repliedMessage = nullptr;
|
||||
fullMessage.selectedPhotoSizeId = 0;
|
||||
fullMessage.repliedMessageFailed = false;
|
||||
|
||||
const char *option = purple_account_get_string(account.purpleAccount, AccountOptions::DownloadBehaviour,
|
||||
AccountOptions::DownloadBehaviourDefault());
|
||||
@@ -321,7 +322,7 @@ static bool isFileMessageReady(const IncomingMessage &fullMessage, ChatId chatId
|
||||
((chat->type_->get_id() != td::td_api::chatTypePrivate::ID) &&
|
||||
(chat->type_->get_id() != td::td_api::chatTypeSecret::ID)) )
|
||||
{
|
||||
// File will be shown as inline link
|
||||
// File will be shown inline
|
||||
if (file->local_ && file->local_->is_downloading_completed_)
|
||||
return true;
|
||||
|
||||
@@ -343,8 +344,11 @@ bool isMessageReady(const IncomingMessage &fullMessage, const TdAccountData &acc
|
||||
const td::td_api::message &message = *fullMessage.message;
|
||||
ChatId chatId = getChatId(message);
|
||||
|
||||
if (getReplyMessageId(message).valid() && !fullMessage.repliedMessage)
|
||||
if (getReplyMessageId(message).valid() && !fullMessage.repliedMessage &&
|
||||
!fullMessage.repliedMessageFailed)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!message.content_) return true;
|
||||
|
||||
|
@@ -1360,22 +1360,36 @@ void PurpleTdClient::onIncomingMessage(td::td_api::object_ptr<td::td_api::messag
|
||||
);
|
||||
m_data.pendingMessages.addPendingMessage(std::move(fullMessage));
|
||||
}
|
||||
}
|
||||
|
||||
void PurpleTdClient::checkMessageReady(const IncomingMessage *message)
|
||||
{
|
||||
if (!message || !message->message) return;
|
||||
|
||||
if (isMessageReady(*message, m_data)) {
|
||||
std::vector<IncomingMessage> readyMessages;
|
||||
m_data.pendingMessages.setMessageReady(getChatId(*message->message), getId(*message->message),
|
||||
readyMessages);
|
||||
message = nullptr;
|
||||
showMessages(readyMessages);
|
||||
}
|
||||
}
|
||||
|
||||
void PurpleTdClient::findMessageResponse(ChatId chatId, MessageId pendingMessageId,
|
||||
td::td_api::object_ptr<td::td_api::Object> object)
|
||||
{
|
||||
if (object && (object->get_id() == td::td_api::message::ID)) {
|
||||
IncomingMessage *pendingMessage = m_data.pendingMessages.findPendingMessage(chatId, pendingMessageId);
|
||||
IncomingMessage *pendingMessage = m_data.pendingMessages.findPendingMessage(chatId, pendingMessageId);
|
||||
if (!pendingMessage) return;
|
||||
|
||||
if (object && (object->get_id() == td::td_api::message::ID))
|
||||
pendingMessage->repliedMessage = td::move_tl_object_as<td::td_api::message>(object);
|
||||
} else
|
||||
else {
|
||||
purple_debug_misc(config::pluginId, "Failed to fetch reply source for message %" G_GINT64_FORMAT "\n",
|
||||
pendingMessageId.value());
|
||||
pendingMessage->repliedMessageFailed = true;
|
||||
}
|
||||
|
||||
std::vector<IncomingMessage> readyMessages;
|
||||
m_data.pendingMessages.setMessageReady(chatId, pendingMessageId, readyMessages);
|
||||
showMessages(readyMessages);
|
||||
checkMessageReady(pendingMessage);
|
||||
}
|
||||
|
||||
void PurpleTdClient::showMessages(std::vector<IncomingMessage>& messages)
|
||||
|
@@ -100,6 +100,7 @@ private:
|
||||
void onIncomingMessage(td::td_api::object_ptr<td::td_api::message> message);
|
||||
void findMessageResponse(ChatId chatId, MessageId pendingMessageId,
|
||||
td::td_api::object_ptr<td::td_api::Object> object);
|
||||
void checkMessageReady(const IncomingMessage *message);
|
||||
void showMessages(std::vector<IncomingMessage> &messages);
|
||||
|
||||
void updateUserStatus(UserId userId, td::td_api::object_ptr<td::td_api::UserStatus> status);
|
||||
|
Reference in New Issue
Block a user