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()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
2018-11-22 07:21:43 +00:00
|
|
|
func BuildAlert(alert Alert, user User /* The current user */) (out string, err error) {
|
2018-03-08 03:59:47 +00:00
|
|
|
var targetUser *User
|
2018-11-22 07:21:43 +00:00
|
|
|
if alert.Actor == nil {
|
|
|
|
alert.Actor, err = Users.Get(alert.ActorID)
|
|
|
|
if err != nil {
|
|
|
|
return "", errors.New(phrases.GetErrorPhrase("alerts_no_actor"))
|
|
|
|
}
|
2018-03-08 03:59:47 +00:00
|
|
|
}
|
|
|
|
|
2018-11-22 07:21:43 +00:00
|
|
|
/*if alert.ElementType != "forum" {
|
|
|
|
targetUser, err = users.Get(alert.TargetUserID)
|
2018-03-08 03:59:47 +00:00
|
|
|
if err != nil {
|
|
|
|
LocalErrorJS("Unable to find the target user",w,r)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}*/
|
2018-11-22 07:21:43 +00:00
|
|
|
if alert.Event == "friend_invite" {
|
2019-05-07 02:33:33 +00:00
|
|
|
return buildAlertString(".new_friend_invite", []string{alert.Actor.Name}, alert.Actor.Link, alert.Actor.Avatar, alert.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
|
2018-11-22 07:21:43 +00:00
|
|
|
if alert.ElementType == "forum" {
|
|
|
|
if alert.Event == "reply" {
|
|
|
|
topic, err := Topics.Get(alert.ElementID)
|
2018-03-08 03:59:47 +00:00
|
|
|
if err != nil {
|
2018-11-22 07:21:43 +00:00
|
|
|
DebugLogf("Unable to find linked topic %d", alert.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...
|
2019-05-07 02:33:33 +00:00
|
|
|
return buildAlertString(".forum_new_topic", []string{alert.Actor.Name, topic.Title}, topic.Link, alert.Actor.Avatar, alert.ASID), nil
|
2018-03-08 03:59:47 +00:00
|
|
|
}
|
2019-05-07 02:33:33 +00:00
|
|
|
return buildAlertString(".forum_unknown_action", []string{alert.Actor.Name}, "", alert.Actor.Avatar, alert.ASID), nil
|
2018-10-05 07:41:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var url, area string
|
2019-09-29 04:56:39 +00:00
|
|
|
phraseName := "." + alert.ElementType
|
2018-11-22 07:21:43 +00:00
|
|
|
switch alert.ElementType {
|
2020-02-13 10:44:03 +00:00
|
|
|
case "convo":
|
|
|
|
convo, err := Convos.Get(alert.ElementID)
|
|
|
|
if err != nil {
|
|
|
|
DebugLogf("Unable to find linked convo %d", alert.ElementID)
|
|
|
|
return "", errors.New(phrases.GetErrorPhrase("alerts_no_linked_convo"))
|
|
|
|
}
|
|
|
|
url = convo.Link
|
|
|
|
area = ""
|
2018-03-08 03:59:47 +00:00
|
|
|
case "topic":
|
2018-11-22 07:21:43 +00:00
|
|
|
topic, err := Topics.Get(alert.ElementID)
|
2018-03-08 03:59:47 +00:00
|
|
|
if err != nil {
|
2018-11-22 07:21:43 +00:00
|
|
|
DebugLogf("Unable to find linked topic %d", alert.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
|
2018-11-22 07:21:43 +00:00
|
|
|
if alert.TargetUserID == user.ID {
|
2018-10-05 07:41:28 +00:00
|
|
|
phraseName += "_own"
|
2018-03-08 03:59:47 +00:00
|
|
|
}
|
|
|
|
case "user":
|
2018-11-22 07:21:43 +00:00
|
|
|
targetUser, err = Users.Get(alert.ElementID)
|
2018-03-08 03:59:47 +00:00
|
|
|
if err != nil {
|
2018-11-22 07:21:43 +00:00
|
|
|
DebugLogf("Unable to find target user %d", alert.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
|
2018-11-22 07:21:43 +00:00
|
|
|
if alert.TargetUserID == user.ID {
|
2018-10-05 07:41:28 +00:00
|
|
|
phraseName += "_own"
|
|
|
|
}
|
2018-03-08 03:59:47 +00:00
|
|
|
case "post":
|
2018-11-22 07:21:43 +00:00
|
|
|
topic, err := TopicByReplyID(alert.ElementID)
|
2018-03-08 03:59:47 +00:00
|
|
|
if err != 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
|
|
|
DebugLogf("Unable to find linked topic by reply ID %d", alert.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
|
2018-11-22 07:21:43 +00:00
|
|
|
if alert.TargetUserID == user.ID {
|
2018-10-05 07:41:28 +00:00
|
|
|
phraseName += "_own"
|
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
|
|
|
}
|
|
|
|
|
2018-11-22 07:21:43 +00:00
|
|
|
switch alert.Event {
|
2020-02-13 10:44:03 +00:00
|
|
|
case "create":
|
|
|
|
phraseName += "_create"
|
2018-03-08 03:59:47 +00:00
|
|
|
case "like":
|
2018-10-05 07:41:28 +00:00
|
|
|
phraseName += "_like"
|
2018-03-08 03:59:47 +00:00
|
|
|
case "mention":
|
2018-10-05 07:41:28 +00:00
|
|
|
phraseName += "_mention"
|
2018-03-08 03:59:47 +00:00
|
|
|
case "reply":
|
2018-10-05 07:41:28 +00:00
|
|
|
phraseName += "_reply"
|
2018-03-08 03:59:47 +00:00
|
|
|
}
|
2018-10-05 07:41:28 +00:00
|
|
|
|
2019-05-07 02:33:33 +00:00
|
|
|
return buildAlertString(phraseName, []string{alert.Actor.Name, area}, url, alert.Actor.Avatar, alert.ASID), nil
|
2018-10-04 02:58:01 +00:00
|
|
|
}
|
|
|
|
|
2020-02-13 10:44:03 +00:00
|
|
|
// TODO: Use a string builder?
|
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 {
|
|
|
|
var subString string
|
2018-10-04 02:58:01 +00:00
|
|
|
for _, item := range sub {
|
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
|
|
|
subString += "\"" + escapeTextInJson(item) + "\","
|
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
|
|
|
if len(subString) > 0 {
|
|
|
|
subString = subString[:len(subString)-1]
|
2018-10-04 02:58:01 +00:00
|
|
|
}
|
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
|
|
|
return `{"msg":"` + escapeTextInJson(msg) + `","sub":[` + subString + `],"path":"` + escapeTextInJson(path) + `","avatar":"` + escapeTextInJson(avatar) + `","id":` + strconv.Itoa(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
|
|
|
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
|
|
|
}
|