aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/plugins/Matrix.cpp46
1 files changed, 26 insertions, 20 deletions
diff --git a/src/plugins/Matrix.cpp b/src/plugins/Matrix.cpp
index 63027ab..230232a 100644
--- a/src/plugins/Matrix.cpp
+++ b/src/plugins/Matrix.cpp
@@ -1684,7 +1684,7 @@ namespace QuickMedia {
next_batch_json = &GetMember(doc, "next_batch");
if(next_batch_json->IsString()) {
- set_next_batch(next_batch_json->GetString());
+ set_next_batch(next_batch_json->GetString(), false);
//fprintf(stderr, "Matrix: next batch: %s\n", next_batch.c_str());
}
}
@@ -1719,29 +1719,19 @@ namespace QuickMedia {
bool initial_sync = next_batch.empty();
bool first_sync = true;
- notification_thread = std::thread([this]() {
- get_previous_notifications([this](const MatrixNotification &notification) {
- if(notification.read)
- return;
-
- MatrixDelegate *delegate = this->delegate;
- ui_thread_tasks.push([delegate, notification] {
- delegate->add_unread_notification(std::move(notification));
- });
- });
- finished_fetching_notifications = true;
- });
-
std::string filter_encoded;
if(initial_sync)
filter_encoded = url_param_encode(INITIAL_FILTER);
else
filter_encoded = url_param_encode(CONTINUE_FILTER);
+ initial_sync = true;
while(sync_running) {
char url[2048];
if(next_batch.empty())
snprintf(url, sizeof(url), "%s/_matrix/client/r0/sync?filter=%s&timeout=0", homeserver.c_str(), filter_encoded.c_str());
+ else if(first_sync)
+ snprintf(url, sizeof(url), "%s/_matrix/client/r0/sync?filter=%s&timeout=0&since=%s", homeserver.c_str(), filter_encoded.c_str(), next_batch.c_str());
else
snprintf(url, sizeof(url), "%s/_matrix/client/r0/sync?filter=%s&timeout=30000&since=%s", homeserver.c_str(), filter_encoded.c_str(), next_batch.c_str());
@@ -1781,7 +1771,7 @@ namespace QuickMedia {
next_batch_json = &GetMember(json_root, "next_batch");
if(next_batch_json->IsString()) {
- set_next_batch(next_batch_json->GetString());
+ set_next_batch(next_batch_json->GetString(), true);
fprintf(stderr, "Matrix: next batch: %s\n", next_batch.c_str());
} else {
//set_next_batch("Invalid");
@@ -1792,7 +1782,22 @@ namespace QuickMedia {
if(first_sync) {
first_sync = false;
- filter_encoded = url_param_encode(CONTINUE_FILTER);
+ initial_sync = false;
+ filter_encoded = url_param_encode(CONTINUE_FILTER); // TODO: limit messages in this continue filter?
+
+ // TODO: This ignores new rooms that are not part of the previous sync message. Fix this.
+ notification_thread = std::thread([this]() {
+ get_previous_notifications([this](const MatrixNotification &notification) {
+ if(notification.read)
+ return;
+
+ MatrixDelegate *delegate = this->delegate;
+ ui_thread_tasks.push([delegate, notification] {
+ delegate->add_unread_notification(std::move(notification));
+ });
+ });
+ finished_fetching_notifications = true;
+ });
}
#if 0
@@ -1812,7 +1817,6 @@ namespace QuickMedia {
// and fetch previous messages etc themselves.
if(!matrix_instance_already_running) {
sync_cache_file = fopen(matrix_cache_dir.data.c_str(), initial_sync ? "wb" : "ab");
- initial_sync = false;
if(sync_cache_file) {
if(json_root.IsObject()) {
rapidjson::StringBuffer buffer;
@@ -1857,11 +1861,12 @@ namespace QuickMedia {
delegate = nullptr;
sync_failed = false;
sync_fail_reason.clear();
- set_next_batch("");
+ set_next_batch("", false);
next_notifications_token.clear();
invites.clear();
filter_cached.reset();
finished_fetching_notifications = false;
+ initial_sync_finished = false;
custom_emoji_by_key.clear();
silenced_invites.clear();
qm_read_markers_by_room_cache.clear();
@@ -5766,10 +5771,11 @@ namespace QuickMedia {
return false;
}
- void Matrix::set_next_batch(std::string new_next_batch) {
+ void Matrix::set_next_batch(std::string new_next_batch, bool set_initial_sync) {
std::lock_guard<std::mutex> lock(next_batch_mutex);
next_batch = std::move(new_next_batch);
- initial_sync_finished = !next_batch.empty();
+ if(set_initial_sync)
+ initial_sync_finished = !next_batch.empty();
}
std::string Matrix::get_next_batch() {