Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/spreed.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/js/models
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2017-09-08 14:13:25 +0300
committerJoas Schilling <coding@schilljs.com>2017-09-08 14:13:25 +0300
commita3103b5dd561e867503619cbe965395f5cdcb8a1 (patch)
treef2615b3bcb6f9b0ae2be2bb9462f9559b107d950 /js/models
parent2fcaec2b9fa18bd152ffccb8be45bd2a675bfb9d (diff)
Sort the participants
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'js/models')
-rw-r--r--js/models/participantcollection.js39
1 files changed, 36 insertions, 3 deletions
diff --git a/js/models/participantcollection.js b/js/models/participantcollection.js
index 74d19dd73..5968d9001 100644
--- a/js/models/participantcollection.js
+++ b/js/models/participantcollection.js
@@ -38,15 +38,48 @@
this.room = room;
this.url = OC.linkToOCS('apps/spreed/api/v1/room', 2) + this.room.get('token') + '/participants';
},
- // comparator: function(model) {
- // return -(model.get('lastPing'));
- // },
+
/**
* @param result
* @returns {Array}
*/
parse: function(result) {
return result.ocs.data;
+ },
+
+ /**
+ * Sort participants:
+ * - Moderators first
+ * - Online status
+ * - Alphabetic
+ *
+ * @param modelA
+ * @param modelB
+ * @returns {*}
+ */
+ comparator: function(modelA, modelB) {
+ var onlineA = modelA.get('sessionId') !== '' && modelA.get('sessionId') !== '0',
+ onlineB = modelB.get('sessionId') !== '' && modelB.get('sessionId') !== '0',
+ moderateA = modelA.get('participantType') === OCA.SpreedMe.app.OWNER ||
+ modelA.get('participantType') === OCA.SpreedMe.app.MODERATOR,
+ moderateB = modelB.get('participantType') === OCA.SpreedMe.app.OWNER ||
+ modelB.get('participantType') === OCA.SpreedMe.app.MODERATOR,
+ guestA = modelA.get('participantType') === OCA.SpreedMe.app.GUEST,
+ guestB = modelB.get('participantType') === OCA.SpreedMe.app.GUEST;
+
+ if (moderateA !== moderateB) {
+ return moderateB - moderateA;
+ }
+
+ if (onlineA !== onlineB) {
+ return onlineB - onlineA;
+ }
+
+ if (guestA !== guestB) {
+ return guestA - guestB;
+ }
+
+ return modelA.get('displayName') > modelB.get('displayName');
}
});