Skip to content

Comment

Implements the Comment class.

Comment(lemmy, comment, community=None, post=None)

A class for Comments.

Initialize a Comment instance.

Parameters:

  • lemmy (Lemmy) –

    A Lemmy instance.

  • comment (CommentView) –
  • community (Optional[Community], default: None ) –

    The Community in which this was posted.

  • post (Optional[Post], default: None ) –

    The Post under which this comment was posted.

Source code in pylemmy/models/comment.py
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
def __init__(
    self,
    lemmy: "pylemmy.Lemmy",
    comment: api.comment.CommentView,
    community: Optional["pylemmy.models.community.Community"] = None,
    post: Optional["pylemmy.models.post.Post"] = None,
):
    """Initialize a Comment instance.

    :param lemmy: A Lemmy instance.
    :param comment: A [CommentView](
    https://join-lemmy.org/api/interfaces/CommentView.html).
    :param community: The Community in which this was posted.
    :param post: The Post under which this comment was posted.
    """
    self.lemmy = lemmy
    self.comment_view = comment

    self._post = post
    self._community = community

community: pylemmy.models.community.Community property

The Community in which this was posted.

post: pylemmy.models.post.Post property

The Post under which this comment was posted.

create_report(reason)

Report this comment.

Parameters:

  • reason (str) –

    A reason for the report.

Source code in pylemmy/models/comment.py
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
def create_report(self, reason: str) -> CommentReport:
    """Report this comment.

    :param reason: A reason for the report.
    """
    self.lemmy.get_token()
    payload = api.comment.CreateCommentReport(
        comment_id=self.comment_view.comment.id,
        reason=reason,
    )
    result = self.lemmy.post_request(LemmyAPI.CreateCommentReport, params=payload)

    parsed_result = api.comment.CommentReportResponse(**result)
    return CommentReport(
        lemmy=self.lemmy, report=parsed_result.comment_report_view, comment=self
    )

CommentReport(lemmy, report, comment=None)

A class for Comment reports.

Initialize a Comment instance.

Parameters:

  • lemmy (Lemmy) –

    A Lemmy instance.

  • report (CommentReportView) –
  • comment (Optional[Comment], default: None ) –

    The comment being reported.

Source code in pylemmy/models/comment.py
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
def __init__(
    self,
    lemmy: "pylemmy.Lemmy",
    report: api.comment.CommentReportView,
    comment: Optional["Comment"] = None,
):
    """Initialize a Comment instance.

    :param lemmy: A Lemmy instance.
    :param report: A [CommentReportView](
    https://join-lemmy.org/api/interfaces/CommentReportView.html).
    :param comment: The comment being reported.
    """
    self.lemmy = lemmy
    self.report_view = report
    self.comment = comment

resolve(*, resolved)

Resolve a comment report.

Parameters:

  • resolved (bool) –

    Either resolve or unresolve the report.

Source code in pylemmy/models/comment.py
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
def resolve(self, *, resolved: bool) -> "CommentReport":
    """Resolve a comment report.

    :param resolved: Either resolve or unresolve the report.
    """
    self.lemmy.get_token()
    payload = api.comment.ResolveCommentReport(
        report_id=self.report_view.comment_report.id,
        resolved=resolved,
    )
    result = self.lemmy.put_request(LemmyAPI.ResolveCommentReport, params=payload)
    parsed_result = api.comment.CommentReportView(**result)

    return CommentReport(
        lemmy=self.lemmy, report=parsed_result, comment=self.comment
    )