kopia lustrzana https://gitlab.com/jaywink/federation
Ensure diaspora mention is extracted even without display name part
rodzic
42b6736361
commit
c997a1a2b4
|
@ -76,6 +76,10 @@
|
|||
enum. `ACTOR` means this receiver is a single actor ID.
|
||||
`FOLLOWERS` means this is the followers of the ID in the receiver.
|
||||
|
||||
### Fixed
|
||||
|
||||
* Ensure Diaspora mentions are extracted when they don't have a display name part.
|
||||
|
||||
### Removed
|
||||
|
||||
* **Backwards incompatible.** Support for Legacy Diaspora payloads have been removed to reduce the amount of code needed to maintain while refactoring for ActivityPub.
|
||||
|
|
|
@ -22,12 +22,17 @@ class DiasporaEntityMixin(BaseEntity):
|
|||
"""
|
||||
if not hasattr(self, "raw_content"):
|
||||
return set()
|
||||
mentions = re.findall(r'@{[^;]+; [\w.-]+@[^}]+}', self.raw_content)
|
||||
mentions = re.findall(r'@{([\S ][^{}]+)}', self.raw_content)
|
||||
if not mentions:
|
||||
return set()
|
||||
mentions = {s.split(';')[1].strip(' }') for s in mentions}
|
||||
mentions = {s for s in mentions}
|
||||
return mentions
|
||||
_mentions = set()
|
||||
for mention in mentions:
|
||||
splits = mention.split(";")
|
||||
if len(splits) == 1:
|
||||
_mentions.add(splits[0].strip(' }'))
|
||||
elif len(splits) == 2:
|
||||
_mentions.add(splits[1].strip(' }'))
|
||||
return _mentions
|
||||
|
||||
def to_string(self) -> str:
|
||||
"""
|
||||
|
|
|
@ -103,6 +103,15 @@ class TestEntitiesExtractMentions:
|
|||
def test_extract_mentions__set_contains_mentioned_handles(self, diasporapost):
|
||||
diasporapost.raw_content = 'yeye @{Jason Robinson 🐍🍻; jaywink@jasonrobinson.me} foobar ' \
|
||||
'@{bar; foo@example.com}'
|
||||
response = diasporapost.extract_mentions()
|
||||
assert response == {
|
||||
'jaywink@jasonrobinson.me',
|
||||
'foo@example.com',
|
||||
}
|
||||
|
||||
def test_extract_mentions__set_contains_mentioned_handles__without_display_name(self, diasporapost):
|
||||
diasporapost.raw_content = 'yeye @{jaywink@jasonrobinson.me} foobar ' \
|
||||
'@{bar; foo@example.com}'
|
||||
assert diasporapost.extract_mentions() == {
|
||||
'jaywink@jasonrobinson.me',
|
||||
'foo@example.com',
|
||||
|
|
Ładowanie…
Reference in New Issue