Commit 172ce7e0 authored by JC Brand's avatar JC Brand

Remove the members-list work and keep the nickname form stuff

It's not stable yet and XMPP server support is very patchy.
However, the nickname form work can be merged into master.
parent 0d105b8a
...@@ -2043,12 +2043,9 @@ ...@@ -2043,12 +2043,9 @@
padding: 2px 5px; padding: 2px 5px;
text-overflow: ellipsis; text-overflow: ellipsis;
white-space: nowrap; white-space: nowrap;
color: #A8ABA1;
width: 100px; } width: 100px; }
#conversejs .chatroom .box-flyout .chatroom-body .occupants .occupant-list li.online { #conversejs .chatroom .box-flyout .chatroom-body .occupants .occupant-list li.moderator {
color: #1A9707; } color: #D24E2B; }
#conversejs .chatroom .box-flyout .chatroom-body .occupants .occupant-list li.online.moderator {
color: #D24E2B; }
#conversejs .chatroom .box-flyout .chatroom-body .chatroom-form-container { #conversejs .chatroom .box-flyout .chatroom-body .chatroom-form-container {
background-color: white; background-color: white;
border-bottom-left-radius: 4px; border-bottom-left-radius: 4px;
......
# Changelog # Changelog
## 1.0.5 (Unreleased) ## 1.0.5 (Unreleased)
- In case of a nickname conflict when joining a room, allow the user to choose a new nickname. [jcbrand] - In case of nickname conflict when joining a room, allow the user to choose a new one.
- Check whether the user has a reserved nickname before entering a room, and if so, use it. [jcbrand] [jcbrand]
- Check whether the user has a reserved nickname before entering a room, and if so,
use it. [jcbrand]
## 1.0.4 (2016-07-26) ## 1.0.4 (2016-07-26)
......
...@@ -108,13 +108,9 @@ ...@@ -108,13 +108,9 @@
padding: 2px 5px; padding: 2px 5px;
text-overflow: ellipsis; text-overflow: ellipsis;
white-space: nowrap; white-space: nowrap;
color: $light-text-color;
width: 100px; width: 100px;
&.online { &.moderator {
color: $online-color; color: $moderator-color;
&.moderator {
color: $moderator-color;
}
} }
} }
} }
......
...@@ -217,7 +217,7 @@ ...@@ -217,7 +217,7 @@
}).nodeTree; }).nodeTree;
converse.connection._dataRecv(test_utils.createRequest(presence)); converse.connection._dataRecv(test_utils.createRequest(presence));
expect(view.onChatRoomPresence).toHaveBeenCalled(); expect(view.onChatRoomPresence).toHaveBeenCalled();
expect($occupants.find('li.online').length).toBe(i+1); expect($occupants.find('li').length).toBe(i+1);
} }
}.bind(converse)); }.bind(converse));
...@@ -522,7 +522,7 @@ ...@@ -522,7 +522,7 @@
*/ */
var __ = utils.__.bind(converse); var __ = utils.__.bind(converse);
test_utils.openAndEnterChatRoom('lounge', 'localhost', 'oldnick'); test_utils.openAndEnterChatRoom('lounge', 'localhost', 'oldnick');
var view = this.chatboxviews.get('lounge@localhost'); var view = converse.chatboxviews.get('lounge@localhost');
var $chat_content = view.$el.find('.chat-content'); var $chat_content = view.$el.find('.chat-content');
spyOn(view, 'onChatRoomPresence').andCallThrough(); spyOn(view, 'onChatRoomPresence').andCallThrough();
...@@ -543,12 +543,11 @@ ...@@ -543,12 +543,11 @@
.c('status').attrs({code:'110'}).up() .c('status').attrs({code:'110'}).up()
.c('status').attrs({code:'210'}).nodeTree; .c('status').attrs({code:'210'}).nodeTree;
this.connection._dataRecv(test_utils.createRequest(presence)); converse.connection._dataRecv(test_utils.createRequest(presence));
expect(view.onChatRoomPresence).toHaveBeenCalled(); expect(view.onChatRoomPresence).toHaveBeenCalled();
var $occupants = view.$('.occupant-list'); var $occupants = view.$('.occupant-list');
expect($occupants.children().length).toBe(1); expect($occupants.children().length).toBe(1);
expect($occupants.children().first(0).text()).toBe("oldnick"); expect($occupants.children().first(0).text()).toBe("oldnick");
expect($occupants.children().first().hasClass('online')).toBe(true);
expect($chat_content.find('div.chat-info').length).toBe(1); expect($chat_content.find('div.chat-info').length).toBe(1);
expect($chat_content.find('div.chat-info').html()).toBe(__(view.newNicknameMessages["210"], "oldnick")); expect($chat_content.find('div.chat-info').html()).toBe(__(view.newNicknameMessages["210"], "oldnick"));
...@@ -569,17 +568,13 @@ ...@@ -569,17 +568,13 @@
.c('status').attrs({code:'303'}).up() .c('status').attrs({code:'303'}).up()
.c('status').attrs({code:'110'}).nodeTree; .c('status').attrs({code:'110'}).nodeTree;
this.connection._dataRecv(test_utils.createRequest(presence)); converse.connection._dataRecv(test_utils.createRequest(presence));
expect(view.onChatRoomPresence).toHaveBeenCalled(); expect(view.onChatRoomPresence).toHaveBeenCalled();
expect($chat_content.find('div.chat-info').length).toBe(2); expect($chat_content.find('div.chat-info').length).toBe(2);
expect($chat_content.find('div.chat-info').last().html()).toBe(__(view.newNicknameMessages["303"], "newnick")); expect($chat_content.find('div.chat-info').last().html()).toBe(__(view.newNicknameMessages["303"], "newnick"));
// The occupant is still listed (because they have affiliation
// of "member"), but they don't have the "online" class
// anymore.
$occupants = view.$('.occupant-list'); $occupants = view.$('.occupant-list');
expect($occupants.children().length).toBe(1); expect($occupants.children().length).toBe(0);
expect($occupants.children().first().hasClass('online')).toBe(false);
presence = $pres().attrs({ presence = $pres().attrs({
from:'lounge@localhost/newnick', from:'lounge@localhost/newnick',
...@@ -594,14 +589,14 @@ ...@@ -594,14 +589,14 @@
}).up() }).up()
.c('status').attrs({code:'110'}).nodeTree; .c('status').attrs({code:'110'}).nodeTree;
this.connection._dataRecv(test_utils.createRequest(presence)); converse.connection._dataRecv(test_utils.createRequest(presence));
expect(view.onChatRoomPresence).toHaveBeenCalled(); expect(view.onChatRoomPresence).toHaveBeenCalled();
expect($chat_content.find('div.chat-info').length).toBe(2); expect($chat_content.find('div.chat-info').length).toBe(2);
expect($chat_content.find('div.chat-info').last().html()).toBe(__(view.newNicknameMessages["303"], "newnick")); expect($chat_content.find('div.chat-info').last().html()).toBe(__(view.newNicknameMessages["303"], "newnick"));
$occupants = view.$('.occupant-list'); $occupants = view.$('.occupant-list');
expect($occupants.children().length).toBe(1); expect($occupants.children().length).toBe(1);
expect($occupants.children().first(0).text()).toBe("newnick"); expect($occupants.children().first(0).text()).toBe("newnick");
}.bind(converse)); });
it("informs users if they have been kicked out of the chat room", function () { it("informs users if they have been kicked out of the chat room", function () {
/* <presence /* <presence
......
...@@ -202,8 +202,6 @@ ...@@ -202,8 +202,6 @@
this.occupantsview.chatroomview = this; this.occupantsview.chatroomview = this;
this.render().$el.hide(); this.render().$el.hide();
this.occupantsview.model.fetch({add:true}); this.occupantsview.model.fetch({add:true});
_.each(['member', 'owner', 'admin'], this.fetchMembersList.bind(this));
var nick = this.model.get('nick'); var nick = this.model.get('nick');
if (!nick) { if (!nick) {
this.checkForReservedNick(); this.checkForReservedNick();
...@@ -262,61 +260,6 @@ ...@@ -262,61 +260,6 @@
converse.ChatBoxView.prototype.close.apply(this, arguments); converse.ChatBoxView.prototype.close.apply(this, arguments);
}, },
fetchMembersList: function (affiliation) {
/* Fetch the member-list for a particular affiliation.
*
* Unfortunately it doesn't seem to work when trying to
* fetch a list for all affiliations, so we need to fetch
* them one by one.
*/
var iq = $iq({
'to': this.model.get('jid'),
'type': "get",
'from': converse.connection.jid
}).c("query", {'xmlns': Strophe.NS.MUC_ADMIN})
.c("item", {'affiliation': affiliation});
return converse.connection.sendIQ(
iq.tree(),
this.occupantsview.updateOccupantsOnMembersList.bind(this.occupantsview),
_.bind(this.onMembersListError, this, affiliation)
);
},
updateMembersList: function (members) {
/* Update the room's member-lists by sending a delta of
* changed memberships (for all affiliations).
*/
var iq = $iq({'to':this.model.get('jid'), 'type':'set', 'from':converse.connection.jid})
.c("query", {'xmlns': Strophe.NS.MUC_ADMIN});
_.each(members, function (member) {
iq.c('item', {
'affiliation': member.affiliation !== 'none' ? member.affiliation : 'member',
'jid': Strophe.getBareJidFromJid(member.jid)
});
});
return converse.connection.sendIQ(
iq.tree(),
this.onMembersListChanged.bind(this),
this.onMembersListChangedError.bind(this)
);
},
onMembersListChanged: function (stanza) {
converse.log("The membership-list for "+this.model.get('jid')+" has been succesfully updated");
},
onMembersListChangedError: function (stanza) {
this.showStatusNotification(__("An error occurred while trying to update the members list."));
},
onMembersListError: function (affiliation, iq) {
if (iq.getElementsByTagName('forbidden').length) {
converse.log("You are forbidden from retrieving the "+affiliation+"-list for "+this.model.get('jid'));
} else {
converse.log("Could not retrieve "+affiliation+"-list for "+this.model.get('jid'), "error");
}
},
toggleOccupants: function (ev, preserve_state) { toggleOccupants: function (ev, preserve_state) {
if (ev) { if (ev) {
ev.preventDefault(); ev.preventDefault();
...@@ -348,10 +291,6 @@ ...@@ -348,10 +291,6 @@
}; };
if (reason !== null) { attrs.reason = reason; } if (reason !== null) { attrs.reason = reason; }
if (this.model.get('password')) { attrs.password = this.model.get('password'); } if (this.model.get('password')) { attrs.password = this.model.get('password'); }
// We also add the invitee to the room's member-list.
this.updateMembersList([{'jid': recipient, 'affiliation': 'member'}]);
var invitation = $msg({ var invitation = $msg({
from: converse.connection.jid, from: converse.connection.jid,
to: recipient, to: recipient,
...@@ -681,20 +620,7 @@ ...@@ -681,20 +620,7 @@
}, },
onConfigSaved: function (stanza) { onConfigSaved: function (stanza) {
/* // TODO: provide feedback
* When changing a room to members-only, do we want to then
* add all current users to the membership list?
*
var members = [];
this.occupantsview.model.each(function (occupant) {
var affiliation = occupant.get('affiliation');
members.push({
'affiliation': affiliation !== 'none' ? affiliation : 'member',
'jid': Strophe.getBareJidFromJid(occupant.get('jid'))
});
});
this.updateMembersList(members);
*/
}, },
onErrorConfigSaved: function (stanza) { onErrorConfigSaved: function (stanza) {
...@@ -1096,7 +1022,6 @@ ...@@ -1096,7 +1022,6 @@
initialize: function (attributes) { initialize: function (attributes) {
this.set(_.extend({ this.set(_.extend({
'id': converse.connection.getUniqueId(), 'id': converse.connection.getUniqueId(),
'online': false
}, attributes)); }, attributes));
} }
}); });
...@@ -1109,13 +1034,12 @@ ...@@ -1109,13 +1034,12 @@
}, },
render: function () { render: function () {
var new_el = converse.templates.occupant( var new_el = converse.templates.occupant(
_.extend({ _.extend(
'nick': this.model.get('jid') || '', this.model.toJSON(), {
'role': null, 'desc_moderator': __('This user is a moderator'),
'desc_moderator': __('This user is a moderator'), 'desc_occupant': __('This user can send messages in this room'),
'desc_occupant': __('This user can send messages in this room'), 'desc_visitor': __('This user can NOT send messages in this room')
'desc_visitor': __('This user can NOT send messages in this room') })
}, this.model.toJSON())
); );
var $parents = this.$el.parents(); var $parents = this.$el.parents();
if ($parents.length) { if ($parents.length) {
...@@ -1226,28 +1150,20 @@ ...@@ -1226,28 +1150,20 @@
}, },
updateOccupantsOnPresence: function (pres) { updateOccupantsOnPresence: function (pres) {
var attributes;
var data = this.parsePresence(pres); var data = this.parsePresence(pres);
var jid = Strophe.getBareJidFromJid(data.jid);
if (data.type === 'error') { if (data.type === 'error') {
return true; return true;
} }
var occupant = this.findOccupant(data); var occupant = this.findOccupant(data);
switch (data.type) { switch (data.type) {
case 'unavailable': case 'unavailable':
if (occupant) { if (occupant) { occupant.destroy(); }
if (_.contains(['owner', 'admin', 'member'], occupant.get('affiliation'))) {
occupant.save({'online': false});
} else {
occupant.destroy();
}
}
break; break;
default: default:
attributes = _.extend(data, { var jid = Strophe.getBareJidFromJid(data.jid);
var attributes = _.extend(data, {
'jid': jid ? jid : undefined, 'jid': jid ? jid : undefined,
'resource': data.jid ? Strophe.getResourceFromJid(data.jid) : undefined, 'resource': data.jid ? Strophe.getResourceFromJid(data.jid) : undefined
'online': true
}); });
if (occupant) { if (occupant) {
occupant.save(attributes); occupant.save(attributes);
...@@ -1257,38 +1173,6 @@ ...@@ -1257,38 +1173,6 @@
} }
}, },
updateOccupantsOnMembersList: function (iq) {
/* Create occupants based upon a received IQ stanza
* containing a member-list.
*
* <iq from='coven@chat.shakespeare.lit'
* id='member3'
* to='crone1@shakespeare.lit/desktop'
* type='result'>
* <query xmlns='http://jabber.org/protocol/muc#admin'>
* <item affiliation='member'
* jid='hag66@shakespeare.lit'
* nick='thirdwitch'
* role='participant'/>
* </query>
* </iq>
*/
_.each($(iq).find('query item'), function (item) {
var jid = item.getAttribute('jid');
var occupant = this.model.where({'jid': jid}).pop();
var data = {
'jid': item.getAttribute('jid'),
'affiliation': item.getAttribute('affiliation')
};
if (occupant) {
occupant.save(data);
} else {
this.model.create(data);
}
}.bind(this));
return;
},
initInviteWidget: function () { initInviteWidget: function () {
var $el = this.$('input.invited-contact'); var $el = this.$('input.invited-contact');
$el.typeahead({ $el.typeahead({
......
<li class="{{role}} {[ if (online) { ]} online {[ } ]}" id="{{id}}" <li class="{{role}}" id="{{id}}"
{[ if (role === "moderator") { ]} {[ if (role === "moderator") { ]}
title="{{desc_moderator}}" title="{{desc_moderator}}"
{[ } ]} {[ } ]}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment