Refactor to async closures.
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
@@ -526,7 +526,7 @@ where
|
||||
|
||||
let mut futures: FuturesUnordered<_> = get_over_federation
|
||||
.into_iter()
|
||||
.map(|(server, vec)| async move {
|
||||
.map(async |(server, vec)| {
|
||||
let mut device_keys_input_fed = BTreeMap::new();
|
||||
for (user_id, keys) in vec {
|
||||
device_keys_input_fed.insert(user_id.to_owned(), keys.clone());
|
||||
@@ -656,7 +656,7 @@ pub(crate) async fn claim_keys_helper(
|
||||
|
||||
let mut futures: FuturesUnordered<_> = get_over_federation
|
||||
.into_iter()
|
||||
.map(|(server, vec)| async move {
|
||||
.map(async |(server, vec)| {
|
||||
let mut one_time_keys_input_fed = BTreeMap::new();
|
||||
for (user_id, keys) in vec {
|
||||
one_time_keys_input_fed.insert(user_id.clone(), keys.clone());
|
||||
|
||||
@@ -550,7 +550,7 @@ async fn join_room_by_id_helper_remote(
|
||||
.validate_and_add_event_id_no_fetch(pdu, &room_version_id)
|
||||
})
|
||||
.ready_filter_map(Result::ok)
|
||||
.fold(HashMap::new(), |mut state, (event_id, value)| async move {
|
||||
.fold(HashMap::new(), async |mut state, (event_id, value)| {
|
||||
let pdu = match PduEvent::from_id_val(&event_id, value.clone()) {
|
||||
| Ok(pdu) => pdu,
|
||||
| Err(e) => {
|
||||
|
||||
@@ -85,7 +85,7 @@ pub(crate) async fn joined_members_route(
|
||||
.state_cache
|
||||
.room_members(&body.room_id)
|
||||
.map(ToOwned::to_owned)
|
||||
.broad_then(|user_id| async move {
|
||||
.broad_then(async |user_id| {
|
||||
let (display_name, avatar_url) = join(
|
||||
services.users.displayname(&user_id).ok(),
|
||||
services.users.avatar_url(&user_id).ok(),
|
||||
|
||||
@@ -151,9 +151,7 @@ pub(crate) async fn get_message_events_route(
|
||||
.map(IterStream::stream)
|
||||
.into_stream()
|
||||
.flatten()
|
||||
.broad_filter_map(|user_id| async move {
|
||||
get_member_event(&services, room_id, &user_id).await
|
||||
})
|
||||
.broad_filter_map(async |user_id| get_member_event(&services, room_id, &user_id).await)
|
||||
.collect()
|
||||
.await;
|
||||
|
||||
|
||||
@@ -350,7 +350,7 @@ pub async fn update_displayname(
|
||||
let all_joined_rooms: Vec<_> = all_joined_rooms
|
||||
.iter()
|
||||
.try_stream()
|
||||
.and_then(|room_id: &OwnedRoomId| async move {
|
||||
.and_then(async |room_id: &OwnedRoomId| {
|
||||
let pdu = PduBuilder::state(user_id.to_string(), &RoomMemberEventContent {
|
||||
displayname: displayname.clone(),
|
||||
membership: MembershipState::Join,
|
||||
@@ -403,7 +403,7 @@ pub async fn update_avatar_url(
|
||||
let all_joined_rooms: Vec<_> = all_joined_rooms
|
||||
.iter()
|
||||
.try_stream()
|
||||
.and_then(|room_id: &OwnedRoomId| async move {
|
||||
.and_then(async |room_id: &OwnedRoomId| {
|
||||
let pdu = PduBuilder::state(user_id.to_string(), &RoomMemberEventContent {
|
||||
avatar_url: avatar_url.clone(),
|
||||
blurhash: blurhash.clone(),
|
||||
|
||||
@@ -95,13 +95,13 @@ async fn category_room_events(
|
||||
});
|
||||
|
||||
let results: Vec<_> = rooms
|
||||
.filter_map(|room_id| async move {
|
||||
.filter_map(async |room_id| {
|
||||
check_room_visible(services, sender_user, &room_id, criteria)
|
||||
.await
|
||||
.is_ok()
|
||||
.then_some(room_id)
|
||||
})
|
||||
.filter_map(|room_id| async move {
|
||||
.filter_map(async |room_id| {
|
||||
let query = RoomQuery {
|
||||
room_id: &room_id,
|
||||
user_id: Some(sender_user),
|
||||
@@ -135,7 +135,7 @@ async fn category_room_events(
|
||||
.iter()
|
||||
.stream()
|
||||
.ready_filter(|_| criteria.include_state.is_some_and(is_true!()))
|
||||
.filter_map(|(room_id, ..)| async move {
|
||||
.filter_map(async |(room_id, ..)| {
|
||||
procure_room_state(services, room_id)
|
||||
.map_ok(|state| (room_id.clone(), state))
|
||||
.await
|
||||
|
||||
@@ -166,7 +166,7 @@ where
|
||||
|
||||
let next_batch: OptionFuture<_> = queue
|
||||
.pop_front()
|
||||
.map(|(room, _)| async move {
|
||||
.map(async |(room, _)| {
|
||||
parents.insert(room);
|
||||
|
||||
let next_short_room_ids: Vec<_> = parents
|
||||
|
||||
@@ -75,7 +75,7 @@ async fn share_encrypted_room(
|
||||
.get_shared_rooms(sender_user, user_id)
|
||||
.ready_filter(|&room_id| Some(room_id) != ignore_room)
|
||||
.map(ToOwned::to_owned)
|
||||
.broad_any(|other_room_id| async move {
|
||||
.broad_any(async |other_room_id| {
|
||||
services
|
||||
.rooms
|
||||
.state_accessor
|
||||
|
||||
@@ -237,7 +237,7 @@ pub(crate) async fn build_sync_events(
|
||||
.rooms
|
||||
.state_cache
|
||||
.rooms_invited(sender_user)
|
||||
.fold_default(|mut invited_rooms: BTreeMap<_, _>, (room_id, invite_state)| async move {
|
||||
.fold_default(async |mut invited_rooms: BTreeMap<_, _>, (room_id, invite_state)| {
|
||||
let invite_count = services
|
||||
.rooms
|
||||
.state_cache
|
||||
@@ -262,7 +262,7 @@ pub(crate) async fn build_sync_events(
|
||||
.rooms
|
||||
.state_cache
|
||||
.rooms_knocked(sender_user)
|
||||
.fold_default(|mut knocked_rooms: BTreeMap<_, _>, (room_id, knock_state)| async move {
|
||||
.fold_default(async |mut knocked_rooms: BTreeMap<_, _>, (room_id, knock_state)| {
|
||||
let knock_count = services
|
||||
.rooms
|
||||
.state_cache
|
||||
@@ -334,7 +334,7 @@ pub(crate) async fn build_sync_events(
|
||||
let device_list_left: HashSet<_> = left_encrypted_users
|
||||
.into_iter()
|
||||
.stream()
|
||||
.broad_filter_map(|user_id| async move {
|
||||
.broad_filter_map(async |user_id: OwnedUserId| {
|
||||
share_encrypted_room(services, sender_user, &user_id, None)
|
||||
.await
|
||||
.eq(&false)
|
||||
@@ -620,7 +620,7 @@ async fn load_joined_room(
|
||||
.rooms
|
||||
.read_receipt
|
||||
.readreceipts_since(room_id, since)
|
||||
.filter_map(|(read_user, _, edu)| async move {
|
||||
.filter_map(async |(read_user, _, edu)| {
|
||||
services
|
||||
.users
|
||||
.user_is_ignored(read_user, sender_user)
|
||||
@@ -806,7 +806,7 @@ async fn load_joined_room(
|
||||
.rooms
|
||||
.typing
|
||||
.last_typing_update(room_id)
|
||||
.and_then(|count| async move {
|
||||
.and_then(async |count| {
|
||||
if count <= since {
|
||||
return Ok(Vec::<Raw<AnySyncEphemeralRoomEvent>>::new());
|
||||
}
|
||||
@@ -1124,8 +1124,9 @@ async fn calculate_state_incremental<'a>(
|
||||
.fold_default(|(mut dlu, mut leu): pair_of!(HashSet<_>), (content, user_id)| async move {
|
||||
use MembershipState::*;
|
||||
|
||||
let shares_encrypted_room =
|
||||
|user_id| share_encrypted_room(services, sender_user, user_id, Some(room_id));
|
||||
let shares_encrypted_room = async |user_id| {
|
||||
share_encrypted_room(services, sender_user, user_id, Some(room_id)).await
|
||||
};
|
||||
|
||||
match content.membership {
|
||||
| Leave => leu.insert(user_id),
|
||||
|
||||
@@ -470,7 +470,7 @@ where
|
||||
.rooms
|
||||
.read_receipt
|
||||
.readreceipts_since(room_id, *roomsince)
|
||||
.filter_map(|(read_user, _ts, v)| async move {
|
||||
.filter_map(async |(read_user, _ts, v)| {
|
||||
services
|
||||
.users
|
||||
.user_is_ignored(read_user, sender_user)
|
||||
@@ -548,7 +548,7 @@ where
|
||||
let required_state = required_state_request
|
||||
.iter()
|
||||
.stream()
|
||||
.filter_map(|state| async move {
|
||||
.filter_map(async |state| {
|
||||
services
|
||||
.rooms
|
||||
.state_accessor
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use axum::extract::State;
|
||||
use futures::StreamExt;
|
||||
use futures::{StreamExt, TryStreamExt};
|
||||
use ruma::{api::client::threads::get_threads, uint};
|
||||
use tuwunel_core::{
|
||||
Result, at,
|
||||
@@ -35,18 +35,17 @@ pub(crate) async fn get_threads_route(
|
||||
.rooms
|
||||
.threads
|
||||
.threads_until(body.sender_user(), &body.room_id, from, &body.include)
|
||||
.await?
|
||||
.take(limit)
|
||||
.filter_map(|(count, pdu)| async move {
|
||||
services
|
||||
.try_filter_map(async |(count, pdu)| {
|
||||
Ok(services
|
||||
.rooms
|
||||
.state_accessor
|
||||
.user_can_see_event(body.sender_user(), &body.room_id, &pdu.event_id)
|
||||
.await
|
||||
.then_some((count, pdu))
|
||||
.then_some((count, pdu)))
|
||||
})
|
||||
.collect()
|
||||
.await;
|
||||
.try_collect()
|
||||
.await?;
|
||||
|
||||
Ok(get_threads::v1::Response {
|
||||
next_batch: threads
|
||||
|
||||
Reference in New Issue
Block a user