Make Event.inline_content & links pure attrs
This commit is contained in:
parent
8a29143b60
commit
e982de1c61
|
@ -499,15 +499,21 @@ class MatrixClient(nio.AsyncClient):
|
|||
|
||||
our_info = self.models[self.user_id, room_id, "members"][self.user_id]
|
||||
|
||||
content = event_fields.get("content", "").strip()
|
||||
|
||||
if content and "inline_content" not in event_fields:
|
||||
event_fields["inline_content"] = HTML.filter(content, inline=True)
|
||||
|
||||
event = Event(
|
||||
id = f"echo-{transaction_id}",
|
||||
event_id = "",
|
||||
event_type = event_type,
|
||||
date = datetime.now(),
|
||||
sender_id = self.user_id,
|
||||
sender_name = our_info.display_name,
|
||||
sender_avatar = our_info.avatar_url,
|
||||
is_local_echo = True,
|
||||
id = f"echo-{transaction_id}",
|
||||
event_id = "",
|
||||
event_type = event_type,
|
||||
date = datetime.now(),
|
||||
sender_id = self.user_id,
|
||||
sender_name = our_info.display_name,
|
||||
sender_avatar = our_info.avatar_url,
|
||||
is_local_echo = True,
|
||||
links = Event.parse_links(content),
|
||||
**event_fields,
|
||||
)
|
||||
|
||||
|
@ -1021,6 +1027,11 @@ class MatrixClient(nio.AsyncClient):
|
|||
await self.get_member_name_avatar(room.room_id, target_id) \
|
||||
if target_id else ("", "")
|
||||
|
||||
content = fields.get("content", "").strip()
|
||||
|
||||
if content and "inline_content" not in fields:
|
||||
fields["inline_content"] = HTML.filter(content, inline=True)
|
||||
|
||||
# Create Event ModelItem
|
||||
item = Event(
|
||||
id = ev.event_id,
|
||||
|
@ -1034,6 +1045,7 @@ class MatrixClient(nio.AsyncClient):
|
|||
target_id = target_id,
|
||||
target_name = target_name,
|
||||
target_avatar = target_avatar,
|
||||
links = Event.parse_links(content),
|
||||
**fields,
|
||||
)
|
||||
|
||||
|
|
|
@ -174,9 +174,10 @@ class Event(ModelItem):
|
|||
sender_name: str = field()
|
||||
sender_avatar: str = field()
|
||||
|
||||
content: str = ""
|
||||
inline_content: str = ""
|
||||
reason: str = ""
|
||||
content: str = ""
|
||||
inline_content: str = ""
|
||||
reason: str = ""
|
||||
links: List[Dict[str, Any]] = field(default_factory=list)
|
||||
|
||||
type_specifier: TypeSpecifier = TypeSpecifier.Unset
|
||||
|
||||
|
@ -201,32 +202,19 @@ class Event(ModelItem):
|
|||
thumbnail_height: int = 0
|
||||
thumbnail_crypt_dict: Dict[str, Any] = field(default_factory=dict)
|
||||
|
||||
def __post_init__(self) -> None:
|
||||
if not self.inline_content:
|
||||
self.inline_content = \
|
||||
HTML_PROCESSOR.filter(self.content, inline=True)
|
||||
|
||||
|
||||
def __lt__(self, other: "Event") -> bool:
|
||||
"""Sort by date in descending order, from newest to oldest."""
|
||||
|
||||
return self.date > other.date
|
||||
|
||||
@property
|
||||
def links(self) -> List[Dict[str, Any]]:
|
||||
"""List of URLs (`<a href=...>` tags) present in the event content."""
|
||||
@staticmethod
|
||||
def parse_links(text: str) -> List[Dict[str, Any]]:
|
||||
"""Return list of URLs (`<a href=...>` tags) present in the text."""
|
||||
|
||||
urls: List[Dict[str, Any]] = []
|
||||
if not text.strip():
|
||||
return []
|
||||
|
||||
if self.content.strip():
|
||||
urls += [
|
||||
{"url": link[2]} for link in lxml.html.iterlinks(self.content)
|
||||
]
|
||||
|
||||
if self.media_url:
|
||||
urls.append({"url": self.media_url})
|
||||
|
||||
return urls
|
||||
return [{"url": link[2]} for link in lxml.html.iterlinks(text)]
|
||||
|
||||
@property
|
||||
def serialized(self) -> Dict[str, Any]:
|
||||
|
|
|
@ -172,7 +172,10 @@ HRowLayout {
|
|||
|
||||
HRepeater {
|
||||
id: linksRepeater
|
||||
model: JSON.parse(eventDelegate.currentModel.links)
|
||||
model: [
|
||||
eventDelegate.currentModel.media_url,
|
||||
...JSON.parse(eventDelegate.currentModel.links),
|
||||
]
|
||||
|
||||
EventMediaLoader {
|
||||
singleMediaInfo: eventDelegate.currentModel
|
||||
|
|
Loading…
Reference in New Issue
Block a user