Skip to content

Commit e254011

Browse files
committed
feat(sdk): Add SendStateEvent
Signed-off-by: Skye Elliot <[email protected]>
1 parent 58fda8c commit e254011

File tree

1 file changed

+36
-2
lines changed

1 file changed

+36
-2
lines changed

crates/matrix-sdk/src/room/futures.rs

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
1717
#![deny(unreachable_pub)]
1818

19-
use std::future::IntoFuture;
19+
use std::{borrow::Borrow, future::IntoFuture};
2020

2121
use eyeball::SharedObservable;
2222
use matrix_sdk_common::boxed_into_future;
@@ -26,7 +26,10 @@ use ruma::events::{MessageLikeUnsigned, SyncMessageLikeEvent};
2626
use ruma::{
2727
api::client::{message::send_message_event, state::send_state_event},
2828
assign,
29-
events::{AnyMessageLikeEventContent, AnyStateEventContent, MessageLikeEventContent},
29+
events::{
30+
AnyMessageLikeEventContent, AnyStateEventContent, MessageLikeEventContent,
31+
StateEventContent,
32+
},
3033
serde::Raw,
3134
OwnedTransactionId, TransactionId,
3235
};
@@ -322,6 +325,37 @@ impl<'a> IntoFuture for SendAttachment<'a> {
322325
}
323326
}
324327

328+
/// TODO: Future returned by `Room::send_state_event`.
329+
#[allow(missing_debug_implementations)]
330+
pub struct SendStateEvent<'a> {
331+
room: &'a Room,
332+
event_type: String,
333+
state_key: String,
334+
content: serde_json::Result<serde_json::Value>,
335+
request_config: Option<RequestConfig>,
336+
}
337+
338+
impl<'a> SendStateEvent<'a> {
339+
pub(crate) fn new<C, K>(room: &'a Room, state_key: &K, content: C) -> Self
340+
where
341+
C: StateEventContent,
342+
C::StateKey: Borrow<K>,
343+
K: AsRef<str> + ?Sized,
344+
{
345+
let event_type = content.event_type().to_string();
346+
let state_key = state_key.as_ref().to_owned();
347+
let content = serde_json::to_value(&content);
348+
Self { room, event_type, state_key, content, request_config: None }
349+
}
350+
351+
/// Assign a given [`RequestConfig`] to configure how this request should
352+
/// behave with respect to the network.
353+
pub fn with_request_config(mut self, request_config: RequestConfig) -> Self {
354+
self.request_config = Some(request_config);
355+
self
356+
}
357+
}
358+
325359
/// Future returned by [`Room::send_state_event_raw`].
326360
#[allow(missing_debug_implementations)]
327361
pub struct SendStateEventRaw<'a> {

0 commit comments

Comments
 (0)