fix deleting like alerts when unliking a reply
immediately delete alerts via websockets when a topic or reply is unliked Add AidsByParams method to ActivityStream.
This commit is contained in:
parent
b38df9773b
commit
2e8c6e6fb6
|
@ -14,6 +14,7 @@ type ActivityStream interface {
|
|||
Delete(id int) error
|
||||
DeleteByParams(event string, targetID int, targetType string) error
|
||||
DeleteByParamsExtra(event string, targetID int, targetType, extra string) error
|
||||
AidsByParams(event string, elementID int, elementType string) (aids []int, err error)
|
||||
AidsByParamsExtra(event string, elementID int, elementType, extra string) (aids []int, err error)
|
||||
Count() (count int)
|
||||
}
|
||||
|
@ -24,6 +25,7 @@ type DefaultActivityStream struct {
|
|||
delete *sql.Stmt
|
||||
deleteByParams *sql.Stmt
|
||||
deleteByParamsExtra *sql.Stmt
|
||||
aidsByParams *sql.Stmt
|
||||
aidsByParamsExtra *sql.Stmt
|
||||
count *sql.Stmt
|
||||
}
|
||||
|
@ -36,6 +38,7 @@ func NewDefaultActivityStream(acc *qgen.Accumulator) (*DefaultActivityStream, er
|
|||
delete: acc.Delete(as).Where("asid=?").Prepare(),
|
||||
deleteByParams: acc.Delete(as).Where("event=? AND elementID=? AND elementType=?").Prepare(),
|
||||
deleteByParamsExtra: acc.Delete(as).Where("event=? AND elementID=? AND elementType=? AND extra=?").Prepare(),
|
||||
aidsByParams: acc.Select(as).Columns("asid").Where("event=? AND elementID=? AND elementType=?").Prepare(),
|
||||
aidsByParamsExtra: acc.Select(as).Columns("asid").Where("event=? AND elementID=? AND elementType=? AND extra=?").Prepare(),
|
||||
count: acc.Count(as).Prepare(),
|
||||
}, acc.FirstError()
|
||||
|
@ -71,6 +74,22 @@ func (s *DefaultActivityStream) DeleteByParamsExtra(event string, elementID int,
|
|||
return err
|
||||
}
|
||||
|
||||
func (s *DefaultActivityStream) AidsByParams(event string, elementID int, elementType string) (aids []int, err error) {
|
||||
rows, err := s.aidsByParams.Query(event, elementID, elementType)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
for rows.Next() {
|
||||
var aid int
|
||||
if err := rows.Scan(&aid); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
aids = append(aids, aid)
|
||||
}
|
||||
return aids, rows.Err()
|
||||
}
|
||||
|
||||
func (s *DefaultActivityStream) AidsByParamsExtra(event string, elementID int, elementType, extra string) (aids []int, err error) {
|
||||
rows, err := s.aidsByParamsExtra.Query(event, elementID, elementType, extra)
|
||||
if err != nil {
|
||||
|
|
|
@ -7,7 +7,7 @@ import (
|
|||
"strings"
|
||||
"sync/atomic"
|
||||
|
||||
"github.com/Azareal/Gosora/query_gen"
|
||||
qgen "github.com/Azareal/Gosora/query_gen"
|
||||
)
|
||||
|
||||
var SettingBox atomic.Value // An atomic value pointing to a SettingBox
|
||||
|
@ -16,7 +16,7 @@ var SettingBox atomic.Value // An atomic value pointing to a SettingBox
|
|||
type SettingMap map[string]interface{}
|
||||
|
||||
type SettingStore interface {
|
||||
ParseSetting(sname string, scontent string, stype string, sconstraint string) string
|
||||
ParseSetting(sname, scontent, stype, sconstraint string) string
|
||||
BypassGet(name string) (*Setting, error)
|
||||
BypassGetAll(name string) ([]*Setting, error)
|
||||
}
|
||||
|
@ -80,7 +80,7 @@ func LoadSettings() error {
|
|||
}
|
||||
|
||||
// TODO: Add better support for HTML attributes (html-attribute). E.g. Meta descriptions.
|
||||
func (sBox SettingMap) ParseSetting(sname string, scontent string, stype string, constraint string) (err error) {
|
||||
func (sBox SettingMap) ParseSetting(sname, scontent, stype, constraint string) (err error) {
|
||||
ssBox := map[string]interface{}(sBox)
|
||||
switch stype {
|
||||
case "bool":
|
||||
|
@ -146,7 +146,7 @@ func (sBox SettingMap) BypassGetAll() (settingList []*Setting, err error) {
|
|||
return settingList, rows.Err()
|
||||
}
|
||||
|
||||
func (sBox SettingMap) Update(name string, content string) RouteError {
|
||||
func (sBox SettingMap) Update(name, content string) RouteError {
|
||||
s, err := sBox.BypassGet(name)
|
||||
if err == ErrNoRows {
|
||||
return FromError(err)
|
||||
|
|
|
@ -566,8 +566,16 @@ func ReplyUnlikeSubmit(w http.ResponseWriter, r *http.Request, user c.User, srid
|
|||
if err != nil {
|
||||
return c.InternalErrorJSQ(err, w, r, js)
|
||||
}
|
||||
// TODO: Push dismiss-event alerts to the users.
|
||||
err = c.Activity.DeleteByParams("like", topic.ID, "reply")
|
||||
|
||||
// TODO: Better coupling between the two params queries
|
||||
aids, err := c.Activity.AidsByParams("like", reply.ID, "post")
|
||||
if err != nil {
|
||||
return c.InternalErrorJSQ(err, w, r, js)
|
||||
}
|
||||
for _, aid := range aids {
|
||||
c.DismissAlert(reply.CreatedBy, aid)
|
||||
}
|
||||
err = c.Activity.DeleteByParams("like", reply.ID, "post")
|
||||
if err != nil {
|
||||
return c.InternalErrorJSQ(err, w, r, js)
|
||||
}
|
||||
|
|
|
@ -993,7 +993,15 @@ func UnlikeTopicSubmit(w http.ResponseWriter, r *http.Request, user c.User, stid
|
|||
if err != nil {
|
||||
return c.InternalErrorJSQ(err, w, r, js)
|
||||
}
|
||||
// TODO: Push dismiss-event alerts to the users.
|
||||
|
||||
// TODO: Better coupling between the two params queries
|
||||
aids, err := c.Activity.AidsByParams("like", topic.ID, "topic")
|
||||
if err != nil {
|
||||
return c.InternalErrorJSQ(err, w, r, js)
|
||||
}
|
||||
for _, aid := range aids {
|
||||
c.DismissAlert(topic.CreatedBy, aid)
|
||||
}
|
||||
err = c.Activity.DeleteByParams("like", topic.ID, "topic")
|
||||
if err != nil {
|
||||
return c.InternalErrorJSQ(err, w, r, js)
|
||||
|
|
Loading…
Reference in New Issue