mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
fix(offlinemsg): fix offline message dispatching on history load
* Fix callback hookup order in ChatHistory * Add correct call to SessionChatLog to insert an unfinished message * Fix incorrect logic in parsing History database response
This commit is contained in:
parent
86b55a0fb0
commit
dbef0b7508
@ -94,9 +94,10 @@ ChatHistory::ChatHistory(Friend& f_, History* history_, const ICoreIdHandler& co
|
|||||||
, settings(settings_)
|
, settings(settings_)
|
||||||
, coreIdHandler(coreIdHandler)
|
, coreIdHandler(coreIdHandler)
|
||||||
{
|
{
|
||||||
connect(&messageDispatcher, &IMessageDispatcher::messageSent, this, &ChatHistory::onMessageSent);
|
|
||||||
connect(&messageDispatcher, &IMessageDispatcher::messageComplete, this,
|
connect(&messageDispatcher, &IMessageDispatcher::messageComplete, this,
|
||||||
&ChatHistory::onMessageComplete);
|
&ChatHistory::onMessageComplete);
|
||||||
|
connect(&messageDispatcher, &IMessageDispatcher::messageReceived, this,
|
||||||
|
&ChatHistory::onMessageReceived);
|
||||||
|
|
||||||
if (canUseHistory()) {
|
if (canUseHistory()) {
|
||||||
// Defer messageSent callback until we finish firing off all our unsent messages.
|
// Defer messageSent callback until we finish firing off all our unsent messages.
|
||||||
@ -105,8 +106,7 @@ ChatHistory::ChatHistory(Friend& f_, History* history_, const ICoreIdHandler& co
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Now that we've fired off our unsent messages we can connect the message
|
// Now that we've fired off our unsent messages we can connect the message
|
||||||
connect(&messageDispatcher, &IMessageDispatcher::messageReceived, this,
|
connect(&messageDispatcher, &IMessageDispatcher::messageSent, this, &ChatHistory::onMessageSent);
|
||||||
&ChatHistory::onMessageReceived);
|
|
||||||
|
|
||||||
// NOTE: this has to be done _after_ sending all sent messages since initial
|
// NOTE: this has to be done _after_ sending all sent messages since initial
|
||||||
// state of the message has to be marked according to our dispatch state
|
// state of the message has to be marked according to our dispatch state
|
||||||
@ -395,14 +395,13 @@ void ChatHistory::loadHistoryIntoSessionChatLog(ChatLogIdx start) const
|
|||||||
[&](RowId dispatchedId) { return dispatchedId == message.id; });
|
[&](RowId dispatchedId) { return dispatchedId == message.id; });
|
||||||
|
|
||||||
bool isComplete = dispatchedMessageIt == dispatchedMessageRowIdMap.end();
|
bool isComplete = dispatchedMessageIt == dispatchedMessageRowIdMap.end();
|
||||||
|
auto chatLogMessage = ChatLogMessage{isComplete, processedMessage};
|
||||||
if (isComplete) {
|
if (isComplete) {
|
||||||
auto chatLogMessage = ChatLogMessage{true, processedMessage};
|
sessionChatLog.insertCompleteMessageAtIdx(currentIdx, sender, message.dispName,
|
||||||
sessionChatLog.insertMessageAtIdx(currentIdx, sender, message.dispName, chatLogMessage);
|
chatLogMessage);
|
||||||
} else {
|
} else {
|
||||||
// If the message is incomplete we have to pretend we sent it to ensure
|
sessionChatLog.insertIncompleteMessageAtIdx(currentIdx, sender, message.dispName,
|
||||||
// sessionChatLog state is correct
|
chatLogMessage, dispatchedMessageIt.key());
|
||||||
sessionChatLog.onMessageSent(dispatchedMessageIt.key(), processedMessage);
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -294,8 +294,8 @@ std::size_t SessionChatLog::size() const
|
|||||||
return items.size();
|
return items.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SessionChatLog::insertMessageAtIdx(ChatLogIdx idx, ToxPk sender, QString senderName,
|
void SessionChatLog::insertCompleteMessageAtIdx(ChatLogIdx idx, const ToxPk& sender, const QString& senderName,
|
||||||
ChatLogMessage message)
|
const ChatLogMessage& message)
|
||||||
{
|
{
|
||||||
auto item = ChatLogItem(sender, message);
|
auto item = ChatLogItem(sender, message);
|
||||||
|
|
||||||
@ -303,10 +303,28 @@ void SessionChatLog::insertMessageAtIdx(ChatLogIdx idx, ToxPk sender, QString se
|
|||||||
item.setDisplayName(senderName);
|
item.setDisplayName(senderName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
assert(message.isComplete == true);
|
||||||
|
|
||||||
items.emplace(idx, std::move(item));
|
items.emplace(idx, std::move(item));
|
||||||
}
|
}
|
||||||
|
|
||||||
void SessionChatLog::insertFileAtIdx(ChatLogIdx idx, ToxPk sender, QString senderName, ChatLogFile file)
|
void SessionChatLog::insertIncompleteMessageAtIdx(ChatLogIdx idx, const ToxPk& sender, const QString& senderName,
|
||||||
|
const ChatLogMessage& message,
|
||||||
|
DispatchedMessageId dispatchId)
|
||||||
|
{
|
||||||
|
auto item = ChatLogItem(sender, message);
|
||||||
|
|
||||||
|
if (!senderName.isEmpty()) {
|
||||||
|
item.setDisplayName(senderName);
|
||||||
|
}
|
||||||
|
|
||||||
|
assert(message.isComplete == false);
|
||||||
|
|
||||||
|
items.emplace(idx, std::move(item));
|
||||||
|
outgoingMessages.insert(dispatchId, idx);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SessionChatLog::insertFileAtIdx(ChatLogIdx idx, const ToxPk& sender, const QString& senderName, const ChatLogFile& file)
|
||||||
{
|
{
|
||||||
auto item = ChatLogItem(sender, file);
|
auto item = ChatLogItem(sender, file);
|
||||||
|
|
||||||
|
@ -47,8 +47,11 @@ public:
|
|||||||
std::vector<DateChatLogIdxPair> getDateIdxs(const QDate& startDate, size_t maxDates) const override;
|
std::vector<DateChatLogIdxPair> getDateIdxs(const QDate& startDate, size_t maxDates) const override;
|
||||||
std::size_t size() const override;
|
std::size_t size() const override;
|
||||||
|
|
||||||
void insertMessageAtIdx(ChatLogIdx idx, ToxPk sender, QString senderName, ChatLogMessage message);
|
void insertCompleteMessageAtIdx(ChatLogIdx idx, const ToxPk& sender, const QString& senderName,
|
||||||
void insertFileAtIdx(ChatLogIdx idx, ToxPk sender, QString senderName, ChatLogFile file);
|
const ChatLogMessage& message);
|
||||||
|
void insertIncompleteMessageAtIdx(ChatLogIdx idx, const ToxPk& sender, const QString& senderName,
|
||||||
|
const ChatLogMessage& message, DispatchedMessageId dispatchId);
|
||||||
|
void insertFileAtIdx(ChatLogIdx idx, const ToxPk& sender, const QString& senderName, const ChatLogFile& file);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void onMessageReceived(const ToxPk& sender, const Message& message);
|
void onMessageReceived(const ToxPk& sender, const Message& message);
|
||||||
|
@ -628,10 +628,8 @@ QList<History::HistMessage> History::getUnsentMessagesForFriend(const ToxPk& fri
|
|||||||
auto friend_key = row[3].toString();
|
auto friend_key = row[3].toString();
|
||||||
auto display_name = QString::fromUtf8(row[4].toByteArray().replace('\0', ""));
|
auto display_name = QString::fromUtf8(row[4].toByteArray().replace('\0', ""));
|
||||||
auto sender_key = row[5].toString();
|
auto sender_key = row[5].toString();
|
||||||
if (row[6].isNull()) {
|
|
||||||
ret += {id, isOfflineMessage, timestamp, friend_key,
|
ret += {id, isOfflineMessage, timestamp, friend_key,
|
||||||
display_name, sender_key, row[6].toString()};
|
display_name, sender_key, row[6].toString()};
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
db->execNow({queryText, rowCallback});
|
db->execNow({queryText, rowCallback});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user