From b20e60ab7f308c40047ebc48ac2371701b6a6203 Mon Sep 17 00:00:00 2001 From: Josh Knight Date: Sat, 29 Jun 2024 10:23:54 -0400 Subject: [PATCH] Send OServiceUserInfoUpdate when formatting screenname This is needed to inform the client that their user info has changed. For example, when viewing a profile with '%n' it was incorrectly still showing the old format. The buddy list header still shows the old format on the 5.1.3036 client but may be a client bug. It works correctly on a 5.9 client. --- cmd/server/main.go | 2 +- foodgroup/admin.go | 12 ++++++++++++ foodgroup/admin_test.go | 24 ++++++++++++++++++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/cmd/server/main.go b/cmd/server/main.go index fffe98dc..ee90750f 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -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) diff --git a/foodgroup/admin.go b/foodgroup/admin.go index 0a9c80af..9dfae923 100644 --- a/foodgroup/admin.go +++ b/foodgroup/admin.go @@ -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, } } @@ -27,6 +29,7 @@ type AdminService struct { sessionManager SessionManager accountManager AccountManager buddyUpdateBroadcaster buddyBroadcaster + messageRelayer MessageRelayer } // ConfirmRequest returns the ScreenName account status. It returns SNAC @@ -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{ diff --git a/foodgroup/admin_test.go b/foodgroup/admin_test.go index c433ec0c..c6e7e9c7 100644 --- a/foodgroup/admin_test.go +++ b/foodgroup/admin_test.go @@ -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{ @@ -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(). @@ -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)