aboutsummaryrefslogtreecommitdiff
path: root/src/plugins/Matrix.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/Matrix.cpp')
-rw-r--r--src/plugins/Matrix.cpp11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/plugins/Matrix.cpp b/src/plugins/Matrix.cpp
index a702841..93eb1d6 100644
--- a/src/plugins/Matrix.cpp
+++ b/src/plugins/Matrix.cpp
@@ -3,6 +3,7 @@
#include "../../include/StringUtils.hpp"
#include "../../include/NetUtils.hpp"
#include "../../include/Notification.hpp"
+#include "../../include/Program.hpp"
#include <rapidjson/document.h>
#include <rapidjson/writer.h>
#include <rapidjson/stringbuffer.h>
@@ -521,8 +522,8 @@ namespace QuickMedia {
}
void Matrix::stop_sync() {
- // TODO: Kill the running download in |sync_thread| instead of waiting until sync returns (which can be up to 30 seconds)
sync_running = false;
+ program_kill_in_thread(sync_thread.get_id());
if(sync_thread.joinable())
sync_thread.join();
}
@@ -534,8 +535,12 @@ namespace QuickMedia {
void Matrix::get_room_sync_data(RoomData *room, SyncData &sync_data) {
room->acquire_room_lock();
auto &room_messages = room->get_messages_thread_unsafe();
- sync_data.messages.insert(sync_data.messages.end(), room_messages.begin() + room->messages_read_index, room_messages.end());
- room->messages_read_index = room_messages.size();
+ if(room->messages_read_index <= room_messages.size()) {
+ sync_data.messages.insert(sync_data.messages.end(), room_messages.begin() + room->messages_read_index, room_messages.end());
+ room->messages_read_index = room_messages.size();
+ } else {
+ fprintf(stderr, "Unexpected behavior!!!! get_room_sync_data said read index is %zu but we only have %zu messages\n", room->messages_read_index, room_messages.size());
+ }
if(room->pinned_events_updated) {
sync_data.pinned_events = room->get_pinned_events_unsafe();
room->pinned_events_updated = false;