2024-03-26 15:05:13 +00:00
|
|
|
package services
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"git.solsynth.dev/hydrogen/identity/pkg/grpc/proto"
|
|
|
|
"git.solsynth.dev/hydrogen/messaging/pkg/grpc"
|
|
|
|
"git.solsynth.dev/hydrogen/messaging/pkg/models"
|
|
|
|
"github.com/spf13/viper"
|
|
|
|
)
|
|
|
|
|
2024-04-06 06:36:36 +00:00
|
|
|
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),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2024-03-31 13:37:13 +00:00
|
|
|
func NotifyAccount(user models.Account, subject, content string, realtime bool, links ...*proto.NotifyLink) error {
|
2024-03-26 15:05:13 +00:00
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
_, err := grpc.Notify.NotifyUser(ctx, &proto.NotifyRequest{
|
|
|
|
ClientId: viper.GetString("identity.client_id"),
|
|
|
|
ClientSecret: viper.GetString("identity.client_secret"),
|
|
|
|
Subject: subject,
|
|
|
|
Content: content,
|
|
|
|
Links: links,
|
2024-03-31 14:49:08 +00:00
|
|
|
RecipientId: uint64(user.ExternalID),
|
2024-03-31 13:37:13 +00:00
|
|
|
IsRealtime: realtime,
|
2024-03-26 15:05:13 +00:00
|
|
|
IsImportant: false,
|
|
|
|
})
|
|
|
|
|
|
|
|
return err
|
|
|
|
}
|