aboutsummaryrefslogtreecommitdiff
path: root/src/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/Matrix.cpp15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/plugins/Matrix.cpp b/src/plugins/Matrix.cpp
index 529d42a..a28aedc 100644
--- a/src/plugins/Matrix.cpp
+++ b/src/plugins/Matrix.cpp
@@ -182,6 +182,7 @@ namespace QuickMedia {
body_item->thumbnail_url = user_info.avatar_url;
// TODO: Show image thumbnail inline instead of url to image
body_item->url = messages[i].url;
+ body_item->author_color = user_info.display_name_color;
result_items.push_back(std::move(body_item));
prev_user_id = messages[i].user_id;
}
@@ -327,6 +328,19 @@ namespace QuickMedia {
return PluginResult::OK;
}
+ static sf::Color user_id_to_color(const std::string &user_id) {
+ uint32_t color = 2166136261;
+ for(unsigned char c : user_id) {
+ color = (color * 16777619) ^ c;
+ }
+ sf::Color result = (sf::Color)color;
+ result.r = 64 + std::max(0, (int)result.r - 64);
+ result.g = 64 + std::max(0, (int)result.g - 64);
+ result.b = 64 + std::max(0, (int)result.b - 64);
+ result.a = 255;
+ return result;
+ }
+
void Matrix::events_add_user_info(const Json::Value &events_json, RoomData *room_data) {
if(!events_json.isArray())
return;
@@ -371,6 +385,7 @@ namespace QuickMedia {
// TODO: What if the user hasn't selected an avatar?
user_info.avatar_url = homeserver + "/_matrix/media/r0/thumbnail/" + user_info.avatar_url + "?width=32&height=32&method=crop";
user_info.display_name = display_name_json.asString();
+ user_info.display_name_color = user_id_to_color(sender_json_str);
room_data->user_info.push_back(std::move(user_info));
room_data->user_info_by_user_id.insert(std::make_pair(sender_json_str, room_data->user_info.size() - 1));
}