Alert dismissals should now be fanned out to other tabs and devices listening to the alert feed.
This commit is contained in:
parent
3822fe12d2
commit
a13b575b72
2
mysql.go
2
mysql.go
@ -53,7 +53,7 @@ func initMySQL() (err error) {
|
||||
|
||||
// TODO: Is there a less noisy way of doing this for tests?
|
||||
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 {
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
|
@ -51,10 +51,8 @@ function addAlert(msg, notice = false) {
|
||||
Avatar: msg.avatar || "",
|
||||
Message: mmsg
|
||||
})
|
||||
|
||||
alertMapping[msg.asid] = aItem;
|
||||
alertList.push(msg.asid);
|
||||
if(alertList.length > 8) alertList.shift();
|
||||
|
||||
if(notice) {
|
||||
// TODO: Add some sort of notification queue to avoid flooding the end-user with notices?
|
||||
@ -206,15 +204,32 @@ function runWebSockets() {
|
||||
wsAlertEvent(data);
|
||||
} else if("event" in data) {
|
||||
if(data.event == "dismiss-alert"){
|
||||
Object.keys(alertBuffer).forEach((key) => {
|
||||
Object.keys(alertMapping).forEach((key) => {
|
||||
if(key==data.asid) {
|
||||
alertCount--;
|
||||
for(var i = 0; i < alertList.length;i++) {
|
||||
let index = -1;
|
||||
for(var i = 0; i < alertList.length; i++) {
|
||||
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];
|
||||
|
||||
|
||||
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
10
routes.go
10
routes.go
@ -48,10 +48,18 @@ func routeAPI(w http.ResponseWriter, r *http.Request, user common.User) common.R
|
||||
if err != nil {
|
||||
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 {
|
||||
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
|
||||
if !user.Loggedin {
|
||||
w.Write(phraseLoginAlerts)
|
||||
|
Loading…
Reference in New Issue
Block a user