+ ErrorCode: [4]byte{0, 0, 0, 1},
+ Fields: []Field{
+ NewField(FieldError, []byte("You are not allowed to request private chat.")),
+ },
+ },
+ },
+ },
+ {
+ name: "when userA invites userB to new private chat",
+ args: args{
+ cc: &ClientConn{
+ ID: [2]byte{0, 1},
+ Account: &Account{
+ Access: func() accessBitmap {
+ var bits accessBitmap
+ bits.Set(AccessOpenChat)
+ return bits
+ }(),
+ },
+ UserName: []byte("UserA"),
+ Icon: []byte{0, 1},
+ Flags: [2]byte{0, 0},
+ Server: &Server{
+ ClientMgr: func() *MockClientMgr {
+ m := MockClientMgr{}
+ m.On("Get", ClientID{0x0, 0x2}).Return(&ClientConn{
+ ID: [2]byte{0, 2},
+ UserName: []byte("UserB"),
+ })
+ return &m
+ }(),
+ ChatMgr: func() *MockChatManager {
+ m := MockChatManager{}
+ m.On("New", mock.AnythingOfType("*hotline.ClientConn")).Return(ChatID{0x52, 0xfd, 0xfc, 0x07})
+ return &m
+ }(),
+ },
+ },
+ t: NewTransaction(
+ TranInviteNewChat, [2]byte{0, 1},
+ NewField(FieldUserID, []byte{0, 2}),
+ ),
+ },
+ wantRes: []Transaction{
+ {
+ clientID: [2]byte{0, 2},
+ Type: [2]byte{0, 0x71},
+ Fields: []Field{
+ NewField(FieldChatID, []byte{0x52, 0xfd, 0xfc, 0x07}),
+ NewField(FieldUserName, []byte("UserA")),
+ NewField(FieldUserID, []byte{0, 1}),
+ },
+ },
+ {
+ clientID: [2]byte{0, 1},
+ IsReply: 0x01,
+ Fields: []Field{
+ NewField(FieldChatID, []byte{0x52, 0xfd, 0xfc, 0x07}),
+ NewField(FieldUserName, []byte("UserA")),
+ NewField(FieldUserID, []byte{0, 1}),
+ NewField(FieldUserIconID, []byte{0, 1}),
+ NewField(FieldUserFlags, []byte{0, 0}),
+ },
+ },
+ },
+ },
+ {
+ name: "when userA invites userB to new private chat, but UserB has refuse private chat enabled",
+ args: args{
+ cc: &ClientConn{
+ ID: [2]byte{0, 1},
+ Account: &Account{
+ Access: func() accessBitmap {
+ var bits accessBitmap
+ bits.Set(AccessOpenChat)
+ return bits
+ }(),
+ },
+ UserName: []byte("UserA"),
+ Icon: []byte{0, 1},
+ Flags: [2]byte{0, 0},
+ Server: &Server{
+ ClientMgr: func() *MockClientMgr {
+ m := MockClientMgr{}
+ m.On("Get", ClientID{0, 2}).Return(&ClientConn{
+ ID: [2]byte{0, 2},
+ Icon: []byte{0, 1},
+ UserName: []byte("UserB"),
+ Flags: [2]byte{255, 255},
+ })
+ return &m
+ }(),
+ ChatMgr: func() *MockChatManager {
+ m := MockChatManager{}
+ m.On("New", mock.AnythingOfType("*hotline.ClientConn")).Return(ChatID{0x52, 0xfd, 0xfc, 0x07})
+ return &m
+ }(),
+ },
+ },
+ t: NewTransaction(
+ TranInviteNewChat, [2]byte{0, 1},
+ NewField(FieldUserID, []byte{0, 2}),
+ ),
+ },
+ wantRes: []Transaction{
+ {
+ clientID: [2]byte{0, 1},
+ Type: [2]byte{0, 0x68},
+ Fields: []Field{
+ NewField(FieldData, []byte("UserB does not accept private chats.")),
+ NewField(FieldUserName, []byte("UserB")),
+ NewField(FieldUserID, []byte{0, 2}),
+ NewField(FieldOptions, []byte{0, 2}),
+ },
+ },
+ {
+ clientID: [2]byte{0, 1},
+ IsReply: 0x01,