Compare commits
No commits in common. "10bf4fdf7727475c5638b3a35fe120a32320a8a3" and "ba6e827cf8d65012b45a4a8fb462f08602ffc739" have entirely different histories.
10bf4fdf77
...
ba6e827cf8
@ -4,12 +4,9 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
|
|
||||||
"git.solsynth.dev/hypernet/interactive/pkg/internal/database"
|
"git.solsynth.dev/hypernet/interactive/pkg/internal/database"
|
||||||
"git.solsynth.dev/hypernet/interactive/pkg/internal/models"
|
|
||||||
"git.solsynth.dev/hypernet/interactive/pkg/internal/services"
|
|
||||||
"git.solsynth.dev/hypernet/nexus/pkg/nex"
|
"git.solsynth.dev/hypernet/nexus/pkg/nex"
|
||||||
"git.solsynth.dev/hypernet/nexus/pkg/proto"
|
"git.solsynth.dev/hypernet/nexus/pkg/proto"
|
||||||
jsoniter "github.com/json-iterator/go"
|
jsoniter "github.com/json-iterator/go"
|
||||||
"github.com/rs/zerolog/log"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func (v *App) BroadcastEvent(ctx context.Context, in *proto.EventInfo) (*proto.EventResponse, error) {
|
func (v *App) BroadcastEvent(ctx context.Context, in *proto.EventInfo) (*proto.EventResponse, error) {
|
||||||
@ -32,26 +29,10 @@ func (v *App) BroadcastEvent(ctx context.Context, in *proto.EventInfo) (*proto.E
|
|||||||
for _, model := range database.AutoMaintainRange {
|
for _, model := range database.AutoMaintainRange {
|
||||||
switch model.(type) {
|
switch model.(type) {
|
||||||
default:
|
default:
|
||||||
tx.Delete(model, "account_id = ?", data.ID)
|
tx.Delete(model, "account_id = ?", data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tx.Commit()
|
tx.Commit()
|
||||||
case "realm":
|
|
||||||
var data struct {
|
|
||||||
ID int `json:"id"`
|
|
||||||
}
|
|
||||||
if err := jsoniter.Unmarshal(in.GetData(), &data); err != nil {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
var posts []models.Post
|
|
||||||
if err := database.C.Where("realm_id = ?", data.ID).
|
|
||||||
Select("Body").Select("ID").
|
|
||||||
Find(&posts).Error; err != nil {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
if err := services.DeletePostInBatch(posts); err != nil {
|
|
||||||
log.Error().Err(err).Msg("An error occurred when deleting post...")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -719,7 +719,9 @@ func DeletePost(item models.Post) error {
|
|||||||
|
|
||||||
pc := pproto.NewAttachmentServiceClient(conn)
|
pc := pproto.NewAttachmentServiceClient(conn)
|
||||||
_, err = pc.DeleteAttachment(context.Background(), &pproto.DeleteAttachmentRequest{
|
_, err = pc.DeleteAttachment(context.Background(), &pproto.DeleteAttachmentRequest{
|
||||||
Rid: lo.Uniq(val),
|
Rid: lo.Map(val, func(item string, _ int) string {
|
||||||
|
return item
|
||||||
|
}),
|
||||||
UserId: lo.ToPtr(uint64(*item.Publisher.AccountID)),
|
UserId: lo.ToPtr(uint64(*item.Publisher.AccountID)),
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -730,35 +732,6 @@ func DeletePost(item models.Post) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func DeletePostInBatch(items []models.Post) error {
|
|
||||||
if err := database.C.Delete(&items).Error; err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
var attachments []string
|
|
||||||
for _, item := range items {
|
|
||||||
if val, ok := item.Body["attachments"].([]string); ok && len(val) > 0 {
|
|
||||||
attachments = append(attachments, val...)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
conn, err := gap.Nx.GetClientGrpcConn("uc")
|
|
||||||
if err != nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
pc := pproto.NewAttachmentServiceClient(conn)
|
|
||||||
_, err = pc.DeleteAttachment(context.Background(), &pproto.DeleteAttachmentRequest{
|
|
||||||
Rid: lo.Uniq(attachments),
|
|
||||||
// FIXME Some issues here, if the user linked others uploaded attachment, it will be deleted
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
log.Error().Err(err).Msg("An error occurred when deleting post attachment...")
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func ReactPost(user authm.Account, reaction models.Reaction) (bool, models.Reaction, error) {
|
func ReactPost(user authm.Account, reaction models.Reaction) (bool, models.Reaction, error) {
|
||||||
var op models.Post
|
var op models.Post
|
||||||
if err := database.C.
|
if err := database.C.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user