From 0f2faff4e73924c286254b9996ae46796b08b709 Mon Sep 17 00:00:00 2001
From: Nicolas Werner <nicolas.werner@hotmail.de>
Date: Wed, 24 Nov 2021 00:47:02 +0100
Subject: [PATCH 1/2] Use a more random hash to generate user colors

Fixes an issue where most uses just had their color determined by their
username length and distributes the colors a bit more evenly.
---
 src/Utils.cpp | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/src/Utils.cpp b/src/Utils.cpp
index dda6f685d..3a785ddb2 100644
--- a/src/Utils.cpp
+++ b/src/Utils.cpp
@@ -7,6 +7,7 @@
 #include <QApplication>
 #include <QBuffer>
 #include <QComboBox>
+#include <QCryptographicHash>
 #include <QDesktopWidget>
 #include <QGuiApplication>
 #include <QImageReader>
@@ -641,13 +642,9 @@ utils::linkColor()
 uint32_t
 utils::hashQString(const QString &input)
 {
-    uint32_t hash = 0;
+    auto h = QCryptographicHash::hash(input.toUtf8(), QCryptographicHash::Sha1);
 
-    for (int i = 0; i < input.length(); i++) {
-        hash = input.at(i).digitValue() + ((hash << 5) - hash);
-    }
-
-    return hash;
+    return (h[0] << 24) ^ (h[1] << 16) ^ (h[2] << 8) ^ h[3];
 }
 
 QColor
@@ -658,7 +655,10 @@ utils::generateContrastingHexColor(const QString &input, const QColor &backgroun
     // Create a color for the input
     auto hash = hashQString(input);
     // create a hue value based on the hash of the input.
-    auto userHue = static_cast<int>(hash % 360);
+    // Adapted to make Nico blue
+    auto userHue =
+      static_cast<int>(static_cast<double>(hash - static_cast<uint32_t>(0x60'00'00'00)) /
+                       std::numeric_limits<uint32_t>::max() * 360.);
     // start with moderate saturation and lightness values.
     auto sat       = 230;
     auto lightness = 125;
-- 
GitLab


From 2324d2de054b3676b0143bd03037ad27682cf6a0 Mon Sep 17 00:00:00 2001
From: Nicolas Werner <nicolas.werner@hotmail.de>
Date: Wed, 24 Nov 2021 04:09:22 +0100
Subject: [PATCH 2/2] Fix colors of sidebar in replies

---
 resources/qml/delegates/Reply.qml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/resources/qml/delegates/Reply.qml b/resources/qml/delegates/Reply.qml
index 601548372..4e973c3d1 100644
--- a/resources/qml/delegates/Reply.qml
+++ b/resources/qml/delegates/Reply.qml
@@ -48,7 +48,7 @@ Item {
         anchors.top: replyContainer.top
         anchors.bottom: replyContainer.bottom
         width: 4
-        color: TimelineManager.userColor(userId, Nheko.colors.window)
+        color: TimelineManager.userColor(userId, Nheko.colors.base)
     }
 
     Column {
-- 
GitLab