def msg_template_factory( msg_id: int, msg_type: str, timestamp: int, *, subject: str = "", stream_id: Optional[int] = None, recipients: Union[str, List[Dict[str, Any]]] = "PTEST", ) -> Message: """ Generate message template for all types of messages(stream/PM/group) """ # TODO: Separate Message into distinct types for stream and private messages. message = Message( id=msg_id, sender_full_name="Foo Foo", timestamp=timestamp, client="website", sender_email="*****@*****.**", type=msg_type, sender_realm_str="", flags=["read"], sender_id=5140, content_type="text/x-markdown", subject=subject, reactions=[], subject_links=[], avatar_url="dummy_avatar_url", is_me_message=False, content=f"{msg_type} content here.", display_recipient=recipients, ) if msg_type == "stream": assert isinstance(stream_id, int) assert isinstance(recipients, str) message["stream_id"] = stream_id else: assert isinstance(recipients, list) for _val in recipients: assert isinstance(_val, dict) return message
initial_index = Index( pointer=defaultdict(set), all_msg_ids=set(), starred_msg_ids=set(), mentioned_msg_ids=set(), private_msg_ids=set(), private_msg_ids_by_user_ids=defaultdict(set), stream_msg_ids_by_stream_id=defaultdict(set), topic_msg_ids=defaultdict(dict), edited_messages=set(), topics=defaultdict(list), search=set(), # mypy bug: https://github.com/python/mypy/issues/7217 messages=defaultdict(lambda: Message()), ) class UnreadCounts(TypedDict): all_msg: int all_pms: int all_mentions: int unread_topics: Dict[Tuple[int, str], int] # stream_id, topic unread_pms: Dict[int, int] # sender_id unread_huddles: Dict[FrozenSet[int], int] # Group pms streams: Dict[int, int] # stream_id def asynch(func: Callable[..., None]) -> Callable[..., None]: """