Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Creating a better Candy.Core.ChatRoom object #21

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
118 changes: 93 additions & 25 deletions src/core/chatRoom.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* Authors:
* - Patrick Stadler <[email protected]>
* - Michael Weibel <[email protected]>
* - Melissa Noelle <[email protected]>
*
* Copyright:
* (c) 2011 Amiado Group AG. All rights reserved.
Expand All @@ -19,24 +20,91 @@
* Parameters:
* (String) roomJid - Room jid
*/
Candy.Core.ChatRoom = function(roomJid) {
/** Object: room
* Object containing roomJid and name.
*/
this.room = {
jid: roomJid,
name: Strophe.getNodeFromJid(roomJid)
};

/** Variable: user
* Current local user of this room.
*/
this.user = null;

/** Variable: Roster
* Candy.Core.ChatRoster instance
*/
this.roster = new Candy.Core.ChatRoster();
Candy.Core.ChatRoom = function(options) {
/** Object: room
* (String) jid
* (String) name
* (String) type (chat|groupchat)
* (String) topic
* (Integer) messageCount
*/
this.room = {
jid: options.roomJid,
name: options.roomName || Strophe.getNodeFromJid(options.roomJid),
type: options.roomType,
topic: null,
messageCount: 0
};

/** Variable: user
* Current local user of this room.
*/
this.user = null;

/** Variable: Roster
* Candy.Core.ChatRoster instance
*/
this.roster = new Candy.Core.ChatRoster();

// DOM-related information for this room.
this.dom = {
id: options.domId,
scrollPosition: options.scrollPosition || -1,
tab: null,
form: null
}
};

Candy.Core.ChatRoom.prototype.setTopic = function(topic) {
this.room.topic = topic;
};

Candy.Core.ChatRoom.prototype.getType = function() {
return this.room.type;
};

Candy.Core.ChatRoom.prototype.incrementMessageCount = function() {
this.room.messageCount += 1;
return this.room.messageCount;
};

Candy.Core.ChatRoom.prototype.getUserCount = function() {
return Object.keys(this.roster.items).length;
};

Candy.Core.ChatRoom.prototype.getDomElement = function() {
return this.Room.getPane(this.room.jid);
};

Candy.Core.ChatRoom.prototype.getDomTab = function() {
return this.Chat.getTab(roomJid);
};

Candy.Core.ChatRoom.prototype.getDomForm = function() {
return this.Room.getPane(roomJid, '.message-form');
};

Candy.Core.ChatRoom.prototype.addRoomDom = function(chatRoomContainerSelector) {
$(chatRoomContainerSelector).append(Mustache.to_html(Candy.View.Template.Room.pane, {
roomId: this.dom.id,
roomJid: this.room.jid,
roomType: this.room.type,
form: {
_messageSubmit: $.i18n._('messageSubmit')
},
roster: {
_userOnline: $.i18n._('userOnline')
}
}, {
roster: Candy.View.Template.Roster.pane,
messages: Candy.View.Template.Message.pane,
form: Candy.View.Template.Room.form
}));

this.Chat.addTab(this.room.jid, roomName, roomType);
this.Room.getPane(this.room.jid, '.message-form').submit(Candy.View.Pane.Message.submit);

return this.getDomElement();
};

/** Function: setUser
Expand All @@ -46,7 +114,7 @@ Candy.Core.ChatRoom = function(roomJid) {
* (Candy.Core.ChatUser) user - Chat user
*/
Candy.Core.ChatRoom.prototype.setUser = function(user) {
this.user = user;
this.user = user;
};

/** Function: getUser
Expand All @@ -56,7 +124,7 @@ Candy.Core.ChatRoom.prototype.setUser = function(user) {
* (Object) - Candy.Core.ChatUser instance or null
*/
Candy.Core.ChatRoom.prototype.getUser = function() {
return this.user;
return this.user;
};

/** Function: getJid
Expand All @@ -66,7 +134,7 @@ Candy.Core.ChatRoom.prototype.getUser = function() {
* (String) - Room jid
*/
Candy.Core.ChatRoom.prototype.getJid = function() {
return this.room.jid;
return this.room.jid;
};

/** Function: setName
Expand All @@ -76,7 +144,7 @@ Candy.Core.ChatRoom.prototype.getJid = function() {
* (String) name - Room name
*/
Candy.Core.ChatRoom.prototype.setName = function(name) {
this.room.name = name;
this.room.name = name;
};

/** Function: getName
Expand All @@ -86,7 +154,7 @@ Candy.Core.ChatRoom.prototype.setName = function(name) {
* (String) - Room name
*/
Candy.Core.ChatRoom.prototype.getName = function() {
return this.room.name;
return this.room.name;
};

/** Function: setRoster
Expand All @@ -96,7 +164,7 @@ Candy.Core.ChatRoom.prototype.getName = function() {
* (Candy.Core.ChatRoster) roster - Chat roster
*/
Candy.Core.ChatRoom.prototype.setRoster = function(roster) {
this.roster = roster;
this.roster = roster;
};

/** Function: getRoster
Expand All @@ -106,5 +174,5 @@ Candy.Core.ChatRoom.prototype.setRoster = function(roster) {
* (Candy.Core.ChatRoster) - instance
*/
Candy.Core.ChatRoom.prototype.getRoster = function() {
return this.roster;
return this.roster;
};
26 changes: 8 additions & 18 deletions src/view/pane/room.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,27 +73,17 @@ Candy.View.Pane = (function(self, $) {
}

var roomId = Candy.Util.jidToId(roomJid);
self.Chat.rooms[roomJid] = {id: roomId, usercount: 0, name: roomName, type: roomType, messageCount: 0, scrollPosition: -1, targetJid: roomJid};

$('#chat-rooms').append(Mustache.to_html(Candy.View.Template.Room.pane, {
roomId: roomId,
var roomObject = new Candy.Core.ChatRoom({
roomJid: roomJid,
roomName: roomName,
roomType: roomType,
form: {
_messageSubmit: $.i18n._('messageSubmit')
},
roster: {
_userOnline: $.i18n._('userOnline')
}
}, {
roster: Candy.View.Template.Roster.pane,
messages: Candy.View.Template.Message.pane,
form: Candy.View.Template.Room.form
}));
self.Chat.addTab(roomJid, roomName, roomType);
self.Room.getPane(roomJid, '.message-form').submit(self.Message.submit);

evtData.element = self.Room.getPane(roomJid);
domId: roomId,
});

self.Chat.rooms[roomJid] = roomObject;

roomObject.addRoomDom('#chat-rooms');

/** Event: candy:view.room.after-add
* After initialising a room
Expand Down