Skip to content
This repository has been archived by the owner on Feb 12, 2023. It is now read-only.

Commit

Permalink
fix(history): select broken messages from History, track in ChatLogMe…
Browse files Browse the repository at this point in the history
…ssage
  • Loading branch information
anthonybilinski committed Oct 20, 2019
1 parent cd75618 commit f6a1536
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/model/chatlogitem.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
struct ChatLogMessage
{
bool isComplete;
bool isBroken;
Message message;
};

Expand Down
14 changes: 9 additions & 5 deletions src/persistence/history.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -641,12 +641,13 @@ QList<History::HistMessage> History::getMessagesForFriend(const ToxPk& friendPk,
"message, file_transfers.file_restart_id, "
"file_transfers.file_path, file_transfers.file_name, "
"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 "
"JOIN peers chat ON history.chat_id = chat.id "
"JOIN aliases ON sender_alias = aliases.id "
"JOIN peers sender ON aliases.owner = sender.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' "
"LIMIT %2 OFFSET %3;")
.arg(friendPk.toString())
Expand All @@ -662,8 +663,9 @@ QList<History::HistMessage> History::getMessagesForFriend(const ToxPk& friendPk,
auto friend_key = row[3].toString();
auto display_name = QString::fromUtf8(row[4].toByteArray().replace('\0', ""));
auto sender_key = row[5].toString();
auto isBroken = !row[13].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()};
} else {
ToxFile file;
Expand All @@ -675,7 +677,7 @@ QList<History::HistMessage> History::getMessagesForFriend(const ToxPk& friendPk,
file.direction = static_cast<ToxFile::FileDirection>(row[11].toLongLong());
file.status = static_cast<ToxFile::FileStatus>(row[12].toInt());
messages +=
{id, isPending, timestamp, friend_key, display_name, sender_key, file};
{id, isPending, isBroken, timestamp, friend_key, display_name, sender_key, file};
}
};

Expand All @@ -688,12 +690,13 @@ QList<History::HistMessage> History::getUndeliveredMessagesForFriend(const ToxPk
{
auto queryText =
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 "
"JOIN faux_offline_pending ON history.id = faux_offline_pending.id "
"JOIN peers chat on history.chat_id = chat.id "
"JOIN aliases on sender_alias = aliases.id "
"JOIN peers sender on aliases.owner = sender.id "
"LEFT JOIN broken_messages ON history.id = broken_messages.id "
"WHERE chat.public_key='%1';")
.arg(friendPk.toString());

Expand All @@ -707,7 +710,8 @@ QList<History::HistMessage> History::getUndeliveredMessagesForFriend(const ToxPk
auto friend_key = row[3].toString();
auto display_name = QString::fromUtf8(row[4].toByteArray().replace('\0', ""));
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()};
};

Expand Down
7 changes: 5 additions & 2 deletions src/persistence/history.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,25 +111,27 @@ class History : public QObject, public std::enable_shared_from_this<History>
public:
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)
: chat{chat}
, sender{sender}
, dispName{dispName}
, timestamp{timestamp}
, id{id}
, isPending{isPending}
, isBroken{isBroken}
, 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)
: chat{chat}
, sender{sender}
, dispName{dispName}
, timestamp{timestamp}
, id{id}
, isPending{isPending}
, isBroken{isBroken}
, content(std::move(file))
{}

Expand All @@ -140,6 +142,7 @@ class History : public QObject, public std::enable_shared_from_this<History>
QDateTime timestamp;
RowId id;
bool isPending;
bool isBroken;
HistMessageContent content;
};

Expand Down

0 comments on commit f6a1536

Please sign in to comment.