1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

fix(history): select broken messages from History, track in ChatLogMessage

This commit is contained in:
Anthony Bilinski 2019-10-07 20:38:24 -07:00
parent cd75618e38
commit f6a15366ef
No known key found for this signature in database
GPG Key ID: 2AA8E0DA1B31FB3C
3 changed files with 15 additions and 7 deletions

View File

@ -29,6 +29,7 @@
struct ChatLogMessage struct ChatLogMessage
{ {
bool isComplete; bool isComplete;
bool isBroken;
Message message; Message message;
}; };

View File

@ -641,12 +641,13 @@ QList<History::HistMessage> History::getMessagesForFriend(const ToxPk& friendPk,
"message, file_transfers.file_restart_id, " "message, file_transfers.file_restart_id, "
"file_transfers.file_path, file_transfers.file_name, " "file_transfers.file_path, file_transfers.file_name, "
"file_transfers.file_size, file_transfers.direction, " "file_transfers.file_size, file_transfers.direction, "
"file_transfers.file_state FROM history " "file_transfers.file_state, broken_messages.id FROM history "
"LEFT JOIN faux_offline_pending ON history.id = faux_offline_pending.id " "LEFT JOIN faux_offline_pending ON history.id = faux_offline_pending.id "
"JOIN peers chat ON history.chat_id = chat.id " "JOIN peers chat ON history.chat_id = chat.id "
"JOIN aliases ON sender_alias = aliases.id " "JOIN aliases ON sender_alias = aliases.id "
"JOIN peers sender ON aliases.owner = sender.id " "JOIN peers sender ON aliases.owner = sender.id "
"LEFT JOIN file_transfers ON history.file_id = file_transfers.id " "LEFT JOIN file_transfers ON history.file_id = file_transfers.id "
"LEFT JOIN broken_messages ON history.id = broken_messages.id "
"WHERE chat.public_key='%1' " "WHERE chat.public_key='%1' "
"LIMIT %2 OFFSET %3;") "LIMIT %2 OFFSET %3;")
.arg(friendPk.toString()) .arg(friendPk.toString())
@ -662,8 +663,9 @@ QList<History::HistMessage> History::getMessagesForFriend(const ToxPk& friendPk,
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();
auto isBroken = !row[13].isNull();
if (row[7].isNull()) { if (row[7].isNull()) {
messages += {id, isPending, timestamp, friend_key, messages += {id, isPending, isBroken, timestamp, friend_key,
display_name, sender_key, row[6].toString()}; display_name, sender_key, row[6].toString()};
} else { } else {
ToxFile file; ToxFile file;
@ -675,7 +677,7 @@ QList<History::HistMessage> History::getMessagesForFriend(const ToxPk& friendPk,
file.direction = static_cast<ToxFile::FileDirection>(row[11].toLongLong()); file.direction = static_cast<ToxFile::FileDirection>(row[11].toLongLong());
file.status = static_cast<ToxFile::FileStatus>(row[12].toInt()); file.status = static_cast<ToxFile::FileStatus>(row[12].toInt());
messages += messages +=
{id, isPending, timestamp, friend_key, display_name, sender_key, file}; {id, isPending, isBroken, timestamp, friend_key, display_name, sender_key, file};
} }
}; };
@ -688,12 +690,13 @@ QList<History::HistMessage> History::getUndeliveredMessagesForFriend(const ToxPk
{ {
auto queryText = auto queryText =
QString("SELECT history.id, faux_offline_pending.id, timestamp, chat.public_key, " QString("SELECT history.id, faux_offline_pending.id, timestamp, chat.public_key, "
"aliases.display_name, sender.public_key, message " "aliases.display_name, sender.public_key, message, broken_messages.id "
"FROM history " "FROM history "
"JOIN faux_offline_pending ON history.id = faux_offline_pending.id " "JOIN faux_offline_pending ON history.id = faux_offline_pending.id "
"JOIN peers chat on history.chat_id = chat.id " "JOIN peers chat on history.chat_id = chat.id "
"JOIN aliases on sender_alias = aliases.id " "JOIN aliases on sender_alias = aliases.id "
"JOIN peers sender on aliases.owner = sender.id " "JOIN peers sender on aliases.owner = sender.id "
"LEFT JOIN broken_messages ON history.id = broken_messages.id "
"WHERE chat.public_key='%1';") "WHERE chat.public_key='%1';")
.arg(friendPk.toString()); .arg(friendPk.toString());
@ -707,7 +710,8 @@ QList<History::HistMessage> History::getUndeliveredMessagesForFriend(const ToxPk
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();
ret += {id, isPending, timestamp, friend_key, auto isBroken = !row[7].isNull();
ret += {id, isPending, isBroken, timestamp, friend_key,
display_name, sender_key, row[6].toString()}; display_name, sender_key, row[6].toString()};
}; };

View File

@ -111,7 +111,7 @@ class History : public QObject, public std::enable_shared_from_this<History>
public: public:
struct HistMessage struct HistMessage
{ {
HistMessage(RowId id, bool isPending, QDateTime timestamp, QString chat, QString dispName, HistMessage(RowId id, bool isPending, bool isBroken, QDateTime timestamp, QString chat, QString dispName,
QString sender, QString message) QString sender, QString message)
: chat{chat} : chat{chat}
, sender{sender} , sender{sender}
@ -119,10 +119,11 @@ public:
, timestamp{timestamp} , timestamp{timestamp}
, id{id} , id{id}
, isPending{isPending} , isPending{isPending}
, isBroken{isBroken}
, content(std::move(message)) , content(std::move(message))
{} {}
HistMessage(RowId id, bool isPending, QDateTime timestamp, QString chat, QString dispName, HistMessage(RowId id, bool isPending, bool isBroken, QDateTime timestamp, QString chat, QString dispName,
QString sender, ToxFile file) QString sender, ToxFile file)
: chat{chat} : chat{chat}
, sender{sender} , sender{sender}
@ -130,6 +131,7 @@ public:
, timestamp{timestamp} , timestamp{timestamp}
, id{id} , id{id}
, isPending{isPending} , isPending{isPending}
, isBroken{isBroken}
, content(std::move(file)) , content(std::move(file))
{} {}
@ -140,6 +142,7 @@ public:
QDateTime timestamp; QDateTime timestamp;
RowId id; RowId id;
bool isPending; bool isPending;
bool isBroken;
HistMessageContent content; HistMessageContent content;
}; };