Skip to content

Commit

Permalink
Rename to usernameToColor
Browse files Browse the repository at this point in the history
Signed-off-by: Joas Schilling <coding@schilljs.com>
  • Loading branch information
nickvergessen committed Jun 16, 2020
1 parent e41efa8 commit 353ca16
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/components/Avatar/Avatar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ import { getCurrentUser } from '@nextcloud/auth'
import axios from '@nextcloud/axios'
import { generateUrl } from '@nextcloud/router'
import Tooltip from '../../directives/Tooltip'
import uidToColor from '../../functions/uidToColor'
import usernameToColor from '../../functions/usernameToColor'
export default {
name: 'Avatar',
Expand Down Expand Up @@ -275,7 +275,7 @@ export default {
}
if (!this.iconClass && !this.avatarSrcSetLoaded) {
const rgb = uidToColor(this.getUserIdentifier)
const rgb = usernameToColor(this.getUserIdentifier)
style.backgroundColor = 'rgb(' + rgb.r + ', ' + rgb.g + ', ' + rgb.b + ')'
}
return style
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@
*
*/

import uidToColor from './uidToColor'
import usernameToColor from './usernameToColor'

export default uidToColor
export default usernameToColor
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ import GenColors from '../../utils/GenColors'

/**
* Originally taken from https://github.com/nextcloud/server/blob/master/core/js/placeholder.js
* @param {string} uid unique id to generate from
* @param {string} username Display name or user id to generate from
* @returns {Object} the rgb colors as {r:255, g:255, b:255}
*/
const uidToColor = function(uid) {
const usernameToColor = function(username) {
// Normalize hash
let hash = uid.toLowerCase()
let hash = username.toLowerCase()

// Already a md5 hash?
if (hash.match(/^([0-9a-f]{4}-?){8}$/) === null) {
Expand Down Expand Up @@ -65,4 +65,4 @@ const uidToColor = function(uid) {
return finalPalette[hashToInt(hash, steps * 3)]
}

export default uidToColor
export default usernameToColor

0 comments on commit 353ca16

Please sign in to comment.