aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2020-09-25 21:40:22 +0200
committerdec05eba <dec05eba@protonmail.com>2020-09-25 22:27:15 +0200
commitd5d462f555ef9d7ce7e001aca5586c19b4d9edc8 (patch)
tree8fa80cce39f3df27513ff16815bb7b5d11814d8e /src
parenteac2ace1c14c1ae0564d757b26a359c6bd4b754a (diff)
Matrix: add display name colors depending on user id
Diffstat (limited to 'src')
-rw-r--r--src/Body.cpp8
-rw-r--r--src/QuickMedia.cpp4
-rw-r--r--src/plugins/Matrix.cpp15
3 files changed, 25 insertions, 2 deletions
diff --git a/src/Body.cpp b/src/Body.cpp
index f97d611..2bd5499 100644
--- a/src/Body.cpp
+++ b/src/Body.cpp
@@ -21,9 +21,11 @@ namespace QuickMedia {
dirty_description(false),
dirty_author(false),
thumbnail_is_local(false),
- title_color(sf::Color::White)
+ title_color(sf::Color::White),
+ author_color(sf::Color::White)
{
- set_title(std::move(_title));
+ if(!_title.empty())
+ set_title(std::move(_title));
}
BodyItem::BodyItem(const BodyItem &other) {
@@ -53,6 +55,7 @@ namespace QuickMedia {
replies = other.replies;
post_number = other.post_number;
title_color = other.title_color;
+ author_color = other.author_color;
}
Body::Body(Program *program, sf::Font *font, sf::Font *bold_font, sf::Font *cjk_font) :
@@ -405,6 +408,7 @@ namespace QuickMedia {
body_item->author_text->setString(std::move(str));
else
body_item->author_text = std::make_unique<Text>(std::move(str), bold_font, cjk_font, 14, size.x - 50 - image_padding_x * 2.0f);
+ body_item->author_text->setFillColor(body_item->author_color);
body_item->author_text->updateGeometry();
}
}
diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp
index c701c14..1039ca7 100644
--- a/src/QuickMedia.cpp
+++ b/src/QuickMedia.cpp
@@ -3195,6 +3195,8 @@ namespace QuickMedia {
messages_tab.body->draw_thumbnails = true;
messages_tab.body->thumbnail_resize_target_size.x = 600;
messages_tab.body->thumbnail_resize_target_size.y = 337;
+ messages_tab.body->thumbnail_fallback_size.x = 32;
+ messages_tab.body->thumbnail_fallback_size.y = 32;
//messages_tab.body->line_seperator_color = sf::Color::Transparent;
messages_tab.text = sf::Text("Messages", *font, tab_text_size);
tabs.push_back(std::move(messages_tab));
@@ -3204,6 +3206,8 @@ namespace QuickMedia {
rooms_tab.body = std::make_unique<Body>(this, font.get(), bold_font.get(), cjk_font.get());
rooms_tab.body->draw_thumbnails = true;
//rooms_tab.body->line_seperator_color = sf::Color::Transparent;
+ rooms_tab.body->thumbnail_fallback_size.x = 32;
+ rooms_tab.body->thumbnail_fallback_size.y = 32;
rooms_tab.text = sf::Text("Rooms", *font, tab_text_size);
tabs.push_back(std::move(rooms_tab));
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));
}