2014-07-08 07:02:26 -04:00
|
|
|
define [
|
|
|
|
"base"
|
|
|
|
], (App) ->
|
2014-07-17 06:05:08 -04:00
|
|
|
App.controller "ChatButtonController", ($scope, ide) ->
|
2014-07-08 07:02:26 -04:00
|
|
|
$scope.toggleChat = () ->
|
|
|
|
$scope.ui.chatOpen = !$scope.ui.chatOpen
|
2014-07-17 06:05:08 -04:00
|
|
|
$scope.resetUnreadMessages()
|
|
|
|
|
|
|
|
$scope.unreadMessages = 0
|
|
|
|
$scope.resetUnreadMessages = () ->
|
|
|
|
$scope.unreadMessages = 0
|
|
|
|
|
|
|
|
$scope.$on "chat:resetUnreadMessages", (e) ->
|
|
|
|
$scope.resetUnreadMessages()
|
|
|
|
|
|
|
|
$scope.$on "chat:newMessage", (e, message) ->
|
|
|
|
if message?
|
2015-02-16 18:16:38 -05:00
|
|
|
if message?.user?.id != ide.$scope.user.id
|
2014-07-17 06:05:08 -04:00
|
|
|
if !$scope.ui.chatOpen
|
|
|
|
$scope.unreadMessages += 1
|
|
|
|
flashTitle()
|
|
|
|
|
|
|
|
focussed = true
|
|
|
|
newMessageNotificationTimeout = null
|
|
|
|
originalTitle = null
|
|
|
|
$(window).on "focus", () ->
|
|
|
|
clearNewMessageNotification()
|
|
|
|
focussed = true
|
|
|
|
$(window).on "blur", () ->
|
|
|
|
focussed = false
|
|
|
|
|
|
|
|
flashTitle = () ->
|
|
|
|
if !focussed and !newMessageNotificationTimeout?
|
|
|
|
originalTitle ||= window.document.title
|
|
|
|
do changeTitle = () =>
|
|
|
|
if window.document.title == originalTitle
|
|
|
|
window.document.title = "New Message"
|
|
|
|
else
|
|
|
|
window.document.title = originalTitle
|
|
|
|
newMessageNotificationTimeout = setTimeout changeTitle, 800
|
|
|
|
|
|
|
|
clearNewMessageNotification = () ->
|
|
|
|
clearTimeout newMessageNotificationTimeout
|
|
|
|
newMessageNotificationTimeout = null
|
|
|
|
if originalTitle?
|
|
|
|
window.document.title = originalTitle
|