Redacted events: Use Any*Event enums for redacted events#114
Conversation
Add the needed event content types for the 5 state events that have a content field. Create full, stub and stripped versions of state events and full and stub versions of message event structs. Uncomment and fix redacted event tests.
It definitely helps, no worries! |
jplatte
left a comment
There was a problem hiding this comment.
First impressions are positive ^^
Add two ruma_event attributes to optionally emit the redacted event code. Conditionally generate a unit struct to represent the redacted events content.
c6720a9 to
e373be7
Compare
All redacted event code is now generated by the *EventContent derive macro. The exception are any content structs with the custom_redaction attribute. This leaves implementing up to the user.
|
I think I mentioned this before, but the (currently only) case I actually think we should have |
|
We also need
You have said that before but a good reminder, I was thinking that implementations could redact their own made-up events but this can't actually happen can it (a server has no way to know what a client is up to and vice-versa)? If the only reason we have custom redacted events is aliases should we maybe remove the custom and add a I'll start working on the |
This PR is already quite big, let's do this separately.
I don't understand what you mean, can you expand on that?
Again not sure what you mean, sorry 😅
I don't fully understand what your idea is here, but if you want, try it out. |
According to spec the redaction event should be inserted into the enum AnyRedactionEvent {
Full(RedactionEvent),
Stub(RedactionEventStub),
// stripped if needed
}
// then
struct UnsignedData {
redacted_because: Option<AnyRedactionEvent>,
}
I see now you weren't misunderstanding I read your comment completely wrong you were just talking about the attribute not custom events in general. So disregard that paragraph. |
I see! I guess the spec could be clearer about this. It definitely makes sense in my mind that |
The *EventContent derive now generates the RedactedEventContent and EventContent trait implementations.
Rename RedactedEventContent::redacted -> empty
642fed7 to
3825e40
Compare
|
Ah sorry about that I squashed a commit the wrong way, I should have squashed the last one into the one I ended up squashing. oldest commit
middle // I squashed this into the commit above it
new // I should have squashed this and rewrote the commit? |
jplatte
left a comment
There was a problem hiding this comment.
So the only missing thing now is the aliases field for RedactedAliasesEventContent and corresponding RedactedEventContent implementation changes, right?
jplatte
left a comment
There was a problem hiding this comment.
So I did another full review and found a few more issues 😅
|
|
||
| /// A stripped-down redacted state event. | ||
| #[derive(Clone, Debug, Event)] | ||
| pub struct RedactedStrippedStateEventStub<C: RedactedStateEventContent> { |
There was a problem hiding this comment.
Is there supposed to also be StrippedStateEvent? If so there is no regular event struct for this either.
There was a problem hiding this comment.
Oh, right. 😄
Yeah no, stripped state events are only ever received as part of the sync response ^^
There was a problem hiding this comment.
So I don't need to change anything right?
| /// Any state event stub that has been redacted. | ||
| RedactedState(AnyRedactedStateEventStub), | ||
| } | ||
|
|
There was a problem hiding this comment.
Maybe something for a followup PR too, but we do now need enums over AnyStateEvent | AnyRedactedStateEvent, AnyStateEventStub | AnyRedactedStateEventStub and AnyStrippedStateEventStub | AnyRedactedStrippedStateEventStub. Maybe we actually need to use a Regular prefix for the generated Message and State enums and reuse their previous named for these new enums.
There was a problem hiding this comment.
I think the rename makes sense. Probably be best to do it as a new PR, and maybe after the format_ident and fixing of the brittle enum name generation (fixing this stuff ident.to_string().replace... and making the event_enum! macro only take certain name/kind: Message)?
Sorry if opening all these is annoying, implementing it even if it's a bit off is the best way for me to understand something and I'm hoping having something to see and talk about helps everyone.
commit 1: Add most of the logic to generate the correct AnyRedactedEvent enums.
commit 2: Add the needed event content types for the 5 state events that have a content field. Create full, stub, and stripped versions of state events and full and stub versions of message event structs. Uncomment and fix redacted event tests.