✨ Post will update related attachments meta & policy
This commit is contained in:
parent
62d09717bb
commit
ef8759e51d
1
go.mod
1
go.mod
@ -26,6 +26,7 @@ require (
|
||||
|
||||
require (
|
||||
filippo.io/edwards25519 v1.1.0 // indirect
|
||||
git.solsynth.dev/hypernet/paperclip v0.0.0-20250124092128-7c3334a57a94 // indirect
|
||||
github.com/andybalholm/brotli v1.1.1 // indirect
|
||||
github.com/beorn7/perks v1.0.1 // indirect
|
||||
github.com/cespare/xxhash/v2 v2.3.0 // indirect
|
||||
|
4
go.sum
4
go.sum
@ -35,6 +35,10 @@ filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
|
||||
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
|
||||
git.solsynth.dev/hypernet/nexus v0.0.0-20241123050605-25ab1371739b h1:8yB9kMwEMY/nIbmDDxrhH5sTypgmK5PIIiIfP5QXx4s=
|
||||
git.solsynth.dev/hypernet/nexus v0.0.0-20241123050605-25ab1371739b/go.mod h1:PhLCv2lsNoscPVJbkWnxwQnJ141lc4RIEkVffrHwl4s=
|
||||
git.solsynth.dev/hypernet/paperclip v0.0.0-20250123165839-2f256a4c3eac h1:d7LZQkkIrb9V9qxdaHhvTTJ/A2DEAg5I9ByKwU+BWYI=
|
||||
git.solsynth.dev/hypernet/paperclip v0.0.0-20250123165839-2f256a4c3eac/go.mod h1:IAmYjvAzQbLWllg0/k9r8az7uXPKILxbZNyXe5yXMts=
|
||||
git.solsynth.dev/hypernet/paperclip v0.0.0-20250124092128-7c3334a57a94 h1:PYk080kR8USiQhbd1uP/U9zJfjioA/PcTYjwsxaPQY4=
|
||||
git.solsynth.dev/hypernet/paperclip v0.0.0-20250124092128-7c3334a57a94/go.mod h1:IAmYjvAzQbLWllg0/k9r8az7uXPKILxbZNyXe5yXMts=
|
||||
git.solsynth.dev/hypernet/passport v0.0.0-20241209153421-573ccc04787f h1:8JNaI1BcdTYPX+w421eM9nJ1WbAXIoy5flDUsLNmsRo=
|
||||
git.solsynth.dev/hypernet/passport v0.0.0-20241209153421-573ccc04787f/go.mod h1:w0wVU43nnOvt8i0+UuGvbzSkvongbSm8EV8HZVbohOQ=
|
||||
git.solsynth.dev/hypernet/pusher v0.0.0-20241026153052-cd2c326efa4e h1:DtHhMjgxS/spUt/KEdbRFtaVnepI6Vx8pbHdJaNH1hs=
|
||||
|
@ -142,7 +142,7 @@ func editArticle(c *fiber.Ctx) error {
|
||||
if err := database.C.Where(models.Post{
|
||||
BaseModel: cruda.BaseModel{ID: uint(id)},
|
||||
PublisherID: publisher.ID,
|
||||
}).First(&item).Error; err != nil {
|
||||
}).Preload("Publisher").First(&item).Error; err != nil {
|
||||
return fiber.NewError(fiber.StatusNotFound, err.Error())
|
||||
}
|
||||
|
||||
|
@ -267,7 +267,7 @@ func deletePost(c *fiber.Ctx) error {
|
||||
if err := database.C.Where(models.Post{
|
||||
BaseModel: cruda.BaseModel{ID: uint(id)},
|
||||
PublisherID: publisher.ID,
|
||||
}).First(&item).Error; err != nil {
|
||||
}).Preload("Publisher").First(&item).Error; err != nil {
|
||||
return fiber.NewError(fiber.StatusNotFound, err.Error())
|
||||
}
|
||||
|
||||
|
@ -166,7 +166,7 @@ func editStory(c *fiber.Ctx) error {
|
||||
if err := database.C.Where(models.Post{
|
||||
BaseModel: cruda.BaseModel{ID: uint(id)},
|
||||
PublisherID: publisher.ID,
|
||||
}).First(&item).Error; err != nil {
|
||||
}).Preload("Publisher").First(&item).Error; err != nil {
|
||||
return fiber.NewError(fiber.StatusNotFound, err.Error())
|
||||
}
|
||||
|
||||
|
@ -12,6 +12,7 @@ import (
|
||||
localCache "git.solsynth.dev/hypernet/interactive/pkg/internal/cache"
|
||||
"git.solsynth.dev/hypernet/interactive/pkg/internal/gap"
|
||||
"git.solsynth.dev/hypernet/nexus/pkg/proto"
|
||||
pproto "git.solsynth.dev/hypernet/paperclip/pkg/proto"
|
||||
"git.solsynth.dev/hypernet/passport/pkg/authkit"
|
||||
authm "git.solsynth.dev/hypernet/passport/pkg/authkit/models"
|
||||
"github.com/eko/gocache/lib/v4/cache"
|
||||
@ -402,6 +403,9 @@ func NewPost(user models.Publisher, item models.Post) (models.Post, error) {
|
||||
return item, err
|
||||
}
|
||||
|
||||
item.Publisher = user
|
||||
_ = updatePostAttachmentVisibility(item)
|
||||
|
||||
// Notify the original poster its post has been replied
|
||||
if item.ReplyID != nil {
|
||||
var op models.Post
|
||||
@ -479,16 +483,70 @@ func EditPost(item models.Post) (models.Post, error) {
|
||||
return item, err
|
||||
}
|
||||
|
||||
database.C.Model(&item).Association("Categories").Replace(item.Categories)
|
||||
database.C.Model(&item).Association("Tags").Replace(item.Tags)
|
||||
_ = database.C.Model(&item).Association("Categories").Replace(item.Categories)
|
||||
_ = database.C.Model(&item).Association("Tags").Replace(item.Tags)
|
||||
|
||||
pub := item.Publisher
|
||||
err = database.C.Save(&item).Error
|
||||
|
||||
if err == nil {
|
||||
item.Publisher = pub
|
||||
_ = updatePostAttachmentVisibility(item)
|
||||
}
|
||||
|
||||
return item, err
|
||||
}
|
||||
|
||||
func updatePostAttachmentVisibility(item models.Post) error {
|
||||
if item.Publisher.AccountID == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
if val, ok := item.Body["attachments"].([]string); ok && len(val) > 0 {
|
||||
conn, err := gap.Nx.GetClientGrpcConn("uc")
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
pc := pproto.NewAttachmentServiceClient(conn)
|
||||
_, err = pc.UpdateVisibility(context.Background(), &pproto.UpdateVisibilityRequest{
|
||||
Rid: lo.Map(val, func(item string, _ int) string {
|
||||
return item
|
||||
}),
|
||||
UserId: lo.ToPtr(uint64(*item.Publisher.AccountID)),
|
||||
IsIndexable: item.Visibility == models.PostVisibilityAll,
|
||||
})
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func DeletePost(item models.Post) error {
|
||||
return database.C.Delete(&item).Error
|
||||
if err := database.C.Delete(&item).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Cleaning up related attachments
|
||||
if val, ok := item.Body["attachments"].([]string); ok && len(val) > 0 {
|
||||
if item.Publisher.AccountID == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
conn, err := gap.Nx.GetClientGrpcConn("uc")
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
pc := pproto.NewAttachmentServiceClient(conn)
|
||||
_, err = pc.DeleteAttachment(context.Background(), &pproto.DeleteAttachmentRequest{
|
||||
Rid: lo.Map(val, func(item string, _ int) string {
|
||||
return item
|
||||
}),
|
||||
UserId: lo.ToPtr(uint64(*item.Publisher.AccountID)),
|
||||
})
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func ReactPost(user authm.Account, reaction models.Reaction) (bool, models.Reaction, error) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user