chat/src/util/colorMXID.js
Ajay Bura 4f09e6bbb5
(chore) remove outdated code (#1765)
* optimize room typing members hook

* remove unused code - WIP

* remove old code from initMatrix

* remove twemojify function

* remove old sanitize util

* delete old markdown util

* delete Math atom component

* uninstall unused dependencies

* remove old notification system

* decrypt message in inbox notification center and fix refresh in background

* improve notification

---------

Co-authored-by: Krishan <33421343+kfiven@users.noreply.github.com>
2024-07-08 21:27:10 +10:00

27 lines
630 B
JavaScript

// https://github.com/cloudrac3r/cadencegq/blob/master/pug/mxid.pug
function hashCode(str) {
let hash = 0;
let i;
let chr;
if (str.length === 0) {
return hash;
}
for (i = 0; i < str.length; i += 1) {
chr = str.charCodeAt(i);
// eslint-disable-next-line no-bitwise
hash = ((hash << 5) - hash) + chr;
// eslint-disable-next-line no-bitwise
hash |= 0;
}
return Math.abs(hash);
}
export function cssColorMXID(userId) {
const colorNumber = hashCode(userId) % 8;
return `--mx-uc-${colorNumber + 1}`;
}
export default function colorMXID(userId) {
return `var(${cssColorMXID(userId)})`;
}