Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Include whether the requesting users has responded to an MSC3440 thread #11399

Closed
clokep opened this issue Nov 19, 2021 · 3 comments · Fixed by #11577
Closed

Include whether the requesting users has responded to an MSC3440 thread #11399

clokep opened this issue Nov 19, 2021 · 3 comments · Fixed by #11577
Assignees
Labels
A-Threads Threaded messages T-Enhancement New features, changes in functionality, improvements in performance, or user-facing enhancements.

Comments

@clokep
Copy link
Member

clokep commented Nov 19, 2021

Per an update to MSC3440. (Note that we're going to be consistent and not use a camel-case version as suggested there.)

@clokep clokep added T-Enhancement New features, changes in functionality, improvements in performance, or user-facing enhancements. A-Threads Threaded messages labels Nov 19, 2021
@clokep clokep self-assigned this Nov 19, 2021
@clokep
Copy link
Member Author

clokep commented Nov 19, 2021

This seems like it might not be super feasible since we don't have the requesting user when serializing events. We could probably pass through the user to those places, but I'm not sure if that is desirable (in terms of caching and such). What do we think of this?

Relevant code is near:

  • if self._msc3440_enabled:
    (
    thread_count,
    latest_thread_event,
    ) = await self.store.get_thread_summary(event_id)
    if latest_thread_event:
    r = serialized_event["unsigned"].setdefault("m.relations", {})
    r[RelationTypes.THREAD] = {
    # Don't bundle aggregations as this could recurse forever.
    "latest_event": await self.serialize_event(
    latest_thread_event, time_now, bundle_aggregations=False
    ),
    "count": thread_count,
    }
    , which calls
  • async def get_thread_summary(
    self, event_id: str
    ) -> Tuple[int, Optional[EventBase]]:
    """Get the number of threaded replies, the senders of those replies, and
    the latest reply (if any) for the given event.
    Args:
    event_id: The original event ID
    Returns:
    The number of items in the thread and the most recent response, if any.
    """
    def _get_thread_summary_txn(txn) -> Tuple[int, Optional[str]]:
    # Fetch the count of threaded events and the latest event ID.
    # TODO Should this only allow m.room.message events.
    sql = """
    SELECT event_id
    FROM event_relations
    INNER JOIN events USING (event_id)
    WHERE
    relates_to_id = ?
    AND relation_type = ?
    ORDER BY topological_ordering DESC, stream_ordering DESC
    LIMIT 1
    """
    txn.execute(sql, (event_id, RelationTypes.THREAD))
    row = txn.fetchone()
    if row is None:
    return 0, None
    latest_event_id = row[0]
    sql = """
    SELECT COALESCE(COUNT(event_id), 0)
    FROM event_relations
    WHERE
    relates_to_id = ?
    AND relation_type = ?
    """
    txn.execute(sql, (event_id, RelationTypes.THREAD))
    count = txn.fetchone()[0]
    return count, latest_event_id
    count, latest_event_id = await self.db_pool.runInteraction(
    "get_thread_summary", _get_thread_summary_txn
    )
    latest_event = None
    if latest_event_id:
    latest_event = await self.get_event(latest_event_id, allow_none=True)
    return count, latest_event

@clokep
Copy link
Member Author

clokep commented Nov 30, 2021

This is not necessary, the filtering adding to MSC3440 is meant to be used for this purpose.

@clokep clokep closed this as completed Nov 30, 2021
@clokep
Copy link
Member Author

clokep commented Dec 14, 2021

We might need to do this for thread previews in the timeline.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A-Threads Threaded messages T-Enhancement New features, changes in functionality, improvements in performance, or user-facing enhancements.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant