JC Brand 3 years ago
parent
commit
75fee76693
3 changed files with 32 additions and 3 deletions
  1. 1 0
      CHANGES.md
  2. 2 2
      src/plugins/muc-views/sidebar.js
  3. 29 1
      src/plugins/muc-views/tests/occupants.js

+ 1 - 0
CHANGES.md

@@ -3,6 +3,7 @@
 ## 8.0.2 (Unreleased)
 
 - #2640: Add `beforeFetchLoginCredentials` hook
+- #2650: Clicking on occupant in sidebar should add nickname to textarea
 
 ## 8.0.1 (2021-09-09)
 

+ 2 - 2
src/plugins/muc-views/sidebar.js

@@ -43,8 +43,8 @@ export default class MUCSidebar extends CustomElement {
 
     onOccupantClicked (ev) {
         ev?.preventDefault?.();
-        const chatview = _converse.chatboxviews.get(this.getAttribute('jid'));
-        chatview?.getBottomPanel().insertIntoTextArea(`@${ev.target.textContent}`);
+        const view = _converse.chatboxviews.get(this.getAttribute('jid'));
+        view?.getMessageForm().insertIntoTextArea(`@${ev.target.textContent}`);
     }
 }
 

+ 29 - 1
src/plugins/muc-views/tests/occupants.js

@@ -2,7 +2,7 @@
 
 const { $pres, sizzle, u } = converse.env;
 
-describe("A Groupchat", function () {
+describe("The occupants sidebar", function () {
 
     it("shows all members even if they're not currently present in the groupchat",
             mock.initConverse([], {}, async function (_converse) {
@@ -135,6 +135,34 @@ describe("A Groupchat", function () {
         await u.waitUntil(() => occupants.querySelectorAll('li').length === 1);
     }));
 
+    it("lets you click on an occupant to insert it into the chat textarea",
+            mock.initConverse([], {'view_mode': 'fullscreen'}, async function (_converse) {
+
+        const muc_jid = 'lounge@montague.lit';
+        await mock.openAndEnterChatRoom(_converse, muc_jid, 'romeo');
+        var view = _converse.chatboxviews.get(muc_jid);
+        const occupants = view.querySelector('.occupant-list');
+        const name = mock.chatroom_names[0];
+        const presence = $pres({
+            to:'romeo@montague.lit/pda',
+            from:'lounge@montague.lit/'+name
+        }).c('x').attrs({xmlns:'http://jabber.org/protocol/muc#user'})
+        .c('item').attrs({
+            affiliation: 'none',
+            jid: name.replace(/ /g,'.').toLowerCase() + '@montague.lit',
+            role: 'participant'
+        }).up()
+        .c('status');
+        _converse.connection._dataRecv(mock.createRequest(presence));
+
+        await u.waitUntil(() => occupants.querySelectorAll('li').length > 1, 500);
+        expect(occupants.querySelectorAll('li').length).toBe(2);
+        view.querySelectorAll('.occupant-nick')[1].click()
+
+        const textarea = view.querySelector('.chat-textarea');
+        expect(textarea.value).toBe('@Dyon van de Wege ');
+    }));
+
     it("indicates moderators and visitors by means of a special css class and tooltip",
             mock.initConverse([], {'view_mode': 'fullscreen'}, async function (_converse) {