def get_group_notifications(self, group: Dict[str, str], count: int = 10, include_seen: bool = False, level=None, verb=None, reverse: bool = False) -> dict: """ Returns all notifications (using the get_notifications fn.) for a user, filtered down to those that reference an Entity of type group with the given id. """ notes = self.get_notifications(count=count, include_seen=include_seen, level=level, verb=verb, reverse=reverse) # group has id and name keys group_notes = {"unseen": 0, "name": group.get("name"), "feed": list()} gid = group["id"] def is_group(e: Entity) -> bool: return e.id == gid and e.type == "group" notes_list = list() for n in notes["feed"]: if is_group(n.actor) or is_group(n.object) or any( [is_group(t) for t in n.target]): notes_list.append(n) if not n.seen: group_notes["unseen"] += 1 Notification.update_entity_names(notes_list, token=self.token) for n in notes_list: group_notes["feed"].append(n.user_view()) return group_notes
def get_notifications(self, count: int = 10, include_seen: bool = False, level=None, verb=None, reverse: bool = False, user_view: bool = False) -> dict: """ Fetches all activities matching the requested inputs. :param count: max number of most recent notifications to return. default=10 :param include_seen: include notifications that have been seen in the response. default = False :param level: if not None, will only return notifications of the given level. default = None :param verb: if not None, will only return notifications made with the given verb. default = None :param reverse: if True, will reverse the order of the result (default False) :param user_view: if True, will return the user_view dict version of each Notification object. If False, will return a list of Notification objects instead. default False :return: a dict with the requested notifications, and a key with the total number in the feed that are marked unseen :rtype: dict :raises ValueError: if count <= 0 """ activities = self.get_activities(count=count, include_seen=include_seen, verb=verb, level=level, reverse=reverse, user_view=user_view) ret_struct = { "unseen": self.get_unseen_count(), "name": self.user.name } if user_view: ret_struct["feed"] = list() Notification.update_entity_names(activities, token=self.token) for act in activities: ret_struct["feed"].append(act.user_view()) else: ret_struct["feed"] = activities return ret_struct