2024-03-26 15:05:13 +00:00
|
|
|
package services
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2024-06-08 08:34:14 +00:00
|
|
|
"fmt"
|
2024-06-22 10:05:41 +00:00
|
|
|
"git.solsynth.dev/hydrogen/messaging/pkg/internal/database"
|
|
|
|
"git.solsynth.dev/hydrogen/messaging/pkg/internal/gap"
|
2024-03-26 15:05:13 +00:00
|
|
|
"time"
|
|
|
|
|
2024-06-22 10:05:41 +00:00
|
|
|
"git.solsynth.dev/hydrogen/messaging/pkg/internal/models"
|
|
|
|
"git.solsynth.dev/hydrogen/passport/pkg/proto"
|
2024-03-26 15:05:13 +00:00
|
|
|
"github.com/spf13/viper"
|
|
|
|
)
|
|
|
|
|
2024-04-06 06:36:36 +00:00
|
|
|
func GetAccountFriend(userId, relatedId uint, status int) (*proto.FriendshipResponse, error) {
|
2024-04-06 15:22:27 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2024-04-06 06:36:36 +00:00
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
|
|
|
|
defer cancel()
|
|
|
|
|
2024-06-22 10:05:41 +00:00
|
|
|
pc, err := gap.H.DiscoverServiceGRPC("Hydrogen.Passport")
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return proto.NewFriendshipsClient(pc).GetFriendship(ctx, &proto.FriendshipTwoSideLookupRequest{
|
2024-04-06 15:22:27 +00:00
|
|
|
AccountId: uint64(user.ExternalID),
|
|
|
|
RelatedId: uint64(related.ExternalID),
|
2024-04-06 06:36:36 +00:00
|
|
|
Status: uint32(status),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2024-06-08 08:34:14 +00:00
|
|
|
func NotifyAccountMessager(user models.Account, t, s, c string, realtime bool, forcePush bool, links ...*proto.NotifyLink) error {
|
2024-03-26 15:05:13 +00:00
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
|
|
|
|
defer cancel()
|
|
|
|
|
2024-06-22 10:05:41 +00:00
|
|
|
pc, err := gap.H.DiscoverServiceGRPC("Hydrogen.Passport")
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
_, err = proto.NewNotifyClient(pc).NotifyUser(ctx, &proto.NotifyRequest{
|
2024-06-08 04:49:26 +00:00
|
|
|
ClientId: viper.GetString("passport.client_id"),
|
|
|
|
ClientSecret: viper.GetString("passport.client_secret"),
|
2024-06-08 08:34:14 +00:00
|
|
|
Type: fmt.Sprintf("messaging.%s", t),
|
|
|
|
Subject: s,
|
|
|
|
Content: c,
|
2024-03-26 15:05:13 +00:00
|
|
|
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-06-08 04:49:26 +00:00
|
|
|
IsForcePush: forcePush,
|
2024-03-26 15:05:13 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
return err
|
|
|
|
}
|