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

github.com/candy-chat/candy.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Langfeld <ben@langfeld.me>2015-03-05 18:55:38 +0300
committerBen Langfeld <ben@langfeld.me>2015-03-05 18:55:38 +0300
commitd09d0e6cebab12452b820668f84f155302a97d0b (patch)
treea186361cc7a512c38caac6e1aead9b4738d7f48d
parent0162423ee1d8c52db94139b439ef9e1c7c0fcfa9 (diff)
Sort MUC members based on status
Does not currently re-sort in the case of a member coming online
-rw-r--r--src/view/pane/roster.js21
-rw-r--r--src/view/template.js2
2 files changed, 19 insertions, 4 deletions
diff --git a/src/view/pane/roster.js b/src/view/pane/roster.js
index cde6ab7..70ccd8f 100644
--- a/src/view/pane/roster.js
+++ b/src/view/pane/roster.js
@@ -92,11 +92,11 @@ Candy.View.Pane = (function(self, $) {
// there are already users in the roster
if(rosterPane.children().length > 0) {
- // insert alphabetically
- var userSortCompare = user.getNick().toUpperCase();
+ // insert alphabetically, sorted by status
+ var userSortCompare = self.Roster._userSortCompare(user.getNick(), user.getStatus());
rosterPane.children().each(function() {
var elem = $(this);
- if(elem.attr('data-nick').toUpperCase() > userSortCompare) {
+ if(self.Roster._userSortCompare(elem.attr('data-nick'), elem.attr('data-status')) > userSortCompare) {
elem.before(html);
userInserted = true;
return false;
@@ -187,6 +187,21 @@ Candy.View.Pane = (function(self, $) {
$(Candy).triggerHandler('candy:view.roster.after-update', evtData);
},
+ _userSortCompare: function(nick, status) {
+ var statusWeight;
+ switch (status) {
+ case 'available':
+ statusWeight = 1;
+ break;
+ case 'unavailable':
+ statusWeight = 9;
+ break;
+ default:
+ statusWeight = 8;
+ }
+ return statusWeight + nick.toUpperCase();
+ },
+
/** Function: userClick
* Click handler for opening a private room
*/
diff --git a/src/view/template.js b/src/view/template.js
index 5c3c104..d116709 100644
--- a/src/view/template.js
+++ b/src/view/template.js
@@ -80,7 +80,7 @@ Candy.View.Template = (function(self){
pane: '<div class="roster-pane"></div>',
user: '<div class="user role-{{role}} affiliation-{{affiliation}}{{#me}} me{{/me}}"' +
' id="user-{{roomId}}-{{userId}}" data-jid="{{userJid}}" data-real-jid="{{realJid}}"' +
- ' data-nick="{{nick}}" data-role="{{role}}" data-affiliation="{{affiliation}}">' +
+ ' data-nick="{{nick}}" data-role="{{role}}" data-affiliation="{{affiliation}}" data-status="{{status}}">' +
'<div class="label">{{displayNick}}</div><ul>' +
'<li class="context" id="context-{{roomId}}-{{userId}}">&#x25BE;</li>' +
'<li class="role role-{{role}} affiliation-{{affiliation}}" data-tooltip="{{tooltipRole}}"></li>' +