Fix sliding-sync room_avatar conditions.
Eliminate jsOption from non-sliding-sync avatar related codepaths. Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
@@ -405,7 +405,11 @@ async fn public_rooms_chunk(services: &Services, room_id: OwnedRoomId) -> Public
|
||||
.get_canonical_alias(&room_id)
|
||||
.ok();
|
||||
|
||||
let avatar_url = services.state_accessor.get_avatar(&room_id);
|
||||
let avatar_url = services
|
||||
.state_accessor
|
||||
.get_avatar(&room_id)
|
||||
.map_ok(|content| content.url)
|
||||
.ok();
|
||||
|
||||
let topic = services
|
||||
.state_accessor
|
||||
@@ -441,7 +445,7 @@ async fn public_rooms_chunk(services: &Services, room_id: OwnedRoomId) -> Public
|
||||
.await;
|
||||
|
||||
PublicRoomsChunk {
|
||||
avatar_url: avatar_url.into_option().unwrap_or_default().url,
|
||||
avatar_url: avatar_url.flatten(),
|
||||
canonical_alias,
|
||||
guest_can_join,
|
||||
join_rule: join_rule.unwrap_or_default(),
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use axum::extract::State;
|
||||
use axum_client_ip::InsecureClientIp;
|
||||
use futures::{
|
||||
FutureExt, StreamExt,
|
||||
FutureExt, StreamExt, TryFutureExt,
|
||||
future::{OptionFuture, join3},
|
||||
stream::FuturesUnordered,
|
||||
};
|
||||
@@ -142,7 +142,9 @@ async fn local_room_summary_response(
|
||||
let avatar_url = services
|
||||
.state_accessor
|
||||
.get_avatar(room_id)
|
||||
.map(|res| res.into_option().unwrap_or_default().url);
|
||||
.map_ok(|content| content.url)
|
||||
.ok()
|
||||
.map(Option::flatten);
|
||||
|
||||
let room_version = services.state.get_room_version(room_id).ok();
|
||||
|
||||
|
||||
@@ -612,24 +612,26 @@ where
|
||||
| Ordering::Less => None,
|
||||
};
|
||||
|
||||
let heroes_avatar = if heroes.len() == 1 {
|
||||
heroes[0].avatar.clone()
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let room_avatar = services
|
||||
.state_accessor
|
||||
.get_avatar(room_id)
|
||||
.map_ok(|content| content.url)
|
||||
.ok()
|
||||
.map(Option::flatten)
|
||||
.await;
|
||||
|
||||
let room_avatar = match services.state_accessor.get_avatar(room_id).await {
|
||||
| ruma::JsOption::Some(avatar) => ruma::JsOption::from_option(avatar.url),
|
||||
| ruma::JsOption::Null => ruma::JsOption::Null,
|
||||
| ruma::JsOption::Undefined => ruma::JsOption::Undefined,
|
||||
};
|
||||
let heroes_avatar = (room_avatar.is_none() && room_name.is_none())
|
||||
.then(|| {
|
||||
heroes
|
||||
.first()
|
||||
.and_then(|hero| hero.avatar.clone())
|
||||
})
|
||||
.flatten();
|
||||
|
||||
let avatar = ruma::JsOption::from_option(room_avatar.or(heroes_avatar));
|
||||
|
||||
rooms.insert(room_id.clone(), sync_events::v5::response::Room {
|
||||
avatar: if room_name.is_some() {
|
||||
room_avatar
|
||||
} else {
|
||||
ruma::JsOption::from_option(heroes_avatar)
|
||||
},
|
||||
avatar,
|
||||
name: room_name.or(hero_name),
|
||||
initial: Some(roomsince == &0),
|
||||
is_dm: None,
|
||||
|
||||
@@ -360,7 +360,8 @@ async fn get_room_summary(
|
||||
.services
|
||||
.state_accessor
|
||||
.get_avatar(room_id)
|
||||
.map(|res| res.into_option().unwrap_or_default().url);
|
||||
.map_ok(|content| content.url)
|
||||
.ok();
|
||||
|
||||
let room_version = self.services.state.get_room_version(room_id).ok();
|
||||
|
||||
@@ -397,12 +398,12 @@ async fn get_room_summary(
|
||||
let summary = SpaceHierarchyParentSummary {
|
||||
children_state,
|
||||
summary: RoomSummary {
|
||||
avatar_url: avatar_url.flatten(),
|
||||
canonical_alias,
|
||||
name,
|
||||
topic,
|
||||
world_readable,
|
||||
guest_can_join,
|
||||
avatar_url,
|
||||
room_type,
|
||||
encryption,
|
||||
room_version,
|
||||
|
||||
@@ -8,7 +8,7 @@ use std::sync::Arc;
|
||||
use async_trait::async_trait;
|
||||
use futures::{FutureExt, TryFutureExt, future::try_join};
|
||||
use ruma::{
|
||||
EventEncryptionAlgorithm, JsOption, OwnedRoomAliasId, RoomId, UserId,
|
||||
EventEncryptionAlgorithm, OwnedRoomAliasId, RoomId, UserId,
|
||||
events::{
|
||||
StateEventType,
|
||||
room::{
|
||||
@@ -88,13 +88,9 @@ impl Service {
|
||||
.map(|c: RoomNameEventContent| c.name)
|
||||
}
|
||||
|
||||
pub async fn get_avatar(&self, room_id: &RoomId) -> JsOption<RoomAvatarEventContent> {
|
||||
let content = self
|
||||
.room_state_get_content(room_id, &StateEventType::RoomAvatar, "")
|
||||
pub async fn get_avatar(&self, room_id: &RoomId) -> Result<RoomAvatarEventContent> {
|
||||
self.room_state_get_content(room_id, &StateEventType::RoomAvatar, "")
|
||||
.await
|
||||
.ok();
|
||||
|
||||
JsOption::from_option(content)
|
||||
}
|
||||
|
||||
pub async fn get_member(
|
||||
|
||||
Reference in New Issue
Block a user