From 40f4ceb53ee157a1755e7e77cded68923bca3dcd Mon Sep 17 00:00:00 2001 From: Melissa Noelle Date: Fri, 9 Jan 2015 16:35:43 -0500 Subject: [PATCH 1/2] Start updating chatroom object. --- src/core/chatRoom.js | 75 ++++++++++++++++++++++++++++++++++++++++--- src/view/pane/room.js | 26 +++++---------- 2 files changed, 79 insertions(+), 22 deletions(-) diff --git a/src/core/chatRoom.js b/src/core/chatRoom.js index 2d842bd1..566d03a4 100644 --- a/src/core/chatRoom.js +++ b/src/core/chatRoom.js @@ -19,13 +19,20 @@ * Parameters: * (String) roomJid - Room jid */ -Candy.Core.ChatRoom = function(roomJid) { +Candy.Core.ChatRoom = function(options) { /** Object: room - * Object containing roomJid and name. + * (String) jid + * (String) name + * (String) type (chat|groupchat) + * (String) topic + * (Integer) messageCount */ this.room = { - jid: roomJid, - name: Strophe.getNodeFromJid(roomJid) + jid: options.roomJid, + name: options.roomName || Strophe.getNodeFromJid(options.roomJid), + type: options.roomType, + topic: null, + messageCount: 0 }; /** Variable: user @@ -37,6 +44,66 @@ Candy.Core.ChatRoom = function(roomJid) { * 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 self.Room.getPane(this.room.jid); +}; + +Candy.Core.ChatRoom.prototype.getDomTab = function() { + return self.Chat.getTab(roomJid); +}; + +Candy.Core.ChatRoom.prototype.getDomForm = function() { + return self.Room.getPane(roomJid, '.message-form'); +}; + +Candy.Core.ChatRoom.prototype.addRoomDom = function(chatRoomContainerSelector) { + $(chatRoomContainerSelector).append(Mustache.to_html(Candy.View.Template.Room.pane, { + roomId: self.dom.id, + roomJid: self.room.jid, + roomType: self.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 + })); + + self.Chat.addTab(roomJid, roomName, roomType); + self.Room.getPane(roomJid, '.message-form').submit(self.Message.submit); + + return this.getDomElement(); }; /** Function: setUser diff --git a/src/view/pane/room.js b/src/view/pane/room.js index d4d4148d..4f1f4a6b 100644 --- a/src/view/pane/room.js +++ b/src/view/pane/room.js @@ -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 From f39e08fb0bffcd88d1a568da34747ad09198aa6c Mon Sep 17 00:00:00 2001 From: Melissa Noelle Date: Fri, 9 Jan 2015 17:22:30 -0500 Subject: [PATCH 2/2] Self vs this, tabs vs spaces. --- src/core/chatRoom.js | 107 ++++++++++++++++++++++--------------------- 1 file changed, 54 insertions(+), 53 deletions(-) diff --git a/src/core/chatRoom.js b/src/core/chatRoom.js index 566d03a4..87cc227a 100644 --- a/src/core/chatRoom.js +++ b/src/core/chatRoom.js @@ -4,6 +4,7 @@ * Authors: * - Patrick Stadler * - Michael Weibel + * - Melissa Noelle * * Copyright: * (c) 2011 Amiado Group AG. All rights reserved. @@ -20,74 +21,74 @@ * (String) roomJid - Room jid */ 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 - } + /** 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; + this.room.topic = topic; }; Candy.Core.ChatRoom.prototype.getType = function() { - return this.room.type; + return this.room.type; }; Candy.Core.ChatRoom.prototype.incrementMessageCount = function() { - this.room.messageCount += 1; - return this.room.messageCount; + this.room.messageCount += 1; + return this.room.messageCount; }; Candy.Core.ChatRoom.prototype.getUserCount = function() { - return Object.keys(this.roster.items).length; + return Object.keys(this.roster.items).length; }; Candy.Core.ChatRoom.prototype.getDomElement = function() { - return self.Room.getPane(this.room.jid); + return this.Room.getPane(this.room.jid); }; Candy.Core.ChatRoom.prototype.getDomTab = function() { - return self.Chat.getTab(roomJid); + return this.Chat.getTab(roomJid); }; Candy.Core.ChatRoom.prototype.getDomForm = function() { - return self.Room.getPane(roomJid, '.message-form'); + 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: self.dom.id, - roomJid: self.room.jid, - roomType: self.room.type, + $(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') }, @@ -100,8 +101,8 @@ Candy.Core.ChatRoom.prototype.addRoomDom = function(chatRoomContainerSelector) { form: Candy.View.Template.Room.form })); - self.Chat.addTab(roomJid, roomName, roomType); - self.Room.getPane(roomJid, '.message-form').submit(self.Message.submit); + 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(); }; @@ -113,7 +114,7 @@ Candy.Core.ChatRoom.prototype.addRoomDom = function(chatRoomContainerSelector) { * (Candy.Core.ChatUser) user - Chat user */ Candy.Core.ChatRoom.prototype.setUser = function(user) { - this.user = user; + this.user = user; }; /** Function: getUser @@ -123,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 @@ -133,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 @@ -143,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 @@ -153,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 @@ -163,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 @@ -173,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; };