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

Added broadcast_message_scoped to allow sending messages only to users with a specific entity in their scope #167

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Jeff425
Copy link

@Jeff425 Jeff425 commented May 10, 2023

@connorcarpenter I noticed it didn't seem possible to broadcast a message to users with a specific entity in their scope. This PR is my attempt to add that feature.

@@ -20,13 +20,18 @@ impl<E: Copy + Eq + Hash> EntityScopeMap<E> {
}
}

pub fn get(&self, user_key: &UserKey, entity: &E) -> Option<&bool> {
pub fn get(&self, user_key: &UserKey, entity: &E) -> bool {
Copy link
Author

Choose a reason for hiding this comment

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

I updated this function to return a bool instead of an option of a borrowed bool.
Let me know if there is a use-case for this function returning None instead of just false.

}

pub fn insert(&mut self, user_key: UserKey, entity: E, in_scope: bool) {
if self.main_map.contains_key(&(user_key, entity)) {
Copy link
Author

Choose a reason for hiding this comment

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

Added in this check to see if the scope is just being updated rather than inserted.
If the user/entity key already existed in the main_map, then we should be able to assume that we just need to update main_map to the new boolean value

} else {
false
};
let should_be_in_scope = self.entity_scope_map.get(user_key, entity);
Copy link
Author

Choose a reason for hiding this comment

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

Updated to take advantage of get returning just a bool instead of an option of a borrowed bool

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