From 59867e6e1b19844370d96c894726960f6aa198d9 Mon Sep 17 00:00:00 2001 From: JC Brand Date: Sun, 15 Sep 2024 00:37:03 +0200 Subject: [PATCH] Bugfix. Ensure there's always an identifier to generate color from --- src/headless/shared/color.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/headless/shared/color.js b/src/headless/shared/color.js index 3c95e4b46d..f3c0703a26 100644 --- a/src/headless/shared/color.js +++ b/src/headless/shared/color.js @@ -1,15 +1,25 @@ import { Model } from '@converse/skeletor'; import u from '../utils/index.js'; +import { CHATROOMS_TYPE } from './constants.js'; const { safeSave, colorize } = u; class ColorAwareModel extends Model { - async setColor() { - const color = await colorize(this.get('jid')); + const color = await colorize(this.getIdentifier()); safeSave(this, { color }); } + getIdentifier() { + if (this.get('type') === CHATROOMS_TYPE) { + return this.get('jid'); + } else if (this.get('type') === 'groupchat') { + return this.get('from_real_jid') || this.get('from'); + } else { + return this.get('occupant_id') || this.get('jid') || this.get('from') || this.get('nick'); + } + } + /** * @returns {Promise} */