diff --git a/mipac/actions/role.py b/mipac/actions/role.py index 1ba501f4..5f4f952f 100644 --- a/mipac/actions/role.py +++ b/mipac/actions/role.py @@ -3,12 +3,11 @@ from typing import TYPE_CHECKING, AsyncGenerator from mipac.abstract.action import AbstractAction -from mipac.config import config from mipac.http import HTTPClient, Route from mipac.models.note import Note -from mipac.models.roles import MeRole, Role, RoleUser +from mipac.models.roles import Role, RoleUser from mipac.types.note import INote -from mipac.types.roles import IMeRole, IRole, IRoleUser, is_me_role +from mipac.types.roles import IRole, IRoleUser from mipac.utils.pagination import Pagination if TYPE_CHECKING: @@ -64,7 +63,7 @@ async def get_users( limit: int = 10, *, get_all: bool = False, - ) -> AsyncGenerator[MeRole | RoleUser, None]: + ) -> AsyncGenerator[RoleUser, None]: """ Get users in a role. Endpoint: `/api/roles/users` @@ -84,7 +83,7 @@ async def get_users( Yields ------ - AsyncGenerator[MeRole | RoleUser, None] + AsyncGenerator[RoleUser, None] The role user data. """ @@ -96,17 +95,13 @@ async def get_users( body = {"roleId": role_id, "limit": limit, "sinceId": since_id, "untilId": until_id} - pagination = Pagination[IRoleUser | IMeRole]( + pagination = Pagination[IRoleUser]( self.__session, Route("POST", "/api/roles/users"), auth=True, json=body ) while True: raw_users = await pagination.next() for raw_user in raw_users: - yield ( - MeRole(raw_user, client=self.__client) - if is_me_role(raw_user, config.account_id) - else RoleUser(raw_user, client=self.__client) - ) + yield RoleUser(raw_user, client=self.__client) if pagination.is_final or get_all is False: break diff --git a/mipac/models/roles.py b/mipac/models/roles.py index a054ea1b..ff12918a 100644 --- a/mipac/models/roles.py +++ b/mipac/models/roles.py @@ -5,12 +5,11 @@ from mipac.models.lite.role import PartialRole from mipac.models.user import MeDetailed, UserDetailedNotMe, packed_user -from mipac.types.roles import IMeRole, IRole, IRolePolicies, IRoleUser +from mipac.types.roles import IRole, IRolePolicies, IRoleUser from mipac.utils.format import str_to_datetime if TYPE_CHECKING: from mipac.manager.client import ClientManager - from mipac.manager.user import UserManager class RoleUser: @@ -23,40 +22,12 @@ def id(self) -> str: return self.__role_user["id"] @property - def user(self) -> UserDetailedNotMe | MeDetailed: - return packed_user(self.__role_user["user"], client=self.__client) + def created_at(self) -> datetime: + return str_to_datetime(self.__role_user["created_at"]) @property - def expires_at(self) -> datetime | None: - return ( - str_to_datetime(self.__role_user["expires_at"]) - if self.__role_user["expires_at"] - else None - ) - - @property - def action(self) -> UserManager: - return self.__client._create_user_instance(self.user) - - def __eq__(self, __value: object) -> bool: - return isinstance(__value, RoleUser) and self.id == __value.id - - def __ne__(self, __value: object) -> bool: - return not self.__eq__(__value) - - -class MeRole: - def __init__(self, data: IMeRole, *, client: ClientManager) -> None: - self.__role_user = data - self.__client = client - - @property - def id(self) -> str: - return self.__role_user["id"] - - @property - def user(self) -> MeDetailed: - return MeDetailed(self.__role_user["user"], client=self.__client) + def user(self) -> UserDetailedNotMe | MeDetailed: + return packed_user(self.__role_user["user"], client=self.__client) @property def expires_at(self) -> datetime | None: @@ -66,10 +37,6 @@ def expires_at(self) -> datetime | None: else None ) - @property - def action(self) -> UserManager: - return self.__client._create_user_instance(self.user) - def __eq__(self, __value: object) -> bool: return isinstance(__value, RoleUser) and self.id == __value.id diff --git a/mipac/types/roles.py b/mipac/types/roles.py index 165aa083..998ffeab 100644 --- a/mipac/types/roles.py +++ b/mipac/types/roles.py @@ -1,20 +1,17 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Literal, TypedDict, TypeGuard +from typing import TYPE_CHECKING, Literal, TypedDict + +from mipac.types.user import IUserDetailedNotMeSchema if TYPE_CHECKING: - from mipac.types.user import IMeDetailedSchema, IUserDetailed + from mipac.types.user import IMeDetailedSchema class IRoleUser(TypedDict): id: str - user: IUserDetailed - expires_at: str | None - - -class IMeRole(TypedDict): - id: str - user: IMeDetailedSchema + created_at: str + user: IUserDetailedNotMeSchema | IMeDetailedSchema expires_at: str | None @@ -67,7 +64,3 @@ class IRole(IPartialRole): can_edit_members_by_moderator: bool policies: IRolePolicies users_count: int - - -def is_me_role(data: IMeRole | IRoleUser, me_id: str) -> TypeGuard[IMeRole]: - return data["user"]["id"] == me_id and data["user"].get("avatar_id") is not None