Skip to content

Commit

Permalink
reading-list-updater: React after handling updates from Matrix
Browse files Browse the repository at this point in the history
  • Loading branch information
gbenson committed Oct 28, 2024
1 parent 9ba666a commit 59d9b5d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class ReadingListEntry:
title: Optional[str] = None
notes: Optional[str] = None
timestamp: str = field(default_factory=NotImplemented)
matrix_event_id: str = None

def __post_init__(self):
if not self.title:
Expand Down Expand Up @@ -51,6 +52,11 @@ def from_email_summary(cls, email: dict[str, str]) -> ReadingListEntry:
if (date := email.get("date")):
kwargs["timestamp"] = date

if (origin := email.get("origin")):
if origin.get("channel") == "matrix":
if (event_id := origin.get("event_id")):
kwargs["matrix_event_id"] = event_id

return cls(link, title, notes, **kwargs)

def as_wikitext(self):
Expand Down
10 changes: 10 additions & 0 deletions services/reading-list-updater/hive/reading_list_updater/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@ def on_update_request(
entry = ReadingListEntry.from_email_summary_bytes(body)
wikitext = entry.as_wikitext()
self.wiki.page("Reading list").append(f"* {wikitext}")
if (source_event_id := entry.matrix_event_id):
channel.publish_request(
message={
"reaction": "👍",
"receiver": {
"event_id": source_event_id,
},
},
routing_key="matrix.reaction.send.requests",
)

def run(self):
with blocking_connection(on_channel_open=self.on_channel_open) as conn:
Expand Down

0 comments on commit 59d9b5d

Please sign in to comment.