| 
									
										
										
										
											2015-09-07 14:53:43 -07:00
										 |  |  | /* | 
					
						
							|  |  |  |  * vim: ts=4:sw=4:expandtab | 
					
						
							| 
									
										
										
										
											2014-11-16 15:30:40 -08:00
										 |  |  |  */ | 
					
						
							|  |  |  | (function () { | 
					
						
							| 
									
										
										
										
											2014-11-16 16:01:28 -08:00
										 |  |  |     'use strict'; | 
					
						
							| 
									
										
										
										
											2014-11-16 15:30:40 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-16 16:01:28 -08:00
										 |  |  |     window.Whisper = window.Whisper || {}; | 
					
						
							| 
									
										
										
										
											2014-11-16 15:30:40 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-07 12:36:30 -08:00
										 |  |  |     var SocketView = Whisper.View.extend({ | 
					
						
							|  |  |  |         className: 'status', | 
					
						
							|  |  |  |         initialize: function() { | 
					
						
							|  |  |  |             setInterval(this.updateStatus.bind(this), 5000); | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |         updateStatus: function() { | 
					
						
							|  |  |  |             var className, message = ''; | 
					
						
							|  |  |  |             switch(getSocketStatus && 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-12-25 18:16:38 -08:00
										 |  |  |                     message = i18n('disconnected'); | 
					
						
							| 
									
										
										
										
											2015-12-07 12:36:30 -08:00
										 |  |  |                     break; | 
					
						
							| 
									
										
										
										
											2015-05-11 14:22:15 -07:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2015-12-07 12:36:30 -08:00
										 |  |  |             if (!this.$el.hasClass(className)) { | 
					
						
							|  |  |  |                 this.$el.attr('class', className); | 
					
						
							|  |  |  |                 this.$el.text(message); | 
					
						
							| 
									
										
										
										
											2015-08-25 16:47:15 -07:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2015-12-07 12:36:30 -08:00
										 |  |  |         } | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2015-08-25 16:47:15 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-07 12:36:30 -08:00
										 |  |  |     Whisper.ConversationStack = Whisper.View.extend({ | 
					
						
							|  |  |  |         className: 'conversation-stack', | 
					
						
							|  |  |  |         open: function(conversation) { | 
					
						
							| 
									
										
										
										
											2016-06-27 14:47:33 +02:00
										 |  |  |             var id = 'conversation-' + conversation.cid; | 
					
						
							|  |  |  |             if(id !== this.el.firstChild.id) { | 
					
						
							|  |  |  |                 this.$("video").each(function() { | 
					
						
							|  |  |  |                     this.pause(); | 
					
						
							| 
									
										
										
										
											2015-08-25 16:47:15 -07:00
										 |  |  |                 }); | 
					
						
							| 
									
										
										
										
											2016-06-27 14:47:33 +02:00
										 |  |  |                 this.$("audio").each(function() { | 
					
						
							|  |  |  |                     this.pause(); | 
					
						
							|  |  |  |                 }); | 
					
						
							|  |  |  |                 var $el = this.$('#'+id); | 
					
						
							|  |  |  |                 if ($el === null || $el.length === 0) { | 
					
						
							|  |  |  |                     var view = new Whisper.ConversationView({ | 
					
						
							|  |  |  |                         model: conversation, | 
					
						
							|  |  |  |                         appWindow: this.model.appWindow | 
					
						
							|  |  |  |                     }); | 
					
						
							|  |  |  |                     $el = view.$el; | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |                 $el.prependTo(this.el); | 
					
						
							|  |  |  |                 conversation.trigger('opened'); | 
					
						
							| 
									
										
										
										
											2015-12-07 12:36:30 -08:00
										 |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2014-11-16 15:30:40 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-07 12:36:30 -08:00
										 |  |  |     Whisper.InboxView = Whisper.View.extend({ | 
					
						
							|  |  |  |         templateName: 'two-column', | 
					
						
							|  |  |  |         className: 'inbox', | 
					
						
							|  |  |  |         initialize: function (options) { | 
					
						
							|  |  |  |             this.render(); | 
					
						
							|  |  |  |             this.conversation_stack = new Whisper.ConversationStack({ | 
					
						
							|  |  |  |                 el: this.$('.conversation-stack'), | 
					
						
							|  |  |  |                 model: { appWindow: options.appWindow } | 
					
						
							|  |  |  |             }); | 
					
						
							| 
									
										
										
										
											2014-11-16 15:30:40 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-07 12:36:30 -08:00
										 |  |  |             var inboxCollection = getInboxCollection(); | 
					
						
							|  |  |  |             this.inboxListView = new Whisper.ConversationListView({ | 
					
						
							|  |  |  |                 el         : this.$('.inbox'), | 
					
						
							|  |  |  |                 collection : inboxCollection | 
					
						
							|  |  |  |             }).render(); | 
					
						
							| 
									
										
										
										
											2015-10-15 12:10:03 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-07 12:36:30 -08:00
										 |  |  |             this.inboxListView.listenTo(inboxCollection, | 
					
						
							| 
									
										
										
										
											2016-03-25 10:39:36 -07:00
										 |  |  |                     'add change:timestamp change:name change:number', | 
					
						
							|  |  |  |                     this.inboxListView.sort); | 
					
						
							| 
									
										
										
										
											2015-10-15 12:10:03 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-07 12:36:30 -08:00
										 |  |  |             this.searchView = new Whisper.ConversationSearchView({ | 
					
						
							|  |  |  |                 el    : this.$('.search-results'), | 
					
						
							|  |  |  |                 input : this.$('input.search') | 
					
						
							|  |  |  |             }); | 
					
						
							| 
									
										
										
										
											2015-10-15 12:10:03 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-07 12:36:30 -08:00
										 |  |  |             this.searchView.$el.hide(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             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-12-01 16:13:58 -08:00
										 |  |  |             this.listenTo(this.searchView, 'open', | 
					
						
							|  |  |  |                 this.openConversation.bind(this, null)); | 
					
						
							| 
									
										
										
										
											2015-10-15 12:10:03 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-07 12:36:30 -08:00
										 |  |  |             new SocketView().render().$el.appendTo(this.$('.socket-status')); | 
					
						
							| 
									
										
										
										
											2015-03-09 13:20:01 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-07 12:36:30 -08:00
										 |  |  |             extension.windows.onClosed(function() { | 
					
						
							|  |  |  |                 this.inboxListView.stopListening(); | 
					
						
							|  |  |  |             }.bind(this)); | 
					
						
							| 
									
										
										
										
											2016-04-03 20:06:27 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |             if (extension.expired()) { | 
					
						
							|  |  |  |                 var banner = new Whisper.ExpiredAlertBanner().render(); | 
					
						
							|  |  |  |                 banner.$el.prependTo(this.$el); | 
					
						
							|  |  |  |                 this.$el.addClass('expired'); | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2015-12-07 12:36:30 -08:00
										 |  |  |         }, | 
					
						
							| 
									
										
										
										
											2015-12-25 18:15:04 -08:00
										 |  |  |         render_attributes: { | 
					
						
							| 
									
										
										
										
											2016-04-03 20:06:27 -07:00
										 |  |  |             welcomeToSignal         : i18n('welcomeToSignal'), | 
					
						
							|  |  |  |             selectAContact          : i18n('selectAContact'), | 
					
						
							|  |  |  |             searchForPeopleOrGroups : i18n('searchForPeopleOrGroups'), | 
					
						
							|  |  |  |             submitDebugLog          : i18n('submitDebugLog'), | 
					
						
							|  |  |  |             settings                : i18n('settings'), | 
					
						
							|  |  |  |             restartSignal           : i18n('restartSignal'), | 
					
						
							| 
									
										
										
										
											2015-12-25 18:15:04 -08:00
										 |  |  |         }, | 
					
						
							| 
									
										
										
										
											2015-12-07 12:36:30 -08:00
										 |  |  |         events: { | 
					
						
							|  |  |  |             'click': 'closeMenu', | 
					
						
							| 
									
										
										
										
											2016-03-20 20:02:38 -07:00
										 |  |  |             'click #header': 'focusHeader', | 
					
						
							|  |  |  |             'click .conversation': 'focusConversation', | 
					
						
							| 
									
										
										
										
											2016-03-18 13:09:45 -07:00
										 |  |  |             'click .global-menu .hamburger': 'toggleMenu', | 
					
						
							| 
									
										
										
										
											2015-12-07 12:36:30 -08:00
										 |  |  |             'click .show-debug-log': 'showDebugLog', | 
					
						
							| 
									
										
										
										
											2016-02-17 16:08:17 -08:00
										 |  |  |             'click .settings': 'showSettings', | 
					
						
							| 
									
										
										
										
											2015-12-01 16:13:58 -08:00
										 |  |  |             'select .gutter .conversation-list-item': 'openConversation', | 
					
						
							| 
									
										
										
										
											2016-03-18 16:21:55 -07:00
										 |  |  |             'input input.search': 'filterContacts', | 
					
						
							| 
									
										
										
										
											2016-06-20 11:37:26 -07:00
										 |  |  |             'click .restart-signal': 'reloadBackgroundPage', | 
					
						
							|  |  |  |             'show .lightbox': 'showLightbox' | 
					
						
							| 
									
										
										
										
											2016-03-18 16:21:55 -07:00
										 |  |  |         }, | 
					
						
							| 
									
										
										
										
											2016-03-20 20:02:38 -07:00
										 |  |  |         focusConversation: function(e) { | 
					
						
							| 
									
										
										
										
											2016-03-21 17:18:29 -07:00
										 |  |  |             if (e && this.$(e.target).closest('.placeholder').length) { | 
					
						
							| 
									
										
										
										
											2016-03-20 20:02:38 -07:00
										 |  |  |                 return; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-01 11:04:20 -07:00
										 |  |  |             this.$('#header, .gutter').addClass('inactive'); | 
					
						
							| 
									
										
										
										
											2016-03-20 20:02:38 -07:00
										 |  |  |             this.$('.conversation-stack').removeClass('inactive'); | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |         focusHeader: function() { | 
					
						
							|  |  |  |             this.$('.conversation-stack').addClass('inactive'); | 
					
						
							| 
									
										
										
										
											2016-04-01 11:04:20 -07:00
										 |  |  |             this.$('#header, .gutter').removeClass('inactive'); | 
					
						
							| 
									
										
										
										
											2016-03-22 11:01:36 -07:00
										 |  |  |             this.$('.conversation:first .menu').trigger('close'); | 
					
						
							| 
									
										
										
										
											2016-03-20 20:02:38 -07:00
										 |  |  |         }, | 
					
						
							| 
									
										
										
										
											2016-03-18 16:21:55 -07:00
										 |  |  |         reloadBackgroundPage: function() { | 
					
						
							|  |  |  |             chrome.runtime.reload(); | 
					
						
							| 
									
										
										
										
											2015-12-07 12:36:30 -08:00
										 |  |  |         }, | 
					
						
							| 
									
										
										
										
											2016-02-17 16:08:17 -08:00
										 |  |  |         showSettings: function() { | 
					
						
							|  |  |  |             var view = new Whisper.SettingsView().render(); | 
					
						
							|  |  |  |             view.update(); | 
					
						
							|  |  |  |             view.$el.insertAfter(this.el); | 
					
						
							|  |  |  |         }, | 
					
						
							| 
									
										
										
										
											2015-12-07 12:36:30 -08:00
										 |  |  |         filterContacts: function(e) { | 
					
						
							|  |  |  |             this.searchView.filterContacts(e); | 
					
						
							|  |  |  |             var input = this.$('input.search'); | 
					
						
							|  |  |  |             if (input.val().length > 0) { | 
					
						
							|  |  |  |                 input.addClass('active'); | 
					
						
							|  |  |  |             } else { | 
					
						
							|  |  |  |                 input.removeClass('active'); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |         openConversation: function(e, conversation) { | 
					
						
							|  |  |  |             this.searchView.hideHints(); | 
					
						
							|  |  |  |             conversation = ConversationController.create(conversation); | 
					
						
							|  |  |  |             this.conversation_stack.open(conversation); | 
					
						
							| 
									
										
										
										
											2016-03-20 20:02:38 -07:00
										 |  |  |             this.focusConversation(); | 
					
						
							| 
									
										
										
										
											2015-12-07 12:36:30 -08:00
										 |  |  |         }, | 
					
						
							|  |  |  |         toggleMenu: function() { | 
					
						
							|  |  |  |             this.$('.global-menu .menu-list').toggle(); | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |         showDebugLog: function() { | 
					
						
							|  |  |  |             this.$('.debug-log').remove(); | 
					
						
							|  |  |  |             new Whisper.DebugLogView().$el.appendTo(this.el); | 
					
						
							|  |  |  |         }, | 
					
						
							| 
									
										
										
										
											2016-06-20 11:37:26 -07:00
										 |  |  |         showLightbox: function(e) { | 
					
						
							|  |  |  |             this.$el.append(e.target); | 
					
						
							|  |  |  |         }, | 
					
						
							| 
									
										
										
										
											2015-12-07 12:36:30 -08:00
										 |  |  |         closeMenu: function(e) { | 
					
						
							| 
									
										
										
										
											2016-03-20 23:34:56 -07:00
										 |  |  |             if (e && this.$(e.target).parent('.global-menu').length > 0 ) { | 
					
						
							|  |  |  |                 return; | 
					
						
							| 
									
										
										
										
											2015-05-11 14:22:15 -07:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2016-03-20 23:34:56 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |             this.$('.global-menu .menu-list').hide(); | 
					
						
							| 
									
										
										
										
											2015-12-07 12:36:30 -08:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2014-11-16 15:30:40 -08:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-03 20:06:27 -07:00
										 |  |  |     Whisper.ExpiredAlertBanner = Whisper.View.extend({ | 
					
						
							|  |  |  |         templateName: 'expired_alert', | 
					
						
							|  |  |  |         className: 'expiredAlert clearfix', | 
					
						
							|  |  |  |         render_attributes: function() { | 
					
						
							|  |  |  |             return { | 
					
						
							|  |  |  |                 expiredWarning: i18n('expiredWarning'), | 
					
						
							|  |  |  |                 upgrade: i18n('upgrade'), | 
					
						
							|  |  |  |             }; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-16 15:30:40 -08:00
										 |  |  | })(); |