♻️ 转移到 Dealer #5

Merged
LittleSheep merged 5 commits from refactor/dealer into master 2024-07-16 05:03:45 +00:00
8 changed files with 21 additions and 47 deletions
Showing only changes of commit 4795da84f9 - Show all commits

View File

@ -5,39 +5,13 @@
</component>
<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">
<change afterPath="$PROJECT_DIR$/pkg/internal/services/relationships.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/grpc/notifier.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/grpc/notifier.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/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/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/perms.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/services/perms.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" />
<change beforePath="$PROJECT_DIR$/pkg/internal/services/relationships.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/services/relationships.go" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />

View File

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

View File

@ -12,7 +12,7 @@ type Notification struct {
Subtitle *string `json:"subtitle"`
Body string `json:"body"`
Metadata datatypes.JSONMap `json:"metadata"`
UserID uint `json:"user_id"`
AccountID uint `json:"account_id"`
SenderID *uint `json:"sender_id"`
IsRealtime bool `json:"is_realtime" gorm:"-"`

View File

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

View File

@ -17,7 +17,7 @@ func getNotifications(c *fiber.Ctx) error {
}
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 notifications []models.Notification
@ -53,7 +53,7 @@ func markNotificationRead(c *fiber.Ctx) error {
var notify models.Notification
if err := database.C.Where(&models.Notification{
BaseModel: models.BaseModel{ID: uint(id)},
UserID: user.ID,
AccountID: user.ID,
}).First(&notify).Error; err != nil {
return fiber.NewError(fiber.StatusNotFound, err.Error())
}

View File

@ -42,7 +42,7 @@ func notifyUser(c *fiber.Ctx) error {
Body: data.Body,
IsRealtime: data.IsRealtime,
IsForcePush: data.IsForcePush,
UserID: user.ID,
AccountID: user.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)
defer cancel()
_, err := proto.NewStreamControllerClient(gap.H.GetDealerGrpcConn()).PushStream(ctx, &proto.PushStreamRequest{
UserId: uint64(notification.UserID),
UserId: uint64(notification.AccountID),
Body: models.UnifiedCommand{
Action: "notifications.new",
Payload: notification,
@ -80,13 +80,13 @@ func PushNotification(notification models.Notification) error {
}
// Skip push notification
if GetStatusDisturbable(notification.UserID) != nil {
if GetStatusDisturbable(notification.AccountID) != nil {
return nil
}
var subscribers []models.NotificationSubscriber
if err := database.C.Where(&models.NotificationSubscriber{
AccountID: notification.UserID,
AccountID: notification.AccountID,
}).Find(&subscribers).Error; err != nil {
return err
}

View File

@ -96,7 +96,7 @@ func NewFriend(userA models.Account, userB models.Account, skipPending ...bool)
_ = NewNotification(models.Notification{
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),
UserID: userB.ID,
AccountID: userB.ID,
})
}