signal-desktop/js/views/inbox_view.js

144 lines
5.6 KiB
JavaScript
Raw Normal View History

/*
* vim: ts=4:sw=4:expandtab
*/
(function () {
'use strict';
window.Whisper = window.Whisper || {};
2015-05-11 21:22:15 +00: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 21:22:15 +00: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 16:10:48 +00:00
message = 'Disconnected';
2015-05-11 21:22:15 +00:00
break;
}
if (!this.$el.hasClass(className)) {
this.$el.attr('class', className);
this.$el.text(message);
}
}.bind(this));
2015-05-11 21:22:15 +00:00
},
events: {
'click': 'reloadBackgroundPage'
},
reloadBackgroundPage: function() {
chrome.runtime.reload();
2015-05-11 21:22:15 +00: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;
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.fetchContacts().then(function() {
conversation.fetchMessages().then(function() {
$el.find('.message-list').removeClass('loading');
});
});
2015-08-26 17:12:05 +00:00
conversation.markRead();
}
});
2015-05-11 21:22:15 +00:00
Whisper.InboxView = Whisper.View.extend({
templateName: 'two-column',
2015-05-11 21:22:15 +00:00
className: 'inbox',
initialize: function (options) {
2015-05-11 21:22:15 +00: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 21:22:15 +00:00
this.listenTo(this.newConversationView, 'open',
this.openConversation.bind(this, null));
var inboxCollection = bg.getInboxCollection();
this.inboxListView = new Whisper.ConversationListView({
2015-05-11 21:22:15 +00:00
el : this.$('.conversations'),
collection : inboxCollection
2015-05-11 21:22:15 +00:00
}).render();
this.inboxListView.listenTo(inboxCollection, 'add change:active_at', this.inboxListView.onChangeActiveAt);
2015-05-11 21:22:15 +00:00
new SocketView().render().$el.appendTo(this.$('.socket-status'));
2015-05-13 18:23:59 +00:00
extension.windows.beforeUnload(function() {
this.inboxListView.stopListening();
2015-05-11 21:22:15 +00:00
}.bind(this));
new Whisper.WindowControlsView({
appWindow: options.appWindow
}).$el.appendTo(this.$('#header'));
2015-05-11 21:22:15 +00:00
},
events: {
'click': 'closeMenu',
'click .hamburger': 'toggleMenu',
'click .show-debug-log': 'showDebugLog',
2015-05-11 21:22:15 +00:00
'click .fab': 'showCompose',
2015-08-27 05:33:00 +00:00
'select .gutter .contact': 'openConversation'
2015-05-11 21:22:15 +00:00
},
openConversation: function(e, data) {
2015-08-27 19:38:51 +00:00
var conversation = data.conversation;
this.conversation_stack.open(conversation);
2015-05-11 21:22:15 +00:00
this.hideCompose();
},
showCompose: function() {
this.newConversationView.reset();
this.newConversationView.$el.prependTo(this.conversation_stack.el);
2015-05-11 21:22:15 +00:00
this.newConversationView.$input.focus();
this.listenToOnce(this.newConversationView, 'back', this.hideCompose);
},
hideCompose: function() {
this.newConversationView.$el.remove();
},
toggleMenu: function() {
this.$('.global-menu .menu-list').toggle();
},
showDebugLog: function() {
this.$('.debug-log').remove();
new Whisper.DebugLogView().$el.appendTo(this.el);
},
closeMenu: function(e) {
if (e && !$(e.target).hasClass('hamburger')) {
this.$('.global-menu .menu-list').hide();
}
2015-05-11 21:22:15 +00:00
}
});
});
})();