fix(state-accessor): hold the state_lock when checking if a user can invite
This commit is contained in:
parent
7ace9b0dff
commit
e40aed3a7d
1 changed files with 3 additions and 12 deletions
|
@ -21,6 +21,7 @@ use ruma::{
|
||||||
EventId, JsOption, OwnedServerName, OwnedUserId, RoomId, ServerName, UserId,
|
EventId, JsOption, OwnedServerName, OwnedUserId, RoomId, ServerName, UserId,
|
||||||
};
|
};
|
||||||
use serde_json::value::to_raw_value;
|
use serde_json::value::to_raw_value;
|
||||||
|
use tokio::sync::MutexGuard;
|
||||||
use tracing::{error, warn};
|
use tracing::{error, warn};
|
||||||
|
|
||||||
use crate::{service::pdu::PduBuilder, services, Error, PduEvent, Result};
|
use crate::{service::pdu::PduBuilder, services, Error, PduEvent, Result};
|
||||||
|
@ -309,6 +310,7 @@ impl Service {
|
||||||
room_id: &RoomId,
|
room_id: &RoomId,
|
||||||
sender: &UserId,
|
sender: &UserId,
|
||||||
target_user: &UserId,
|
target_user: &UserId,
|
||||||
|
state_lock: &MutexGuard<'_, ()>,
|
||||||
) -> Result<bool> {
|
) -> Result<bool> {
|
||||||
let content = to_raw_value(&RoomMemberEventContent::new(MembershipState::Invite))
|
let content = to_raw_value(&RoomMemberEventContent::new(MembershipState::Invite))
|
||||||
.expect("Event content always serializes");
|
.expect("Event content always serializes");
|
||||||
|
@ -321,21 +323,10 @@ impl Service {
|
||||||
redacts: None,
|
redacts: None,
|
||||||
};
|
};
|
||||||
|
|
||||||
let mutex_state = Arc::clone(
|
|
||||||
services()
|
|
||||||
.globals
|
|
||||||
.roomid_mutex_state
|
|
||||||
.write()
|
|
||||||
.await
|
|
||||||
.entry(room_id.to_owned())
|
|
||||||
.or_default(),
|
|
||||||
);
|
|
||||||
let state_lock = mutex_state.lock().await;
|
|
||||||
|
|
||||||
Ok(services()
|
Ok(services()
|
||||||
.rooms
|
.rooms
|
||||||
.timeline
|
.timeline
|
||||||
.create_hash_and_sign_event(new_event, sender, room_id, &state_lock)
|
.create_hash_and_sign_event(new_event, sender, room_id, state_lock)
|
||||||
.is_ok())
|
.is_ok())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue