- 
                Notifications
    You must be signed in to change notification settings 
- Fork 406
MSC4354: Sticky Events #18968
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?
MSC4354: Sticky Events #18968
Changes from all commits
abf658c
              8699534
              7801e68
              e01a22b
              3e7a5a6
              7af7429
              0cfdd0d
              7c8daf4
              ac0f8c2
              1e812e4
              2728b21
              666e94b
              771692a
              ad6a2b9
              33d80be
              148caef
              de3e9b4
              105d2cd
              651e829
              4acc98d
              78c4097
              15453d4
              aa45bf7
              888ab79
              aac3c84
              075312c
              7f1e057
              58bf128
              686ce52
              4def404
              adb601b
              b1af5fe
              f0689ce
              b2c967f
              4d02a4c
              a4cac85
              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 @@ | ||
| Implement support for MSC4354: Sticky Events. | 
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
|  | @@ -195,6 +195,8 @@ async def _check_sigs_and_hash( | |
| # using the event in prev_events). | ||
| redacted_event = prune_event(pdu) | ||
| redacted_event.internal_metadata.soft_failed = True | ||
| # Mark this as spam so we don't re-evaluate soft-failure status. | ||
| redacted_event.internal_metadata.policy_server_spammy = True | ||
| 
      Comment on lines
    
      +198
     to 
      +199
    
   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. Seems unrelated to sticky events 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. It's related because spam is currently flagged in Synapse via soft-failure, and sometimes via  | ||
| return redacted_event | ||
|  | ||
| return pdu | ||
|  | ||
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
|  | @@ -17,7 +17,7 @@ | |
|  | ||
| from twisted.internet.interfaces import IDelayedCall | ||
|  | ||
| from synapse.api.constants import EventTypes | ||
| from synapse.api.constants import EventTypes, StickyEvent | ||
| from synapse.api.errors import ShadowBanError, SynapseError | ||
| from synapse.api.ratelimiting import Ratelimiter | ||
| from synapse.config.workers import MAIN_PROCESS_INSTANCE_NAME | ||
|  | @@ -331,6 +331,7 @@ async def add( | |
| origin_server_ts: Optional[int], | ||
| content: JsonDict, | ||
| delay: int, | ||
| sticky_duration_ms: Optional[int], | ||
| ) -> str: | ||
| """ | ||
| Creates a new delayed event and schedules its delivery. | ||
|  | @@ -344,7 +345,7 @@ async def add( | |
| If None, the timestamp will be the actual time when the event is sent. | ||
| content: The content of the event to be sent. | ||
| delay: How long (in milliseconds) to wait before automatically sending the event. | ||
|  | ||
| sticky_duration_ms: The sticky duration if any, see MSC4354. | ||
| 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 think this could be expanded a bit to explain what it means without having to look at MSC4354. I have to make a lot of assumptions otherwise. "Time since xxx that the event should appear in xxx" | ||
| Returns: The ID of the added delayed event. | ||
|  | ||
| Raises: | ||
|  | @@ -380,6 +381,7 @@ async def add( | |
| origin_server_ts=origin_server_ts, | ||
| content=content, | ||
| delay=delay, | ||
| sticky_duration_ms=sticky_duration_ms, | ||
| ) | ||
|  | ||
| if self._repl_client is not None: | ||
|  | @@ -487,6 +489,7 @@ async def send(self, requester: Requester, delay_id: str) -> None: | |
| origin_server_ts=event.origin_server_ts, | ||
| content=event.content, | ||
| device_id=event.device_id, | ||
| sticky_duration_ms=event.sticky_duration_ms, | ||
| ) | ||
| ) | ||
|  | ||
|  | @@ -596,7 +599,10 @@ async def _send_event( | |
|  | ||
| if event.state_key is not None: | ||
| event_dict["state_key"] = event.state_key | ||
|  | ||
| if event.sticky_duration_ms is not None: | ||
| event_dict[StickyEvent.FIELD_NAME] = { | ||
| "duration_ms": event.sticky_duration_ms, | ||
| } | ||
| ( | ||
| sent_event, | ||
| _, | ||
|  | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be good to add a docstring to indicate where this is from and what's used for.