"""Utils module providing helper functions related to Stream.""" from notifications.constants.stream import DELIMITER, FEED_ID_ENCODING def get_user_feed_id(user_id: str, user_feed_id: str | None) -> str: """Select and format the user feed id to use. Args: user_id (str): the orchard user id user_feed_id (str): the user feed id to use instead of the user id Returns: str: the formatted user feed id """ if not user_feed_id: return user_id.replace(':', DELIMITER) for key, value in FEED_ID_ENCODING.items(): user_feed_id = user_feed_id.replace(key, value) return user_feed_id def get_profile_feed_id(namespace: str, identifier: int | str) -> str: """Generate feed_id for profile namespaced feeds. - Join namespace and identifier with DELIMITER - Replace ":" with DELIMITER Args: namespace (str): namespace (ex. InsightsProfile or GlobalParticipant) identifier (int|str): either particpant or profile id Returns: str: formatted feed id """ result = DELIMITER.join([namespace, str(identifier)]) result = result.replace(':', DELIMITER) return result