🐛 Fix model relation issue

This commit is contained in:
LittleSheep 2024-07-16 00:05:09 +08:00
parent a8d919dc5b
commit 4795da84f9
8 changed files with 21 additions and 47 deletions

View File

@ -5,39 +5,13 @@
</component> </component>
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="3fefb2c4-b6f9-466b-a523-53352e8d6f95" name="更改" comment=":recycle: Refactored relation system&#10;:arrow_up: Support new realm &amp; relation api"> <list default="true" id="3fefb2c4-b6f9-466b-a523-53352e8d6f95" name="更改" comment=":recycle: Refactored relation system&#10;:arrow_up: Support new realm &amp; relation api">
<change afterPath="$PROJECT_DIR$/pkg/internal/services/relationships.go" afterDir="false" /> <change beforePath="$PROJECT_DIR$/pkg/internal/grpc/notifier.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/grpc/notifier.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/go.mod" beforeDir="false" afterPath="$PROJECT_DIR$/go.mod" afterDir="false" />
<change beforePath="$PROJECT_DIR$/go.sum" beforeDir="false" afterPath="$PROJECT_DIR$/go.sum" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/internal/database/migrator.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/database/migrator.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/internal/grpc/auth.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/grpc/auth.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/internal/grpc/friendships.go" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/internal/grpc/notify.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/grpc/notifier.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/internal/grpc/realms.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/grpc/realms.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/internal/grpc/server.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/grpc/server.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/internal/models/accounts.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/models/accounts.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/internal/models/clients.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/models/clients.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/internal/models/friendships.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/models/relationships.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/internal/models/notifications.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/models/notifications.go" afterDir="false" /> <change beforePath="$PROJECT_DIR$/pkg/internal/models/notifications.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/models/notifications.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/internal/server/admin/notify_api.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/server/admin/notify_api.go" afterDir="false" /> <change beforePath="$PROJECT_DIR$/pkg/internal/server/admin/notify_api.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/server/admin/notify_api.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/internal/server/api/friendships_api.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/server/api/relationships_api.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/internal/server/api/index.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/server/api/index.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/internal/server/api/notifications_api.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/server/api/notifications_api.go" afterDir="false" /> <change beforePath="$PROJECT_DIR$/pkg/internal/server/api/notifications_api.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/server/api/notifications_api.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/internal/server/api/notify_api.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/server/api/notify_api.go" afterDir="false" /> <change beforePath="$PROJECT_DIR$/pkg/internal/server/api/notify_api.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/server/api/notify_api.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/internal/services/accounts.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/services/accounts.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/internal/services/friendships.go" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/internal/services/notifications.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/services/notifications.go" afterDir="false" /> <change beforePath="$PROJECT_DIR$/pkg/internal/services/notifications.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/services/notifications.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/internal/services/perms.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/services/perms.go" afterDir="false" /> <change beforePath="$PROJECT_DIR$/pkg/internal/services/relationships.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/services/relationships.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/internal/services/realms.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/services/realms.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/proto/friendships.pb.go" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/proto/friendships.proto" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/proto/friendships_grpc.pb.go" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/proto/notify.pb.go" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/proto/notify.proto" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/proto/notify_grpc.pb.go" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/proto/realms.pb.go" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/proto/realms.proto" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/proto/realms_grpc.pb.go" beforeDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />

View File

@ -28,7 +28,7 @@ func (v *Server) NotifyUser(_ context.Context, in *proto.NotifyUserRequest) (*pr
Metadata: metadata, Metadata: metadata,
IsRealtime: in.GetNotify().GetIsRealtime(), IsRealtime: in.GetNotify().GetIsRealtime(),
IsForcePush: in.GetNotify().GetIsForcePush(), IsForcePush: in.GetNotify().GetIsForcePush(),
UserID: user.ID, AccountID: user.ID,
} }
if notification.IsRealtime { if notification.IsRealtime {

View File

@ -7,13 +7,13 @@ import (
type Notification struct { type Notification struct {
BaseModel BaseModel
Topic string `json:"topic"` Topic string `json:"topic"`
Title string `json:"title"` Title string `json:"title"`
Subtitle *string `json:"subtitle"` Subtitle *string `json:"subtitle"`
Body string `json:"body"` Body string `json:"body"`
Metadata datatypes.JSONMap `json:"metadata"` Metadata datatypes.JSONMap `json:"metadata"`
UserID uint `json:"user_id"` AccountID uint `json:"account_id"`
SenderID *uint `json:"sender_id"` SenderID *uint `json:"sender_id"`
IsRealtime bool `json:"is_realtime" gorm:"-"` IsRealtime bool `json:"is_realtime" gorm:"-"`
IsForcePush bool `json:"is_force_push" gorm:"-"` IsForcePush bool `json:"is_force_push" gorm:"-"`

View File

@ -47,7 +47,7 @@ func notifyAllUser(c *fiber.Ctx) error {
Body: data.Body, Body: data.Body,
IsRealtime: data.IsRealtime, IsRealtime: data.IsRealtime,
IsForcePush: data.IsForcePush, IsForcePush: data.IsForcePush,
UserID: user.ID, AccountID: user.ID,
} }
if data.IsRealtime { if data.IsRealtime {
@ -103,7 +103,7 @@ func notifyOneUser(c *fiber.Ctx) error {
Body: data.Body, Body: data.Body,
IsRealtime: data.IsRealtime, IsRealtime: data.IsRealtime,
IsForcePush: data.IsForcePush, IsForcePush: data.IsForcePush,
UserID: user.ID, AccountID: user.ID,
} }
if data.IsRealtime { if data.IsRealtime {

View File

@ -17,7 +17,7 @@ func getNotifications(c *fiber.Ctx) error {
} }
user := c.Locals("user").(models.Account) user := c.Locals("user").(models.Account)
tx := database.C.Where(&models.Notification{UserID: user.ID}).Model(&models.Notification{}) tx := database.C.Where(&models.Notification{AccountID: user.ID}).Model(&models.Notification{})
var count int64 var count int64
var notifications []models.Notification var notifications []models.Notification
@ -53,7 +53,7 @@ func markNotificationRead(c *fiber.Ctx) error {
var notify models.Notification var notify models.Notification
if err := database.C.Where(&models.Notification{ if err := database.C.Where(&models.Notification{
BaseModel: models.BaseModel{ID: uint(id)}, BaseModel: models.BaseModel{ID: uint(id)},
UserID: user.ID, AccountID: user.ID,
}).First(&notify).Error; err != nil { }).First(&notify).Error; err != nil {
return fiber.NewError(fiber.StatusNotFound, err.Error()) return fiber.NewError(fiber.StatusNotFound, err.Error())
} }

View File

@ -42,7 +42,7 @@ func notifyUser(c *fiber.Ctx) error {
Body: data.Body, Body: data.Body,
IsRealtime: data.IsRealtime, IsRealtime: data.IsRealtime,
IsForcePush: data.IsForcePush, IsForcePush: data.IsForcePush,
UserID: user.ID, AccountID: user.ID,
SenderID: &client.ID, SenderID: &client.ID,
} }

View File

@ -69,7 +69,7 @@ func PushNotification(notification models.Notification) error {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel() defer cancel()
_, err := proto.NewStreamControllerClient(gap.H.GetDealerGrpcConn()).PushStream(ctx, &proto.PushStreamRequest{ _, err := proto.NewStreamControllerClient(gap.H.GetDealerGrpcConn()).PushStream(ctx, &proto.PushStreamRequest{
UserId: uint64(notification.UserID), UserId: uint64(notification.AccountID),
Body: models.UnifiedCommand{ Body: models.UnifiedCommand{
Action: "notifications.new", Action: "notifications.new",
Payload: notification, Payload: notification,
@ -80,13 +80,13 @@ func PushNotification(notification models.Notification) error {
} }
// Skip push notification // Skip push notification
if GetStatusDisturbable(notification.UserID) != nil { if GetStatusDisturbable(notification.AccountID) != nil {
return nil return nil
} }
var subscribers []models.NotificationSubscriber var subscribers []models.NotificationSubscriber
if err := database.C.Where(&models.NotificationSubscriber{ if err := database.C.Where(&models.NotificationSubscriber{
AccountID: notification.UserID, AccountID: notification.AccountID,
}).Find(&subscribers).Error; err != nil { }).Find(&subscribers).Error; err != nil {
return err return err
} }

View File

@ -94,9 +94,9 @@ func NewFriend(userA models.Account, userB models.Account, skipPending ...bool)
return relA, err return relA, err
} else { } else {
_ = NewNotification(models.Notification{ _ = NewNotification(models.Notification{
Title: fmt.Sprintf("New friend request from %s", userA.Name), Title: fmt.Sprintf("New friend request from %s", userA.Name),
Body: fmt.Sprintf("You got a new friend request from %s. Go to your settings and decide how to deal it.", userA.Nick), Body: fmt.Sprintf("You got a new friend request from %s. Go to your settings and decide how to deal it.", userA.Nick),
UserID: userB.ID, AccountID: userB.ID,
}) })
} }