浏览代码

Only add unsaved contact if not blocked

JC Brand 5 月之前
父节点
当前提交
a8a2c9898e

+ 17 - 18
src/headless/shared/model-with-contact.js

@@ -8,33 +8,32 @@ import api from './api/index.js';
  * @param {T} BaseModel
  */
 export default function ModelWithContact(BaseModel) {
-
     return class ModelWithContact extends BaseModel {
         /**
-        * @typedef {import('../plugins/vcard/vcard').default} VCard
-        * @typedef {import('../plugins/roster/contact').default} RosterContact
-        * @typedef {import('./_converse.js').XMPPStatus} XMPPStatus
-        */
+         * @typedef {import('../plugins/vcard/vcard').default} VCard
+         * @typedef {import('../plugins/roster/contact').default} RosterContact
+         * @typedef {import('./_converse.js').XMPPStatus} XMPPStatus
+         */
 
         initialize() {
             super.initialize();
             this.rosterContactAdded = getOpenPromise();
             /**
-            * @public
-            * @type {RosterContact|XMPPStatus}
-            */
+             * @public
+             * @type {RosterContact|XMPPStatus}
+             */
             this.contact = null;
 
             /**
-            * @public
-            * @type {VCard}
-            */
+             * @public
+             * @type {VCard}
+             */
             this.vcard = null;
         }
 
         /**
-        * @param {string} jid
-        */
+         * @param {string} jid
+         */
         async setModelContact(jid) {
             if (this.contact?.get('jid') === jid) return;
 
@@ -44,10 +43,10 @@ export default function ModelWithContact(BaseModel) {
             if (Strophe.getBareJidFromJid(jid) === session.get('bare_jid')) {
                 contact = state.xmppstatus;
             } else {
-                contact = await api.contacts.get(jid) || await api.contacts.add({
-                    jid,
-                    subscription: 'none',
-                }, false, false);
+                contact = await api.contacts.get(jid);
+                if (!contact && !(await api.blocklist.get()).get(jid)) {
+                    await api.contacts.add({ jid, subscription: 'none' }, false, false);
+                }
             }
 
             if (contact) {
@@ -65,5 +64,5 @@ export default function ModelWithContact(BaseModel) {
                 this.trigger('contactAdded', this.contact);
             }
         }
-    }
+    };
 }

+ 3 - 2
src/plugins/chatview/tests/markers.js

@@ -35,9 +35,10 @@ describe("A XEP-0333 Chat Marker", function () {
     }));
 
     it("is not sent when a markable message is received from someone not on the roster",
-            mock.initConverse([], {'allow_non_roster_messaging': true}, async function (_converse) {
+            mock.initConverse([], { allow_non_roster_messaging: true }, async function (_converse) {
 
         await mock.waitForRoster(_converse, 'current', 0);
+        await mock.waitUntilBlocklistInitialized(_converse);
         const contact_jid = 'someone@montague.lit';
         const msgid = u.getUniqueId();
         const stanza = stx`
@@ -58,7 +59,7 @@ describe("A XEP-0333 Chat Marker", function () {
             .map(s => s?.nodeTree ?? s)
             .filter(e => e.nodeName === 'message');
 
-        await u.waitUntil(() => sent_messages.length === 2);
+        await u.waitUntil(() => sent_messages.length === 1);
         expect(Strophe.serialize(sent_messages[0])).toBe(
             `<message id="${sent_messages[0].getAttribute('id')}" to="${contact_jid}" type="chat" xmlns="jabber:client">`+
                 `<active xmlns="http://jabber.org/protocol/chatstates"/>`+

+ 3 - 1
src/plugins/chatview/tests/messages.js

@@ -972,6 +972,7 @@ describe("A Chat Message", function () {
                     async function (_converse) {
 
                 const { api } = _converse;
+                await mock.waitUntilBlocklistInitialized(_converse);
                 await mock.waitForRoster(_converse, 'current', 0);
                 spyOn(_converse.api, "trigger").and.callThrough();
 
@@ -1017,7 +1018,6 @@ describe("A Chat Message", function () {
             }));
         });
 
-
         describe("who is not on the roster", function () {
 
             it("will open a chatbox and be displayed inside it if allow_non_roster_messaging is true",
@@ -1025,6 +1025,7 @@ describe("A Chat Message", function () {
                     [], {'allow_non_roster_messaging': false},
                     async function (_converse) {
 
+                await mock.waitUntilBlocklistInitialized(_converse);
                 await mock.waitForRoster(_converse, 'current', 0);
 
                 const { api } = _converse;
@@ -1049,6 +1050,7 @@ describe("A Chat Message", function () {
                 expect(view).not.toBeDefined();
 
                 api.settings.set('allow_non_roster_messaging', true);
+                        debugger;
                 await _converse.handleMessageStanza(msg);
                 view = _converse.chatboxviews.get(sender_jid);
                 await u.waitUntil(() => view.querySelectorAll('.chat-msg').length);

+ 5 - 0
src/shared/modals/styles/user-details.scss

@@ -0,0 +1,5 @@
+.conversejs {
+    .remove-contact {
+        margin-inline-end: 0.5em;
+    }
+}

+ 2 - 0
src/shared/modals/user-details.js

@@ -4,6 +4,8 @@ import BaseModal from "plugins/modal/modal.js";
 import { __ } from 'i18n';
 import { tplUserDetailsModal } from "./templates/user-details.js";
 
+import './styles/user-details.scss';
+
 
 export default class UserDetailsModal extends BaseModal {