Skip to content

Commit

Permalink
reinstate buddy arrivals at signon
Browse files Browse the repository at this point in the history
  • Loading branch information
mk6i committed Dec 10, 2024
1 parent 0189734 commit 6cef441
Show file tree
Hide file tree
Showing 11 changed files with 145 additions and 37 deletions.
11 changes: 6 additions & 5 deletions foodgroup/buddy.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (s BuddyService) AddBuddies(
for _, entry := range inBody.Buddies {
toNotify = append(toNotify, state.NewIdentScreenName(entry.ScreenName))
}
if err := s.buddyBroadcaster.BroadcastVisibility(ctx, sess, toNotify); err != nil {
if err := s.buddyBroadcaster.BroadcastVisibility(ctx, sess, toNotify, true); err != nil {
return fmt.Errorf("buddyBroadcaster.BroadcastVisibility: %w", err)
}

Expand All @@ -96,7 +96,7 @@ func (s BuddyService) DelBuddies(
toNotify = append(toNotify, sn)
}

if err := s.buddyBroadcaster.BroadcastVisibility(ctx, sess, toNotify); err != nil {
if err := s.buddyBroadcaster.BroadcastVisibility(ctx, sess, toNotify, true); err != nil {
return fmt.Errorf("buddyBroadcaster.BroadcastVisibility: %w", err)
}

Expand Down Expand Up @@ -207,9 +207,9 @@ func (s buddyNotifier) BroadcastBuddyDeparted(ctx context.Context, sess *state.S
// - Sends arrival notifications to users that you block who have you on
// their buddy lists.
// - Sends you departure notifications for users on your buddy list that you
// block.
// block (if doSendDepartures is true).
// - Sends departure notifications to users that you block who have you on
// their buddy lists.
// their buddy lists (if doSendDepartures is true).
// - Don't send notifications for any user that blocks you.
//
// This method is called when your visibility settings change, ensuring that
Expand All @@ -218,6 +218,7 @@ func (s buddyNotifier) BroadcastVisibility(
ctx context.Context,
you *state.Session,
filter []state.IdentScreenName,
doSendDepartures bool,
) error {

relationships, err := s.buddyListRetriever.AllRelationships(you.IdentScreenName(), filter)
Expand Down Expand Up @@ -258,7 +259,7 @@ func (s buddyNotifier) BroadcastVisibility(
// tell you they're online
s.unicastBuddyArrived(ctx, theirInfo, you.IdentScreenName())
}
} else {
} else if relationship.YouBlock && doSendDepartures {
if relationship.IsOnTheirList {
// tell them you're offline
s.unicastBuddyDeparted(ctx, you, theirSess.IdentScreenName())
Expand Down
109 changes: 106 additions & 3 deletions foodgroup/buddy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func TestBuddyService_AddBuddies(t *testing.T) {
mockBuddyBroadcaster := newMockbuddyBroadcaster(t)
for _, params := range tt.mockParams.broadcastVisibilityParams {
mockBuddyBroadcaster.EXPECT().
BroadcastVisibility(mock.Anything, matchSession(params.from), params.filter).
BroadcastVisibility(mock.Anything, matchSession(params.from), params.filter, true).
Return(params.err)
}

Expand Down Expand Up @@ -209,7 +209,7 @@ func TestBuddyService_DelBuddies(t *testing.T) {
mockBuddyBroadcaster := newMockbuddyBroadcaster(t)
for _, params := range tt.mockParams.broadcastVisibilityParams {
mockBuddyBroadcaster.EXPECT().
BroadcastVisibility(mock.Anything, matchSession(params.from), params.filter).
BroadcastVisibility(mock.Anything, matchSession(params.from), params.filter, true).
Return(params.err)
}
localBuddyListManager := newMockLocalBuddyListManager(t)
Expand Down Expand Up @@ -484,6 +484,8 @@ func Test_buddyNotifier_BroadcastVisibility(t *testing.T) {
userSession *state.Session
// filter limits specific users that can be notified
filter []state.IdentScreenName
// doSendDepartures indicates whether departure messages should be sent
doSendDepartures bool
// mockParams is the list of params sent to mocks that satisfy this
// method's dependencies
mockParams mockParams
Expand Down Expand Up @@ -641,6 +643,106 @@ func Test_buddyNotifier_BroadcastVisibility(t *testing.T) {
},
},
},
doSendDepartures: true,
},
{
name: "don't send departure notifications",
userSession: newTestSession("me"),
mockParams: mockParams{
buddyListRetrieverParams: buddyListRetrieverParams{
allRelationshipsParams: allRelationshipsParams{
{
screenName: state.NewIdentScreenName("me"),
filter: nil,
result: []state.Relationship{
{
User: state.NewIdentScreenName("friend2-visible-on-their-list"),
BlocksYou: false,
YouBlock: false,
IsOnYourList: false,
IsOnTheirList: true,
},
{
User: state.NewIdentScreenName("friend3-visible-on-your-list"),
BlocksYou: false,
YouBlock: false,
IsOnYourList: true,
IsOnTheirList: false,
},
{
User: state.NewIdentScreenName("friend4-visible-on-both-lists"),
BlocksYou: false,
YouBlock: false,
IsOnYourList: true,
IsOnTheirList: true,
},
{
User: state.NewIdentScreenName("friend7-visible-offline"),
BlocksYou: false,
YouBlock: false,
IsOnYourList: true,
IsOnTheirList: true,
},
},
},
},
buddyIconRefByNameParams: buddyIconRefByNameParams{
{
screenName: state.NewIdentScreenName("me"),
result: nil,
},
{
screenName: state.NewIdentScreenName("friend3-visible-on-your-list"),
result: nil,
},
{
screenName: state.NewIdentScreenName("friend4-visible-on-both-lists"),
result: nil,
},
},
},
messageRelayerParams: messageRelayerParams{
relayToScreenNameParams: relayToScreenNameParams{
{
screenName: state.NewIdentScreenName("friend2-visible-on-their-list"),
message: newBuddyArrivedNotif(newTestSession("me").TLVUserInfo()),
},
{
screenName: state.NewIdentScreenName("me"),
message: newBuddyArrivedNotif(newTestSession("friend3-visible-on-your-list").TLVUserInfo()),
},
{
screenName: state.NewIdentScreenName("friend4-visible-on-both-lists"),
message: newBuddyArrivedNotif(newTestSession("me").TLVUserInfo()),
},
{
screenName: state.NewIdentScreenName("me"),
message: newBuddyArrivedNotif(newTestSession("friend4-visible-on-both-lists").TLVUserInfo()),
},
},
},
sessionRetrieverParams: sessionRetrieverParams{
retrieveSessionParams: retrieveSessionParams{
{
screenName: state.NewIdentScreenName("friend2-visible-on-their-list"),
result: newTestSession("friend2-visible-on-their-list"),
},
{
screenName: state.NewIdentScreenName("friend3-visible-on-your-list"),
result: newTestSession("friend3-visible-on-your-list"),
},
{
screenName: state.NewIdentScreenName("friend4-visible-on-both-lists"),
result: newTestSession("friend4-visible-on-both-lists"),
},
{
screenName: state.NewIdentScreenName("friend7-visible-offline"),
result: nil,
},
},
},
},
doSendDepartures: false,
},
{
name: "users have buddy icons",
Expand Down Expand Up @@ -724,6 +826,7 @@ func Test_buddyNotifier_BroadcastVisibility(t *testing.T) {
},
},
},
doSendDepartures: true,
},
}

Expand Down Expand Up @@ -758,7 +861,7 @@ func Test_buddyNotifier_BroadcastVisibility(t *testing.T) {
sessionRetriever: sessionRetriever,
}

err := svc.BroadcastVisibility(nil, tc.userSession, tc.filter)
err := svc.BroadcastVisibility(nil, tc.userSession, tc.filter, tc.doSendDepartures)
assert.NoError(t, err)
})
}
Expand Down
4 changes: 2 additions & 2 deletions foodgroup/feedbag.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ func (s FeedbagService) UpsertItem(ctx context.Context, sess *state.Session, inF
}

if alertAll || len(filter) > 0 {
if err := s.buddyBroadcaster.BroadcastVisibility(ctx, sess, filter); err != nil {
if err := s.buddyBroadcaster.BroadcastVisibility(ctx, sess, filter, true); err != nil {
return wire.SNACMessage{}, err
}
}
Expand Down Expand Up @@ -306,7 +306,7 @@ func (s FeedbagService) DeleteItem(ctx context.Context, sess *state.Session, inF
}
}

if err := s.buddyBroadcaster.BroadcastVisibility(ctx, sess, filter); err != nil {
if err := s.buddyBroadcaster.BroadcastVisibility(ctx, sess, filter, true); err != nil {
return wire.SNACMessage{}, err
}

Expand Down
4 changes: 2 additions & 2 deletions foodgroup/feedbag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -907,7 +907,7 @@ func TestFeedbagService_UpsertItem(t *testing.T) {
}
for _, params := range tc.mockParams.broadcastVisibilityParams {
buddyUpdateBroadcaster.EXPECT().
BroadcastVisibility(mock.Anything, matchSession(params.from), params.filter).
BroadcastVisibility(mock.Anything, matchSession(params.from), params.filter, true).
Return(params.err)
}
svc := NewFeedbagService(slog.Default(), messageRelayer, feedbagManager, bartManager, nil, nil)
Expand Down Expand Up @@ -1016,7 +1016,7 @@ func TestFeedbagService_DeleteItem(t *testing.T) {
buddyUpdateBroadcast := newMockbuddyBroadcaster(t)
for _, params := range tc.mockParams.broadcastVisibilityParams {
buddyUpdateBroadcast.EXPECT().
BroadcastVisibility(mock.Anything, matchSession(params.from), params.filter).
BroadcastVisibility(mock.Anything, matchSession(params.from), params.filter, true).
Return(params.err)
}

Expand Down
23 changes: 12 additions & 11 deletions foodgroup/mock_buddy_broadcaster_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion foodgroup/oservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -849,7 +849,7 @@ func (s OServiceServiceForBOS) ServiceRequest(ctx context.Context, sess *state.S
func (s OServiceServiceForBOS) ClientOnline(ctx context.Context, _ wire.SNAC_0x01_0x02_OServiceClientOnline, sess *state.Session) error {
sess.SetSignonComplete()

if err := s.buddyBroadcaster.BroadcastBuddyArrived(ctx, sess); err != nil {
if err := s.buddyBroadcaster.BroadcastVisibility(ctx, sess, nil, false); err != nil {
return fmt.Errorf("unable to send buddy arrival notification: %w", err)
}

Expand Down
10 changes: 6 additions & 4 deletions foodgroup/oservice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1734,9 +1734,11 @@ func TestOServiceServiceForBOS_ClientOnline(t *testing.T) {
bodyIn: wire.SNAC_0x01_0x02_OServiceClientOnline{},
mockParams: mockParams{
buddyBroadcasterParams: buddyBroadcasterParams{
broadcastBuddyArrivedParams: broadcastBuddyArrivedParams{
broadcastVisibilityParams: broadcastVisibilityParams{
{
screenName: state.NewIdentScreenName("me"),
from: state.NewIdentScreenName("me"),
filter: nil,
doSendDepartures: false,
},
},
},
Expand All @@ -1747,9 +1749,9 @@ func TestOServiceServiceForBOS_ClientOnline(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
buddyUpdateBroadcaster := newMockbuddyBroadcaster(t)
for _, params := range tt.mockParams.broadcastBuddyArrivedParams {
for _, params := range tt.mockParams.broadcastVisibilityParams {
buddyUpdateBroadcaster.EXPECT().
BroadcastBuddyArrived(mock.Anything, matchSession(params.screenName)).
BroadcastVisibility(mock.Anything, matchSession(params.from), params.filter, params.doSendDepartures).
Return(params.err)
}

Expand Down
2 changes: 1 addition & 1 deletion foodgroup/permit_deny.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ func (s PermitDenyService) maybeBroadcastVisibility(ctx context.Context, sess *s
filter = append(filter, state.NewIdentScreenName(user.ScreenName))
}
}
return s.buddyBroadcaster.BroadcastVisibility(ctx, sess, filter)
return s.buddyBroadcaster.BroadcastVisibility(ctx, sess, filter, true)
}

// RightsQuery returns settings for the PermitDeny food group. It returns SNAC
Expand Down
8 changes: 4 additions & 4 deletions foodgroup/permit_deny_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ func TestPermitDenyService_AddDenyListEntries(t *testing.T) {
mockBuddyBroadcaster := newMockbuddyBroadcaster(t)
for _, item := range tt.mockParams.broadcastVisibilityParams {
mockBuddyBroadcaster.EXPECT().
BroadcastVisibility(context.TODO(), matchSession(item.from), item.filter).
BroadcastVisibility(context.TODO(), matchSession(item.from), item.filter, true).
Return(item.err)
}

Expand Down Expand Up @@ -400,7 +400,7 @@ func TestPermitDenyService_AddPermListEntries(t *testing.T) {
mockBuddyBroadcaster := newMockbuddyBroadcaster(t)
for _, item := range tt.mockParams.broadcastVisibilityParams {
mockBuddyBroadcaster.EXPECT().
BroadcastVisibility(context.TODO(), matchSession(item.from), item.filter).
BroadcastVisibility(context.TODO(), matchSession(item.from), item.filter, true).
Return(item.err)
}

Expand Down Expand Up @@ -512,7 +512,7 @@ func TestPermitDenyService_DelDenyListEntries(t *testing.T) {
mockBuddyBroadcaster := newMockbuddyBroadcaster(t)
for _, item := range tt.mockParams.broadcastVisibilityParams {
mockBuddyBroadcaster.EXPECT().
BroadcastVisibility(context.TODO(), matchSession(item.from), item.filter).
BroadcastVisibility(context.TODO(), matchSession(item.from), item.filter, true).
Return(item.err)
}

Expand Down Expand Up @@ -624,7 +624,7 @@ func TestPermitDenyService_DelPermListEntries(t *testing.T) {
mockBuddyBroadcaster := newMockbuddyBroadcaster(t)
for _, item := range tt.mockParams.broadcastVisibilityParams {
mockBuddyBroadcaster.EXPECT().
BroadcastVisibility(context.TODO(), matchSession(item.from), item.filter).
BroadcastVisibility(context.TODO(), matchSession(item.from), item.filter, true).
Return(item.err)
}

Expand Down
7 changes: 4 additions & 3 deletions foodgroup/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -638,9 +638,10 @@ type buddyBroadcasterParams struct {
// broadcastVisibilityParams is the list of parameters passed at the mock
// buddyBroadcaster.BroadcastVisibility call site
type broadcastVisibilityParams []struct {
from state.IdentScreenName
filter []state.IdentScreenName
err error
from state.IdentScreenName
filter []state.IdentScreenName
doSendDepartures bool
err error
}

// broadcastBuddyArrivedParams is the list of parameters passed at the mock
Expand Down
2 changes: 1 addition & 1 deletion foodgroup/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ type BARTManager interface {
type buddyBroadcaster interface {
BroadcastBuddyArrived(ctx context.Context, sess *state.Session) error
BroadcastBuddyDeparted(ctx context.Context, sess *state.Session) error
BroadcastVisibility(ctx context.Context, from *state.Session, filter []state.IdentScreenName) error
BroadcastVisibility(ctx context.Context, you *state.Session, filter []state.IdentScreenName, sendDepartures bool) error
}

type BuddyListRetriever interface {
Expand Down

0 comments on commit 6cef441

Please sign in to comment.