From 48ffee5fa78f44bd00d76772ad79ae4eeb6c8dc4 Mon Sep 17 00:00:00 2001 From: Alexey Andreyev Date: Wed, 15 May 2019 16:36:02 +0300 Subject: Move out the logic of the hue calculation to utils --- lib/user.cpp | 20 +------------------- 1 file changed, 1 insertion(+), 19 deletions(-) (limited to 'lib/user.cpp') diff --git a/lib/user.cpp b/lib/user.cpp index 7f3f11f6..7b695618 100644 --- a/lib/user.cpp +++ b/lib/user.cpp @@ -33,9 +33,6 @@ #include #include -#include -#include - #include using namespace QMatrixClient; @@ -50,23 +47,8 @@ class User::Private return Avatar(move(url)); } - qreal makeHueF() - { - Q_ASSERT(!userId.isEmpty()); - QByteArray hash = QCryptographicHash::hash(userId.toUtf8(), - QCryptographicHash::Sha1); - QDataStream dataStream(qToLittleEndian(hash).left(2)); - dataStream.setByteOrder(QDataStream::LittleEndian); - quint16 hashValue; - dataStream >> hashValue; - const auto hueF = - qreal(hashValue)/std::numeric_limits::max(); - Q_ASSERT((0 <= hueF) && (hueF <= 1)); - return hueF; - } - Private(QString userId, Connection* connection) - : userId(move(userId)), connection(connection), hueF(makeHueF()) + : userId(move(userId)), connection(connection), hueF(stringToHueF(this->userId)) { } QString userId; -- cgit v1.2.3