diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/plugins/Matrix.cpp | 67 |
1 files changed, 29 insertions, 38 deletions
diff --git a/src/plugins/Matrix.cpp b/src/plugins/Matrix.cpp index e604745..9a64bda 100644 --- a/src/plugins/Matrix.cpp +++ b/src/plugins/Matrix.cpp @@ -1372,6 +1372,7 @@ namespace QuickMedia { const rapidjson::Value &events_json = GetMember(timeline_json, "events"); events_add_user_info(events_json, room); events_set_room_name(events_json, room); + set_room_name_to_users_if_empty(room, user_id); if(account_data_json.IsObject()) { const rapidjson::Value &events_json = GetMember(account_data_json, "events"); @@ -1386,6 +1387,7 @@ namespace QuickMedia { if(!is_additional_messages_sync) events_add_pinned_events(events_json, room); } else { + set_room_name_to_users_if_empty(room, user_id); if(account_data_json.IsObject()) { const rapidjson::Value &events_json = GetMember(account_data_json, "events"); auto me = get_me(room); @@ -1952,6 +1954,7 @@ namespace QuickMedia { continue; room_data->set_name(name_json.GetString()); + room_data->name_is_fallback = false; } for(const rapidjson::Value &event_item_json : events_json.GetArray()) { @@ -1972,48 +1975,33 @@ namespace QuickMedia { std::string url_json_str = url_json.GetString() + 6; room_data->set_avatar_url(homeserver + "/_matrix/media/r0/thumbnail/" + thumbnail_url_extract_media_id(url_json_str) + "?width=32&height=32&method=crop"); + room_data->avatar_is_fallback = false; } + } - bool has_room_name = room_data->has_name(); - bool has_room_avatar_url = room_data->has_avatar_url(); + void Matrix::set_room_name_to_users_if_empty(RoomData *room, const std::string &room_creator_user_id) { + bool has_room_name = room->has_name(); + bool has_room_avatar_url = room->has_avatar_url(); - // TODO: Fix. This can be incorrect because this method can be called before we have added all users to the room std::vector<std::shared_ptr<UserInfo>> users_excluding_me; - if(!has_room_name || !has_room_avatar_url) - users_excluding_me = room_data->get_users_excluding_me(user_id); // TODO: What about thread safety with user_id? its reset in /logout - - for(const rapidjson::Value &event_item_json : events_json.GetArray()) { - if(!event_item_json.IsObject()) - continue; - - const rapidjson::Value &type_json = GetMember(event_item_json, "type"); - if(!type_json.IsString() || strcmp(type_json.GetString(), "m.room.create") != 0) - continue; - - const rapidjson::Value &content_json = GetMember(event_item_json, "content"); - if(!content_json.IsObject()) - continue; + if(!has_room_name || !has_room_avatar_url || room->name_is_fallback || room->avatar_is_fallback) + users_excluding_me = room->get_users_excluding_me(user_id); - const rapidjson::Value &creator_json = GetMember(content_json, "creator"); - if(!creator_json.IsString()) - continue; - - if(!has_room_name) { - room_data->set_name(combine_user_display_names_for_room_name(users_excluding_me, creator_json.GetString())); - has_room_name = true; - } + if(!has_room_name) { + room->set_name(combine_user_display_names_for_room_name(users_excluding_me, room_creator_user_id)); + room->name_is_fallback = true; + } - if(!has_room_avatar_url) { - if(users_excluding_me.empty()) { - auto user = get_user_by_id(room_data, creator_json.GetString()); - if(user) - room_data->set_avatar_url(room_data->get_user_avatar_url(user)); - } else { - // TODO: If there are multiple users, then we want to use some other type of avatar, not the first users avatar - room_data->set_avatar_url(room_data->get_user_avatar_url(users_excluding_me.front())); - } - has_room_avatar_url = true; + if(!has_room_avatar_url) { + if(users_excluding_me.empty()) { + auto user = get_user_by_id(room, room_creator_user_id); + if(user) + room->set_avatar_url(room->get_user_avatar_url(user)); + } else { + // TODO: If there are multiple users, then we want to use some other type of avatar, not the first users avatar + room->set_avatar_url(room->get_user_avatar_url(users_excluding_me.front())); } + room->avatar_is_fallback = true; } } @@ -2167,12 +2155,15 @@ namespace QuickMedia { events_add_user_info(events_json, &invite_room); events_set_room_name(events_json, &invite_room); - auto invited_by = get_user_by_id(&invite_room, sender_json.GetString()); + std::string sender_json_str(sender_json.GetString(), sender_json.GetStringLength()); + auto invited_by = get_user_by_id(&invite_room, sender_json_str); if(!invited_by) { fprintf(stderr, "Invited by unknown user. Bug in homeserver?\n"); break; } + set_room_name_to_users_if_empty(&invite_room, sender_json_str); + invite.room_name = invite_room.get_name(); invite.room_avatar_url = invite_room.get_avatar_url(); invite.invited_by = invited_by; @@ -2308,7 +2299,7 @@ namespace QuickMedia { const rapidjson::Value &state_json = GetMember(json_root, "state"); events_add_user_info(state_json, room_data); - events_set_room_name(state_json, room_data); + //events_set_room_name(state_json, room_data); const rapidjson::Value &chunk_json = GetMember(json_root, "chunk"); events_add_messages(chunk_json, room_data, MessageDirection::BEFORE, false); @@ -2724,7 +2715,7 @@ namespace QuickMedia { const rapidjson::Value &state_json = GetMember(json_root, "state"); events_add_user_info(state_json, room); - events_set_room_name(state_json, room); + //events_set_room_name(state_json, room); const rapidjson::Value &event_json = GetMember(json_root, "event"); std::shared_ptr<Message> new_message = parse_message_event(event_json, room); |