aboutsummaryrefslogtreecommitdiff
path: root/src/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/Matrix.cpp37
1 files changed, 26 insertions, 11 deletions
diff --git a/src/plugins/Matrix.cpp b/src/plugins/Matrix.cpp
index 4b78978..446cdf1 100644
--- a/src/plugins/Matrix.cpp
+++ b/src/plugins/Matrix.cpp
@@ -1056,10 +1056,8 @@ namespace QuickMedia {
}
}
- if(next_batch.empty()) {
- additional_messages_queue.push(true);
+ if(next_batch.empty())
clear_sync_cache_for_new_sync();
- }
result = parse_sync_response(json_root, false);
if(result != PluginResult::OK) {
@@ -1067,6 +1065,9 @@ namespace QuickMedia {
goto sync_end;
}
+ if(next_batch.empty())
+ additional_messages_queue.push(true);
+
next_batch_json = &GetMember(json_root, "next_batch");
if(next_batch_json->IsString()) {
set_next_batch(next_batch_json->GetString());
@@ -2376,7 +2377,7 @@ namespace QuickMedia {
return "m.file";
}
- PluginResult Matrix::post_message(RoomData *room, const std::string &body, const std::optional<UploadInfo> &file_info, const std::optional<UploadInfo> &thumbnail_info, const std::string &msgtype) {
+ 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) {
char random_characters[18];
if(!generate_random_characters(random_characters, sizeof(random_characters)))
return PluginResult::ERR;
@@ -2473,6 +2474,7 @@ namespace QuickMedia {
return PluginResult::ERR;
fprintf(stderr, "Matrix post message, response event id: %s\n", event_id_json.GetString());
+ event_id_response = std::string(event_id_json.GetString(), event_id_json.GetStringLength());
return PluginResult::OK;
}
@@ -2557,7 +2559,7 @@ namespace QuickMedia {
}
// TODO: Support greentext
- PluginResult Matrix::post_reply(RoomData *room, const std::string &body, void *relates_to) {
+ PluginResult Matrix::post_reply(RoomData *room, const std::string &body, void *relates_to, std::string &event_id_response) {
// TODO: Store shared_ptr<Message> instead of raw pointer...
Message *relates_to_message_raw = (Message*)relates_to;
@@ -2609,10 +2611,11 @@ namespace QuickMedia {
return PluginResult::ERR;
fprintf(stderr, "Matrix post reply, response event id: %s\n", event_id_json.GetString());
+ event_id_response = std::string(event_id_json.GetString(), event_id_json.GetStringLength());
return PluginResult::OK;
}
- PluginResult Matrix::post_edit(RoomData *room, const std::string &body, void *relates_to) {
+ PluginResult Matrix::post_edit(RoomData *room, const std::string &body, void *relates_to, std::string &event_id_response) {
Message *relates_to_message_raw = (Message*)relates_to;
char random_characters[18];
@@ -2693,6 +2696,7 @@ namespace QuickMedia {
return PluginResult::ERR;
fprintf(stderr, "Matrix post edit, response event id: %s\n", event_id_json.GetString());
+ event_id_response = std::string(event_id_json.GetString(), event_id_json.GetStringLength());
return PluginResult::OK;
}
@@ -2704,7 +2708,7 @@ namespace QuickMedia {
auto fetched_message_it = room->fetched_messages_by_event_id.find(event_id);
if(fetched_message_it != room->fetched_messages_by_event_id.end())
return fetched_message_it->second;
-
+#if 0
rapidjson::Document request_data(rapidjson::kObjectType);
request_data.AddMember("lazy_load_members", true, request_data.GetAllocator());
@@ -2720,7 +2724,14 @@ namespace QuickMedia {
char url[512];
snprintf(url, sizeof(url), "%s/_matrix/client/r0/rooms/%s/context/%s?limit=0&filter=%s", homeserver.c_str(), room->id.c_str(), event_id.c_str(), filter.c_str());
+#else
+ std::vector<CommandArg> additional_args = {
+ { "-H", "Authorization: Bearer " + access_token }
+ };
+ char url[512];
+ snprintf(url, sizeof(url), "%s/_matrix/client/r0/rooms/%s/event/%s", homeserver.c_str(), room->id.c_str(), event_id.c_str());
+#endif
std::string err_msg;
rapidjson::Document json_root;
DownloadResult download_result = download_json(json_root, url, std::move(additional_args), true, &err_msg);
@@ -2738,13 +2749,17 @@ namespace QuickMedia {
room->fetched_messages_by_event_id.insert(std::make_pair(event_id, nullptr));
return nullptr;
}
-
+#if 0
const rapidjson::Value &state_json = GetMember(json_root, "state");
events_add_user_info(state_json, room);
+#endif
//events_set_room_name(state_json, room);
-
+#if 0
const rapidjson::Value &event_json = GetMember(json_root, "event");
std::shared_ptr<Message> new_message = parse_message_event(event_json, room);
+#else
+ std::shared_ptr<Message> new_message = parse_message_event(json_root, room);
+#endif
room->fetched_messages_by_event_id.insert(std::make_pair(event_id, new_message));
return new_message;
}
@@ -2756,7 +2771,7 @@ namespace QuickMedia {
return filepath.c_str() + index + 1;
}
- PluginResult Matrix::post_file(RoomData *room, const std::string &filepath, std::string &err_msg) {
+ PluginResult Matrix::post_file(RoomData *room, const std::string &filepath, std::string &event_id_response, std::string &err_msg) {
UploadInfo file_info;
UploadInfo thumbnail_info;
PluginResult upload_file_result = upload_file(room, filepath, file_info, thumbnail_info, err_msg);
@@ -2769,7 +2784,7 @@ namespace QuickMedia {
thumbnail_info_opt = std::move(thumbnail_info);
const char *filename = file_get_filename(filepath);
- return post_message(room, filename, file_info_opt, thumbnail_info_opt);
+ return post_message(room, filename, event_id_response, file_info_opt, thumbnail_info_opt);
}
PluginResult Matrix::upload_file(RoomData *room, const std::string &filepath, UploadInfo &file_info, UploadInfo &thumbnail_info, std::string &err_msg) {