🐛 Fix notifier

This commit is contained in:
LittleSheep 2024-04-27 00:13:47 +08:00
parent 017b67d738
commit 82a6c6dd31
4 changed files with 18 additions and 7 deletions

View File

@ -41,11 +41,9 @@ func main() {
} }
// Connect other services // Connect other services
go func() {
if err := grpc.ConnectPassport(); err != nil { if err := grpc.ConnectPassport(); err != nil {
log.Fatal().Err(err).Msg("An error occurred when connecting to passport grpc endpoint...") log.Fatal().Err(err).Msg("An error occurred when connecting to passport grpc endpoint...")
} }
}()
// Configure timed tasks // Configure timed tasks
quartz := cron.New(cron.WithLogger(cron.VerbosePrintfLogger(&log.Logger))) quartz := cron.New(cron.WithLogger(cron.VerbosePrintfLogger(&log.Logger)))

View File

@ -6,6 +6,7 @@ import (
"git.solsynth.dev/hydrogen/interactive/pkg/grpc" "git.solsynth.dev/hydrogen/interactive/pkg/grpc"
"git.solsynth.dev/hydrogen/interactive/pkg/models" "git.solsynth.dev/hydrogen/interactive/pkg/models"
"git.solsynth.dev/hydrogen/passport/pkg/grpc/proto" "git.solsynth.dev/hydrogen/passport/pkg/grpc/proto"
"github.com/rs/zerolog/log"
"github.com/spf13/viper" "github.com/spf13/viper"
"time" "time"
) )
@ -68,6 +69,11 @@ func NotifyAccount(user models.Account, subject, content string, realtime bool,
IsRealtime: realtime, IsRealtime: realtime,
IsImportant: false, IsImportant: false,
}) })
if err != nil {
log.Warn().Err(err).Msg("An error occurred when notify account...")
} else {
log.Debug().Uint("external", user.ExternalID).Msg("Notified account.")
}
return err return err
} }

View File

@ -85,7 +85,11 @@ func (v *PostTypeContext) CountComment(id uint) (int64, error) {
func CommentNotify(this models.PostInterface, original models.Feed, columnName, tableName string) { func CommentNotify(this models.PostInterface, original models.Feed, columnName, tableName string) {
var op models.Feed var op models.Feed
if err := database.C.Where(columnName+"_id = ?", original.ID).Preload("Author").Table(tableName).First(&op).Error; err == nil { if err := database.C.
Where(columnName+"_id = ?", original.ID).
Preload("Author").
Table(tableName).
First(&op).Error; err == nil {
if op.Author.ID != this.GetAuthor().ID { if op.Author.ID != this.GetAuthor().ID {
postUrl := fmt.Sprintf("https://%s/posts/%d", viper.GetString("domain"), this.GetID()) postUrl := fmt.Sprintf("https://%s/posts/%d", viper.GetString("domain"), this.GetID())
err := NotifyAccount( err := NotifyAccount(

View File

@ -314,7 +314,10 @@ func NewPost[T models.PostInterface](item T) (T, error) {
if item.GetReplyTo() != nil { if item.GetReplyTo() != nil {
go func() { go func() {
var op models.Moment var op models.Moment
if err := database.C.Where("id = ?", item.GetReplyTo()).Preload("Author").First(&op).Error; err == nil { if err := database.C.
Where("id = ?", item.GetReplyTo()).
Preload("Author").
First(&op).Error; err == nil {
if op.Author.ID != item.GetAuthor().ID { if op.Author.ID != item.GetAuthor().ID {
postUrl := fmt.Sprintf("https://%s/posts/%d", viper.GetString("domain"), item.GetID()) postUrl := fmt.Sprintf("https://%s/posts/%d", viper.GetString("domain"), item.GetID())
err := NotifyAccount( err := NotifyAccount(