mirror of
https://github.com/matrix-org/matrix-rust-sdk.git
synced 2026-05-06 23:15:08 -04:00
base: Use member event is_direct field for is_direct() on invited rooms
This commit is contained in:
committed by
Jonas Platte
parent
be67c91a6b
commit
fe10bcc814
@@ -59,7 +59,7 @@ impl Room {
|
||||
}
|
||||
|
||||
pub fn is_direct(&self) -> bool {
|
||||
self.room.is_direct()
|
||||
RUNTIME.block_on(async move { self.room.is_direct().await.unwrap_or(false) })
|
||||
}
|
||||
|
||||
pub fn is_public(&self) -> bool {
|
||||
|
||||
@@ -37,10 +37,11 @@ use ruma::{
|
||||
RoomVersionId, UserId,
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use tracing::debug;
|
||||
use tracing::{debug, info, instrument, warn};
|
||||
|
||||
use super::{BaseRoomInfo, DisplayName, RoomMember};
|
||||
use crate::{
|
||||
deserialized_responses::MemberEvent,
|
||||
store::{DynStateStore, Result as StoreResult, StateStoreExt},
|
||||
sync::UnreadNotificationsCount,
|
||||
MinimalStateEvent,
|
||||
@@ -207,8 +208,32 @@ impl Room {
|
||||
}
|
||||
|
||||
/// Is this room considered a direct message.
|
||||
pub fn is_direct(&self) -> bool {
|
||||
!self.inner.read().unwrap().base_info.dm_targets.is_empty()
|
||||
#[instrument(skip_all, fields(room_id = ?self.room_id))]
|
||||
pub async fn is_direct(&self) -> StoreResult<bool> {
|
||||
match self.state() {
|
||||
RoomState::Joined | RoomState::Left => {
|
||||
Ok(!self.inner.read().unwrap().base_info.dm_targets.is_empty())
|
||||
}
|
||||
RoomState::Invited => {
|
||||
let member = self.get_member(self.own_user_id()).await?;
|
||||
|
||||
match member {
|
||||
None => {
|
||||
info!("RoomMember not found for the user's own id");
|
||||
Ok(false)
|
||||
}
|
||||
Some(member) => match member.event.as_ref() {
|
||||
MemberEvent::Sync(_) => {
|
||||
warn!("Got MemberEvent::Sync in an invited room");
|
||||
Ok(false)
|
||||
}
|
||||
MemberEvent::Stripped(event) => {
|
||||
Ok(event.content.is_direct.unwrap_or(false))
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// If this room is a direct message, get the members that we're sharing the
|
||||
|
||||
Reference in New Issue
Block a user