Skip to content
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

Update sidebar users #24

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open

Update sidebar users #24

wants to merge 6 commits into from

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.

1 participant