Skip to content

Commit

Permalink
issue #48 - fix chat in pidgin client
Browse files Browse the repository at this point in the history
This commit implements the following changes that makes Pidgin chat
work:

- chat detail level value must be "2"
- set TLV 0xDA in chat room info
- change the chat cookie to this format: %s-%s-%s, where the third %s is
  the chat room name.

All chat room business logic is now consolidated in the state package.

Co-authored-by: Josh Knight <[email protected]>
  • Loading branch information
mk6i and jgknight committed Jul 14, 2024
1 parent 966f115 commit 3a3bc85
Show file tree
Hide file tree
Showing 21 changed files with 324 additions and 434 deletions.
4 changes: 2 additions & 2 deletions cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func main() {
authService := foodgroup.NewAuthService(cfg, sessionManager, chatSessionManager, feedbagStore, adjListBuddyListStore, cookieBaker, sessionManager, feedbagStore, chatSessionManager, feedbagStore)
bartService := foodgroup.NewBARTService(logger, feedbagStore, sessionManager, feedbagStore, adjListBuddyListStore)
buddyService := foodgroup.NewBuddyService(sessionManager, feedbagStore, adjListBuddyListStore)
chatNavService := foodgroup.NewChatNavService(logger, feedbagStore, state.NewChatRoom)
chatNavService := foodgroup.NewChatNavService(logger, feedbagStore)
feedbagService := foodgroup.NewFeedbagService(logger, sessionManager, feedbagStore, feedbagStore, adjListBuddyListStore)
foodgroupService := foodgroup.NewPermitDenyService()
icbmService := foodgroup.NewICBMService(sessionManager, feedbagStore, adjListBuddyListStore)
Expand Down Expand Up @@ -105,7 +105,7 @@ func main() {
logger = logger.With("svc", "CHAT_NAV")
sessionManager := state.NewInMemorySessionManager(logger)
authService := foodgroup.NewAuthService(cfg, sessionManager, chatSessionManager, feedbagStore, adjListBuddyListStore, cookieBaker, sessionManager, feedbagStore, chatSessionManager, feedbagStore)
chatNavService := foodgroup.NewChatNavService(logger, feedbagStore, state.NewChatRoom)
chatNavService := foodgroup.NewChatNavService(logger, feedbagStore)
oServiceService := foodgroup.NewOServiceServiceForChatNav(cfg, logger, sessionManager, adjListBuddyListStore, feedbagStore)

oscar.BOSServer{
Expand Down
10 changes: 1 addition & 9 deletions foodgroup/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1056,18 +1056,13 @@ func TestAuthService_SignoutChat(t *testing.T) {
name string
// userSession is the session of the user signing out
userSession *state.Session
// chatRoom is the chat room user is exiting
chatRoom state.ChatRoom
// mockParams is the list of params sent to mocks that satisfy this
// method's dependencies
mockParams mockParams
}{
{
name: "user signs out of chat room, room is empty after user leaves",
userSession: newTestSession("the-screen-name", sessOptCannedSignonTime, sessOptChatRoomCookie("the-chat-cookie")),
chatRoom: state.ChatRoom{
Cookie: "the-chat-cookie",
},
mockParams: mockParams{
chatMessageRelayerParams: chatMessageRelayerParams{
chatRelayToAllExceptParams: chatRelayToAllExceptParams{
Expand Down Expand Up @@ -1104,9 +1099,6 @@ func TestAuthService_SignoutChat(t *testing.T) {
{
name: "user signs out of chat room, room is not empty after user leaves",
userSession: newTestSession("the-screen-name", sessOptCannedSignonTime, sessOptChatRoomCookie("the-chat-cookie")),
chatRoom: state.ChatRoom{
Cookie: "the-chat-cookie",
},
mockParams: mockParams{
chatMessageRelayerParams: chatMessageRelayerParams{
chatRelayToAllExceptParams: chatRelayToAllExceptParams{
Expand Down Expand Up @@ -1146,7 +1138,7 @@ func TestAuthService_SignoutChat(t *testing.T) {
chatMessageRelayer := newMockChatMessageRelayer(t)
for _, params := range tt.mockParams.chatRelayToAllExceptParams {
chatMessageRelayer.EXPECT().
RelayToAllExcept(nil, tt.chatRoom.Cookie, params.screenName, params.message)
RelayToAllExcept(nil, tt.userSession.ChatRoomCookie(), params.screenName, params.message)
}
sessionManager := newMockChatSessionRegistry(t)
for _, params := range tt.mockParams.removeSessionParams {
Expand Down
8 changes: 4 additions & 4 deletions foodgroup/chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,10 @@ func sendChatRoomInfoUpdate(ctx context.Context, sess *state.Session, chatMessag
SubGroup: wire.ChatRoomInfoUpdate,
},
Body: wire.SNAC_0x0E_0x02_ChatRoomInfoUpdate{
Exchange: room.Exchange,
Cookie: room.Cookie,
InstanceNumber: room.InstanceNumber,
DetailLevel: room.DetailLevel,
Exchange: room.Exchange(),
Cookie: room.Cookie(),
InstanceNumber: room.InstanceNumber(),
DetailLevel: room.DetailLevel(),
TLVBlock: wire.TLVBlock{
TLVList: room.TLVList(),
},
Expand Down
31 changes: 12 additions & 19 deletions foodgroup/chat_nav.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,10 @@ var (
)

// NewChatNavService creates a new instance of NewChatNavService.
func NewChatNavService(logger *slog.Logger, chatRoomManager ChatRoomRegistry, fnNewChatRoom func() state.ChatRoom) *ChatNavService {
func NewChatNavService(logger *slog.Logger, chatRoomManager ChatRoomRegistry) *ChatNavService {
return &ChatNavService{
logger: logger,
chatRoomManager: chatRoomManager,
fnNewChatRoom: fnNewChatRoom,
}
}

Expand All @@ -45,7 +44,6 @@ func NewChatNavService(logger *slog.Logger, chatRoomManager ChatRoomRegistry, fn
type ChatNavService struct {
logger *slog.Logger
chatRoomManager ChatRoomRegistry
fnNewChatRoom func() state.ChatRoom
}

// RequestChatRights returns SNAC wire.ChatNavNavInfo, which contains chat
Expand Down Expand Up @@ -102,14 +100,9 @@ func (s ChatNavService) CreateRoom(_ context.Context, sess *state.Session, inFra
return sendChatNavErrorSNAC(inFrame, wire.ErrorCodeNoMatch)
}

room = s.fnNewChatRoom()
room.Creator = sess.IdentScreenName()
room.DetailLevel = inBody.DetailLevel
room.Exchange = inBody.Exchange
room.InstanceNumber = inBody.InstanceNumber
room.Name = name
room = state.NewChatRoom(name, sess.IdentScreenName(), inBody.Exchange)

if err := s.chatRoomManager.CreateChatRoom(room); err != nil {
if err := s.chatRoomManager.CreateChatRoom(&room); err != nil {
return wire.SNACMessage{}, fmt.Errorf("%w: %w", errChatNavRoomCreateFailed, err)
}
break
Expand All @@ -126,10 +119,10 @@ func (s ChatNavService) CreateRoom(_ context.Context, sess *state.Session, inFra
TLVRestBlock: wire.TLVRestBlock{
TLVList: wire.TLVList{
wire.NewTLV(wire.ChatNavTLVRoomInfo, wire.SNAC_0x0E_0x02_ChatRoomInfoUpdate{
Exchange: room.Exchange,
Cookie: room.Cookie,
InstanceNumber: room.InstanceNumber,
DetailLevel: room.DetailLevel,
Cookie: room.Cookie(),
Exchange: room.Exchange(),
DetailLevel: room.DetailLevel(),
InstanceNumber: room.InstanceNumber(),
TLVBlock: wire.TLVBlock{
TLVList: room.TLVList(),
},
Expand All @@ -153,7 +146,7 @@ func (s ChatNavService) RequestRoomInfo(_ context.Context, inFrame wire.SNACFram
return wire.SNACMessage{}, fmt.Errorf("%w: %w", state.ErrChatRoomNotFound, err)
}

if room.Exchange != inBody.Exchange {
if room.Exchange() != inBody.Exchange {
return wire.SNACMessage{}, errChatNavMismatchedExchange
}

Expand All @@ -167,10 +160,10 @@ func (s ChatNavService) RequestRoomInfo(_ context.Context, inFrame wire.SNACFram
TLVRestBlock: wire.TLVRestBlock{
TLVList: wire.TLVList{
wire.NewTLV(wire.ChatNavTLVRoomInfo, wire.SNAC_0x0E_0x02_ChatRoomInfoUpdate{
Exchange: room.Exchange,
Cookie: room.Cookie,
InstanceNumber: room.InstanceNumber,
DetailLevel: room.DetailLevel,
Cookie: room.Cookie(),
Exchange: room.Exchange(),
DetailLevel: room.DetailLevel(),
InstanceNumber: room.InstanceNumber(),
TLVBlock: wire.TLVBlock{
TLVList: room.TLVList(),
},
Expand Down
Loading

0 comments on commit 3a3bc85

Please sign in to comment.