Browse Source

feat: add granting owner support

Used for extending owner privileges to other participants in the chat room.
dev1
Gabriel Imre 5 years ago
parent
commit
6c04e2739a
2 changed files with 37 additions and 0 deletions
  1. 13
    0
      JitsiConference.js
  2. 24
    0
      modules/xmpp/ChatRoom.js

+ 13
- 0
JitsiConference.js View File

@@ -1417,6 +1417,19 @@ JitsiConference.prototype.getParticipantById = function(id) {
1417 1417
     return this.participants[id];
1418 1418
 };
1419 1419
 
1420
+/**
1421
+ * Grant owner rights to the participant.
1422
+ * @param {string} id id of the participant to grant owner rights to.
1423
+ */
1424
+JitsiConference.prototype.grantOwner = function(id) {
1425
+    const participant = this.getParticipantById(id);
1426
+
1427
+    if (!participant) {
1428
+        return;
1429
+    }
1430
+    this.room.setAffiliation(participant.getJid(), 'owner');
1431
+};
1432
+
1420 1433
 /**
1421 1434
  * Kick participant from this conference.
1422 1435
  * @param {string} id id of the participant to kick

+ 24
- 0
modules/xmpp/ChatRoom.js View File

@@ -1130,6 +1130,30 @@ export default class ChatRoom extends Listenable {
1130 1130
         }
1131 1131
     }
1132 1132
 
1133
+    /**
1134
+     *
1135
+     * @param jid
1136
+     * @param affiliation
1137
+     */
1138
+    setAffiliation(jid, affiliation) {
1139
+        const grantIQ = $iq({
1140
+            to: this.roomjid,
1141
+            type: 'set'
1142
+        })
1143
+        .c('query', { xmlns: 'http://jabber.org/protocol/muc#admin' })
1144
+        .c('item', {
1145
+            affiliation,
1146
+            nick: Strophe.getResourceFromJid(jid)
1147
+        })
1148
+        .c('reason').t(`Your affiliation has been changed to '${affiliation}'.`)
1149
+        .up().up().up();
1150
+
1151
+        this.connection.sendIQ(
1152
+            grantIQ,
1153
+            result => logger.log('Set affiliation of participant with jid: ', jid, 'to', affiliation, result),
1154
+            error => logger.log('Set affiliation of participant error: ', error));
1155
+    }
1156
+
1133 1157
     /**
1134 1158
      *
1135 1159
      * @param jid

Loading…
Cancel
Save