overleaf/services/web/public/coffee/ide/chat/controllers/ChatButtonController.coffee

47 lines
1.3 KiB
CoffeeScript
Raw Normal View History

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?
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