mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
1ebc8a79cb
Upgrade Prettier to v2 GitOrigin-RevId: 85aa3fa1acb6332c4f58c46165a43d1a51471f33
59 lines
1.9 KiB
JavaScript
59 lines
1.9 KiB
JavaScript
/* 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
|
|
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
|
*/
|
|
import App from '../base'
|
|
const MESSAGE_POLL_INTERVAL = 15 * 60 * 1000
|
|
// Controller for messages (array)
|
|
App.controller('SystemMessagesController', ($http, $scope) => {
|
|
$scope.messages = []
|
|
var pollSystemMessages = function () {
|
|
// Ignore polling if tab is hidden or browser is offline
|
|
if (document.hidden || !navigator.onLine) {
|
|
return
|
|
}
|
|
|
|
$http
|
|
.get('/system/messages')
|
|
.then(response => {
|
|
// Ignore if content-type is anything but JSON, prevents a bug where
|
|
// the user logs out in another tab, then a 302 redirect was returned,
|
|
// which is transparently resolved by the browser to the login (HTML)
|
|
// page.
|
|
// This then caused an Angular error where it was attempting to loop
|
|
// through the HTML as a string
|
|
if (response.headers('content-type').includes('json')) {
|
|
$scope.messages = response.data
|
|
}
|
|
})
|
|
.catch(() => {
|
|
// ignore errors
|
|
})
|
|
}
|
|
pollSystemMessages()
|
|
setInterval(pollSystemMessages, MESSAGE_POLL_INTERVAL)
|
|
})
|
|
|
|
export default App.controller(
|
|
'SystemMessageController',
|
|
function ($scope, $sce) {
|
|
$scope.hidden = $.localStorage(`systemMessage.hide.${$scope.message._id}`)
|
|
$scope.protected = $scope.message._id === 'protected'
|
|
$scope.htmlContent = $scope.message.content
|
|
|
|
return ($scope.hide = function () {
|
|
if (!$scope.protected) {
|
|
// do not allow protected messages to be hidden
|
|
$scope.hidden = true
|
|
return $.localStorage(`systemMessage.hide.${$scope.message._id}`, true)
|
|
}
|
|
})
|
|
}
|
|
)
|