浏览代码

Make the `(me)` suffix filterable in the contacts list

JC Brand 2 月之前
父节点
当前提交
e4d45c9db1

+ 1 - 1
src/headless/plugins/chat/model.js

@@ -133,7 +133,7 @@ class ChatBox extends ModelWithVCard(ModelWithMessages(ModelWithContact(ColorAwa
      */
      */
     getDisplayName() {
     getDisplayName() {
         if (this.contact) {
         if (this.contact) {
-            const display_name = this.contact.getDisplayName(false);
+            const display_name = this.contact.getDisplayName({ no_jid: true });
             if (display_name) return display_name;
             if (display_name) return display_name;
         }
         }
 
 

+ 4 - 3
src/headless/plugins/roster/contact.js

@@ -68,10 +68,11 @@ class RosterContact extends ModelWithVCard(ColorAwareModel(Model)) {
     }
     }
 
 
     /**
     /**
-     * @returns {string|null}
+     * @param {import('./types').ContactDisplayNameOptions} [options]
+     * @returns {string}
      */
      */
-    getDisplayName (jid_fallback=true) {
-        return this.get('nickname') || this.vcard?.getDisplayName() || (jid_fallback ? this.get('jid') : null);
+    getDisplayName (options) {
+        return this.get('nickname') || this.vcard?.getDisplayName() || (options?.no_jid ? null : this.get('jid'));
     }
     }
 
 
     /**
     /**

+ 5 - 0
src/headless/plugins/roster/types.ts

@@ -11,3 +11,8 @@ export type RosterContactAttributes = {
     groups?: string[]; // Any roster groups the user might belong to
     groups?: string[]; // Any roster groups the user might belong to
     requesting?: boolean;
     requesting?: boolean;
 }
 }
+
+export type ContactDisplayNameOptions = {
+    no_jid?: boolean; // If true, null will be returned instead of the JID
+    context?: 'roster'; // The context in which the display name is being requested
+}

+ 7 - 3
src/headless/plugins/status/status.js

@@ -9,7 +9,6 @@ import { isIdle, getIdleSeconds } from './utils.js';
 const { Strophe, $pres } = converse.env;
 const { Strophe, $pres } = converse.env;
 
 
 export default class XMPPStatus extends ModelWithVCard(ColorAwareModel(Model)) {
 export default class XMPPStatus extends ModelWithVCard(ColorAwareModel(Model)) {
-
     defaults() {
     defaults() {
         return { status: api.settings.get('default_state') };
         return { status: api.settings.get('default_state') };
     }
     }
@@ -54,8 +53,13 @@ export default class XMPPStatus extends ModelWithVCard(ColorAwareModel(Model)) {
         });
         });
     }
     }
 
 
-    getDisplayName() {
-        return this.vcard?.get('fullname') || this.getNickname() || this.get('jid');
+    /**
+     * @param {import('../roster/types.js').ContactDisplayNameOptions} [options]
+     */
+    getDisplayName(options) {
+        const { __ } = _converse;
+        const name = this.vcard?.get('fullname') || this.getNickname() || this.get('jid');
+        return options?.context === 'roster' ? `${name} (${__('me')})` : name;
     }
     }
 
 
     getNickname() {
     getNickname() {

+ 3 - 2
src/headless/types/plugins/roster/contact.d.ts

@@ -156,9 +156,10 @@ declare class RosterContact extends RosterContact_base {
     getStatus(): any;
     getStatus(): any;
     openChat(): void;
     openChat(): void;
     /**
     /**
-     * @returns {string|null}
+     * @param {import('./types').ContactDisplayNameOptions} [options]
+     * @returns {string}
      */
      */
-    getDisplayName(jid_fallback?: boolean): string | null;
+    getDisplayName(options?: import("./types").ContactDisplayNameOptions): string;
     /**
     /**
      * Send a presence subscription request to this roster contact
      * Send a presence subscription request to this roster contact
      * @param {string} message - An optional message to explain the
      * @param {string} message - An optional message to explain the

+ 4 - 0
src/headless/types/plugins/roster/types.d.ts

@@ -10,4 +10,8 @@ export type RosterContactAttributes = {
     groups?: string[];
     groups?: string[];
     requesting?: boolean;
     requesting?: boolean;
 };
 };
+export type ContactDisplayNameOptions = {
+    no_jid?: boolean;
+    context?: 'roster';
+};
 //# sourceMappingURL=types.d.ts.map
 //# sourceMappingURL=types.d.ts.map

+ 4 - 1
src/headless/types/plugins/status/status.d.ts

@@ -149,7 +149,10 @@ export default class XMPPStatus extends XMPPStatus_base {
      */
      */
     set(key: string | any, val?: string | any, options?: any): false | this;
     set(key: string | any, val?: string | any, options?: any): false | this;
     initialize(): void;
     initialize(): void;
-    getDisplayName(): any;
+    /**
+     * @param {import('../roster/types.js').ContactDisplayNameOptions} [options]
+     */
+    getDisplayName(options?: import("../roster/types.js").ContactDisplayNameOptions): any;
     getNickname(): any;
     getNickname(): any;
     /** Constructs a presence stanza
     /** Constructs a presence stanza
      * @param {string} [type]
      * @param {string} [type]

+ 2 - 2
src/plugins/rosterview/templates/roster_item.js

@@ -37,7 +37,7 @@ export default  (el) => {
    const is_self = bare_jid === el.model.get('jid');
    const is_self = bare_jid === el.model.get('jid');
    const desc_status = STATUSES[show];
    const desc_status = STATUSES[show];
    const num_unread = getUnreadMsgsDisplay(el.model);
    const num_unread = getUnreadMsgsDisplay(el.model);
-   const display_name = el.model.getDisplayName();
+   const display_name = el.model.getDisplayName({ context: 'roster' });
    const jid = el.model.get('jid');
    const jid = el.model.get('jid');
    const i18n_chat = is_self ?
    const i18n_chat = is_self ?
       __('Click to chat with yourself') :
       __('Click to chat with yourself') :
@@ -63,7 +63,7 @@ export default  (el) => {
             class="${classes} chat-status chat-status--avatar"></converse-icon>
             class="${classes} chat-status chat-status--avatar"></converse-icon>
       </span>
       </span>
       ${ num_unread ? html`<span class="msgs-indicator badge">${ num_unread }</span>` : '' }
       ${ num_unread ? html`<span class="msgs-indicator badge">${ num_unread }</span>` : '' }
-      <span class="contact-name contact-name--${show} ${ num_unread ? 'unread-msgs' : ''}">${display_name + (is_self ? ` ${__('(me)')}` : '')}</span>
+      <span class="contact-name contact-name--${show} ${ num_unread ? 'unread-msgs' : ''}">${display_name}</span>
    </a>
    </a>
    <span class="contact-actions">
    <span class="contact-actions">
       ${ api.settings.get('allow_contact_removal') && !is_self ? tplRemoveLink(el) : '' }
       ${ api.settings.get('allow_contact_removal') && !is_self ? tplRemoveLink(el) : '' }

+ 1 - 1
src/plugins/rosterview/utils.js

@@ -117,7 +117,7 @@ export function toggleGroup(ev, name) {
 function getFilterCriteria(contact) {
 function getFilterCriteria(contact) {
     const nick = contact instanceof XMPPStatus ? contact.getNickname() : contact.get('nickname');
     const nick = contact instanceof XMPPStatus ? contact.getNickname() : contact.get('nickname');
     const jid = contact.get('jid');
     const jid = contact.get('jid');
-    let criteria = contact.getDisplayName();
+    let criteria = contact.getDisplayName({ context: 'roster' });
     criteria = !criteria.includes(jid) ? criteria.concat(`   ${jid}`) : criteria;
     criteria = !criteria.includes(jid) ? criteria.concat(`   ${jid}`) : criteria;
     criteria = !criteria.includes(nick) ? criteria.concat(`   ${nick}`) : criteria;
     criteria = !criteria.includes(nick) ? criteria.concat(`   ${nick}`) : criteria;
     return criteria.toLowerCase();
     return criteria.toLowerCase();