aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Storage.cpp15
-rw-r--r--src/plugins/Matrix.cpp42
2 files changed, 52 insertions, 5 deletions
diff --git a/src/Storage.cpp b/src/Storage.cpp
index 7bb3be6..5c12911 100644
--- a/src/Storage.cpp
+++ b/src/Storage.cpp
@@ -244,6 +244,21 @@ namespace QuickMedia {
return rename_atomic(tmp_path.data.c_str(), path.data.c_str());
}
+ bool file_append(const Path &path, const std::string &data) {
+ FILE *file = fopen_eintr(path.data.c_str(), "ab");
+ if(!file) {
+ perror(path.data.c_str());
+ return false;
+ }
+
+ if(fwrite_eintr(data.data(), data.size(), file) != data.size()) {
+ fclose(file);
+ return false;
+ }
+
+ return fclose(file) == 0;
+ }
+
void for_files_in_dir(const Path &path, FileIteratorCallback callback) {
try {
for(auto &p : std::filesystem::directory_iterator(path.data)) {
diff --git a/src/plugins/Matrix.cpp b/src/plugins/Matrix.cpp
index 1b43b2d..7080bf9 100644
--- a/src/plugins/Matrix.cpp
+++ b/src/plugins/Matrix.cpp
@@ -629,12 +629,15 @@ namespace QuickMedia {
rooms_page->add_body_item(body_item);
}
- void MatrixQuickMedia::leave_room(RoomData *room, LeaveType leave_type, const std::string &reason) {
+ void MatrixQuickMedia::leave_room(RoomData *room, const std::string &event_id, LeaveType leave_type, const std::string &reason) {
room_body_item_by_room.erase(room);
rooms_page->remove_body_item_by_room_id(room->id);
room_tags_page->remove_body_item_by_room_id(room->id);
- if(leave_type != LeaveType::LEAVE)
+ if(leave_type != LeaveType::LEAVE && (event_id.empty() || !matrix->is_other_notification_read(event_id))) {
show_notification("QuickMedia", reason);
+ if(!event_id.empty())
+ matrix->mark_other_notification_as_read(event_id);
+ }
}
void MatrixQuickMedia::room_add_tag(RoomData *room, const std::string &tag) {
@@ -1674,6 +1677,7 @@ namespace QuickMedia {
load_silenced_invites();
load_custom_emoji_from_cache();
+ load_other_notifications();
sync_thread = std::thread([this, matrix_cache_dir]() {
FILE *sync_cache_file;
@@ -1858,8 +1862,8 @@ namespace QuickMedia {
fwrite(json_data.data(), 1, json_data.size(), sync_cache_file);
file_overwrite(get_cache_dir().join("matrix").join(update_cache_file_name), "1"); // To make sure the cache format is up to date
- malloc_trim(0);
}
+ malloc_trim(0);
fclose(sync_cache_file);
}
}
@@ -2208,6 +2212,18 @@ namespace QuickMedia {
parse_custom_emoji(json_root);
}
+ void Matrix::load_other_notifications() {
+ std::string result;
+ if(file_get_content(get_storage_dir().join("matrix").join("other_notifications_read"), result) != 0)
+ return;
+
+ other_notifications_read.clear();
+ string_split_view(result, '\n', [this](const char *str, size_t line) {
+ other_notifications_read.insert(std::string(str, line));
+ return true;
+ });
+ }
+
PluginResult Matrix::parse_sync_account_data(const rapidjson::Value &account_data_json) {
if(!account_data_json.IsObject())
return PluginResult::OK;
@@ -3884,6 +3900,10 @@ namespace QuickMedia {
if(!type_json.IsString() || strcmp(type_json.GetString(), "m.room.member") != 0)
continue;
+ const rapidjson::Value &event_id_json = GetMember(event_json, "event_id");
+ if(!event_id_json.IsString())
+ continue;
+
const rapidjson::Value &sender_json = GetMember(event_json, "sender");
if(!sender_json.IsString())
continue;
@@ -3924,7 +3944,10 @@ namespace QuickMedia {
if(!reason_str.empty())
desc += ", reason: " + reason_str;
- ui_thread_tasks.push([this, room, leave_type, desc{std::move(desc)}]{ delegate->leave_room(room, leave_type, desc); });
+ std::string event_id_str = event_id_json.GetString();
+ ui_thread_tasks.push([this, room, event_id_str{std::move(event_id_str)}, leave_type, desc{std::move(desc)}]{
+ delegate->leave_room(room, event_id_str, leave_type, desc);
+ });
remove_room(room_id_str);
break;
}
@@ -4213,6 +4236,15 @@ namespace QuickMedia {
return delegate;
}
+ void Matrix::mark_other_notification_as_read(const std::string &event_id) {
+ other_notifications_read.insert(event_id);
+ file_append(get_storage_dir().join("matrix").join("other_notifications_read"), event_id + "\n");
+ }
+
+ bool Matrix::is_other_notification_read(const std::string &event_id) const {
+ return other_notifications_read.find(event_id) != other_notifications_read.end();
+ }
+
PluginResult Matrix::post_message(RoomData *room, const std::string &body, std::string &event_id_response, const std::optional<UploadInfo> &file_info, const std::optional<UploadInfo> &thumbnail_info, const std::string &msgtype, const std::string &custom_transaction_id) {
std::string transaction_id = custom_transaction_id;
if(transaction_id.empty())
@@ -5629,7 +5661,7 @@ namespace QuickMedia {
if(download_result == DownloadResult::OK) {
RoomData *room = get_room_by_id(room_id);
if(room) {
- ui_thread_tasks.push([this, room]{ delegate->leave_room(room, LeaveType::LEAVE, ""); });
+ ui_thread_tasks.push([this, room]{ delegate->leave_room(room, "", LeaveType::LEAVE, ""); });
remove_room(room_id);
}
}