♻️ All parts into nexus
This commit is contained in:
@ -3,10 +3,11 @@ package services
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"git.solsynth.dev/hypernet/nexus/pkg/nex"
|
||||
"git.solsynth.dev/hypernet/nexus/pkg/proto"
|
||||
"time"
|
||||
"unicode"
|
||||
|
||||
"git.solsynth.dev/hydrogen/dealer/pkg/proto"
|
||||
"git.solsynth.dev/hydrogen/passport/pkg/internal/gap"
|
||||
|
||||
"gorm.io/gorm/clause"
|
||||
@ -312,9 +313,12 @@ func DeleteAccount(id uint) error {
|
||||
return err
|
||||
} else {
|
||||
InvalidAuthCacheWithUser(id)
|
||||
_, _ = proto.NewServiceDirectoryClient(gap.Nx.GetNexusGrpcConn()).BroadcastDeletion(context.Background(), &proto.DeletionRequest{
|
||||
ResourceType: "account",
|
||||
ResourceId: fmt.Sprintf("%d", id),
|
||||
_, _ = proto.NewDirectoryServiceClient(gap.Nx.GetNexusGrpcConn()).BroadcastEvent(context.Background(), &proto.EventInfo{
|
||||
Event: "deletion",
|
||||
Data: nex.EncodeMap(map[string]any{
|
||||
"type": "account",
|
||||
"id": fmt.Sprintf("%d", id),
|
||||
}),
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -1,19 +1,16 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"git.solsynth.dev/hydrogen/dealer/pkg/proto"
|
||||
"git.solsynth.dev/hydrogen/passport/pkg/internal/database"
|
||||
"git.solsynth.dev/hydrogen/passport/pkg/internal/gap"
|
||||
"git.solsynth.dev/hydrogen/passport/pkg/internal/models"
|
||||
"git.solsynth.dev/hypernet/pusher/pkg/pushkit"
|
||||
"github.com/google/uuid"
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/samber/lo"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"git.solsynth.dev/hydrogen/passport/pkg/internal/database"
|
||||
"git.solsynth.dev/hydrogen/passport/pkg/internal/models"
|
||||
"github.com/google/uuid"
|
||||
"github.com/spf13/viper"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const EmailPasswordTemplate = `Dear %s,
|
||||
@ -86,13 +83,11 @@ func GetFactorCode(factor models.AuthFactor) (bool, error) {
|
||||
subject := fmt.Sprintf("[%s] Login verification code", viper.GetString("name"))
|
||||
content := fmt.Sprintf(EmailPasswordTemplate, user.Name, factor.Secret, viper.GetString("maintainer"))
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
defer cancel()
|
||||
_, err := proto.NewPostmanClient(gap.Nx.GetNexusGrpcConn()).DeliverEmail(ctx, &proto.DeliverEmailRequest{
|
||||
err := gap.Px.PushEmail(pushkit.EmailDeliverRequest{
|
||||
To: user.GetPrimaryEmail().Content,
|
||||
Email: &proto.EmailRequest{
|
||||
Subject: subject,
|
||||
TextBody: &content,
|
||||
Email: pushkit.EmailData{
|
||||
Subject: subject,
|
||||
Text: &content,
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
|
@ -4,22 +4,20 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"git.solsynth.dev/hypernet/nexus/pkg/nex"
|
||||
"git.solsynth.dev/hypernet/nexus/pkg/proto"
|
||||
"git.solsynth.dev/hypernet/pusher/pkg/pushkit"
|
||||
"reflect"
|
||||
"time"
|
||||
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/samber/lo"
|
||||
|
||||
"git.solsynth.dev/hydrogen/dealer/pkg/proto"
|
||||
"git.solsynth.dev/hydrogen/passport/pkg/internal/gap"
|
||||
|
||||
"git.solsynth.dev/hydrogen/passport/pkg/internal/database"
|
||||
"git.solsynth.dev/hydrogen/passport/pkg/internal/models"
|
||||
)
|
||||
|
||||
// TODO Awaiting for the new notification pusher
|
||||
|
||||
func AddNotifySubscriber(user models.Account, provider, id, tk, ua string) (models.NotificationSubscriber, error) {
|
||||
var prev models.NotificationSubscriber
|
||||
var subscriber models.NotificationSubscriber
|
||||
@ -101,7 +99,7 @@ func PushNotification(notification models.Notification, skipNotifiableCheck ...b
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
defer cancel()
|
||||
_, err := proto.NewStreamControllerClient(gap.Nx.GetNexusGrpcConn()).PushStream(ctx, &proto.PushStreamRequest{
|
||||
_, err := proto.NewStreamServiceClient(gap.Nx.GetNexusGrpcConn()).PushStream(ctx, &proto.PushStreamRequest{
|
||||
UserId: lo.ToPtr(uint64(notification.AccountID)),
|
||||
Body: nex.WebSocketPackage{
|
||||
Action: "notifications.new",
|
||||
@ -131,23 +129,17 @@ func PushNotification(notification models.Notification, skipNotifiableCheck ...b
|
||||
tokens = append(tokens, subscriber.DeviceToken)
|
||||
}
|
||||
|
||||
metadata, _ := jsoniter.Marshal(notification.Metadata)
|
||||
|
||||
ctx, cancel = context.WithTimeout(context.Background(), 5*time.Second)
|
||||
defer cancel()
|
||||
_, err = proto.NewPostmanClient(gap.Nx.GetNexusGrpcConn()).DeliverNotificationBatch(ctx, &proto.DeliverNotificationBatchRequest{
|
||||
Providers: providers,
|
||||
DeviceTokens: tokens,
|
||||
Notify: &proto.NotifyRequest{
|
||||
Topic: notification.Topic,
|
||||
Title: notification.Title,
|
||||
Subtitle: notification.Subtitle,
|
||||
Body: notification.Body,
|
||||
Metadata: metadata,
|
||||
Avatar: notification.Avatar,
|
||||
Picture: notification.Picture,
|
||||
IsRealtime: notification.IsRealtime,
|
||||
IsForcePush: notification.IsForcePush,
|
||||
err = gap.Px.PushNotifyBatch(pushkit.NotificationPushBatchRequest{
|
||||
Providers: providers,
|
||||
Tokens: tokens,
|
||||
Notification: pushkit.Notification{
|
||||
Topic: notification.Topic,
|
||||
Title: notification.Title,
|
||||
Subtitle: notification.Subtitle,
|
||||
Body: notification.Body,
|
||||
Metadata: notification.Metadata,
|
||||
},
|
||||
})
|
||||
|
||||
@ -188,7 +180,7 @@ func PushNotificationBatch(notifications []models.Notification, skipNotifiableCh
|
||||
var subscribers []models.NotificationSubscriber
|
||||
database.C.Where("account_id IN ?", accountIdx).Find(&subscribers)
|
||||
|
||||
stream := proto.NewStreamControllerClient(gap.Nx.GetNexusGrpcConn())
|
||||
stream := proto.NewStreamServiceClient(gap.Nx.GetNexusGrpcConn())
|
||||
for _, notification := range notifications {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
_, _ = stream.PushStream(ctx, &proto.PushStreamRequest{
|
||||
@ -214,22 +206,16 @@ func PushNotificationBatch(notifications []models.Notification, skipNotifiableCh
|
||||
tokens = append(tokens, subscriber.DeviceToken)
|
||||
}
|
||||
|
||||
metadata, _ := jsoniter.Marshal(notification.Metadata)
|
||||
|
||||
ctx, cancel = context.WithTimeout(context.Background(), 5*time.Second)
|
||||
_, _ = proto.NewPostmanClient(gap.Nx.GetNexusGrpcConn()).DeliverNotificationBatch(ctx, &proto.DeliverNotificationBatchRequest{
|
||||
Providers: providers,
|
||||
DeviceTokens: tokens,
|
||||
Notify: &proto.NotifyRequest{
|
||||
Topic: notification.Topic,
|
||||
Title: notification.Title,
|
||||
Subtitle: notification.Subtitle,
|
||||
Body: notification.Body,
|
||||
Metadata: metadata,
|
||||
Avatar: notification.Avatar,
|
||||
Picture: notification.Picture,
|
||||
IsRealtime: notification.IsRealtime,
|
||||
IsForcePush: notification.IsForcePush,
|
||||
_ = gap.Px.PushNotifyBatch(pushkit.NotificationPushBatchRequest{
|
||||
Providers: providers,
|
||||
Tokens: tokens,
|
||||
Notification: pushkit.Notification{
|
||||
Topic: notification.Topic,
|
||||
Title: notification.Title,
|
||||
Subtitle: notification.Subtitle,
|
||||
Body: notification.Body,
|
||||
Metadata: notification.Metadata,
|
||||
},
|
||||
})
|
||||
cancel()
|
||||
|
@ -6,7 +6,6 @@ import (
|
||||
|
||||
"git.solsynth.dev/hydrogen/passport/pkg/internal/database"
|
||||
"git.solsynth.dev/hydrogen/passport/pkg/internal/models"
|
||||
"github.com/samber/lo"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
@ -131,7 +130,7 @@ func NewFriend(userA models.Account, userB models.Account, skipPending ...bool)
|
||||
} else {
|
||||
_ = NewNotification(models.Notification{
|
||||
Title: "New Friend Request",
|
||||
Subtitle: lo.ToPtr(fmt.Sprintf("New friend request from %s", userA.Name)),
|
||||
Subtitle: fmt.Sprintf("New friend request from %s", userA.Name),
|
||||
Body: fmt.Sprintf("You got a new friend request from %s. Go to your account page and decide how to deal it.", userA.Nick),
|
||||
Account: userB,
|
||||
AccountID: userB.ID,
|
||||
@ -168,7 +167,7 @@ func HandleFriend(userA models.Account, userB models.Account, isAccept bool) err
|
||||
|
||||
_ = NewNotification(models.Notification{
|
||||
Title: "Friend Request Processed",
|
||||
Subtitle: lo.ToPtr(fmt.Sprintf("Your friend request to %s has been processsed.", userA.Name)),
|
||||
Subtitle: fmt.Sprintf("Your friend request to %s has been processsed.", userA.Name),
|
||||
Body: fmt.Sprintf("Your relationship status with %s has been updated, go check it out!", userA.Nick),
|
||||
Account: userB,
|
||||
AccountID: userB.ID,
|
||||
|
@ -5,7 +5,6 @@ import (
|
||||
|
||||
"git.solsynth.dev/hydrogen/passport/pkg/internal/database"
|
||||
"git.solsynth.dev/hydrogen/passport/pkg/internal/models"
|
||||
"github.com/samber/lo"
|
||||
)
|
||||
|
||||
func ListAbuseReport(account models.Account) ([]models.AbuseReport, error) {
|
||||
@ -42,10 +41,10 @@ func UpdateAbuseReportStatus(id uint, status, message string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
NewNotification(models.Notification{
|
||||
_ = NewNotification(models.Notification{
|
||||
Topic: "reports.feedback",
|
||||
Title: "Abuse report status has been changed.",
|
||||
Subtitle: lo.ToPtr(fmt.Sprintf("The report #%d's status updated", id)),
|
||||
Subtitle: fmt.Sprintf("The report #%d's status updated", id),
|
||||
Body: fmt.Sprintf("The report created by you with ID #%d's status has been changed to %s. Moderator message: %s", id, status, message),
|
||||
Account: account,
|
||||
AccountID: account.ID,
|
||||
|
@ -3,9 +3,9 @@ package services
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"git.solsynth.dev/hypernet/nexus/pkg/proto"
|
||||
"time"
|
||||
|
||||
"git.solsynth.dev/hydrogen/dealer/pkg/proto"
|
||||
localCache "git.solsynth.dev/hydrogen/passport/pkg/internal/cache"
|
||||
"git.solsynth.dev/hydrogen/passport/pkg/internal/gap"
|
||||
|
||||
@ -60,7 +60,7 @@ func CacheUserStatus(uid uint, status models.Status) {
|
||||
}
|
||||
|
||||
func GetUserOnline(uid uint) bool {
|
||||
pc := proto.NewStreamControllerClient(gap.Nx.GetNexusGrpcConn())
|
||||
pc := proto.NewStreamServiceClient(gap.Nx.GetNexusGrpcConn())
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
defer cancel()
|
||||
resp, err := pc.CountStreamConnection(ctx, &proto.CountConnectionRequest{
|
||||
|
@ -129,15 +129,15 @@ func ActiveTicket(ticket models.AuthTicket) (models.AuthTicket, error) {
|
||||
_ = NewNotification(models.Notification{
|
||||
Topic: "passport.security.alert",
|
||||
Title: "New sign in alert",
|
||||
Subtitle: lo.ToPtr(fmt.Sprintf("New sign in from %s", ticket.IpAddress)),
|
||||
Subtitle: fmt.Sprintf("New sign in from %s", ticket.IpAddress),
|
||||
Body: fmt.Sprintf("Your account just got a new sign in from %s. Make sure you recongize this device, or sign out it immediately and reset password.", ticket.IpAddress),
|
||||
Metadata: datatypes.JSONMap{
|
||||
"ip_address": ticket.IpAddress,
|
||||
"created_at": ticket.CreatedAt,
|
||||
"available_at": ticket.AvailableAt,
|
||||
},
|
||||
AccountID: ticket.AccountID,
|
||||
IsForcePush: true,
|
||||
AccountID: ticket.AccountID,
|
||||
Priority: 5,
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -1,10 +1,9 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"git.solsynth.dev/hydrogen/dealer/pkg/proto"
|
||||
"git.solsynth.dev/hydrogen/passport/pkg/internal/gap"
|
||||
"git.solsynth.dev/hypernet/pusher/pkg/pushkit"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@ -143,13 +142,11 @@ func NotifyMagicToken(token models.MagicToken) error {
|
||||
return fmt.Errorf("unsupported magic token type to notify")
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
defer cancel()
|
||||
_, err := proto.NewPostmanClient(gap.Nx.GetNexusGrpcConn()).DeliverEmail(ctx, &proto.DeliverEmailRequest{
|
||||
err := gap.Px.PushEmail(pushkit.EmailDeliverRequest{
|
||||
To: user.GetPrimaryEmail().Content,
|
||||
Email: &proto.EmailRequest{
|
||||
Subject: subject,
|
||||
TextBody: &content,
|
||||
Email: pushkit.EmailData{
|
||||
Subject: subject,
|
||||
Text: &content,
|
||||
},
|
||||
})
|
||||
return err
|
||||
|
Reference in New Issue
Block a user