Commit a4b69ded authored by JC Brand's avatar JC Brand

Save to localStorage messages sent in chatroom.

Also removed the need for the appendMessage method.
parent b49f2155
...@@ -294,11 +294,14 @@ ...@@ -294,11 +294,14 @@
'<span class="chat-message-content">{{message}}</span>' + '<span class="chat-message-content">{{message}}</span>' +
'</div>'), '</div>'),
appendMessage: function (message) { insertStatusNotification: function (message, replace) {
var now = new Date(), var $chat_content = this.$el.find('.chat-content');
time = now.toLocaleTimeString().substring(0,5), $chat_content.find('div.chat-event').remove().end()
minutes = now.getMinutes().toString(), .append($('<div class="chat-event"></div>').text(message));
$chat_content = this.$el.find('.chat-content'); this.scrollDown();
},
showMessage: function (message) {
/* /*
* FIXME: we don't use client storage anymore * FIXME: we don't use client storage anymore
var msg = xmppchat.storage.getLastMessage(this.model.get('jid')); var msg = xmppchat.storage.getLastMessage(this.model.get('jid'));
...@@ -310,28 +313,6 @@ ...@@ -310,28 +313,6 @@
} }
} }
*/ */
message = xmppchat.autoLink(message);
// TODO use minutes logic or remove it
if (minutes.length==1) {minutes = '0'+minutes;}
$chat_content.find('div.chat-event').remove();
$chat_content.append(this.message_template({
'sender': 'me',
'time': time,
'message': message,
'username': 'me',
'extra_classes': ''
}));
this.scrollDown();
},
insertStatusNotification: function (message, replace) {
var $chat_content = this.$el.find('.chat-content');
$chat_content.find('div.chat-event').remove().end()
.append($('<div class="chat-event"></div>').text(message));
this.scrollDown();
},
showMessage: function (message) {
var $chat_content = this.$el.find('.chat-content'); var $chat_content = this.$el.find('.chat-content');
if (xmppchat.xmppstatus.getStatus() === 'offline') { if (xmppchat.xmppstatus.getStatus() === 'offline') {
// only update the UI if the user is not offline // only update the UI if the user is not offline
...@@ -357,7 +338,10 @@ ...@@ -357,7 +338,10 @@
}, },
isDifferentDay: function (prev_date, next_date) { isDifferentDay: function (prev_date, next_date) {
return ((next_date.getDate() != prev_date.getDate()) || (next_date.getFullYear() != prev_date.getFullYear()) || (next_date.getMonth() != prev_date.getMonth())); return (
(next_date.getDate() != prev_date.getDate()) ||
(next_date.getFullYear() != prev_date.getFullYear()) ||
(next_date.getMonth() != prev_date.getMonth()));
}, },
addHelpMessages: function (msgs) { addHelpMessages: function (msgs) {
...@@ -520,10 +504,6 @@ ...@@ -520,10 +504,6 @@
return this; return this;
}, },
isVisible: function () {
return this.$el.is(':visible');
},
focus: function () { focus: function () {
this.$el.find('.chat-textarea').focus(); this.$el.find('.chat-textarea').focus();
return this; return this;
...@@ -809,7 +789,6 @@ ...@@ -809,7 +789,6 @@
}, },
sendChatRoomMessage: function (body) { sendChatRoomMessage: function (body) {
this.appendMessage(body);
var match = body.replace(/^\s*/, "").match(/^\/(.*?)(?: (.*))?$/) || [false], var match = body.replace(/^\s*/, "").match(/^\/(.*?)(?: (.*))?$/) || [false],
$chat_content; $chat_content;
switch (match[1]) { switch (match[1]) {
...@@ -844,8 +823,13 @@ ...@@ -844,8 +823,13 @@
this.scrollDown(); this.scrollDown();
break; break;
default: default:
// TODO see why muc is flagged as unresolved variable
this.last_msgid = xmppchat.connection.muc.groupchat(this.model.get('jid'), body); this.last_msgid = xmppchat.connection.muc.groupchat(this.model.get('jid'), body);
this.model.messages.create({
fullname: 'me',
sender: 'me',
time: (new Date()).toLocaleTimeString().substring(0,5),
message: body
});
break; break;
} }
}, },
...@@ -872,7 +856,6 @@ ...@@ -872,7 +856,6 @@
'</div>'), '</div>'),
initialize: function () { initialize: function () {
// TODO see why muc is flagged as unresolved variable
xmppchat.connection.muc.join( xmppchat.connection.muc.join(
this.model.get('jid'), this.model.get('jid'),
this.model.get('nick'), this.model.get('nick'),
...@@ -881,6 +864,7 @@ ...@@ -881,6 +864,7 @@
$.proxy(this.onChatRoomRoster, this)); $.proxy(this.onChatRoomRoster, this));
this.model.messages.on('add', this.showMessage, this);
this.model.on('destroy', function (model, response, options) { this.model.on('destroy', function (model, response, options) {
this.$el.hide('fast'); this.$el.hide('fast');
xmppchat.connection.muc.leave( xmppchat.connection.muc.leave(
...@@ -890,9 +874,8 @@ ...@@ -890,9 +874,8 @@
undefined); undefined);
}, },
this); this);
this.$el.appendTo(xmppchat.chatboxesview.$el); this.$el.appendTo(xmppchat.chatboxesview.$el);
this.render().show(); this.render().show().model.messages.fetch({add: true});
}, },
onLeave: function () { onLeave: function () {
......
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