Skip to content

Commit

Permalink
Handle thread.pinned changes (dbv266) in exporthtml. Todo: importfrom…
Browse files Browse the repository at this point in the history
…desktop and merge
  • Loading branch information
bepaald committed Mar 5, 2025
1 parent 031b8f6 commit 535085b
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 13 deletions.
2 changes: 1 addition & 1 deletion autoversion.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@
#ifndef VERSION_H_
#define VERSION_H_

#define VERSIONDATE "20250304.135848"
#define VERSIONDATE "20250305.100036"

#endif
12 changes: 5 additions & 7 deletions signalbackup/htmlwriteindex.cc
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ bool SignalBackup::HTMLwriteIndexImpl(std::vector<long long int> const &threads,
"json_extract(thread.snippet_extras, '$.individualRecipientId') AS 'group_sender_id', "
"json_extract(thread.snippet_extras, '$.bodyRanges') AS 'snippet_ranges', "
"json_extract(thread.snippet_extras, '$.isRemoteDelete') AS 'deleted', "
+ (d_database.tableContainsColumn("thread", "pinned") ? "pinned," : "") +
+ (d_database.tableContainsColumn("thread", d_thread_pinned) ? "IFNULL(" + d_thread_pinned + ", 0) AS pinned," : "0 AS pinned,") +
+ (d_database.tableContainsColumn("thread", "archived") ? "archived," : "") +
//"IFNULL(recipient.mute_until, 0) AS mute_until, " // dont think this is ever NULL
//"recipient.blocked, "
Expand All @@ -87,7 +87,7 @@ bool SignalBackup::HTMLwriteIndexImpl(std::vector<long long int> const &threads,
"FROM thread "
"LEFT JOIN recipient ON recipient._id IS thread." + d_thread_recipient_id + " "
"WHERE thread._id IN (" + threadlist + ") AND " + d_thread_message_count + " > 0 ORDER BY "
+ (d_database.tableContainsColumn("thread", "pinned") ? "(pinned != 0) DESC, pinned ASC, " : "") +
"(pinned != 0) DESC, pinned ASC, " // before 266 pinned == 0 meant 'not pinned', after pinned = NULL is not pinned. But in the code, pinned = 0 is still not possible (when pining something, even the first thread, the value is set to 1 to start)
+ (d_database.tableContainsColumn("thread", "archived") ? "archived ASC, " : "") +
"date DESC", &results))
{
Expand Down Expand Up @@ -135,7 +135,7 @@ bool SignalBackup::HTMLwriteIndexImpl(std::vector<long long int> const &threads,
"CAST(" + d_mms_table + "." + d_mms_recipient_id + " AS text) AS 'group_sender_id', "
+ d_mms_ranges + " AS 'snippet_ranges', "
+ (d_database.tableContainsColumn(d_mms_table, "remote_deleted") ? "remote_deleted AS 'deleted', " : "0 AS 'deleted', ")
+ (d_database.tableContainsColumn("thread", "pinned") ? "thread.pinned, " : "") +
+ (d_database.tableContainsColumn("thread", d_thread_pinned) ? "IFNULL(" + d_thread_pinned + ", 0) AS pinned," : "0 AS pinned,") +
+ (d_database.tableContainsColumn("thread", "archived") ? "thread.archived, " : "") +
//"IFNULL(recipient.mute_until, 0) AS mute_until, "
//"recipient.blocked, "
Expand All @@ -154,7 +154,7 @@ bool SignalBackup::HTMLwriteIndexImpl(std::vector<long long int> const &threads,
"AND (" + d_mms_table + "." + d_mms_type + " & ?) IS NOT ? "
"AND (" + d_mms_table + "." + d_mms_type + " & ?) IS NOT ?) SELECT * FROM partitioned_messages WHERE partition_idx = 1 "
"ORDER BY "
+ (d_database.tableContainsColumn("thread", "pinned") ? "(pinned != 0) DESC, pinned ASC, " : "") +
"(pinned != 0) DESC, pinned ASC, " // before 266 pinned == 0 meant 'not pinned', after pinned = NULL is not pinned. But in the code, pinned = 0 is still not possible (when pining something, even the first thread, the value is set to 1 to start)
+ (d_database.tableContainsColumn("thread", "archived") ? "archived ASC, " : "") + "date DESC",
{maxtimestamp,
Types::BASE_TYPE_MASK, Types::PROFILE_CHANGE_TYPE,
Expand Down Expand Up @@ -988,9 +988,7 @@ bool SignalBackup::HTMLwriteIndexImpl(std::vector<long long int> const &threads,
archivedheader = true;
}

bool pinned = false;
if (d_database.tableContainsColumn("thread", "pinned"))
pinned = (results.getValueAs<long long int>(i, "pinned") != 0);
bool pinned = (results.valueAsInt(i, "pinned", 0) != 0); // before 266 pinned == 0 meant 'not pinned', after pinned = NULL is not pinned. But in the code, pinned = 0 is still not possible (when pining something, even the first thread, the value is set to 1 to start)
if (pinned && !pinnedheader)
{
outputfile << " <div class=\"header\">Pinned</div>\n";
Expand Down
6 changes: 3 additions & 3 deletions signalbackup/importfromdesktop.cc
Original file line number Diff line number Diff line change
Expand Up @@ -479,9 +479,9 @@ bool SignalBackup::importFromDesktop(std::unique_ptr<DesktopDatabase> const &dtd
// we have the Android thread id (ttid) and the desktop data (results_all_conversations.value(i, "xxx")), update
// Androids pinned and archived status if desktop is newer:
if (desktop_is_newer)
if (!d_database.exec("UPDATE thread SET archived = ?, pinned = ? WHERE _id = ?", {results_all_conversations.getValueAs<long long int>(i, "is_archived"),
results_all_conversations.getValueAs<long long int>(i, "is_pinned"),
ttid}))
if (!d_database.exec("UPDATE thread SET archived = ?, " + d_thread_pinned + " = ? WHERE _id = ?", {results_all_conversations.getValueAs<long long int>(i, "is_archived"),
results_all_conversations.getValueAs<long long int>(i, "is_pinned"),
ttid}))
Logger::warning("Failed to update thread properties (id: ", ttid, ")");

// now lets get all messages for this conversation
Expand Down
9 changes: 8 additions & 1 deletion signalbackup/setcolumnnames.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (C) 2021-2024 Selwin van Dijk
Copyright (C) 2021-2025 Selwin van Dijk
This file is part of signalbackup-tools.
Expand Down Expand Up @@ -110,6 +110,13 @@ bool SignalBackup::setColumnNames()
d_database.tableContainsColumn("thread", "read_receipt_count"))
d_thread_read_receipts = "read_receipt_count";

// from dbv266
d_thread_pinned = "pinned_order";
// before 211
if (!d_database.tableContainsColumn("thread", "pinned_order") &&
d_database.tableContainsColumn("thread", "pinned"))
d_thread_pinned = "pinned";



// started at dbv166
Expand Down
1 change: 1 addition & 0 deletions signalbackup/signalbackup.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ class SignalBackup
std::string d_thread_message_count;
std::string d_thread_delivery_receipts;
std::string d_thread_read_receipts;
std::string d_thread_pinned;
std::string d_sms_date_received;
std::string d_sms_recipient_id;
std::string d_sms_recipient_device_id;
Expand Down
3 changes: 2 additions & 1 deletion signalbackup/tgimportmessages.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ bool SignalBackup::tgImportMessages(SqliteDB const &db, std::vector<std::pair<st
{{d_thread_recipient_id, thread_recipient_id},
{"active", 1},
{"archived", 0},
{"pinned", 0}},
//{d_thread_pinned, 0}
},
"_id", &new_thread_id))
{
Logger::message_end();
Expand Down

0 comments on commit 535085b

Please sign in to comment.