Skip to content

Commit

Permalink
Merge pull request #46 from jgknight/admin-send-oservice-userinfo
Browse files Browse the repository at this point in the history
Send OServiceUserInfoUpdate when formatting screenname
  • Loading branch information
mk6i authored Jun 29, 2024
2 parents 840ca35 + b20e60a commit ca2b8e5
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func main() {
go func(logger *slog.Logger) {
logger = logger.With("svc", "ADMIN")
buddyService := foodgroup.NewBuddyService(sessionManager, feedbagStore, adjListBuddyListStore)
adminService := foodgroup.NewAdminService(sessionManager, feedbagStore, buddyService)
adminService := foodgroup.NewAdminService(sessionManager, feedbagStore, buddyService, sessionManager)
authService := foodgroup.NewAuthService(cfg, sessionManager, chatSessionManager, feedbagStore, adjListBuddyListStore, cookieBaker, sessionManager, feedbagStore, chatSessionManager)
oServiceService := foodgroup.NewOServiceServiceForAdmin(cfg, logger, buddyService)

Expand Down
12 changes: 12 additions & 0 deletions foodgroup/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ func NewAdminService(
sessionManager SessionManager,
accountManager AccountManager,
buddyUpdateBroadcaster buddyBroadcaster,
messageRelayer MessageRelayer,
) *AdminService {
return &AdminService{
sessionManager: sessionManager,
accountManager: accountManager,
buddyUpdateBroadcaster: buddyUpdateBroadcaster,
messageRelayer: messageRelayer,
}
}

Expand All @@ -27,6 +29,7 @@ type AdminService struct {
sessionManager SessionManager
accountManager AccountManager
buddyUpdateBroadcaster buddyBroadcaster
messageRelayer MessageRelayer
}

// ConfirmRequest returns the ScreenName account status. It returns SNAC
Expand Down Expand Up @@ -145,6 +148,15 @@ func (s AdminService) InfoChangeRequest(ctx context.Context, sess *state.Session
if err := s.buddyUpdateBroadcaster.BroadcastBuddyArrived(ctx, sess); err != nil {
return wire.SNACMessage{}, err
}
s.messageRelayer.RelayToScreenName(ctx, sess.IdentScreenName(), wire.SNACMessage{
Frame: wire.SNACFrame{
FoodGroup: wire.OService,
SubGroup: wire.OServiceUserInfoUpdate,
},
Body: wire.SNAC_0x01_0x0F_OServiceUserInfoUpdate{
TLVUserInfo: sess.TLVUserInfo(),
},
})
return replyMessage(wire.AdminTLVScreenNameFormatted, proposedName.String()), nil
}
return wire.SNACMessage{
Expand Down
24 changes: 24 additions & 0 deletions foodgroup/admin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,22 @@ func TestAdminService_InfoChangeRequest(t *testing.T) {
},
},
},
messageRelayerParams: messageRelayerParams{
relayToScreenNameParams: relayToScreenNameParams{
{
screenName: state.NewIdentScreenName("Chatting Chuck"),
message: wire.SNACMessage{
Frame: wire.SNACFrame{
FoodGroup: wire.OService,
SubGroup: wire.OServiceUserInfoUpdate,
},
Body: wire.SNAC_0x01_0x0F_OServiceUserInfoUpdate{
TLVUserInfo: newTestSession("Chatting Chuck").TLVUserInfo(),
},
},
},
},
},
},
inputSNAC: wire.SNACMessage{
Frame: wire.SNACFrame{
Expand Down Expand Up @@ -358,6 +374,7 @@ func TestAdminService_InfoChangeRequest(t *testing.T) {
sessionManager := newMockSessionManager(t)
accountManager := newMockAccountManager(t)
buddyBroadcaster := newMockbuddyBroadcaster(t)
messageRelayer := newMockMessageRelayer(t)

for _, params := range tc.mockParams.accountManagerParams.accountManagerUpdateDisplayScreenNameParams {
accountManager.EXPECT().
Expand All @@ -374,10 +391,17 @@ func TestAdminService_InfoChangeRequest(t *testing.T) {
Return(nil)
}

for _, params := range tc.mockParams.messageRelayerParams.relayToScreenNameParams {
p := params
messageRelayer.EXPECT().
RelayToScreenName(mock.Anything, p.screenName, p.message)
}

svc := AdminService{
sessionManager: sessionManager,
accountManager: accountManager,
buddyUpdateBroadcaster: buddyBroadcaster,
messageRelayer: messageRelayer,
}
outputSNAC, err := svc.InfoChangeRequest(nil, tc.userSession, tc.inputSNAC.Frame, tc.inputSNAC.Body.(wire.SNAC_0x07_0x04_AdminInfoChangeRequest))
assert.ErrorIs(t, err, tc.expectErr)
Expand Down

0 comments on commit ca2b8e5

Please sign in to comment.