aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/QuickMedia.cpp17
-rw-r--r--src/plugins/Matrix.cpp8
2 files changed, 16 insertions, 9 deletions
diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp
index 315fef0..d0eadb4 100644
--- a/src/QuickMedia.cpp
+++ b/src/QuickMedia.cpp
@@ -3199,7 +3199,7 @@ namespace QuickMedia {
auto find_body_item_by_event_id = [](std::shared_ptr<BodyItem> *body_items, size_t num_body_items, const std::string &event_id, size_t *index_result = nullptr) -> std::shared_ptr<BodyItem> {
for(size_t i = 0; i < num_body_items; ++i) {
auto &body_item = body_items[i];
- if(static_cast<Message*>(body_item->userdata)->event_id == event_id) {
+ if(body_item->userdata && static_cast<Message*>(body_item->userdata)->event_id == event_id) {
if(index_result)
*index_result = i;
return body_item;
@@ -3610,6 +3610,8 @@ namespace QuickMedia {
return;
Message *message = static_cast<Message*>(body_item->userdata);
+ if(!message)
+ return;
assert(message);
#if 0
@@ -3848,7 +3850,7 @@ namespace QuickMedia {
for(auto &message_body_items : tabs[MESSAGES_TAB_INDEX].body->items) {
Message *message = static_cast<Message*>(message_body_items->userdata);
- if(message->user != user)
+ if(!message || message->user != user)
continue;
message_body_items->set_author(user_display_name);
@@ -3885,6 +3887,9 @@ namespace QuickMedia {
fprintf(stderr, "updated messages author for all users in room: %s\n", current_room->id.c_str());
for(auto &message_body_items : tabs[MESSAGES_TAB_INDEX].body->items) {
Message *message = static_cast<Message*>(message_body_items->userdata);
+ if(!message)
+ continue;
+
message_body_items->set_author(current_room->get_user_display_name(message->user));
if(!is_visual_media_message_type(message->type)) {
message_body_items->thumbnail_url = current_room->get_user_avatar_url(message->user);
@@ -4326,6 +4331,7 @@ namespace QuickMedia {
} else if(provisional_message->body_item) {
provisional_message->body_item->set_description("Failed to send: " + provisional_message->body_item->get_description());
provisional_message->body_item->set_description_color(sf::Color::Red);
+ provisional_message->body_item->userdata = nullptr;
}
}
@@ -4543,9 +4549,10 @@ namespace QuickMedia {
// TODO: What if the message is no longer valid?
setting_read_marker = true;
RoomData *room = current_room;
- set_read_marker_future = [this, room, message]() mutable {
- if(matrix->set_read_marker(room, message) != PluginResult::OK) {
- fprintf(stderr, "Warning: failed to set read marker to %s\n", message->event_id.c_str());
+ std::string event_id = message->event_id;
+ set_read_marker_future = [this, room, event_id]() mutable {
+ if(matrix->set_read_marker(room, event_id) != PluginResult::OK) {
+ fprintf(stderr, "Warning: failed to set read marker to %s\n", event_id.c_str());
}
};
}
diff --git a/src/plugins/Matrix.cpp b/src/plugins/Matrix.cpp
index 9da6185..199cba5 100644
--- a/src/plugins/Matrix.cpp
+++ b/src/plugins/Matrix.cpp
@@ -3109,10 +3109,10 @@ namespace QuickMedia {
return download_result_to_plugin_result(download_result);
}
- PluginResult Matrix::set_read_marker(RoomData *room, const Message *message) {
+ PluginResult Matrix::set_read_marker(RoomData *room, const std::string &event_id) {
rapidjson::Document request_data(rapidjson::kObjectType);
- request_data.AddMember("m.fully_read", rapidjson::StringRef(message->event_id.c_str()), request_data.GetAllocator());
- request_data.AddMember("m.read", rapidjson::StringRef(message->event_id.c_str()), request_data.GetAllocator());
+ request_data.AddMember("m.fully_read", rapidjson::StringRef(event_id.c_str()), request_data.GetAllocator());
+ request_data.AddMember("m.read", rapidjson::StringRef(event_id.c_str()), request_data.GetAllocator());
request_data.AddMember("m.hidden", false, request_data.GetAllocator()); // What is this for? element sends it but its not part of the documentation. Is it for hiding read receipt from other users? in that case, TODO: make it configurable
rapidjson::StringBuffer buffer;
@@ -3132,7 +3132,7 @@ namespace QuickMedia {
auto me = get_me(room);
if(me)
- room->set_user_read_marker(me, message->event_id);
+ room->set_user_read_marker(me, event_id);
return PluginResult::OK;
}