Ensure diaspora mention is extracted even without display name part

merge-requests/157/merge
Jason Robinson 2019-09-08 02:01:58 +03:00
rodzic 42b6736361
commit c997a1a2b4
3 zmienionych plików z 22 dodań i 4 usunięć

Wyświetl plik

@ -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.

Wyświetl plik

@ -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:
"""

Wyświetl plik

@ -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',