Skip to content

Commit

Permalink
Bugfix. Ensure there's always an identifier to generate color from
Browse files Browse the repository at this point in the history
  • Loading branch information
jcbrand committed Sep 14, 2024
1 parent b545246 commit 59867e6
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/headless/shared/color.js
Original file line number Diff line number Diff line change
@@ -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<string>}
*/
Expand Down

0 comments on commit 59867e6

Please sign in to comment.