Przeglądaj źródła

Add private messages feature

master
Guénaël Muller 7 lat temu
rodzic
commit
d8019ad8bd

+ 10
- 0
JitsiConference.js Wyświetl plik

@@ -583,6 +583,16 @@ JitsiConference.prototype.sendTextMessage = function(message) {
583 583
     }
584 584
 };
585 585
 
586
+/**
587
+ * Send private text message to another participant of the conference
588
+ * @param message the text message.
589
+ */
590
+JitsiConference.prototype.sendPrivateTextMessage = function(id, message) {
591
+    if (this.room) {
592
+        this.room.sendPrivateMessage(id, message);
593
+    }
594
+};
595
+
586 596
 /**
587 597
  * Send presence command.
588 598
  * @param name {String} the name of the command.

+ 12
- 0
JitsiConferenceEventManager.js Wyświetl plik

@@ -310,6 +310,18 @@ JitsiConferenceEventManager.prototype.setupChatRoomListeners = function() {
310 310
                 id, txt, ts);
311 311
         });
312 312
 
313
+    chatRoom.addListener(
314
+        XMPPEvents.PRIVATE_MESSAGE_RECEIVED,
315
+
316
+        // eslint-disable-next-line max-params
317
+        (jid, displayName, txt, myJid, ts) => {
318
+            const id = Strophe.getResourceFromJid(jid);
319
+
320
+            conference.eventEmitter.emit(
321
+                JitsiConferenceEvents.PRIVATE_MESSAGE_RECEIVED,
322
+                id, txt, ts);
323
+        });
324
+
313 325
     chatRoom.addListener(XMPPEvents.PRESENCE_STATUS,
314 326
         (jid, status) => {
315 327
             const id = Strophe.getResourceFromJid(jid);

+ 5
- 0
JitsiConferenceEvents.js Wyświetl plik

@@ -125,6 +125,11 @@ export const LOCK_STATE_CHANGED = 'conference.lock_state_changed';
125 125
  */
126 126
 export const MESSAGE_RECEIVED = 'conference.messageReceived';
127 127
 
128
+/**
129
+ * New private text message was received.
130
+ */
131
+export const PRIVATE_MESSAGE_RECEIVED = 'conference.privateMessageReceived';
132
+
128 133
 /**
129 134
  * Event fired when JVB sends notification about interrupted/restored user's
130 135
  * ICE connection status or we detect local problem with the video track.

+ 34
- 3
modules/xmpp/ChatRoom.js Wyświetl plik

@@ -675,7 +675,7 @@ export default class ChatRoom extends Listenable {
675 675
     }
676 676
 
677 677
     /**
678
-     *
678
+     * Send text message to the other participants in the conference
679 679
      * @param body
680 680
      * @param nickname
681 681
      */
@@ -694,6 +694,29 @@ export default class ChatRoom extends Listenable {
694 694
         this.eventEmitter.emit(XMPPEvents.SENDING_CHAT_MESSAGE, body);
695 695
     }
696 696
 
697
+    /**
698
+     * Send private text message to another participant of the conference
699
+     * @param id id/muc resource of the receiver
700
+     * @param body
701
+     * @param nickname
702
+     */
703
+    sendPrivateMessage(id, body, nickname) {
704
+        const msg = $msg({ to: `${this.roomjid}/${id}`,
705
+            type: 'chat' });
706
+
707
+        msg.c('body', body).up();
708
+        if (nickname) {
709
+            msg.c('nick', { xmlns: 'http://jabber.org/protocol/nick' })
710
+                .t(nickname)
711
+                .up()
712
+                .up();
713
+        }
714
+
715
+        this.connection.send(msg);
716
+        this.eventEmitter.emit(XMPPEvents.SENDING_PRIVATE_CHAT_MESSAGE, body);
717
+    }
718
+
719
+
697 720
     /**
698 721
      *
699 722
      * @param subject
@@ -864,8 +887,16 @@ export default class ChatRoom extends Listenable {
864 887
         }
865 888
 
866 889
         if (txt) {
867
-            this.eventEmitter.emit(XMPPEvents.MESSAGE_RECEIVED,
868
-                from, nick, txt, this.myroomjid, stamp);
890
+            if (type === 'chat') {
891
+                logger.log('privatechat', nick, txt);
892
+                this.eventEmitter.emit(XMPPEvents.PRIVATE_MESSAGE_RECEIVED,
893
+                        from, nick, txt, this.myroomjid, stamp);
894
+            }
895
+            if (type === 'groupchat') {
896
+                logger.log('chat', nick, txt);
897
+                this.eventEmitter.emit(XMPPEvents.MESSAGE_RECEIVED,
898
+                        from, nick, txt, this.myroomjid, stamp);
899
+            }
869 900
         }
870 901
     }
871 902
 

+ 8
- 0
service/xmpp/XMPPEvents.js Wyświetl plik

@@ -97,6 +97,10 @@ const XMPPEvents = {
97 97
     // received.
98 98
     MESSAGE_RECEIVED: 'xmpp.message_received',
99 99
 
100
+    // Designates an event indicating that a private XMPP message in the MUC was
101
+    // received.
102
+    PRIVATE_MESSAGE_RECEIVED: 'xmpp.private_message_received',
103
+
100 104
     // Designates an event indicating that the XMPP MUC was destroyed.
101 105
     MUC_DESTROYED: 'xmpp.muc_destroyed',
102 106
 
@@ -171,6 +175,10 @@ const XMPPEvents = {
171 175
     // Designates an event indicating that we sent an XMPP message to the MUC.
172 176
     SENDING_CHAT_MESSAGE: 'xmpp.sending_chat_message',
173 177
 
178
+    // Designates an event indicating that we sent a private XMPP message to
179
+    // a specific user of the muc.
180
+    SENDING_PRIVATE_CHAT_MESSAGE: 'xmpp.sending_private_chat_message',
181
+
174 182
     /**
175 183
      * Event fired when we do not get our 'session-accept' acknowledged by
176 184
      * Jicofo. It most likely means that there is serious problem with our

Ładowanie…
Anuluj
Zapisz