2014-11-16 23:30:40 +00:00
|
|
|
/* vim: ts=4:sw=4:expandtab
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
(function () {
|
2014-11-17 00:01:28 +00:00
|
|
|
'use strict';
|
2014-11-16 23:30:40 +00:00
|
|
|
|
2014-11-17 00:01:28 +00:00
|
|
|
window.Whisper = window.Whisper || {};
|
2014-11-16 23:30:40 +00:00
|
|
|
|
2015-05-11 21:22:15 +00:00
|
|
|
extension.windows.getBackground(function(bg) {
|
|
|
|
var SocketView = Whisper.View.extend({
|
|
|
|
className: 'status',
|
|
|
|
initialize: function() {
|
|
|
|
setInterval(function() {
|
|
|
|
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';
|
|
|
|
message = 'Websocket closed';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!this.$el.hasClass(className)) {
|
|
|
|
this.$el.attr('class', className);
|
|
|
|
this.$el.text(message);
|
|
|
|
}
|
|
|
|
}.bind(this), 1000);
|
|
|
|
},
|
|
|
|
events: {
|
|
|
|
'click': 'reloadBackgroundPage'
|
|
|
|
},
|
|
|
|
reloadBackgroundPage: function() {
|
|
|
|
bg.location.reload();
|
|
|
|
}
|
|
|
|
});
|
2015-03-09 20:20:01 +00:00
|
|
|
|
2015-05-11 21:22:15 +00:00
|
|
|
Whisper.InboxView = Whisper.View.extend({
|
|
|
|
template: $('#inbox').html(),
|
|
|
|
className: 'inbox',
|
2015-05-21 20:05:52 +00:00
|
|
|
initialize: function (options) {
|
2015-05-11 21:22:15 +00:00
|
|
|
this.render();
|
2014-11-16 23:30:40 +00:00
|
|
|
|
2015-06-04 20:29:01 +00:00
|
|
|
this.newConversationView = new Whisper.NewConversationView({
|
|
|
|
appWindow: options.appWindow
|
|
|
|
});
|
2015-05-11 21:22:15 +00:00
|
|
|
this.newConversationView.$el.hide();
|
|
|
|
this.listenTo(this.newConversationView, 'open',
|
|
|
|
this.openConversation.bind(this, null));
|
2014-11-16 23:30:40 +00:00
|
|
|
|
2015-05-11 21:22:15 +00:00
|
|
|
this.inbox = new Whisper.ConversationListView({
|
|
|
|
el : this.$('.conversations'),
|
|
|
|
collection : bg.inbox
|
|
|
|
}).render();
|
2014-11-17 00:01:28 +00:00
|
|
|
|
2015-05-11 21:22:15 +00:00
|
|
|
this.inbox.listenTo(bg.inbox, 'sort', this.inbox.render);
|
2015-03-11 19:06:19 +00:00
|
|
|
|
2015-05-11 21:22:15 +00:00
|
|
|
new SocketView().render().$el.appendTo(this.$('.socket-status'));
|
2015-03-09 20:20:01 +00:00
|
|
|
|
2015-05-13 18:23:59 +00:00
|
|
|
extension.windows.beforeUnload(function() {
|
2015-05-11 21:22:15 +00:00
|
|
|
this.inbox.stopListening();
|
|
|
|
}.bind(this));
|
2015-05-21 20:05:52 +00:00
|
|
|
|
|
|
|
new Whisper.WindowControlsView({
|
|
|
|
appWindow: options.appWindow
|
|
|
|
}).$el.appendTo(this.$('#header'));
|
2015-05-11 21:22:15 +00:00
|
|
|
},
|
|
|
|
events: {
|
|
|
|
'click .fab': 'showCompose',
|
|
|
|
'select .contact': 'openConversation',
|
|
|
|
},
|
|
|
|
openConversation: function(e, data) {
|
|
|
|
bg.openConversation(data.modelId);
|
|
|
|
this.hideCompose();
|
|
|
|
},
|
|
|
|
showCompose: function() {
|
|
|
|
this.newConversationView.reset();
|
|
|
|
this.$el.hide();
|
|
|
|
this.newConversationView.$el.insertAfter(this.$el);
|
|
|
|
this.newConversationView.$el.show();
|
|
|
|
this.newConversationView.$input.focus();
|
|
|
|
this.listenToOnce(this.newConversationView, 'back', this.hideCompose);
|
|
|
|
},
|
|
|
|
hideCompose: function() {
|
|
|
|
this.newConversationView.$el.hide();
|
|
|
|
this.$el.show();
|
|
|
|
}
|
|
|
|
});
|
2014-11-16 23:30:40 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
})();
|