Skip to content

Commit

Permalink
Imp new methods in comment.py and post.py (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
coder0422 authored Jul 18, 2023
1 parent 85de8cb commit 0d82fd8
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 0 deletions.
53 changes: 53 additions & 0 deletions pythorhead/comment.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,59 @@ def remove(self, comment_id: int, removed: bool, reason: Optional[str] = None) -
json=remove_comment,
)

def report_list(
self,
community_id: Optional[int] = None,
limit: Optional[int] = None,
page: Optional[int] = None,
unresolved_only: Optional[bool] = None,
) -> List[dict]:
"""
Returns a list of reported posts
Args:
community_id (int, optional): Defaults to None
limit (int, optional): Defaults to None
page (int, optional): Defaults to None
unresolved_only (bool, optional): Defaults to None
Return:
List[dict]
"""

list_reports = {}
if community_id is not None:
list_reports["community_id"] = community_id
if limit is not None:
list_reports["limit"] = limit
if page is not None:
list_reports["page"] = page
if unresolved_only is not None:
list_reports['unresolved_only'] = unresolved_only

if data := self._requestor.api(Request.GET, "/comment/report/list", params=list_reports):
return data["comment_reports"]
return []

def resolve_report(self, report_id: int) -> Optional[dict]:
"""
Resolve a report
Args:
report_id (int)
Returns:
Optional[dict]
"""
return self._requestor.api(
Request.PUT,
"/comment/report/resolve",
json={
"report_id": report_id,
"resolved": True
})

def save(self, comment_id: int, save: bool) -> Optional[dict]:
"""
Add / Remove a comment from saved.
Expand Down
55 changes: 55 additions & 0 deletions pythorhead/post.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,61 @@ def site_metadata(self, url: str) -> Optional[dict]:
}
return self._requestor.api(Request.GET, "/post/site_metadata", params=site_metadata_post)

def report_list(
self,
community_id: Optional[int] = None,
limit: Optional[int] = None,
page: Optional[int] = None,
unresolved_only: Optional[bool] = None,
) -> List[dict]:
"""
Returns a list of reported posts
https://github.com/LemmyNet/lemmy/blob/main/crates/api/src/post_report/list.rs#L14
Args:
community_id: Optional[int], defaults to None
unresolved_only: Optional[bool], defaults to None
limit: Optional[int], defaults to None
page: Optional[int], defaults to None
Returns:
List[dict]
"""

list_reports = {}
if community_id is not None:
list_reports["community_id"] = community_id
if unresolved_only is not None:
list_reports['unresolved_only'] = unresolved_only
if limit is not None:
list_reports["limit"] = limit
if page is not None:
list_reports["page"] = page

if data := self._requestor.api(Request.GET, "/post/report/list", params=list_reports):
return data["post_reports"]
return []

def resolve_report(self, report_id: int) -> Optional[dict]:
"""
Resolve a post report
https://github.com/LemmyNet/lemmy/blob/main/crates/api_common/src/post.rs#L202
Args:
report_id: int
Returns:
Optional[dict]
"""
return self._requestor.api(
Request.PUT,
"/post/report/resolve",
json={
"report_id": report_id,
"resolved": True
})

def purge(self, id: int, reason: Optional[str]) -> Optional[dict]:
"""
Admin purge / delete a post from the database
Expand Down

0 comments on commit 0d82fd8

Please sign in to comment.