2018-03-08 03:59:47 +00:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Gosora Alerts System
|
2019-05-03 08:34:18 +00:00
|
|
|
* Copyright Azareal 2017 - 2020
|
2018-03-08 03:59:47 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
package common
|
|
|
|
|
|
|
|
import (
|
|
|
|
"database/sql"
|
|
|
|
"errors"
|
|
|
|
"strconv"
|
|
|
|
"strings"
|
2019-05-11 23:07:24 +00:00
|
|
|
"time"
|
Cascade delete attachments properly.
Cascade delete replied to topic events for replies properly.
Cascade delete likes on topic posts properly.
Cascade delete replies and their children properly.
Recalculate user stats properly when items are deleted.
Users can now unlike topic opening posts.
Add a recalculator to fix abnormalities across upgrades.
Try fixing a last_ip daily update bug.
Add Existable interface.
Add Delete method to LikeStore.
Add Each, Exists, Create, CountUser, CountMegaUser and CountBigUser methods to ReplyStore.
Add CountUser, CountMegaUser, CountBigUser methods to TopicStore.
Add Each method to UserStore.
Add Add, Delete and DeleteResource methods to SubscriptionStore.
Add Delete, DeleteByParams, DeleteByParamsExtra and AidsByParamsExtra methods to ActivityStream.
Add Exists method to ProfileReplyStore.
Add DropColumn, RenameColumn and ChangeColumn to the database adapters.
Shorten ipaddress column names to ip.
- topics table.
- replies table
- users_replies table.
- polls_votes table.
Add extra column to activity_stream table.
Fix an issue upgrading sites to MariaDB 10.3 from older versions of Gosora. Please report any other issues you find.
You need to run the updater / patcher for this commit.
2020-01-31 07:22:08 +00:00
|
|
|
|
2019-06-01 12:31:48 +00:00
|
|
|
//"fmt"
|
2018-03-08 03:59:47 +00:00
|
|
|
|
2018-11-01 06:43:56 +00:00
|
|
|
"github.com/Azareal/Gosora/common/phrases"
|
Cascade delete attachments properly.
Cascade delete replied to topic events for replies properly.
Cascade delete likes on topic posts properly.
Cascade delete replies and their children properly.
Recalculate user stats properly when items are deleted.
Users can now unlike topic opening posts.
Add a recalculator to fix abnormalities across upgrades.
Try fixing a last_ip daily update bug.
Add Existable interface.
Add Delete method to LikeStore.
Add Each, Exists, Create, CountUser, CountMegaUser and CountBigUser methods to ReplyStore.
Add CountUser, CountMegaUser, CountBigUser methods to TopicStore.
Add Each method to UserStore.
Add Add, Delete and DeleteResource methods to SubscriptionStore.
Add Delete, DeleteByParams, DeleteByParamsExtra and AidsByParamsExtra methods to ActivityStream.
Add Exists method to ProfileReplyStore.
Add DropColumn, RenameColumn and ChangeColumn to the database adapters.
Shorten ipaddress column names to ip.
- topics table.
- replies table
- users_replies table.
- polls_votes table.
Add extra column to activity_stream table.
Fix an issue upgrading sites to MariaDB 10.3 from older versions of Gosora. Please report any other issues you find.
You need to run the updater / patcher for this commit.
2020-01-31 07:22:08 +00:00
|
|
|
qgen "github.com/Azareal/Gosora/query_gen"
|
2018-03-08 03:59:47 +00:00
|
|
|
)
|
|
|
|
|
2018-11-22 07:21:43 +00:00
|
|
|
type Alert struct {
|
|
|
|
ASID int
|
|
|
|
ActorID int
|
|
|
|
TargetUserID int
|
|
|
|
Event string
|
|
|
|
ElementType string
|
|
|
|
ElementID int
|
Cascade delete attachments properly.
Cascade delete replied to topic events for replies properly.
Cascade delete likes on topic posts properly.
Cascade delete replies and their children properly.
Recalculate user stats properly when items are deleted.
Users can now unlike topic opening posts.
Add a recalculator to fix abnormalities across upgrades.
Try fixing a last_ip daily update bug.
Add Existable interface.
Add Delete method to LikeStore.
Add Each, Exists, Create, CountUser, CountMegaUser and CountBigUser methods to ReplyStore.
Add CountUser, CountMegaUser, CountBigUser methods to TopicStore.
Add Each method to UserStore.
Add Add, Delete and DeleteResource methods to SubscriptionStore.
Add Delete, DeleteByParams, DeleteByParamsExtra and AidsByParamsExtra methods to ActivityStream.
Add Exists method to ProfileReplyStore.
Add DropColumn, RenameColumn and ChangeColumn to the database adapters.
Shorten ipaddress column names to ip.
- topics table.
- replies table
- users_replies table.
- polls_votes table.
Add extra column to activity_stream table.
Fix an issue upgrading sites to MariaDB 10.3 from older versions of Gosora. Please report any other issues you find.
You need to run the updater / patcher for this commit.
2020-01-31 07:22:08 +00:00
|
|
|
CreatedAt time.Time
|
|
|
|
Extra string
|
2018-11-22 07:21:43 +00:00
|
|
|
|
|
|
|
Actor *User
|
|
|
|
}
|
|
|
|
|
2018-03-08 03:59:47 +00:00
|
|
|
type AlertStmts struct {
|
Cascade delete attachments properly.
Cascade delete replied to topic events for replies properly.
Cascade delete likes on topic posts properly.
Cascade delete replies and their children properly.
Recalculate user stats properly when items are deleted.
Users can now unlike topic opening posts.
Add a recalculator to fix abnormalities across upgrades.
Try fixing a last_ip daily update bug.
Add Existable interface.
Add Delete method to LikeStore.
Add Each, Exists, Create, CountUser, CountMegaUser and CountBigUser methods to ReplyStore.
Add CountUser, CountMegaUser, CountBigUser methods to TopicStore.
Add Each method to UserStore.
Add Add, Delete and DeleteResource methods to SubscriptionStore.
Add Delete, DeleteByParams, DeleteByParamsExtra and AidsByParamsExtra methods to ActivityStream.
Add Exists method to ProfileReplyStore.
Add DropColumn, RenameColumn and ChangeColumn to the database adapters.
Shorten ipaddress column names to ip.
- topics table.
- replies table
- users_replies table.
- polls_votes table.
Add extra column to activity_stream table.
Fix an issue upgrading sites to MariaDB 10.3 from older versions of Gosora. Please report any other issues you find.
You need to run the updater / patcher for this commit.
2020-01-31 07:22:08 +00:00
|
|
|
notifyWatchers *sql.Stmt
|
|
|
|
notifyOne *sql.Stmt
|
|
|
|
getWatchers *sql.Stmt
|
2018-03-08 03:59:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var alertStmts AlertStmts
|
|
|
|
|
|
|
|
// TODO: Move these statements into some sort of activity abstraction
|
|
|
|
// TODO: Rewrite the alerts logic
|
|
|
|
func init() {
|
|
|
|
DbInits.Add(func(acc *qgen.Accumulator) error {
|
|
|
|
alertStmts = AlertStmts{
|
|
|
|
notifyWatchers: acc.SimpleInsertInnerJoin(
|
2019-12-31 21:57:54 +00:00
|
|
|
qgen.DBInsert{"activity_stream_matches", "watcher,asid", ""},
|
Cascade delete attachments properly.
Cascade delete replied to topic events for replies properly.
Cascade delete likes on topic posts properly.
Cascade delete replies and their children properly.
Recalculate user stats properly when items are deleted.
Users can now unlike topic opening posts.
Add a recalculator to fix abnormalities across upgrades.
Try fixing a last_ip daily update bug.
Add Existable interface.
Add Delete method to LikeStore.
Add Each, Exists, Create, CountUser, CountMegaUser and CountBigUser methods to ReplyStore.
Add CountUser, CountMegaUser, CountBigUser methods to TopicStore.
Add Each method to UserStore.
Add Add, Delete and DeleteResource methods to SubscriptionStore.
Add Delete, DeleteByParams, DeleteByParamsExtra and AidsByParamsExtra methods to ActivityStream.
Add Exists method to ProfileReplyStore.
Add DropColumn, RenameColumn and ChangeColumn to the database adapters.
Shorten ipaddress column names to ip.
- topics table.
- replies table
- users_replies table.
- polls_votes table.
Add extra column to activity_stream table.
Fix an issue upgrading sites to MariaDB 10.3 from older versions of Gosora. Please report any other issues you find.
You need to run the updater / patcher for this commit.
2020-01-31 07:22:08 +00:00
|
|
|
qgen.DBJoin{"activity_stream", "activity_subscriptions", "activity_subscriptions.user, activity_stream.asid", "activity_subscriptions.targetType = activity_stream.elementType AND activity_subscriptions.targetID = activity_stream.elementID AND activity_subscriptions.user != activity_stream.actor", "asid=?", "", ""},
|
2018-03-08 03:59:47 +00:00
|
|
|
),
|
Cascade delete attachments properly.
Cascade delete replied to topic events for replies properly.
Cascade delete likes on topic posts properly.
Cascade delete replies and their children properly.
Recalculate user stats properly when items are deleted.
Users can now unlike topic opening posts.
Add a recalculator to fix abnormalities across upgrades.
Try fixing a last_ip daily update bug.
Add Existable interface.
Add Delete method to LikeStore.
Add Each, Exists, Create, CountUser, CountMegaUser and CountBigUser methods to ReplyStore.
Add CountUser, CountMegaUser, CountBigUser methods to TopicStore.
Add Each method to UserStore.
Add Add, Delete and DeleteResource methods to SubscriptionStore.
Add Delete, DeleteByParams, DeleteByParamsExtra and AidsByParamsExtra methods to ActivityStream.
Add Exists method to ProfileReplyStore.
Add DropColumn, RenameColumn and ChangeColumn to the database adapters.
Shorten ipaddress column names to ip.
- topics table.
- replies table
- users_replies table.
- polls_votes table.
Add extra column to activity_stream table.
Fix an issue upgrading sites to MariaDB 10.3 from older versions of Gosora. Please report any other issues you find.
You need to run the updater / patcher for this commit.
2020-01-31 07:22:08 +00:00
|
|
|
notifyOne: acc.Insert("activity_stream_matches").Columns("watcher,asid").Fields("?,?").Prepare(),
|
|
|
|
getWatchers: acc.SimpleInnerJoin("activity_stream", "activity_subscriptions", "activity_subscriptions.user", "activity_subscriptions.targetType = activity_stream.elementType AND activity_subscriptions.targetID = activity_stream.elementID AND activity_subscriptions.user != activity_stream.actor", "asid=?", "", ""),
|
2018-03-08 03:59:47 +00:00
|
|
|
}
|
|
|
|
return acc.FirstError()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-03-12 01:08:56 +00:00
|
|
|
const AlertsGrowHint = len(`{"msgs":[],"count":,"tc":}`) + 1 + 10
|
2020-03-04 23:56:45 +00:00
|
|
|
|
2018-10-04 02:58:01 +00:00
|
|
|
// TODO: See if we can json.Marshal instead?
|
|
|
|
func escapeTextInJson(in string) string {
|
2018-10-05 07:41:28 +00:00
|
|
|
in = strings.Replace(in, "\"", "\\\"", -1)
|
2018-10-04 02:58:01 +00:00
|
|
|
return strings.Replace(in, "/", "\\/", -1)
|
|
|
|
}
|
|
|
|
|
2020-03-04 04:31:11 +00:00
|
|
|
func BuildAlert(a Alert, user User /* The current user */) (out string, err error) {
|
2018-03-08 03:59:47 +00:00
|
|
|
var targetUser *User
|
2020-03-04 04:31:11 +00:00
|
|
|
if a.Actor == nil {
|
|
|
|
a.Actor, err = Users.Get(a.ActorID)
|
2018-11-22 07:21:43 +00:00
|
|
|
if err != nil {
|
|
|
|
return "", errors.New(phrases.GetErrorPhrase("alerts_no_actor"))
|
|
|
|
}
|
2018-03-08 03:59:47 +00:00
|
|
|
}
|
|
|
|
|
2020-03-04 04:31:11 +00:00
|
|
|
/*if a.ElementType != "forum" {
|
|
|
|
targetUser, err = users.Get(a.TargetUserID)
|
2018-03-08 03:59:47 +00:00
|
|
|
if err != nil {
|
|
|
|
LocalErrorJS("Unable to find the target user",w,r)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}*/
|
2020-03-04 04:31:11 +00:00
|
|
|
if a.Event == "friend_invite" {
|
|
|
|
return buildAlertString(".new_friend_invite", []string{a.Actor.Name}, a.Actor.Link, a.Actor.Avatar, a.ASID), nil
|
2018-03-08 03:59:47 +00:00
|
|
|
}
|
|
|
|
|
2018-10-05 07:41:28 +00:00
|
|
|
// Not that many events for us to handle in a forum
|
2020-03-04 04:31:11 +00:00
|
|
|
if a.ElementType == "forum" {
|
|
|
|
if a.Event == "reply" {
|
|
|
|
topic, err := Topics.Get(a.ElementID)
|
2018-03-08 03:59:47 +00:00
|
|
|
if err != nil {
|
2020-03-04 04:31:11 +00:00
|
|
|
DebugLogf("Unable to find linked topic %d", a.ElementID)
|
2018-11-01 06:43:56 +00:00
|
|
|
return "", errors.New(phrases.GetErrorPhrase("alerts_no_linked_topic"))
|
2018-03-08 03:59:47 +00:00
|
|
|
}
|
|
|
|
// Store the forum ID in the targetUser column instead of making a new one? o.O
|
|
|
|
// Add an additional column for extra information later on when we add the ability to link directly to posts. We don't need the forum data for now...
|
2020-03-04 04:31:11 +00:00
|
|
|
return buildAlertString(".forum_new_topic", []string{a.Actor.Name, topic.Title}, topic.Link, a.Actor.Avatar, a.ASID), nil
|
2018-03-08 03:59:47 +00:00
|
|
|
}
|
2020-03-04 04:31:11 +00:00
|
|
|
return buildAlertString(".forum_unknown_action", []string{a.Actor.Name}, "", a.Actor.Avatar, a.ASID), nil
|
2018-10-05 07:41:28 +00:00
|
|
|
}
|
|
|
|
|
2020-03-04 04:31:11 +00:00
|
|
|
var url, area, phraseName string
|
|
|
|
own := false
|
|
|
|
switch a.ElementType {
|
2020-02-13 10:44:03 +00:00
|
|
|
case "convo":
|
2020-03-04 04:31:11 +00:00
|
|
|
convo, err := Convos.Get(a.ElementID)
|
2020-02-13 10:44:03 +00:00
|
|
|
if err != nil {
|
2020-03-04 04:31:11 +00:00
|
|
|
DebugLogf("Unable to find linked convo %d", a.ElementID)
|
2020-02-13 10:44:03 +00:00
|
|
|
return "", errors.New(phrases.GetErrorPhrase("alerts_no_linked_convo"))
|
|
|
|
}
|
|
|
|
url = convo.Link
|
2018-03-08 03:59:47 +00:00
|
|
|
case "topic":
|
2020-03-04 04:31:11 +00:00
|
|
|
topic, err := Topics.Get(a.ElementID)
|
2018-03-08 03:59:47 +00:00
|
|
|
if err != nil {
|
2020-03-04 04:31:11 +00:00
|
|
|
DebugLogf("Unable to find linked topic %d", a.ElementID)
|
2018-11-01 06:43:56 +00:00
|
|
|
return "", errors.New(phrases.GetErrorPhrase("alerts_no_linked_topic"))
|
2018-03-08 03:59:47 +00:00
|
|
|
}
|
|
|
|
url = topic.Link
|
|
|
|
area = topic.Title
|
2020-03-04 04:31:11 +00:00
|
|
|
own = a.TargetUserID == user.ID
|
2018-03-08 03:59:47 +00:00
|
|
|
case "user":
|
2020-03-04 04:31:11 +00:00
|
|
|
targetUser, err = Users.Get(a.ElementID)
|
2018-03-08 03:59:47 +00:00
|
|
|
if err != nil {
|
2020-03-04 04:31:11 +00:00
|
|
|
DebugLogf("Unable to find target user %d", a.ElementID)
|
2018-11-01 06:43:56 +00:00
|
|
|
return "", errors.New(phrases.GetErrorPhrase("alerts_no_target_user"))
|
2018-03-08 03:59:47 +00:00
|
|
|
}
|
|
|
|
area = targetUser.Name
|
|
|
|
url = targetUser.Link
|
2020-03-04 04:31:11 +00:00
|
|
|
own = a.TargetUserID == user.ID
|
2018-03-08 03:59:47 +00:00
|
|
|
case "post":
|
2020-03-04 04:31:11 +00:00
|
|
|
topic, err := TopicByReplyID(a.ElementID)
|
2018-03-08 03:59:47 +00:00
|
|
|
if err != nil {
|
2020-03-04 04:31:11 +00:00
|
|
|
DebugLogf("Unable to find linked topic by reply ID %d", a.ElementID)
|
2018-11-01 06:43:56 +00:00
|
|
|
return "", errors.New(phrases.GetErrorPhrase("alerts_no_linked_topic_by_reply"))
|
2018-03-08 03:59:47 +00:00
|
|
|
}
|
|
|
|
url = topic.Link
|
|
|
|
area = topic.Title
|
2020-03-04 04:31:11 +00:00
|
|
|
own = a.TargetUserID == user.ID
|
2018-03-08 03:59:47 +00:00
|
|
|
default:
|
2018-11-01 06:43:56 +00:00
|
|
|
return "", errors.New(phrases.GetErrorPhrase("alerts_invalid_elementtype"))
|
2018-03-08 03:59:47 +00:00
|
|
|
}
|
|
|
|
|
2020-03-04 04:31:11 +00:00
|
|
|
badEv := false
|
|
|
|
switch a.Event {
|
|
|
|
case "create", "like", "mention", "reply":
|
|
|
|
// skip
|
|
|
|
default:
|
|
|
|
badEv = true
|
|
|
|
}
|
|
|
|
|
|
|
|
if own && !badEv {
|
|
|
|
phraseName = "." + a.ElementType + "_own_" + a.Event
|
|
|
|
} else if !badEv {
|
|
|
|
phraseName = "." + a.ElementType + "_" + a.Event
|
|
|
|
} else if own {
|
|
|
|
phraseName = "." + a.ElementType + "_own"
|
|
|
|
} else {
|
|
|
|
phraseName = "." + a.ElementType
|
2018-03-08 03:59:47 +00:00
|
|
|
}
|
2018-10-05 07:41:28 +00:00
|
|
|
|
2020-03-04 04:31:11 +00:00
|
|
|
return buildAlertString(phraseName, []string{a.Actor.Name, area}, url, a.Actor.Avatar, a.ASID), nil
|
2018-10-04 02:58:01 +00:00
|
|
|
}
|
|
|
|
|
Cascade delete attachments properly.
Cascade delete replied to topic events for replies properly.
Cascade delete likes on topic posts properly.
Cascade delete replies and their children properly.
Recalculate user stats properly when items are deleted.
Users can now unlike topic opening posts.
Add a recalculator to fix abnormalities across upgrades.
Try fixing a last_ip daily update bug.
Add Existable interface.
Add Delete method to LikeStore.
Add Each, Exists, Create, CountUser, CountMegaUser and CountBigUser methods to ReplyStore.
Add CountUser, CountMegaUser, CountBigUser methods to TopicStore.
Add Each method to UserStore.
Add Add, Delete and DeleteResource methods to SubscriptionStore.
Add Delete, DeleteByParams, DeleteByParamsExtra and AidsByParamsExtra methods to ActivityStream.
Add Exists method to ProfileReplyStore.
Add DropColumn, RenameColumn and ChangeColumn to the database adapters.
Shorten ipaddress column names to ip.
- topics table.
- replies table
- users_replies table.
- polls_votes table.
Add extra column to activity_stream table.
Fix an issue upgrading sites to MariaDB 10.3 from older versions of Gosora. Please report any other issues you find.
You need to run the updater / patcher for this commit.
2020-01-31 07:22:08 +00:00
|
|
|
func buildAlertString(msg string, sub []string, path, avatar string, asid int) string {
|
2020-03-04 04:31:11 +00:00
|
|
|
var sb strings.Builder
|
|
|
|
buildAlertSb(&sb, msg, sub, path, avatar, asid)
|
|
|
|
return sb.String()
|
|
|
|
}
|
|
|
|
|
2020-03-12 01:08:56 +00:00
|
|
|
const AlertsGrowHint2 = len(`{"msg":"","sub":[],"path":"","avatar":"","id":}`) + 5 + 3 + 1 + 1 + 1
|
2020-03-04 23:56:45 +00:00
|
|
|
|
2020-03-04 04:31:11 +00:00
|
|
|
// TODO: Use a string builder?
|
|
|
|
func buildAlertSb(sb *strings.Builder, msg string, sub []string, path, avatar string, asid int) {
|
|
|
|
sb.WriteString(`{"msg":"`)
|
|
|
|
sb.WriteString(escapeTextInJson(msg))
|
|
|
|
sb.WriteString(`","sub":[`)
|
|
|
|
for i, it := range sub {
|
|
|
|
if i != 0 {
|
|
|
|
sb.WriteString(",\"")
|
|
|
|
} else {
|
|
|
|
sb.WriteString("\"")
|
|
|
|
}
|
|
|
|
sb.WriteString(escapeTextInJson(it))
|
|
|
|
sb.WriteString("\"")
|
|
|
|
}
|
|
|
|
sb.WriteString(`],"path":"`)
|
|
|
|
sb.WriteString(escapeTextInJson(path))
|
|
|
|
sb.WriteString(`","avatar":"`)
|
|
|
|
sb.WriteString(escapeTextInJson(avatar))
|
|
|
|
sb.WriteString(`","id":`)
|
|
|
|
sb.WriteString(strconv.Itoa(asid))
|
|
|
|
sb.WriteRune('}')
|
|
|
|
}
|
|
|
|
|
2020-03-09 05:16:44 +00:00
|
|
|
func BuildAlertSb(sb *strings.Builder, a *Alert, user User /* The current user */) (err error) {
|
2020-03-04 04:31:11 +00:00
|
|
|
var targetUser *User
|
|
|
|
if a.Actor == nil {
|
|
|
|
a.Actor, err = Users.Get(a.ActorID)
|
|
|
|
if err != nil {
|
|
|
|
return errors.New(phrases.GetErrorPhrase("alerts_no_actor"))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*if a.ElementType != "forum" {
|
|
|
|
targetUser, err = users.Get(a.TargetUserID)
|
|
|
|
if err != nil {
|
|
|
|
LocalErrorJS("Unable to find the target user",w,r)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}*/
|
|
|
|
if a.Event == "friend_invite" {
|
|
|
|
buildAlertSb(sb, ".new_friend_invite", []string{a.Actor.Name}, a.Actor.Link, a.Actor.Avatar, a.ASID)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Not that many events for us to handle in a forum
|
|
|
|
if a.ElementType == "forum" {
|
|
|
|
if a.Event == "reply" {
|
|
|
|
topic, err := Topics.Get(a.ElementID)
|
|
|
|
if err != nil {
|
|
|
|
DebugLogf("Unable to find linked topic %d", a.ElementID)
|
|
|
|
return errors.New(phrases.GetErrorPhrase("alerts_no_linked_topic"))
|
|
|
|
}
|
|
|
|
// Store the forum ID in the targetUser column instead of making a new one? o.O
|
|
|
|
// Add an additional column for extra information later on when we add the ability to link directly to posts. We don't need the forum data for now...
|
|
|
|
buildAlertSb(sb, ".forum_new_topic", []string{a.Actor.Name, topic.Title}, topic.Link, a.Actor.Avatar, a.ASID)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
buildAlertSb(sb, ".forum_unknown_action", []string{a.Actor.Name}, "", a.Actor.Avatar, a.ASID)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
var url, area string
|
|
|
|
own := false
|
|
|
|
switch a.ElementType {
|
|
|
|
case "convo":
|
|
|
|
convo, err := Convos.Get(a.ElementID)
|
|
|
|
if err != nil {
|
|
|
|
DebugLogf("Unable to find linked convo %d", a.ElementID)
|
|
|
|
return errors.New(phrases.GetErrorPhrase("alerts_no_linked_convo"))
|
|
|
|
}
|
|
|
|
url = convo.Link
|
|
|
|
case "topic":
|
|
|
|
topic, err := Topics.Get(a.ElementID)
|
|
|
|
if err != nil {
|
|
|
|
DebugLogf("Unable to find linked topic %d", a.ElementID)
|
|
|
|
return errors.New(phrases.GetErrorPhrase("alerts_no_linked_topic"))
|
|
|
|
}
|
|
|
|
url = topic.Link
|
|
|
|
area = topic.Title
|
|
|
|
own = a.TargetUserID == user.ID
|
|
|
|
case "user":
|
|
|
|
targetUser, err = Users.Get(a.ElementID)
|
|
|
|
if err != nil {
|
|
|
|
DebugLogf("Unable to find target user %d", a.ElementID)
|
|
|
|
return errors.New(phrases.GetErrorPhrase("alerts_no_target_user"))
|
|
|
|
}
|
|
|
|
area = targetUser.Name
|
|
|
|
url = targetUser.Link
|
|
|
|
own = a.TargetUserID == user.ID
|
|
|
|
case "post":
|
|
|
|
topic, err := TopicByReplyID(a.ElementID)
|
|
|
|
if err != nil {
|
|
|
|
DebugLogf("Unable to find linked topic by reply ID %d", a.ElementID)
|
|
|
|
return errors.New(phrases.GetErrorPhrase("alerts_no_linked_topic_by_reply"))
|
|
|
|
}
|
|
|
|
url = topic.Link
|
|
|
|
area = topic.Title
|
|
|
|
own = a.TargetUserID == user.ID
|
|
|
|
default:
|
|
|
|
return errors.New(phrases.GetErrorPhrase("alerts_invalid_elementtype"))
|
2018-10-04 02:58:01 +00:00
|
|
|
}
|
2020-03-04 04:31:11 +00:00
|
|
|
|
2020-03-09 07:11:58 +00:00
|
|
|
sb.WriteString(`{"msg":".`)
|
2020-03-04 04:31:11 +00:00
|
|
|
sb.WriteString(a.ElementType)
|
|
|
|
if own {
|
|
|
|
sb.WriteString("_own_")
|
|
|
|
} else {
|
|
|
|
sb.WriteRune('_')
|
2018-10-04 02:58:01 +00:00
|
|
|
}
|
2020-03-04 04:31:11 +00:00
|
|
|
switch a.Event {
|
|
|
|
case "create", "like", "mention", "reply":
|
|
|
|
sb.WriteString(a.Event)
|
|
|
|
}
|
|
|
|
|
|
|
|
sb.WriteString(`","sub":["`)
|
|
|
|
sb.WriteString(escapeTextInJson(a.Actor.Name))
|
|
|
|
sb.WriteString("\",\"")
|
|
|
|
sb.WriteString(escapeTextInJson(area))
|
|
|
|
sb.WriteString(`"],"path":"`)
|
|
|
|
sb.WriteString(escapeTextInJson(url))
|
|
|
|
sb.WriteString(`","avatar":"`)
|
|
|
|
sb.WriteString(escapeTextInJson(a.Actor.Avatar))
|
|
|
|
sb.WriteString(`","id":`)
|
|
|
|
sb.WriteString(strconv.Itoa(a.ASID))
|
|
|
|
sb.WriteRune('}')
|
2018-03-08 03:59:47 +00:00
|
|
|
|
2020-03-04 04:31:11 +00:00
|
|
|
return nil
|
2018-03-08 03:59:47 +00:00
|
|
|
}
|
|
|
|
|
2020-03-09 07:11:58 +00:00
|
|
|
//var AlertsGrowHint3 = len(`{"msg":"._","sub":["",""],"path":"","avatar":"","id":}`) + 3 + 2 + 2 + 2 + 2 + 1
|
|
|
|
|
Cascade delete attachments properly.
Cascade delete replied to topic events for replies properly.
Cascade delete likes on topic posts properly.
Cascade delete replies and their children properly.
Recalculate user stats properly when items are deleted.
Users can now unlike topic opening posts.
Add a recalculator to fix abnormalities across upgrades.
Try fixing a last_ip daily update bug.
Add Existable interface.
Add Delete method to LikeStore.
Add Each, Exists, Create, CountUser, CountMegaUser and CountBigUser methods to ReplyStore.
Add CountUser, CountMegaUser, CountBigUser methods to TopicStore.
Add Each method to UserStore.
Add Add, Delete and DeleteResource methods to SubscriptionStore.
Add Delete, DeleteByParams, DeleteByParamsExtra and AidsByParamsExtra methods to ActivityStream.
Add Exists method to ProfileReplyStore.
Add DropColumn, RenameColumn and ChangeColumn to the database adapters.
Shorten ipaddress column names to ip.
- topics table.
- replies table
- users_replies table.
- polls_votes table.
Add extra column to activity_stream table.
Fix an issue upgrading sites to MariaDB 10.3 from older versions of Gosora. Please report any other issues you find.
You need to run the updater / patcher for this commit.
2020-01-31 07:22:08 +00:00
|
|
|
func AddActivityAndNotifyAll(a Alert) error {
|
|
|
|
id, err := Activity.Add(a)
|
2018-03-08 03:59:47 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2019-06-01 12:31:48 +00:00
|
|
|
return NotifyWatchers(id)
|
2018-03-08 03:59:47 +00:00
|
|
|
}
|
|
|
|
|
Cascade delete attachments properly.
Cascade delete replied to topic events for replies properly.
Cascade delete likes on topic posts properly.
Cascade delete replies and their children properly.
Recalculate user stats properly when items are deleted.
Users can now unlike topic opening posts.
Add a recalculator to fix abnormalities across upgrades.
Try fixing a last_ip daily update bug.
Add Existable interface.
Add Delete method to LikeStore.
Add Each, Exists, Create, CountUser, CountMegaUser and CountBigUser methods to ReplyStore.
Add CountUser, CountMegaUser, CountBigUser methods to TopicStore.
Add Each method to UserStore.
Add Add, Delete and DeleteResource methods to SubscriptionStore.
Add Delete, DeleteByParams, DeleteByParamsExtra and AidsByParamsExtra methods to ActivityStream.
Add Exists method to ProfileReplyStore.
Add DropColumn, RenameColumn and ChangeColumn to the database adapters.
Shorten ipaddress column names to ip.
- topics table.
- replies table
- users_replies table.
- polls_votes table.
Add extra column to activity_stream table.
Fix an issue upgrading sites to MariaDB 10.3 from older versions of Gosora. Please report any other issues you find.
You need to run the updater / patcher for this commit.
2020-01-31 07:22:08 +00:00
|
|
|
func AddActivityAndNotifyTarget(a Alert) error {
|
|
|
|
id, err := Activity.Add(a)
|
2018-03-08 03:59:47 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-11-22 07:21:43 +00:00
|
|
|
|
Cascade delete attachments properly.
Cascade delete replied to topic events for replies properly.
Cascade delete likes on topic posts properly.
Cascade delete replies and their children properly.
Recalculate user stats properly when items are deleted.
Users can now unlike topic opening posts.
Add a recalculator to fix abnormalities across upgrades.
Try fixing a last_ip daily update bug.
Add Existable interface.
Add Delete method to LikeStore.
Add Each, Exists, Create, CountUser, CountMegaUser and CountBigUser methods to ReplyStore.
Add CountUser, CountMegaUser, CountBigUser methods to TopicStore.
Add Each method to UserStore.
Add Add, Delete and DeleteResource methods to SubscriptionStore.
Add Delete, DeleteByParams, DeleteByParamsExtra and AidsByParamsExtra methods to ActivityStream.
Add Exists method to ProfileReplyStore.
Add DropColumn, RenameColumn and ChangeColumn to the database adapters.
Shorten ipaddress column names to ip.
- topics table.
- replies table
- users_replies table.
- polls_votes table.
Add extra column to activity_stream table.
Fix an issue upgrading sites to MariaDB 10.3 from older versions of Gosora. Please report any other issues you find.
You need to run the updater / patcher for this commit.
2020-01-31 07:22:08 +00:00
|
|
|
err = NotifyOne(a.TargetUserID, id)
|
2018-03-08 03:59:47 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
Cascade delete attachments properly.
Cascade delete replied to topic events for replies properly.
Cascade delete likes on topic posts properly.
Cascade delete replies and their children properly.
Recalculate user stats properly when items are deleted.
Users can now unlike topic opening posts.
Add a recalculator to fix abnormalities across upgrades.
Try fixing a last_ip daily update bug.
Add Existable interface.
Add Delete method to LikeStore.
Add Each, Exists, Create, CountUser, CountMegaUser and CountBigUser methods to ReplyStore.
Add CountUser, CountMegaUser, CountBigUser methods to TopicStore.
Add Each method to UserStore.
Add Add, Delete and DeleteResource methods to SubscriptionStore.
Add Delete, DeleteByParams, DeleteByParamsExtra and AidsByParamsExtra methods to ActivityStream.
Add Exists method to ProfileReplyStore.
Add DropColumn, RenameColumn and ChangeColumn to the database adapters.
Shorten ipaddress column names to ip.
- topics table.
- replies table
- users_replies table.
- polls_votes table.
Add extra column to activity_stream table.
Fix an issue upgrading sites to MariaDB 10.3 from older versions of Gosora. Please report any other issues you find.
You need to run the updater / patcher for this commit.
2020-01-31 07:22:08 +00:00
|
|
|
a.ASID = id
|
2018-03-08 03:59:47 +00:00
|
|
|
|
|
|
|
// Live alerts, if the target is online and WebSockets is enabled
|
2019-06-01 12:31:48 +00:00
|
|
|
if EnableWebsockets {
|
Cascade delete attachments properly.
Cascade delete replied to topic events for replies properly.
Cascade delete likes on topic posts properly.
Cascade delete replies and their children properly.
Recalculate user stats properly when items are deleted.
Users can now unlike topic opening posts.
Add a recalculator to fix abnormalities across upgrades.
Try fixing a last_ip daily update bug.
Add Existable interface.
Add Delete method to LikeStore.
Add Each, Exists, Create, CountUser, CountMegaUser and CountBigUser methods to ReplyStore.
Add CountUser, CountMegaUser, CountBigUser methods to TopicStore.
Add Each method to UserStore.
Add Add, Delete and DeleteResource methods to SubscriptionStore.
Add Delete, DeleteByParams, DeleteByParamsExtra and AidsByParamsExtra methods to ActivityStream.
Add Exists method to ProfileReplyStore.
Add DropColumn, RenameColumn and ChangeColumn to the database adapters.
Shorten ipaddress column names to ip.
- topics table.
- replies table
- users_replies table.
- polls_votes table.
Add extra column to activity_stream table.
Fix an issue upgrading sites to MariaDB 10.3 from older versions of Gosora. Please report any other issues you find.
You need to run the updater / patcher for this commit.
2020-01-31 07:22:08 +00:00
|
|
|
go func() {
|
|
|
|
_ = WsHub.pushAlert(a.TargetUserID, a)
|
|
|
|
//fmt.Println("err:",err)
|
|
|
|
}()
|
2019-06-01 12:31:48 +00:00
|
|
|
}
|
2018-03-08 03:59:47 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
Cascade delete attachments properly.
Cascade delete replied to topic events for replies properly.
Cascade delete likes on topic posts properly.
Cascade delete replies and their children properly.
Recalculate user stats properly when items are deleted.
Users can now unlike topic opening posts.
Add a recalculator to fix abnormalities across upgrades.
Try fixing a last_ip daily update bug.
Add Existable interface.
Add Delete method to LikeStore.
Add Each, Exists, Create, CountUser, CountMegaUser and CountBigUser methods to ReplyStore.
Add CountUser, CountMegaUser, CountBigUser methods to TopicStore.
Add Each method to UserStore.
Add Add, Delete and DeleteResource methods to SubscriptionStore.
Add Delete, DeleteByParams, DeleteByParamsExtra and AidsByParamsExtra methods to ActivityStream.
Add Exists method to ProfileReplyStore.
Add DropColumn, RenameColumn and ChangeColumn to the database adapters.
Shorten ipaddress column names to ip.
- topics table.
- replies table
- users_replies table.
- polls_votes table.
Add extra column to activity_stream table.
Fix an issue upgrading sites to MariaDB 10.3 from older versions of Gosora. Please report any other issues you find.
You need to run the updater / patcher for this commit.
2020-01-31 07:22:08 +00:00
|
|
|
func NotifyOne(watcher, asid int) error {
|
2018-03-08 03:59:47 +00:00
|
|
|
_, err := alertStmts.notifyOne.Exec(watcher, asid)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-06-01 12:31:48 +00:00
|
|
|
func NotifyWatchers(asid int) error {
|
2018-03-08 03:59:47 +00:00
|
|
|
_, err := alertStmts.notifyWatchers.Exec(asid)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Alert the subscribers about this without blocking us from doing something else
|
|
|
|
if EnableWebsockets {
|
|
|
|
go notifyWatchers(asid)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-06-01 12:31:48 +00:00
|
|
|
func notifyWatchers(asid int) {
|
2018-03-08 03:59:47 +00:00
|
|
|
rows, err := alertStmts.getWatchers.Query(asid)
|
|
|
|
if err != nil && err != ErrNoRows {
|
2018-03-11 09:33:49 +00:00
|
|
|
LogError(err)
|
2018-03-08 03:59:47 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
defer rows.Close()
|
|
|
|
|
|
|
|
var uid int
|
|
|
|
var uids []int
|
|
|
|
for rows.Next() {
|
|
|
|
err := rows.Scan(&uid)
|
|
|
|
if err != nil {
|
2018-03-11 09:33:49 +00:00
|
|
|
LogError(err)
|
2018-03-08 03:59:47 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
uids = append(uids, uid)
|
|
|
|
}
|
2019-10-27 23:13:24 +00:00
|
|
|
if err = rows.Err(); err != nil {
|
2018-03-11 09:33:49 +00:00
|
|
|
LogError(err)
|
2018-03-08 03:59:47 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-06-01 12:31:48 +00:00
|
|
|
alert, err := Activity.Get(asid)
|
2018-03-08 03:59:47 +00:00
|
|
|
if err != nil && err != ErrNoRows {
|
2018-03-11 09:33:49 +00:00
|
|
|
LogError(err)
|
2018-03-08 03:59:47 +00:00
|
|
|
return
|
|
|
|
}
|
2018-11-22 07:21:43 +00:00
|
|
|
_ = WsHub.pushAlerts(uids, alert)
|
2018-03-08 03:59:47 +00:00
|
|
|
}
|
Cascade delete attachments properly.
Cascade delete replied to topic events for replies properly.
Cascade delete likes on topic posts properly.
Cascade delete replies and their children properly.
Recalculate user stats properly when items are deleted.
Users can now unlike topic opening posts.
Add a recalculator to fix abnormalities across upgrades.
Try fixing a last_ip daily update bug.
Add Existable interface.
Add Delete method to LikeStore.
Add Each, Exists, Create, CountUser, CountMegaUser and CountBigUser methods to ReplyStore.
Add CountUser, CountMegaUser, CountBigUser methods to TopicStore.
Add Each method to UserStore.
Add Add, Delete and DeleteResource methods to SubscriptionStore.
Add Delete, DeleteByParams, DeleteByParamsExtra and AidsByParamsExtra methods to ActivityStream.
Add Exists method to ProfileReplyStore.
Add DropColumn, RenameColumn and ChangeColumn to the database adapters.
Shorten ipaddress column names to ip.
- topics table.
- replies table
- users_replies table.
- polls_votes table.
Add extra column to activity_stream table.
Fix an issue upgrading sites to MariaDB 10.3 from older versions of Gosora. Please report any other issues you find.
You need to run the updater / patcher for this commit.
2020-01-31 07:22:08 +00:00
|
|
|
|
|
|
|
func DismissAlert(uid, aid int) {
|
|
|
|
_ = WsHub.PushMessage(uid, `{"event":"dismiss-alert","id":`+strconv.Itoa(aid)+`}`)
|
2020-02-13 10:44:03 +00:00
|
|
|
}
|