Cable-Desktop/js/views/inbox_view.js

128 lines
4.9 KiB
JavaScript
Raw Normal View History

/*
* vim: ts=4:sw=4:expandtab
*/
(function () {
'use strict';
window.Whisper = window.Whisper || {};
2015-05-11 23:22:15 +02:00
extension.windows.getBackground(function(bg) {
var SocketView = Whisper.View.extend({
className: 'status',
initialize: function() {
setInterval(this.updateStatus.bind(this), 1000);
},
updateStatus: function() {
extension.windows.getBackground(function(bg) {
2015-05-11 23:22:15 +02:00
var className, message = '';
switch(bg.getSocketStatus && bg.getSocketStatus()) {
case WebSocket.CONNECTING:
className = 'connecting';
break;
case WebSocket.OPEN:
className = 'open';
break;
case WebSocket.CLOSING:
className = 'closing';
break;
case WebSocket.CLOSED:
className = 'closed';
2015-08-24 18:10:48 +02:00
message = 'Disconnected';
2015-05-11 23:22:15 +02:00
break;
}
if (!this.$el.hasClass(className)) {
this.$el.attr('class', className);
this.$el.text(message);
}
}.bind(this));
2015-05-11 23:22:15 +02:00
},
events: {
'click': 'reloadBackgroundPage'
},
reloadBackgroundPage: function() {
chrome.runtime.reload();
2015-05-11 23:22:15 +02:00
}
});
Whisper.ConversationStack = Whisper.View.extend({
className: 'conversation-stack',
open: function(conversation) {
var $el = this.$('#conversation-' + conversation.cid);
if ($el === null || $el.length === 0) {
var view = new Whisper.ConversationView({
model: conversation,
appWindow: this.model.appWindow
});
$el = view.$el;
conversation.fetchContacts();
if (conversation.messageCollection.length === 0) {
$el.find('.message-list').addClass('loading');
}
}
$el.prependTo(this.el);
$el.find('.message-list').trigger('reset-scroll');
$el.trigger('force-resize');
conversation.fetchMessages().then(function() {
$el.find('.message-list').removeClass('loading');
});
2015-08-26 19:12:05 +02:00
conversation.markRead();
}
});
2015-05-11 23:22:15 +02:00
Whisper.InboxView = Whisper.View.extend({
template: $('#two-column').html(),
2015-05-11 23:22:15 +02:00
className: 'inbox',
initialize: function (options) {
2015-05-11 23:22:15 +02:00
this.render();
this.conversation_stack = new Whisper.ConversationStack({
el: this.$('.conversation-stack'),
model: { appWindow: options.appWindow }
});
this.newConversationView = new Whisper.NewConversationView({
appWindow: options.appWindow
});
2015-05-11 23:22:15 +02:00
this.listenTo(this.newConversationView, 'open',
this.openConversation.bind(this, null));
var inboxCollection = bg.getInboxCollection();
this.inboxView = new Whisper.ConversationListView({
2015-05-11 23:22:15 +02:00
el : this.$('.conversations'),
collection : inboxCollection
2015-05-11 23:22:15 +02:00
}).render();
this.inboxView.listenTo(inboxCollection, 'sort', this.inboxView.render);
2015-05-11 23:22:15 +02:00
new SocketView().render().$el.appendTo(this.$('.socket-status'));
2015-05-13 20:23:59 +02:00
extension.windows.beforeUnload(function() {
this.inboxView.stopListening();
2015-05-11 23:22:15 +02:00
}.bind(this));
new Whisper.WindowControlsView({
appWindow: options.appWindow
}).$el.appendTo(this.$('#header'));
2015-05-11 23:22:15 +02:00
},
events: {
'click .fab': 'showCompose',
2015-08-27 07:33:00 +02:00
'select .gutter .contact': 'openConversation'
2015-05-11 23:22:15 +02:00
},
openConversation: function(e, data) {
2015-08-27 21:38:51 +02:00
var conversation = data.conversation;
this.conversation_stack.open(conversation);
2015-05-11 23:22:15 +02:00
this.hideCompose();
},
showCompose: function() {
this.newConversationView.reset();
this.newConversationView.$el.prependTo(this.conversation_stack.el);
2015-05-11 23:22:15 +02:00
this.newConversationView.$input.focus();
this.listenToOnce(this.newConversationView, 'back', this.hideCompose);
},
hideCompose: function() {
this.newConversationView.$el.remove();
2015-05-11 23:22:15 +02:00
}
});
});
})();