async def METHOD_NAME(store: DataStore, user_id: str, group_by_room: bool) -> int:
    invites = await store.get_invited_rooms_for_local_user(user_id)
    joins = await store.get_rooms_for_user(user_id)
    badge = len(invites)
    room_to_count = await store.get_unread_counts_by_room_for_user(user_id)
    for room_id, notify_count in room_to_count.items():
        # room_to_count may include rooms which the user has left,
        # ignore those.
        if room_id not in joins:
            continue
        if notify_count == 0:
            continue
        if group_by_room:
            # return one badge count per conversation
            badge += 1
        else:
            # Increase badge by number of notifications in room
            # NOTE: this includes threaded and unthreaded notifications.
            badge += notify_count
    return badge