Skip to content

feat: Add pin and unpin methods to Message class#84

Open
nik1062 wants to merge 6 commits into
Code-Society-Lab:mainfrom
nik1062:issue-67-pin-unpin
Open

feat: Add pin and unpin methods to Message class#84
nik1062 wants to merge 6 commits into
Code-Society-Lab:mainfrom
nik1062:issue-67-pin-unpin

Conversation

@nik1062

@nik1062 nik1062 commented Jul 1, 2026

Copy link
Copy Markdown

Hi there, I have resolved the issue by implementing the pin() and unpin() methods on the Message class!

@PenguinBoi12 PenguinBoi12 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work getting pin/unpin functionally correct here, the approach is generally good. A just left few suggestions to tighten up the implementation.

Comment thread matrix/message.py Outdated
Comment thread matrix/message.py
Comment thread matrix/message.py
Comment thread matrix/message.py Outdated
@nik1062

nik1062 commented Jul 1, 2026 via email

Copy link
Copy Markdown
Author

@PenguinBoi12 PenguinBoi12 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🦭 I left a small nit I missed earlier, but otherwise it looks good to me. Thank you!

However the CI fails, Run those locally (from the project directory) and make sure everything passes:

  • Run tests: pytest
  • Run type check: mypy matrix
  • Run formatting: black .

Comment thread matrix/message.py Outdated
)

if isinstance(response, RoomGetStateEventResponse):
return list(response.content["pinned"])

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: return response.content.get("pinned", [])

@PenguinBoi12 PenguinBoi12 Jul 2, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nik1062 I've seen that you changed it and it's good but you don't need to cast it. return response.content.get("pinned", []) should be enough. You only need to fix that and the PR is good to go.

@PenguinBoi12 PenguinBoi12 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CI is not passing

Make sure all those passes:

  • Run tests: pytest
  • Run type check: mypy matrix
  • Run formatting: black .

@PenguinBoi12 PenguinBoi12 added the feature A new feature label Jul 2, 2026
@nik1062

nik1062 commented Jul 2, 2026

Copy link
Copy Markdown
Author

Hi @PenguinBoi12,

Thanks for the review! I've addressed all the requested changes and verified everything locally (black, mypy, and pytest). Please let me know if there's anything else I should improve. Thanks!

@nik1062

nik1062 commented Jul 3, 2026 via email

Copy link
Copy Markdown
Author

@PenguinBoi12

PenguinBoi12 commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Thanks for the tip!

You're welcome! Please make the changes to use matrix_call and remove the redundant exceptions. Once this is done the PR will be good to go.

Thank you @nik1062!

@nik1062 nik1062 requested a review from PenguinBoi12 July 4, 2026 06:44

@PenguinBoi12 PenguinBoi12 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You forgot to address the matrix_call comment.

@nik1062

nik1062 commented Jul 4, 2026

Copy link
Copy Markdown
Author

Thanks for the feedback, @PenguinBoi12. I've refactored pin() and unpin() in
message.py to use matrix_call for the room_put_state calls, bringing them in line
with the rest of the codebase. The _fetch_pinned helper intentionally retains its
manual response handling, as a 404 from room_get_state_event represents a valid "no
pinned events" state rather than an error. Tests have been updated accordingly — all 295
passing.

@nik1062 nik1062 requested a review from PenguinBoi12 July 4, 2026 09:12
@PenguinBoi12

Copy link
Copy Markdown
Contributor

Thanks for the feedback, @PenguinBoi12. I've refactored pin() and unpin() in
message.py to use matrix_call for the room_put_state calls, bringing them in line
with the rest of the codebase. The _fetch_pinned helper intentionally retains its
manual response handling, as a 404 from room_get_state_event represents a valid "no
pinned events" state rather than an error. Tests have been updated accordingly — all 295
passing.

Did you forget to push because I can't see those changes.

@nik1062

nik1062 commented Jul 4, 2026 via email

Copy link
Copy Markdown
Author

@PenguinBoi12 PenguinBoi12 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR is almost ready to get approved. As I mentioned I did some research and there's a validation that you do in _fetch_pinned that will always raise an error. Fix that and it's good to go.

It's important to test with real data when possible, test, specially when mocked, can give false positive.

Comment thread matrix/message.py
if isinstance(response, RoomGetStateEventResponse):
return list(response.content.get("pinned", []))
if isinstance(response, RoomGetStateEventError):
if response.status_code == "404":

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I did some research and testing and this won't work. matrix does not return "404" as status code, it returns a "M_NOT_FOUND". So you need to change if response.status_code == "M_NOT_FOUND":

The reason why your tests worked is because you mocked the response; it was a false positive.

@PenguinBoi12 PenguinBoi12 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're almost there, only one thing to fix and it's ready to be merge : )

@PenguinBoi12 PenguinBoi12 linked an issue Jul 4, 2026 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature A new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Message: Add pin() and unpin() methods

2 participants