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'
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
export default App.controller('ChatButtonController', function ($scope, ide) {
|
|
|
|
$scope.toggleChat = function () {
|
2020-05-19 05:02:56 -04:00
|
|
|
$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-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-05-19 05:02:56 -04:00
|
|
|
}
|
2020-11-24 06:58:08 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
window.addEventListener('Chat.MessageReceived', ({ detail: { message } }) =>
|
|
|
|
handleNewMessage(message)
|
|
|
|
)
|
2020-05-19 05:02:56 -04:00
|
|
|
})
|
2018-11-05 05:06:39 -05:00
|
|
|
|
|
|
|
function __guard__(value, transform) {
|
|
|
|
return typeof value !== 'undefined' && value !== null
|
|
|
|
? transform(value)
|
|
|
|
: undefined
|
|
|
|
}
|