Skip to content

Commit

Permalink
Fix #175: Unify URL fragment updates.
Browse files Browse the repository at this point in the history
The URL fragment needs to always reflect the current room.
This means it must also be updated in response to external events -
failure to join a room, being kicked from it, etc.

Additionally, the /join command had a bug that failed to strip a space
preceding the room name in the URL fragment.
  • Loading branch information
cburschka committed Mar 28, 2015
1 parent 46cc16e commit a3547bc
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
10 changes: 4 additions & 6 deletions js/core/chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,9 @@ var chat = {
var room = chat.getRoomFromTitle(name);
if (room)
return ui.messageAddInfo(strings.error.roomExists, {room: room}, 'error');
ui.urlFragment = '#' + name;
window.location.hash = '#' + name;
xmpp.joinNewRoom(name);
ui.updateFragment(name);
chat.setSetting('xmpp.room', room);
};
if (!chat.getRoomFromTitle(name)) create();
else xmpp.discoverRooms(create);
Expand All @@ -287,8 +287,7 @@ var chat = {
}
room = room ? room.id : name;
xmpp.joinExistingRoom(room);
ui.urlFragment = '#' + arg;
window.location.hash = '#' + arg;
ui.updateFragment(room);
chat.setSetting('xmpp.room', room);
};
// If the room is known, join it now. Otherwise, refresh before joining.
Expand Down Expand Up @@ -373,8 +372,7 @@ var chat = {
*/
part: function() {
if (xmpp.room.current) xmpp.leaveRoom(xmpp.room.current);
ui.urlFragment = '';
window.location.hash = '';
ui.updateFragment(null);
},

/**
Expand Down
8 changes: 8 additions & 0 deletions js/core/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,14 @@ var ui = {
}
},

/**
* Update the current URL fragment.
*/
updateFragment: function(room) {
ui.urlFragment = '#' + (room || '');
window.location.hash = ui.urlFragment;
},

/**
* Remove the online list with a new roster, and set the room selection menu.
*/
Expand Down
8 changes: 7 additions & 1 deletion js/core/xmpp.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ var xmpp = {

prejoin: function() {
this.room.current = null;
ui.updateFragment(null);
this.status = 'prejoin';
ui.setStatus(this.status);
chat.commands.list();
Expand Down Expand Up @@ -234,7 +235,11 @@ var xmpp = {
}.bind(this);

this.getRoomInfo(room, function(roomInfo) {
if (!roomInfo) return ui.messageAddInfo(strings.error.unknownRoom, {name: room}, 'error');
if (!roomInfo) {
console.log("Room does not exist");
ui.updateFragment(xmpp.room.current);
return ui.messageAddInfo(strings.error.unknownRoom, {name: room}, 'error');
}
this.room.available[room] = roomInfo;
ui.refreshRooms(this.room.available);
ui.messageAddInfo(strings.info.joining, {
Expand Down Expand Up @@ -588,6 +593,7 @@ var xmpp = {
// Cancel any join attempt:
this.room.target = this.room.current;
ui.updateRoom(this.room.current);
ui.updateFragment(this.room.current);
}
},

Expand Down

0 comments on commit a3547bc

Please sign in to comment.