Skip to content

Conversation

@bemesa21
Copy link
Contributor

UserTracker is created to periodically send updates to the active users sidebar.

It keeps a convenient state, a map with the following structure:

%{
  active_users: %{},
  user_leaves: [],
  user_joins: []
}
  • active_users keeps a map with the active users ids as keys and the user struct as value
  • user_leaves and user_joins keep the list of users who joined or left during the current interval, they are cleared every time an interval ends.

UserTracker receives updates sent from LiveBeats.PresenceClient every time that the callbacks handle_joinand handle_leave are called and updates its own state (active_users,user_leaves, and user_joins) with the users data.

Every time the configured interval ends, it broadcast the users who joined or left during the interval to the ProfileLive and SettingsLive liveviews.

A hook called active_users is defined to receive the active user updates and update the active_users assign.

The active_users assign is defined as a temporary_assign and initialized on_mount with the active_users saved in the UserTracker state.

The remove-el event is used to delete the users who left from the sidebar elements in both navigations mobile-active-users and desktop-active-users

{:ok,
schedule_updates(%{
active_users: %{},
user_leaves: [],
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be better if I only save the user IDs and not the whole user structure in the user_leaves and user_joins lists

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants