removed user specific motd, added hasnewmsg check

This commit is contained in:
mrfry 2022-05-01 19:00:09 +02:00
parent 2f4786987d
commit d213f2516b

View file

@ -120,7 +120,7 @@
const forcedMatchString = isDevel ? 'default' : null
// only one of these should be true for testing
const forceTestPage = isDevel && false
const forceResultPage = isDevel && false
const forceResultPage = isDevel && true
const forceDefaultPage = isDevel && false
// ------------------------------------------------------------------------------
@ -137,7 +137,6 @@
const minMessageOpacity = 0.2
let infoExpireTime = 60 * 5 // Every n seconds basic info should be loaded from server
var motd = ''
var userSpecificMotd = undefined
var lastestVersion = ''
var subjInfo
@ -1650,13 +1649,6 @@
}
subjInfo = inf.subjinfo
setVal('userId', inf.uid)
userSpecificMotd = inf.userSpecificMotd
if (userSpecificMotd) {
overlay.querySelector('#mailButton').style.cursor = 'pointer'
overlay.querySelector('#mailButton').innerText = userSpecificMotd.seen
? '📭'
: '📬'
}
overlay.querySelector(
'#infoMainDiv'
).innerText = `${subjInfo.subjects.toLocaleString(
@ -1664,6 +1656,9 @@
)} tárgy, ${subjInfo.questions.toLocaleString(
'hu'
)} kérdés.\nUser ID: ${getUid()}`
if (inf.unreads.length > 0) {
overlay.querySelector('#mailButton').innerText = '📬'
}
// FIXME: if cwith() throws an unhandled error it sais server is not avaible
cwith()
})
@ -1745,11 +1740,6 @@
greetMsg.push(texts.newVersionAvaible + lastestVersion)
timeout = undefined
}
if (userSpecificMotd && !userSpecificMotd.seen) {
timeout = null
greetMsg.push(texts.userSpecifitMotdAvailable)
timeout = undefined
}
if (newVersion) {
greetMsg.push(texts.versionUpdated + info().script.version)
setVal('lastVerson', info().script.version) // setting lastVersion
@ -2481,24 +2471,13 @@
bottom: '15px',
margin: '5px',
fontSize: '30px',
cursor: 'pointer',
},
title: 'Messages',
onClick: () => {
if (userSpecificMotd && !userSpecificMotd.seen) {
SafeGetElementById('mailButton', (elem) => {
elem.innerText = '📭'
})
post('infos', {
userSpecificMotdSeen: true,
})
}
if (!userSpecificMotd) {
return
}
clearAllMessages()
ShowMessage(
'Üzenet oldal készítéjétől (csak te látod):\n' +
userSpecificMotd.msg
)
openInTab(serverAdress + 'chat', {
active: true,
})
},
},
buttonContainer: {
@ -2802,32 +2781,26 @@
'&cid=' +
getCid()
xmlhttpRequest({
method: 'GET',
url: url,
crossDomain: true,
xhrFields: { withCredentials: true },
headers: {
'Content-Type': 'application/json',
},
onload: function (response) {
Promise.all([get(url), get(apiAdress + 'hasNewMsg')])
.then(([{ responseText: infos }, { responseText: hasNewMsg }]) => {
try {
setVal('lastInfoCheckTime', now)
const res = JSON.parse(response.responseText)
setVal('lastInfo', response.responseText)
resolve(res)
const infosObj = JSON.parse(infos)
const hasNewMsgsObj = JSON.parse(hasNewMsg)
const merged = Object.assign({}, infosObj, hasNewMsgsObj)
setVal('lastInfo', JSON.stringify(merged))
resolve(merged)
} catch (e) {
log('Errro paring JSON in GetXHRInfos')
log(response.responseText)
log({ infos: infos, hasNewMsg: hasNewMsg })
log(e)
reject(e)
}
},
onerror: (e) => {
})
.catch((e) => {
log('Info get Error', e)
reject(e)
},
})
})
})
} else {
return new Promise((resolve, reject) => {
@ -2842,6 +2815,26 @@
}
}
function get(url) {
return new Promise((resolve, reject) => {
xmlhttpRequest({
method: 'GET',
url: url,
crossDomain: true,
xhrFields: { withCredentials: true },
headers: {
'Content-Type': 'application/json',
},
onload: function (response) {
resolve(response)
},
onerror: (e) => {
reject(e)
},
})
})
}
function post(path, message) {
if (typeof message === 'object') {
message = JSON.stringify(message)