Only can invite friends now

This commit is contained in:
LittleSheep 2024-04-06 12:05:54 +08:00
parent e74d38f479
commit 49363c801a
3 changed files with 18 additions and 1 deletions

View File

@ -8,6 +8,7 @@ import (
"google.golang.org/grpc" "google.golang.org/grpc"
) )
var Friendships idpb.FriendshipsClient
var Notify idpb.NotifyClient var Notify idpb.NotifyClient
var Auth idpb.AuthClient var Auth idpb.AuthClient
@ -16,6 +17,7 @@ func ConnectPassport() error {
if conn, err := grpc.Dial(addr, grpc.WithTransportCredentials(insecure.NewCredentials())); err != nil { if conn, err := grpc.Dial(addr, grpc.WithTransportCredentials(insecure.NewCredentials())); err != nil {
return err return err
} else { } else {
Friendships = idpb.NewFriendshipsClient(conn)
Notify = idpb.NewNotifyClient(conn) Notify = idpb.NewNotifyClient(conn)
Auth = idpb.NewAuthClient(conn) Auth = idpb.NewAuthClient(conn)
} }

View File

@ -34,6 +34,17 @@ func GetAccountFollowed(user models.Account, target models.Account) (models.Acco
return relationship, err == nil return relationship, err == nil
} }
func GetAccountFriend(userId, relatedId uint, status int) (*proto.FriendshipResponse, error) {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
defer cancel()
return grpc.Friendships.GetFriendship(ctx, &proto.FriendshipTwoSideLookupRequest{
AccountId: uint64(userId),
RelatedId: uint64(relatedId),
Status: uint32(status),
})
}
func NotifyAccount(user models.Account, subject, content string, realtime bool, links ...*proto.NotifyLink) error { func NotifyAccount(user models.Account, subject, content string, realtime bool, links ...*proto.NotifyLink) error {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5) ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
defer cancel() defer cancel()

View File

@ -1,6 +1,7 @@
package services package services
import ( import (
"fmt"
"git.solsynth.dev/hydrogen/interactive/pkg/database" "git.solsynth.dev/hydrogen/interactive/pkg/database"
"git.solsynth.dev/hydrogen/interactive/pkg/models" "git.solsynth.dev/hydrogen/interactive/pkg/models"
"github.com/samber/lo" "github.com/samber/lo"
@ -76,13 +77,16 @@ func ListRealmMember(realmId uint) ([]models.RealmMember, error) {
} }
func InviteRealmMember(user models.Account, target models.Realm) error { func InviteRealmMember(user models.Account, target models.Realm) error {
if _, err := GetAccountFriend(user.ID, target.AccountID, 1); err != nil {
return fmt.Errorf("you only can invite your friends to your realm")
}
member := models.RealmMember{ member := models.RealmMember{
RealmID: target.ID, RealmID: target.ID,
AccountID: user.ID, AccountID: user.ID,
} }
err := database.C.Save(&member).Error err := database.C.Save(&member).Error
return err return err
} }