2018-11-05 05:06:39 -05:00
|
|
|
/* eslint-disable
|
|
|
|
max-len,
|
|
|
|
no-return-assign,
|
|
|
|
*/
|
|
|
|
// TODO: This file was created by bulk-decaffeinate.
|
|
|
|
// Fix any style issues and re-enable lint.
|
|
|
|
/*
|
|
|
|
* decaffeinate suggestions:
|
|
|
|
* DS102: Remove unnecessary code created because of implicit returns
|
|
|
|
* DS103: Rewrite code to no longer use __guard__
|
|
|
|
* DS207: Consider shorter variations of null checks
|
|
|
|
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
|
|
|
*/
|
2020-05-19 05:02:56 -04:00
|
|
|
import App from '../../../base'
|
|
|
|
|
|
|
|
export default App.controller('ChatButtonController', function($scope, ide) {
|
|
|
|
let clearNewMessageNotification
|
|
|
|
$scope.toggleChat = function() {
|
|
|
|
$scope.ui.chatOpen = !$scope.ui.chatOpen
|
|
|
|
return $scope.resetUnreadMessages()
|
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
$scope.unreadMessages = 0
|
|
|
|
$scope.resetUnreadMessages = () => ($scope.unreadMessages = 0)
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
$scope.$on('chat:resetUnreadMessages', e => $scope.resetUnreadMessages())
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-11-24 06:58:08 -05:00
|
|
|
function handleNewMessage(message) {
|
2020-05-19 05:02:56 -04:00
|
|
|
if (message != null) {
|
|
|
|
if (
|
|
|
|
__guard__(message != null ? message.user : undefined, x => x.id) !==
|
|
|
|
ide.$scope.user.id
|
|
|
|
) {
|
|
|
|
if (!$scope.ui.chatOpen) {
|
2020-11-24 06:58:08 -05:00
|
|
|
$scope.$applyAsync(() => {
|
|
|
|
$scope.unreadMessages += 1
|
|
|
|
})
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
2020-11-24 06:58:08 -05:00
|
|
|
flashTitle()
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
}
|
2020-11-24 06:58:08 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
$scope.$on('chat:newMessage', (e, message) => handleNewMessage(message))
|
|
|
|
window.addEventListener('Chat.MessageReceived', ({ detail: { message } }) =>
|
|
|
|
handleNewMessage(message)
|
|
|
|
)
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
let focussed = true
|
|
|
|
let newMessageNotificationTimeout = null
|
|
|
|
let originalTitle = null
|
|
|
|
$(window).on('focus', function() {
|
|
|
|
clearNewMessageNotification()
|
|
|
|
return (focussed = true)
|
|
|
|
})
|
|
|
|
$(window).on('blur', () => (focussed = false))
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
var flashTitle = function() {
|
|
|
|
if (!focussed && newMessageNotificationTimeout == null) {
|
|
|
|
let changeTitle
|
|
|
|
if (!originalTitle) {
|
|
|
|
originalTitle = window.document.title
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
return (changeTitle = () => {
|
|
|
|
if (window.document.title === originalTitle) {
|
|
|
|
window.document.title = 'New Message'
|
|
|
|
} else {
|
|
|
|
window.document.title = originalTitle
|
|
|
|
}
|
|
|
|
return (newMessageNotificationTimeout = setTimeout(changeTitle, 800))
|
|
|
|
})()
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
return (clearNewMessageNotification = function() {
|
|
|
|
clearTimeout(newMessageNotificationTimeout)
|
|
|
|
newMessageNotificationTimeout = null
|
|
|
|
if (originalTitle != null) {
|
|
|
|
return (window.document.title = originalTitle)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
2018-11-05 05:06:39 -05:00
|
|
|
|
|
|
|
function __guard__(value, transform) {
|
|
|
|
return typeof value !== 'undefined' && value !== null
|
|
|
|
? transform(value)
|
|
|
|
: undefined
|
|
|
|
}
|