2015-09-07 23:53:43 +02:00
|
|
|
/*
|
|
|
|
* vim: ts=4:sw=4:expandtab
|
2014-11-17 00:30:40 +01:00
|
|
|
*/
|
|
|
|
(function () {
|
2014-11-17 01:01:28 +01:00
|
|
|
'use strict';
|
2014-11-17 00:30:40 +01:00
|
|
|
|
2014-11-17 01:01:28 +01:00
|
|
|
window.Whisper = window.Whisper || {};
|
2014-11-17 00:30:40 +01:00
|
|
|
|
2015-05-11 23:22:15 +02:00
|
|
|
extension.windows.getBackground(function(bg) {
|
|
|
|
var SocketView = Whisper.View.extend({
|
|
|
|
className: 'status',
|
|
|
|
initialize: function() {
|
2015-10-22 02:00:09 +02:00
|
|
|
setInterval(this.updateStatus.bind(this), 5000);
|
2015-06-09 20:30:35 +02:00
|
|
|
},
|
|
|
|
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);
|
|
|
|
}
|
2015-06-09 20:30:35 +02:00
|
|
|
}.bind(this));
|
2015-05-11 23:22:15 +02:00
|
|
|
},
|
|
|
|
events: {
|
|
|
|
'click': 'reloadBackgroundPage'
|
|
|
|
},
|
|
|
|
reloadBackgroundPage: function() {
|
2015-07-09 02:40:42 +02:00
|
|
|
chrome.runtime.reload();
|
2015-05-11 23:22:15 +02:00
|
|
|
}
|
|
|
|
});
|
2015-03-09 21:20:01 +01:00
|
|
|
|
2015-08-26 01:47: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;
|
|
|
|
}
|
|
|
|
$el.prependTo(this.el);
|
2015-10-15 21:10:03 +02:00
|
|
|
conversation.trigger('opened');
|
2015-08-26 01:47:15 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-05-11 23:22:15 +02:00
|
|
|
Whisper.InboxView = Whisper.View.extend({
|
2015-09-16 08:28:00 +02:00
|
|
|
templateName: 'two-column',
|
2015-05-11 23:22:15 +02:00
|
|
|
className: 'inbox',
|
2015-05-21 22:05:52 +02:00
|
|
|
initialize: function (options) {
|
2015-05-11 23:22:15 +02:00
|
|
|
this.render();
|
2015-08-26 01:47:15 +02:00
|
|
|
this.conversation_stack = new Whisper.ConversationStack({
|
|
|
|
el: this.$('.conversation-stack'),
|
|
|
|
model: { appWindow: options.appWindow }
|
|
|
|
});
|
2014-11-17 00:30:40 +01:00
|
|
|
|
2015-06-04 22:29:01 +02:00
|
|
|
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));
|
2014-11-17 00:30:40 +01:00
|
|
|
|
2015-09-09 04:19:30 +02:00
|
|
|
var inboxCollection = bg.getInboxCollection();
|
2015-09-15 01:28:27 +02:00
|
|
|
this.inboxListView = new Whisper.ConversationListView({
|
2015-10-15 21:10:03 +02:00
|
|
|
el : this.$('.inbox'),
|
2015-09-09 04:19:30 +02:00
|
|
|
collection : inboxCollection
|
2015-05-11 23:22:15 +02:00
|
|
|
}).render();
|
2014-11-17 01:01:28 +01:00
|
|
|
|
2015-10-15 21:10:03 +02:00
|
|
|
this.inboxListView.listenTo(inboxCollection,
|
|
|
|
'add change:active_at',
|
|
|
|
this.inboxListView.onChangeActiveAt);
|
|
|
|
|
|
|
|
this.searchView = new Whisper.ConversationSearchView({
|
|
|
|
el : this.$('.search-results'),
|
|
|
|
input : this.$('input.search')
|
|
|
|
});
|
|
|
|
|
2015-11-23 21:52:18 +01:00
|
|
|
this.searchView.$el.hide();
|
2015-10-15 21:10:03 +02:00
|
|
|
|
|
|
|
this.listenTo(this.searchView, 'hide', function() {
|
|
|
|
this.searchView.$el.hide();
|
|
|
|
this.inboxListView.$el.show();
|
|
|
|
});
|
|
|
|
this.listenTo(this.searchView, 'show', function() {
|
|
|
|
this.searchView.$el.show();
|
|
|
|
this.inboxListView.$el.hide();
|
|
|
|
});
|
|
|
|
|
2015-11-21 01:58:52 +01:00
|
|
|
if (inboxCollection.length === 0) {
|
2015-11-28 01:11:42 +01:00
|
|
|
this.searchView.showAllContacts = true;
|
|
|
|
this.searchView.reset();
|
2015-11-29 00:50:44 +01:00
|
|
|
this.listenToOnce(inboxCollection, 'add', function(model) {
|
2015-11-28 01:11:42 +01:00
|
|
|
this.searchView.showAllContacts = false;
|
|
|
|
this.searchView.reset();
|
2015-11-29 00:50:44 +01:00
|
|
|
model.trigger('opened');
|
2015-11-28 01:11:42 +01:00
|
|
|
}.bind(this));
|
2015-11-21 01:58:52 +01:00
|
|
|
}
|
2015-03-11 20:06:19 +01:00
|
|
|
|
2015-05-11 23:22:15 +02:00
|
|
|
new SocketView().render().$el.appendTo(this.$('.socket-status'));
|
2015-03-09 21:20:01 +01:00
|
|
|
|
2015-11-08 19:40:37 +01:00
|
|
|
extension.windows.onClosed(function() {
|
2015-09-15 01:28:27 +02:00
|
|
|
this.inboxListView.stopListening();
|
2015-05-11 23:22:15 +02:00
|
|
|
}.bind(this));
|
|
|
|
},
|
|
|
|
events: {
|
2015-09-16 08:28:00 +02:00
|
|
|
'click': 'closeMenu',
|
|
|
|
'click .hamburger': 'toggleMenu',
|
|
|
|
'click .show-debug-log': 'showDebugLog',
|
2015-09-18 22:07:19 +02:00
|
|
|
'click .show-new-conversation': 'showCompose',
|
2015-10-15 21:10:03 +02:00
|
|
|
'select .gutter .contact': 'openConversation',
|
|
|
|
'input input.search': 'filterContacts'
|
|
|
|
},
|
|
|
|
filterContacts: function(e) {
|
|
|
|
this.searchView.filterContacts(e);
|
|
|
|
var input = this.$('input.search');
|
|
|
|
if (input.val().length > 0) {
|
|
|
|
input.addClass('active');
|
|
|
|
} else {
|
|
|
|
input.removeClass('active');
|
|
|
|
}
|
2015-05-11 23:22:15 +02:00
|
|
|
},
|
2015-09-21 19:21:33 +02:00
|
|
|
openConversation: function(e, conversation) {
|
2015-12-06 03:46:32 +01:00
|
|
|
this.searchView.hideHints();
|
2015-10-15 21:10:03 +02:00
|
|
|
conversation = ConversationController.create(conversation);
|
2015-08-26 01:47:15 +02:00
|
|
|
this.conversation_stack.open(conversation);
|
2015-05-11 23:22:15 +02:00
|
|
|
this.hideCompose();
|
|
|
|
},
|
|
|
|
showCompose: function() {
|
|
|
|
this.newConversationView.reset();
|
2015-08-27 00:13:14 +02:00
|
|
|
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() {
|
2015-08-27 00:13:14 +02:00
|
|
|
this.newConversationView.$el.remove();
|
2015-09-16 08:28:00 +02:00
|
|
|
},
|
|
|
|
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 23:22:15 +02:00
|
|
|
}
|
|
|
|
});
|
2014-11-17 00:30:40 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
})();
|