-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ensure user state is never conveyed for "appear offline" users #257
Changes from all commits
aa548a1
a7db6b8
1634db5
ff7e5a6
26fb4fd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,7 +68,6 @@ public override async Task OnConnectedAsync() | |
usage.Item = new MetadataClientState(Context.ConnectionId, Context.GetUserId(), versionHash); | ||
|
||
await logLogin(usage); | ||
await broadcastUserPresenceUpdate(usage.Item.UserId, usage.Item.ToUserPresence()); | ||
await Clients.Caller.DailyChallengeUpdated(dailyChallengeUpdater.Current); | ||
} | ||
} | ||
|
@@ -116,7 +115,8 @@ public async Task UpdateActivity(UserActivity? activity) | |
|
||
usage.Item.UserActivity = activity; | ||
|
||
await broadcastUserPresenceUpdate(usage.Item.UserId, usage.Item.ToUserPresence()); | ||
if (shouldBroadcastPresenceToOtherUsers(usage.Item)) | ||
await broadcastUserPresenceUpdate(usage.Item.UserId, usage.Item.ToUserPresence()); | ||
} | ||
} | ||
|
||
|
@@ -129,7 +129,14 @@ public async Task UpdateStatus(UserStatus? status) | |
if (usage.Item.UserStatus != status) | ||
{ | ||
usage.Item.UserStatus = status; | ||
await broadcastUserPresenceUpdate(usage.Item.UserId, usage.Item.ToUserPresence()); | ||
|
||
if (status == UserStatus.Offline) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any reason why this is a local check that isn't using the helper method? ( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's actually a different condition – this case we explicitly want to sent the null status just once when a user transitions to "appear offline". See comment just below, hopefully. |
||
{ | ||
// special case of users that already broadcast that they are online switching to "appear offline". | ||
await broadcastUserPresenceUpdate(usage.Item.UserId, null); | ||
} | ||
else | ||
await broadcastUserPresenceUpdate(usage.Item.UserId, usage.Item.ToUserPresence()); | ||
} | ||
} | ||
} | ||
|
@@ -205,16 +212,36 @@ public async Task EndWatchingMultiplayerRoom(long id) | |
protected override async Task CleanUpState(MetadataClientState state) | ||
{ | ||
await base.CleanUpState(state); | ||
await broadcastUserPresenceUpdate(state.UserId, null); | ||
if (shouldBroadcastPresenceToOtherUsers(state)) | ||
await broadcastUserPresenceUpdate(state.UserId, null); | ||
await scoreProcessedSubscriber.UnregisterFromAllMultiplayerRoomsAsync(state.UserId); | ||
} | ||
|
||
private Task broadcastUserPresenceUpdate(int userId, UserPresence? userPresence) | ||
{ | ||
if (userPresence?.Status == UserStatus.Offline) | ||
userPresence = null; | ||
// we never want appearing offline users to have their status broadcast to other clients. | ||
Debug.Assert(userPresence?.Status != UserStatus.Offline); | ||
|
||
return Clients.Group(ONLINE_PRESENCE_WATCHERS_GROUP).UserPresenceUpdated(userId, userPresence); | ||
} | ||
|
||
private bool shouldBroadcastPresenceToOtherUsers(MetadataClientState state) | ||
{ | ||
if (state.UserStatus == null) | ||
return false; | ||
|
||
switch (state.UserStatus.Value) | ||
{ | ||
case UserStatus.Offline: | ||
return false; | ||
|
||
case UserStatus.DoNotDisturb: | ||
case UserStatus.Online: | ||
return true; | ||
|
||
default: | ||
throw new ArgumentOutOfRangeException(); | ||
} | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to confirm intent, this is deleted because it's basically conveying nothing, correct? I'm not really sure why I put that there in the first place but I guess that makes sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it should never fire anything.