✨ Add metadata to post related notification
This commit is contained in:
parent
4d602220d2
commit
9bb55f10ce
2
go.mod
2
go.mod
@ -3,7 +3,7 @@ module git.solsynth.dev/hydrogen/interactive
|
|||||||
go 1.21.6
|
go 1.21.6
|
||||||
|
|
||||||
require (
|
require (
|
||||||
git.solsynth.dev/hydrogen/dealer v0.0.0-20241014131829-4de0c4c969ad
|
git.solsynth.dev/hydrogen/dealer v0.0.0-20241015165700-60e4bbfd9782
|
||||||
github.com/go-playground/validator/v10 v10.17.0
|
github.com/go-playground/validator/v10 v10.17.0
|
||||||
github.com/gofiber/fiber/v2 v2.52.4
|
github.com/gofiber/fiber/v2 v2.52.4
|
||||||
github.com/json-iterator/go v1.1.12
|
github.com/json-iterator/go v1.1.12
|
||||||
|
2
go.sum
2
go.sum
@ -6,6 +6,8 @@ git.solsynth.dev/hydrogen/dealer v0.0.0-20240919131945-00c52eba6827 h1:1ACMPm2Ar
|
|||||||
git.solsynth.dev/hydrogen/dealer v0.0.0-20240919131945-00c52eba6827/go.mod h1:Q51JPkKnV0UoOT/IRmdBh5CyfSlp7s8BRGzgooYHqkI=
|
git.solsynth.dev/hydrogen/dealer v0.0.0-20240919131945-00c52eba6827/go.mod h1:Q51JPkKnV0UoOT/IRmdBh5CyfSlp7s8BRGzgooYHqkI=
|
||||||
git.solsynth.dev/hydrogen/dealer v0.0.0-20241014131829-4de0c4c969ad h1:QzK7mg+02jvdfjsXu89KMP3l/QoAMRyWgGDuNzUvTpg=
|
git.solsynth.dev/hydrogen/dealer v0.0.0-20241014131829-4de0c4c969ad h1:QzK7mg+02jvdfjsXu89KMP3l/QoAMRyWgGDuNzUvTpg=
|
||||||
git.solsynth.dev/hydrogen/dealer v0.0.0-20241014131829-4de0c4c969ad/go.mod h1:Q51JPkKnV0UoOT/IRmdBh5CyfSlp7s8BRGzgooYHqkI=
|
git.solsynth.dev/hydrogen/dealer v0.0.0-20241014131829-4de0c4c969ad/go.mod h1:Q51JPkKnV0UoOT/IRmdBh5CyfSlp7s8BRGzgooYHqkI=
|
||||||
|
git.solsynth.dev/hydrogen/dealer v0.0.0-20241015165700-60e4bbfd9782 h1:HUgt8RmDp5AKLlT/QGk4QXcO23OEMVpRYRjgLfOf45c=
|
||||||
|
git.solsynth.dev/hydrogen/dealer v0.0.0-20241015165700-60e4bbfd9782/go.mod h1:Q51JPkKnV0UoOT/IRmdBh5CyfSlp7s8BRGzgooYHqkI=
|
||||||
github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ=
|
github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ=
|
||||||
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
|
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
|
||||||
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
|
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
|
||||||
|
@ -88,7 +88,7 @@ func ModifyPosterVoteCount(user models.Account, isUpvote bool, delta int) error
|
|||||||
return database.C.Save(&user).Error
|
return database.C.Save(&user).Error
|
||||||
}
|
}
|
||||||
|
|
||||||
func NotifyPosterAccount(user models.Account, title, body string, subtitle *string) error {
|
func NotifyPosterAccount(user models.Account, post models.Post, title, body string, subtitle *string) error {
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
|
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
@ -103,6 +103,9 @@ func NotifyPosterAccount(user models.Account, title, body string, subtitle *stri
|
|||||||
Title: title,
|
Title: title,
|
||||||
Subtitle: subtitle,
|
Subtitle: subtitle,
|
||||||
Body: body,
|
Body: body,
|
||||||
|
Metadata: hyper.EncodeMap(map[string]any{
|
||||||
|
"related_post": post,
|
||||||
|
}),
|
||||||
IsRealtime: false,
|
IsRealtime: false,
|
||||||
IsForcePush: true,
|
IsForcePush: true,
|
||||||
},
|
},
|
||||||
|
@ -339,6 +339,7 @@ func NewPost(user models.Account, item models.Post) (models.Post, error) {
|
|||||||
log.Debug().Uint("user", op.AuthorID).Msg("Notifying the original poster their post got replied...")
|
log.Debug().Uint("user", op.AuthorID).Msg("Notifying the original poster their post got replied...")
|
||||||
err = NotifyPosterAccount(
|
err = NotifyPosterAccount(
|
||||||
op.Author,
|
op.Author,
|
||||||
|
op,
|
||||||
"Post got replied",
|
"Post got replied",
|
||||||
fmt.Sprintf("%s (%s) replied your post (#%d).", user.Nick, user.Name, op.ID),
|
fmt.Sprintf("%s (%s) replied your post (#%d).", user.Nick, user.Name, op.ID),
|
||||||
lo.ToPtr(fmt.Sprintf("%s replied you", user.Nick)),
|
lo.ToPtr(fmt.Sprintf("%s replied you", user.Nick)),
|
||||||
@ -421,6 +422,7 @@ func ReactPost(user models.Account, reaction models.Reaction) (bool, models.Reac
|
|||||||
if op.Author.ID != user.ID {
|
if op.Author.ID != user.ID {
|
||||||
err = NotifyPosterAccount(
|
err = NotifyPosterAccount(
|
||||||
op.Author,
|
op.Author,
|
||||||
|
op,
|
||||||
"Post got reacted",
|
"Post got reacted",
|
||||||
fmt.Sprintf("%s (%s) reacted your post a %s.", user.Nick, user.Name, reaction.Symbol),
|
fmt.Sprintf("%s (%s) reacted your post a %s.", user.Nick, user.Name, reaction.Symbol),
|
||||||
lo.ToPtr(fmt.Sprintf("%s reacted you", user.Nick)),
|
lo.ToPtr(fmt.Sprintf("%s reacted you", user.Nick)),
|
||||||
|
Loading…
Reference in New Issue
Block a user