Skip to content

Commit

Permalink
Merge pull request #837 from johannescpk/appservice/refactor-cleanup
Browse files Browse the repository at this point in the history
refactor(appservice)!: Improve API and cleanup docs
  • Loading branch information
gnunicorn authored Jul 13, 2022
2 parents 9a45325 + ec00af0 commit 15e22cb
Show file tree
Hide file tree
Showing 6 changed files with 397 additions and 409 deletions.
8 changes: 5 additions & 3 deletions crates/matrix-sdk-appservice/examples/appservice_autojoin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub async fn handle_room_member(
error_if_user_not_in_use(error)?;
}

let client = appservice.virtual_user_client(user_id.localpart()).await?;
let client = appservice.virtual_user(Some(user_id.localpart())).await?;
client.join_room_by_id(room.room_id()).await?;
}

Expand Down Expand Up @@ -61,15 +61,17 @@ pub async fn main() -> Result<(), Box<dyn std::error::Error>> {
let appservice = AppService::new(homeserver_url, server_name, registration).await?;
appservice.register_user_query(Box::new(|_, _| Box::pin(async { true }))).await;
appservice
.register_event_handler_context(appservice.clone())?
.virtual_user(None)
.await?
.register_event_handler_context(appservice.clone())
.register_event_handler(
move |event: OriginalSyncRoomMemberEvent,
room: Room,
Ctx(appservice): Ctx<AppService>| {
handle_room_member(appservice, room, event)
},
)
.await?;
.await;

let (host, port) = appservice.registration().get_host_and_port()?;
appservice.run(host, port).await?;
Expand Down
14 changes: 14 additions & 0 deletions crates/matrix-sdk-appservice/src/event_handler.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright 2022 Famedly GmbH
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

use std::{future::Future, pin::Pin, sync::Arc};

use matrix_sdk::locks::Mutex;
Expand Down
Loading

0 comments on commit 15e22cb

Please sign in to comment.