فهرست منبع

Bugfix. Ensure there's always an identifier to generate color from

JC Brand 10 ماه پیش
والد
کامیت
59867e6e1b
1فایلهای تغییر یافته به همراه12 افزوده شده و 2 حذف شده
  1. 12 2
      src/headless/shared/color.js

+ 12 - 2
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<string>}
      */