Alert dismissals should now be fanned out to other tabs and devices listening to the alert feed.

This commit is contained in:
Azareal 2018-09-08 23:50:15 +10:00
parent 3822fe12d2
commit a13b575b72
3 changed files with 30 additions and 7 deletions

View File

@ -53,7 +53,7 @@ func initMySQL() (err error) {
// TODO: Is there a less noisy way of doing this for tests? // TODO: Is there a less noisy way of doing this for tests?
log.Print("Preparing getActivityFeedByWatcher statement.") log.Print("Preparing getActivityFeedByWatcher statement.")
stmts.getActivityFeedByWatcher, err = db.Prepare("SELECT activity_stream_matches.asid, activity_stream.actor, activity_stream.targetUser, activity_stream.event, activity_stream.elementType, activity_stream.elementID FROM `activity_stream_matches` INNER JOIN `activity_stream` ON activity_stream_matches.asid = activity_stream.asid AND activity_stream_matches.watcher != activity_stream.actor WHERE `watcher` = ? ORDER BY activity_stream.asid DESC LIMIT 8") stmts.getActivityFeedByWatcher, err = db.Prepare("SELECT activity_stream_matches.asid, activity_stream.actor, activity_stream.targetUser, activity_stream.event, activity_stream.elementType, activity_stream.elementID FROM `activity_stream_matches` INNER JOIN `activity_stream` ON activity_stream_matches.asid = activity_stream.asid AND activity_stream_matches.watcher != activity_stream.actor WHERE `watcher` = ? ORDER BY activity_stream.asid DESC LIMIT 16")
if err != nil { if err != nil {
return errors.WithStack(err) return errors.WithStack(err)
} }

View File

@ -51,10 +51,8 @@ function addAlert(msg, notice = false) {
Avatar: msg.avatar || "", Avatar: msg.avatar || "",
Message: mmsg Message: mmsg
}) })
alertMapping[msg.asid] = aItem; alertMapping[msg.asid] = aItem;
alertList.push(msg.asid); alertList.push(msg.asid);
if(alertList.length > 8) alertList.shift();
if(notice) { if(notice) {
// TODO: Add some sort of notification queue to avoid flooding the end-user with notices? // TODO: Add some sort of notification queue to avoid flooding the end-user with notices?
@ -206,15 +204,32 @@ function runWebSockets() {
wsAlertEvent(data); wsAlertEvent(data);
} else if("event" in data) { } else if("event" in data) {
if(data.event == "dismiss-alert"){ if(data.event == "dismiss-alert"){
Object.keys(alertBuffer).forEach((key) => { Object.keys(alertMapping).forEach((key) => {
if(key==data.asid) { if(key==data.asid) {
alertCount--; alertCount--;
let index = -1;
for(var i = 0; i < alertList.length; i++) { for(var i = 0; i < alertList.length; i++) {
if(alertList[i]==key) { if(alertList[i]==key) {
alertList.splice(i); alertList[i] = 0;
index = i;
} }
} }
for(var i = index; (i+1) < alertList.length; i++) {
alertList[i] = alertList[i+1];
}
alertList.splice(alertList.length-1,1);
delete alertMapping[key]; delete alertMapping[key];
// TODO: Add support for other alert feeds like PM Alerts
var generalAlerts = document.getElementById("general_alerts");
if(alertList.length < 8) {
loadAlerts(generalAlerts);
} else {
updateAlertList(generalAlerts);
}
} }
}); });
} }

View File

@ -48,10 +48,18 @@ func routeAPI(w http.ResponseWriter, r *http.Request, user common.User) common.R
if err != nil { if err != nil {
return common.PreErrorJS("Invalid asid", w, r) return common.PreErrorJS("Invalid asid", w, r)
} }
_, err = stmts.deleteActivityStreamMatch.Exec(user.ID, asid) res, err := stmts.deleteActivityStreamMatch.Exec(user.ID, asid)
if err != nil { if err != nil {
return common.InternalError(err, w, r) return common.InternalError(err, w, r)
} }
count, err := res.RowsAffected()
if err != nil {
return common.InternalError(err, w, r)
}
// Don't want to throw an internal error due to a socket closing
if common.EnableWebsockets && count > 0 {
_ = common.WsHub.PushMessage(user.ID, `{"event":"dismiss-alert","asid":`+strconv.Itoa(asid)+`}`)
}
case "alerts": // A feed of events tailored for a specific user case "alerts": // A feed of events tailored for a specific user
if !user.Loggedin { if !user.Loggedin {
w.Write(phraseLoginAlerts) w.Write(phraseLoginAlerts)