Skip to content

feat: add reject/accept to Activity class#35

Merged
AmaseCocoa merged 3 commits intofedi-libs:developfrom
AmaseCocoa:develop
Apr 7, 2026
Merged

feat: add reject/accept to Activity class#35
AmaseCocoa merged 3 commits intofedi-libs:developfrom
AmaseCocoa:develop

Conversation

@AmaseCocoa
Copy link
Copy Markdown
Member

No description provided.

@AmaseCocoa AmaseCocoa merged commit 45d7d2f into fedi-libs:develop Apr 7, 2026
5 checks passed
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 7, 2026

Codecov Report

❌ Patch coverage is 50.00000% with 4 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/apmodel/mixins/activity.py 50.00% 4 Missing ⚠️

📢 Thoughts on this report? Let us know!

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request adds an ActivityMixin to the core schema and implements it in a new Python module to provide helper methods for creating Accept and Reject activities. Feedback suggests making the id parameter optional, allowing the actor to be a string, and adding future annotations for better type handling.

Comment on lines +1 to +18
from typing import TYPE_CHECKING

if TYPE_CHECKING:
from apmodel.activity import Accept, Reject
from apmodel.core import Activity
from apmodel.objects import Actor


class ActivityMixin:
def accept(self: "Activity", id: str, actor: "Actor") -> "Accept":
from apmodel.activity.accept import Accept

return Accept(id=id, actor=actor, object=self)

def reject(self: "Activity", id: str, actor: "Actor") -> "Reject":
from apmodel.activity.reject import Reject

return Reject(id=id, actor=actor, object=self)
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.

medium

The current implementation of accept and reject requires an id as a positional argument. In many ActivityPub scenarios, the ID of a new activity might not be known at creation time (e.g., it's assigned by the server later) or should be optional.

Additionally, the actor parameter is typed strictly as Actor, but in practice, it is often provided as a URI string.

I suggest:

  1. Making id optional with a default of None.
  2. Swapping the order of actor and id to allow id to be optional while keeping actor required.
  3. Allowing actor to be a str.
  4. Adding from __future__ import annotations to simplify type hints and avoid circular evaluation issues at runtime.
Suggested change
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from apmodel.activity import Accept, Reject
from apmodel.core import Activity
from apmodel.objects import Actor
class ActivityMixin:
def accept(self: "Activity", id: str, actor: "Actor") -> "Accept":
from apmodel.activity.accept import Accept
return Accept(id=id, actor=actor, object=self)
def reject(self: "Activity", id: str, actor: "Actor") -> "Reject":
from apmodel.activity.reject import Reject
return Reject(id=id, actor=actor, object=self)
from __future__ import annotations
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from apmodel.activity import Accept, Reject
from apmodel.core import Activity
from apmodel.objects import Actor
class ActivityMixin:
def accept(self: Activity, actor: Actor | str, id: str | None = None) -> Accept:
from apmodel.activity.accept import Accept
return Accept(id=id, actor=actor, object=self)
def reject(self: Activity, actor: Actor | str, id: str | None = None) -> Reject:
from apmodel.activity.reject import Reject
return Reject(id=id, actor=actor, object=self)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant