-
Notifications
You must be signed in to change notification settings - Fork 457
Support sending and receiving MSC4354 Sticky Event metadata. #19365
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
aaa229f
a25a5b5
7abcf6d
c2d4cf4
ec5f2f8
003fe1f
c7075d6
0a4f7e6
53e4968
137c457
90e9539
9a0b28e
b41ef41
fb67e9a
383d97c
47306d2
beead8a
1353ec3
a424310
2522c38
450d5ee
34d23ef
f1ec22b
d28f17a
33f953e
5f8f302
015819e
3c51231
11378ac
db9504f
ae5f1c5
6527373
d80d2c4
e3a8f19
f42af6a
3be0e87
efc08d2
5a5efc5
d83656a
cf16293
b0693b5
c0c78dc
2b822dd
601b1f3
02d245f
737d482
a535477
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Support sending and receiving [MSC4354 Sticky Event](https://github.com/matrix-org/matrix-spec-proposals/pull/4354) metadata. |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -24,7 +24,7 @@ | |||||
| import attr | ||||||
| from signedjson.types import SigningKey | ||||||
|
|
||||||
| from synapse.api.constants import MAX_DEPTH, EventTypes | ||||||
| from synapse.api.constants import MAX_DEPTH, EventTypes, StickyEvent, StickyEventField | ||||||
| from synapse.api.room_versions import ( | ||||||
| KNOWN_EVENT_FORMAT_VERSIONS, | ||||||
| EventFormatVersions, | ||||||
|
|
@@ -89,6 +89,10 @@ class EventBuilder: | |||||
|
|
||||||
| content: JsonDict = attr.Factory(dict) | ||||||
| unsigned: JsonDict = attr.Factory(dict) | ||||||
| sticky: StickyEventField | None = None | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
🤷 Not necessarily better but it's a bit strange to onboard to these names and what they are.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't entirely prefer 'content' but maybe attributes, properties, or something like that? Any thoughts on those two?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. They don't stand out to me as better. The problem with "content" is we already have event The problem with the others is we're talking about "content" for the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. meh, I'm not sure but maybe My thought behind attributes/properties what naming it after what the class is, rather than where it sits within the event. 'These are the properties for sticky events'. Hm. But I really don't like sticky event 'content' given the conflict with event
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess this is the only thing I would like to see if you had any further thoughts on before the PR lands? @MadLittleMods
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably fine as-is. We don't have any great options ⏩ |
||||||
| """ | ||||||
| Fields for MSC4354: Sticky Events | ||||||
| """ | ||||||
|
|
||||||
| # These only exist on a subset of events, so they raise AttributeError if | ||||||
| # someone tries to get them when they don't exist. | ||||||
|
|
@@ -269,6 +273,9 @@ async def build( | |||||
| if self._origin_server_ts is not None: | ||||||
| event_dict["origin_server_ts"] = self._origin_server_ts | ||||||
|
|
||||||
| if self.sticky is not None: | ||||||
| event_dict[StickyEvent.EVENT_FIELD_NAME] = self.sticky | ||||||
|
|
||||||
| return create_local_event_from_event_dict( | ||||||
| clock=self._clock, | ||||||
| hostname=self._hostname, | ||||||
|
|
@@ -318,6 +325,7 @@ def for_room_version( | |||||
| unsigned=key_values.get("unsigned", {}), | ||||||
| redacts=key_values.get("redacts", None), | ||||||
| origin_server_ts=key_values.get("origin_server_ts", None), | ||||||
| sticky=key_values.get(StickyEvent.EVENT_FIELD_NAME, None), | ||||||
| ) | ||||||
|
|
||||||
|
|
||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -763,3 +763,48 @@ async def _update_function( | |
| return [], to_token, False | ||
|
|
||
| return rows, rows[-1][0], len(updates) == limit | ||
|
|
||
|
|
||
| @attr.s(slots=True, auto_attribs=True) | ||
| class StickyEventsStreamRow: | ||
| """Stream to inform workers about changes to sticky events.""" | ||
|
Comment on lines
+769
to
+770
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For my own reference, dev notes on creating a new stream: |
||
|
|
||
| room_id: str | ||
|
|
||
| event_id: str | ||
| """The sticky event ID""" | ||
|
|
||
|
|
||
| class StickyEventsStream(_StreamFromIdGen): | ||
| """A sticky event was changed.""" | ||
|
|
||
| NAME = "sticky_events" | ||
| ROW_TYPE = StickyEventsStreamRow | ||
|
|
||
| def __init__(self, hs: "HomeServer"): | ||
| self.store = hs.get_datastores().main | ||
| super().__init__( | ||
| hs.get_instance_name(), | ||
| self._update_function, | ||
| self.store._sticky_events_id_gen, | ||
| ) | ||
|
|
||
| async def _update_function( | ||
| self, instance_name: str, from_token: int, to_token: int, limit: int | ||
| ) -> StreamUpdateResult: | ||
| updates = await self.store.get_updated_sticky_events( | ||
| from_id=from_token, to_id=to_token, limit=limit | ||
| ) | ||
| rows = [ | ||
| ( | ||
| update.stream_id, | ||
| # These are the args to `StickyEventsStreamRow` | ||
| (update.room_id, update.event_id), | ||
| ) | ||
| for update in updates | ||
| ] | ||
|
|
||
| if not rows: | ||
| return [], to_token, False | ||
|
|
||
| return rows, rows[-1][0], len(updates) == limit | ||
Uh oh!
There was an error while loading. Please reload this page.