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 19:35:12 +0300
committerBen Langfeld <ben@langfeld.me>2015-03-05 19:35:12 +0300
commitf0338122001e563de03352505102b9716caa241d (patch)
tree1735812012a580c148832db657fd4d44f919f8fc
parent1089c44b7b3dd53fbc30eb2cf50f970348116c2d (diff)
Re-insert members into a roster when their status changesfeature/offline_muc_roster
They need to go in the correct order
-rw-r--r--src/view/pane/roster.js86
1 files changed, 45 insertions, 41 deletions
diff --git a/src/view/pane/roster.js b/src/view/pane/roster.js
index 70ccd8f..c7d94ca 100644
--- a/src/view/pane/roster.js
+++ b/src/view/pane/roster.js
@@ -69,52 +69,15 @@ Candy.View.Pane = (function(self, $) {
// a user joined the room
if(action === 'join') {
usercountDiff = 1;
- var contact = user.getContact();
- var html = Mustache.to_html(Candy.View.Template.Roster.user, {
- roomId: roomId,
- userId : userId,
- userJid: user.getJid(),
- realJid: user.getRealJid(),
- status: user.getStatus(),
- contact_status: contact ? contact.getStatus() : 'unavailable',
- nick: user.getNick(),
- displayNick: Candy.Util.crop(user.getNick(), Candy.View.getOptions().crop.roster.nickname),
- role: user.getRole(),
- affiliation: user.getAffiliation(),
- me: currentUser !== undefined && user.getNick() === currentUser.getNick(),
- tooltipRole: $.i18n._('tooltipRole'),
- tooltipIgnored: $.i18n._('tooltipIgnored')
- });
if(userElem.length < 1) {
- var userInserted = false,
- rosterPane = self.Room.getPane(roomJid, '.roster-pane');
-
- // there are already users in the roster
- if(rosterPane.children().length > 0) {
- // insert alphabetically, sorted by status
- var userSortCompare = self.Roster._userSortCompare(user.getNick(), user.getStatus());
- rosterPane.children().each(function() {
- var elem = $(this);
- if(self.Roster._userSortCompare(elem.attr('data-nick'), elem.attr('data-status')) > userSortCompare) {
- elem.before(html);
- userInserted = true;
- return false;
- }
- return true;
- });
- }
- // first user in roster
- if(!userInserted) {
- rosterPane.append(html);
- }
-
+ self.Roster._insertUser(roomJid, roomId, user, userId, currentUser);
self.Roster.showJoinAnimation(user, userId, roomId, roomJid, currentUser);
// user is in room but maybe the affiliation/role has changed
} else {
usercountDiff = 0;
- userElem.replaceWith(html);
- $('#user-' + roomId + '-' + userId).css({opacity: 1}).show();
+ userElem.remove();
+ self.Roster._insertUser(roomJid, roomId, user, userId, currentUser);
// it's me, update the toolbar
if(currentUser !== undefined && user.getNick() === currentUser.getNick() && self.Room.getUser(roomJid)) {
self.Chat.Toolbar.update(roomJid);
@@ -145,7 +108,7 @@ Candy.View.Pane = (function(self, $) {
if (self.Chat.rooms[roomJid].type === 'chat') {
self.Chat.onInfoMessage(roomJid, $.i18n._('userLeftRoom', [user.getNick()]));
} else {
- self.Chat.infoMessage(roomJid, $.i18n._('userLeftRoom', [user.getNick()]));
+ self.Chat.infoMessage(roomJid, $.i18n._('userLeftRoom', [user.getNick()]), '');
}
} else if(action === 'nickchange') {
@@ -187,6 +150,47 @@ Candy.View.Pane = (function(self, $) {
$(Candy).triggerHandler('candy:view.roster.after-update', evtData);
},
+ _insertUser: function(roomJid, roomId, user, userId, currentUser) {
+ var contact = user.getContact();
+ var html = Mustache.to_html(Candy.View.Template.Roster.user, {
+ roomId: roomId,
+ userId : userId,
+ userJid: user.getJid(),
+ realJid: user.getRealJid(),
+ status: user.getStatus(),
+ contact_status: contact ? contact.getStatus() : 'unavailable',
+ nick: user.getNick(),
+ displayNick: Candy.Util.crop(user.getNick(), Candy.View.getOptions().crop.roster.nickname),
+ role: user.getRole(),
+ affiliation: user.getAffiliation(),
+ me: currentUser !== undefined && user.getNick() === currentUser.getNick(),
+ tooltipRole: $.i18n._('tooltipRole'),
+ tooltipIgnored: $.i18n._('tooltipIgnored')
+ });
+
+ var userInserted = false,
+ rosterPane = self.Room.getPane(roomJid, '.roster-pane');
+
+ // there are already users in the roster
+ if(rosterPane.children().length > 0) {
+ // insert alphabetically, sorted by status
+ var userSortCompare = self.Roster._userSortCompare(user.getNick(), user.getStatus());
+ rosterPane.children().each(function() {
+ var elem = $(this);
+ if(self.Roster._userSortCompare(elem.attr('data-nick'), elem.attr('data-status')) > userSortCompare) {
+ elem.before(html);
+ userInserted = true;
+ return false;
+ }
+ return true;
+ });
+ }
+ // first user in roster
+ if(!userInserted) {
+ rosterPane.append(html);
+ }
+ },
+
_userSortCompare: function(nick, status) {
var statusWeight;
switch (status) {