瀏覽代碼

feat: participant kick reason add

dev1
muammer.yilmaz.x 4 年之前
父節點
當前提交
7f5d7ce192
共有 2 個檔案被更改,包括 22 行新增8 行删除
  1. 7
    5
      JitsiConference.js
  2. 15
    3
      modules/xmpp/ChatRoom.js

+ 7
- 5
JitsiConference.js 查看文件

1473
 /**
1473
 /**
1474
  * Kick participant from this conference.
1474
  * Kick participant from this conference.
1475
  * @param {string} id id of the participant to kick
1475
  * @param {string} id id of the participant to kick
1476
+ * @param {string} reason reason of the participant to kick
1476
  */
1477
  */
1477
-JitsiConference.prototype.kickParticipant = function(id) {
1478
+JitsiConference.prototype.kickParticipant = function(id, reason) {
1478
     const participant = this.getParticipantById(id);
1479
     const participant = this.getParticipantById(id);
1479
 
1480
 
1480
     if (!participant) {
1481
     if (!participant) {
1481
         return;
1482
         return;
1482
     }
1483
     }
1483
-    this.room.kick(participant.getJid());
1484
+    this.room.kick(participant.getJid(), reason);
1484
 };
1485
 };
1485
 
1486
 
1486
 /**
1487
 /**
1708
  * of the kick.
1709
  * of the kick.
1709
  * @param {string?} kickedParticipantId - when it is not a kick for local participant,
1710
  * @param {string?} kickedParticipantId - when it is not a kick for local participant,
1710
  * this is the id of the participant which was kicked.
1711
  * this is the id of the participant which was kicked.
1712
+ * @param {string} reason - reason of the participant to kick
1711
  */
1713
  */
1712
-JitsiConference.prototype.onMemberKicked = function(isSelfPresence, actorId, kickedParticipantId) {
1714
+JitsiConference.prototype.onMemberKicked = function(isSelfPresence, actorId, kickedParticipantId, reason) {
1713
     // This check which be true when we kick someone else. With the introduction of lobby
1715
     // This check which be true when we kick someone else. With the introduction of lobby
1714
     // the ChatRoom KICKED event is now also emitted for ourselves (the kicker) so we want to
1716
     // the ChatRoom KICKED event is now also emitted for ourselves (the kicker) so we want to
1715
     // avoid emitting an event where `undefined` kicked someone.
1717
     // avoid emitting an event where `undefined` kicked someone.
1721
 
1723
 
1722
     if (isSelfPresence) {
1724
     if (isSelfPresence) {
1723
         this.eventEmitter.emit(
1725
         this.eventEmitter.emit(
1724
-            JitsiConferenceEvents.KICKED, actorParticipant);
1726
+            JitsiConferenceEvents.KICKED, actorParticipant, reason);
1725
 
1727
 
1726
         this.leave();
1728
         this.leave();
1727
 
1729
 
1731
     const kickedParticipant = this.participants[kickedParticipantId];
1733
     const kickedParticipant = this.participants[kickedParticipantId];
1732
 
1734
 
1733
     this.eventEmitter.emit(
1735
     this.eventEmitter.emit(
1734
-        JitsiConferenceEvents.PARTICIPANT_KICKED, actorParticipant, kickedParticipant);
1736
+        JitsiConferenceEvents.PARTICIPANT_KICKED, actorParticipant, kickedParticipant, reason);
1735
 };
1737
 };
1736
 
1738
 
1737
 /**
1739
 /**

+ 15
- 3
modules/xmpp/ChatRoom.js 查看文件

987
                 actorNick = actorSelect.attr('nick');
987
                 actorNick = actorSelect.attr('nick');
988
             }
988
             }
989
 
989
 
990
+            let reason;
991
+            const reasonSelect
992
+                = $(pres).find(
993
+                '>x[xmlns="http://jabber.org/protocol/muc#user"]'
994
+                + '>item>reason');
995
+
996
+            if (reasonSelect.length) {
997
+                reason = reasonSelect.text();
998
+            }
999
+
990
             // we first fire the kicked so we can show the participant
1000
             // we first fire the kicked so we can show the participant
991
             // who kicked, before notifying that participant left
1001
             // who kicked, before notifying that participant left
992
             // we fire kicked for us and for any participant kicked
1002
             // we fire kicked for us and for any participant kicked
994
                 XMPPEvents.KICKED,
1004
                 XMPPEvents.KICKED,
995
                 isSelfPresence,
1005
                 isSelfPresence,
996
                 actorNick,
1006
                 actorNick,
997
-                Strophe.getResourceFromJid(from));
1007
+                Strophe.getResourceFromJid(from),
1008
+                reason);
998
         }
1009
         }
999
 
1010
 
1000
         if (isSelfPresence) {
1011
         if (isSelfPresence) {
1201
     /**
1212
     /**
1202
      *
1213
      *
1203
      * @param jid
1214
      * @param jid
1215
+     * @param reason
1204
      */
1216
      */
1205
-    kick(jid) {
1217
+    kick(jid, reason = 'You have been kicked.') {
1206
         const kickIQ = $iq({ to: this.roomjid,
1218
         const kickIQ = $iq({ to: this.roomjid,
1207
             type: 'set' })
1219
             type: 'set' })
1208
             .c('query', { xmlns: 'http://jabber.org/protocol/muc#admin' })
1220
             .c('query', { xmlns: 'http://jabber.org/protocol/muc#admin' })
1209
             .c('item', { nick: Strophe.getResourceFromJid(jid),
1221
             .c('item', { nick: Strophe.getResourceFromJid(jid),
1210
                 role: 'none' })
1222
                 role: 'none' })
1211
-            .c('reason').t('You have been kicked.').up().up().up();
1223
+            .c('reason').t(reason).up().up().up();
1212
 
1224
 
1213
         this.connection.sendIQ(
1225
         this.connection.sendIQ(
1214
             kickIQ,
1226
             kickIQ,

Loading…
取消
儲存