Skip to content

Commit 829655b

Browse files
committed
Update mention json payload
1 parent a3a53e9 commit 829655b

File tree

4 files changed

+19
-1
lines changed

4 files changed

+19
-1
lines changed

Diff for: docs/_extra/api-reference/schemas/annotation.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,9 @@ Annotation:
209209
pattern: "acct:^[A-Za-z0-9._]{3,30}@.*$"
210210
description: user account ID in the format `"acct:<username>@<authority>"`
211211
example: "acct:[email protected]"
212+
original_userid:
213+
type: string
214+
description: The original account ID mentioned in the annotation text
212215
username:
213216
type: string
214217
description: The username of the user at the time of the mention

Diff for: h/presenters/mention_json.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from typing import Any
22

33
from h.models import Mention
4+
from h.util.user import format_userid
45

56

67
class MentionJSONPresenter:
@@ -12,7 +13,10 @@ def __init__(self, mention: Mention):
1213
def asdict(self) -> dict[str, Any]:
1314
return {
1415
"userid": self._mention.user.userid,
15-
"username": self._mention.username,
16+
"original_userid": format_userid(
17+
self._mention.username, self._mention.user.authority
18+
),
19+
"username": self._mention.user.username,
1620
"display_name": self._mention.user.display_name,
1721
"link": self._mention.user.uri,
1822
}

Diff for: tests/unit/h/presenters/mention_json_test.py

+10
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from h.models import Mention
44
from h.presenters.mention_json import MentionJSONPresenter
5+
from h.util.user import format_userid
56

67

78
class TestMentionJSONPresenter:
@@ -12,11 +13,20 @@ def test_as_dict(self, user, annotation):
1213

1314
assert data == {
1415
"userid": user.userid,
16+
"original_userid": user.userid,
1517
"username": user.username,
1618
"display_name": user.display_name,
1719
"link": user.uri,
1820
}
1921

22+
def test_as_dict_with_different_username(self, user, annotation):
23+
new_username = "new_username"
24+
mention = Mention(annotation=annotation, user=user, username=new_username)
25+
26+
data = MentionJSONPresenter(mention).asdict()
27+
28+
assert data["original_userid"] == format_userid(new_username, user.authority)
29+
2030
@pytest.fixture
2131
def user(self, factories):
2232
return factories.User.build()

Diff for: tests/unit/h/services/mention_test.py

+1
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ def test_it(self, pyramid_request, user_service, MentionService):
104104
session=pyramid_request.db,
105105
user_service=user_service,
106106
)
107+
107108
assert service == MentionService.return_value
108109

109110
@pytest.fixture

0 commit comments

Comments
 (0)