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 1 commit
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
75 changes: 71 additions & 4 deletions src/core/chatRoom.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spaces v tabs

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What?! My editor is setup for 2 spaces!!

/me goes off to bring hell to sublime2.

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
Expand Down
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