🐛 Fix friend detection issue

This commit is contained in:
LittleSheep 2024-04-06 23:22:27 +08:00
parent 50f2d88abc
commit 6e73cf41a8

View File

@ -2,6 +2,7 @@ package services
import ( import (
"context" "context"
"git.solsynth.dev/hydrogen/messaging/pkg/database"
"time" "time"
"git.solsynth.dev/hydrogen/identity/pkg/grpc/proto" "git.solsynth.dev/hydrogen/identity/pkg/grpc/proto"
@ -11,12 +12,21 @@ import (
) )
func GetAccountFriend(userId, relatedId uint, status int) (*proto.FriendshipResponse, error) { func GetAccountFriend(userId, relatedId uint, status int) (*proto.FriendshipResponse, error) {
var user models.Account
if err := database.C.Where("id = ?", userId).First(&user).Error; err != nil {
return nil, err
}
var related models.Account
if err := database.C.Where("id = ?", relatedId).First(&related).Error; err != nil {
return nil, err
}
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5) ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
defer cancel() defer cancel()
return grpc.Friendships.GetFriendship(ctx, &proto.FriendshipTwoSideLookupRequest{ return grpc.Friendships.GetFriendship(ctx, &proto.FriendshipTwoSideLookupRequest{
AccountId: uint64(userId), AccountId: uint64(user.ExternalID),
RelatedId: uint64(relatedId), RelatedId: uint64(related.ExternalID),
Status: uint32(status), Status: uint32(status),
}) })
} }