-
Notifications
You must be signed in to change notification settings - Fork 246
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
feat: appservice #204
feat: appservice #204
Conversation
65032fb
to
5e62867
Compare
90593fe
to
18ea98a
Compare
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.
Generally this looks really neat. I know this is an initial version but I pointed out that we should be a bit better with the docs anyways.
I need to double check if it's ok to have a crate in the repo that I'm technically not maintaining myself, and after we fix those couple small nits we can merge this.
matrix_sdk/src/http_client.rs
Outdated
// this should be unreachable since assert_identity on request_config can only be set | ||
// with the appservice feature active | ||
#[cfg(not(feature = "appservice"))] | ||
return Err(HttpError::NeedsAppserviceFeature); |
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.
Hmm it feels a bit wrong to have an error that never gets returned. Can't we restructure that somehow so we don't need this error?
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.
Changed to cfg
-based feature-switch, also allows restricting all assert_identity
things to the appservice feature. The catch here is that because of crate-interdependence currently the appservice
feature seems to be always enabled when running commands in the crate root. So cargo test
in the root will run with the appservice
feature in matrix-sdk
active. Something we could do is running cargo test --workspace --exclude matrix-sdk-appservice
in CI and the appservice tests with an additional command? I'll open a PR to rework the test-features
CI pipeline and try how that would look.
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.
I've integrated the CI changes here directly, with #226 being a possible cleanup to reduce CI time
|
||
/// Appservice | ||
#[derive(Debug, Clone)] | ||
pub struct Appservice { |
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.
Don't we want to put at least some of those behind an Arc
? The Client
already is but the registration
might end up being quite big and costly to clone, no (I have no idea how big those files might end up being)?
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.
Good point. I'll check which Arc
-strategy would make sense and would work on that preferably in a follow-up: Noted in the Todos, will move them into a tracking issue if landing should happen after your double check.
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.
Since they are read-only I think we can just put them inside an Arc
and we're good to go, no?
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.
Right, probably doesn't need a lock 👍
18ea98a
to
8709967
Compare
@@ -37,6 +43,7 @@ | |||
//! .unwrap(); | |||
//! | |||
//! let appservice = Appservice::new(homeserver_url, server_name, registration).await.unwrap(); | |||
//! // set event handler with `appservice.client().set_event_handler()` here |
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.
Plan is to refactor that into a compiling run_with_callback
example instead and commenting that with "using event handler is also available", since constructing an event handler for the quick start is a bit heavy
7c74840
to
325531d
Compare
eb876e3
to
d9453b4
Compare
d9453b4
to
a2125ad
Compare
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.
I think this is fine to merge, that is if you want to take care of the rest of the TODOs and the Arc
ing in separate PRs.
|
||
/// Appservice | ||
#[derive(Debug, Clone)] | ||
pub struct Appservice { |
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.
Since they are read-only I think we can just put them inside an Arc
and we're good to go, no?
Thanks for the feedback so far!
Yeah, I'd definitely continue working on it. If you prefer I could do it in this PR as well, but otherwise with tracking issue & follow-up PRs. Also if you think at some point that it might make sense to externalize the crate, feel free to let me know |
No, let's merge. Smaller PRs are way easier to review |
Follow-up tracking issue: #228
Todo
/sync
for every virtual userclient_with_localpart
toclient_with_identity_assertion
get_host_and_port_from_registration
intoAppserviceRegistration::get_host_and_port
run_with_callback(sync_response: SyncResponse)
cargo test --exclude matrix_sdk_appservice
to work around unwantedappservice
feature-activation in the main crate: that would allow to get rid of feat: appservice #204 (comment). The issue here is that it'd no longer be possible to justcargo test
in the workspace rootInnerAppservice
forArc
-purposes, or singleArc
s for member fields (from feat: appservice #204 (comment))new
for appservice scopedIncomingRequest
s in ruma (behindincoming-ctors
feature) so we can get rid of activating theunstable-exhaustive-types
featureappservice
feature is enabled, it currently breaks things as the tests rely on mockito URL matching, and the appservice feature appends the user_id query GET parameter. Possible solution: Add something likeassert_identity: bool
to theRequestConfig
instead of changing the behavior based on the feature flagThe general idea is that incoming appservice transactions from the homeserver are translated into an
api::client::r0::sync::sync_events::Response
and then passed intoreceive_sync_response
.The user associated with the client
Session
is the "main appservice user" (sender_localpart
in the registration). This allows for the state store to properly propagated and an API surface similar to a regular client while still handling most events coming in over transactions:This draft only handles
AnyStateEvent::RoomMember
withMembershipState::Join
for now. If the general direction sounds like something you'd consider supporting I'd keep completing the approach.There's also support in ruma now to assign
user_id
s toOutgoingRequest
s, so another API surface that I'd like to add is something likeappservice.client_with_user_id()
which returns a client that attaches the given user_id to all requests.Another topic is whether the SDK wants to expose the actual webserver that receives HTTP requests from the homeserver. Currently there's only an actix example included, but it could be considered to expose it behind a feature flag like
appservice-actix
or something.And finally, this isn't E2EE-ready. I guess it would need a crypto store instance for every virtual appservice user.