Skip to content

Commit 80c9d91

Browse files
committed
feat(crypto-js): Extract RoomMessageRequest.content as a JSON-encoded string.
1 parent 7de6779 commit 80c9d91

File tree

1 file changed

+21
-17
lines changed

1 file changed

+21
-17
lines changed

src/requests.rs

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -226,9 +226,9 @@ pub struct RoomMessageRequest {
226226
#[wasm_bindgen(readonly)]
227227
pub txn_id: JsString,
228228

229-
/// A JSON-encoded string containing the rest of the payload: `content`.
229+
/// A JSON-encoded string containing the `content` field of this event.
230230
#[wasm_bindgen(readonly)]
231-
pub extra: JsString,
231+
pub content: JsString,
232232
}
233233

234234
#[wasm_bindgen]
@@ -239,9 +239,9 @@ impl RoomMessageRequest {
239239
id: JsString,
240240
room_id: JsString,
241241
txn_id: JsString,
242-
extra: JsString,
242+
content: JsString,
243243
) -> RoomMessageRequest {
244-
Self { id: Some(id), room_id, txn_id, extra }
244+
Self { id: Some(id), room_id, txn_id, content }
245245
}
246246

247247
/// Get its request type.
@@ -303,8 +303,8 @@ pub struct SigningKeysUploadRequest {
303303
macro_rules! request {
304304
(
305305
$destination_request:ident from $source_request:ident
306-
$( extracts fields $( $field:ident: $field_type:ident ),+ $(,)? )?
307-
$( $( and )? groups fields $( $grouped_field:ident ),+ $(,)? )?
306+
$( extracts fields $( $field_name:ident : $field_type:ident ),+ $(,)? )?
307+
$( $( and )? groups fields $( $grouped_field_name:ident ),+ $(,)? )?
308308
) => {
309309
impl TryFrom<&$source_request> for $destination_request {
310310
type Error = serde_json::Error;
@@ -313,8 +313,8 @@ macro_rules! request {
313313
request!(
314314
@__try_from $destination_request from $source_request
315315
(request_id = None, request = request)
316-
$( extracts [ $( $field: $field_type, )+ ] )?
317-
$( groups [ $( $grouped_field, )+ ] )?
316+
$( extracts [ $( $field_name : $field_type, )+ ] )?
317+
$( groups [ $( $grouped_field_name, )+ ] )?
318318
)
319319
}
320320
}
@@ -328,8 +328,8 @@ macro_rules! request {
328328
request!(
329329
@__try_from $destination_request from $source_request
330330
(request_id = Some(request_id.into()), request = request)
331-
$( extracts [ $( $field: $field_type, )+ ] )?
332-
$( groups [ $( $grouped_field, )+ ] )?
331+
$( extracts [ $( $field_name : $field_type, )+ ] )?
332+
$( groups [ $( $grouped_field_name, )+ ] )?
333333
)
334334
}
335335
}
@@ -338,22 +338,22 @@ macro_rules! request {
338338
(
339339
@__try_from $destination_request:ident from $source_request:ident
340340
(request_id = $request_id:expr, request = $request:expr)
341-
$( extracts [ $( $field:ident: $field_type:ident ),* $(,)? ] )?
342-
$( groups [ $( $grouped_field:ident ),* $(,)? ] )?
341+
$( extracts [ $( $field_name:ident : $field_type:ident ),* $(,)? ] )?
342+
$( groups [ $( $grouped_field_name:ident ),* $(,)? ] )?
343343
) => {
344344
{
345345
Ok($destination_request {
346346
id: $request_id,
347347
$(
348348
$(
349-
$field: request!(@__field as $field_type (request = $request, field = $field)),
349+
$field_name: request!(@__field as $field_type (request = $request, field = $field_name)),
350350
)*
351351
)?
352352
$(
353353
extra: {
354354
let mut map = serde_json::Map::new();
355355
$(
356-
map.insert(stringify!($grouped_field).to_owned(), serde_json::to_value(&$request.$grouped_field).unwrap());
356+
map.insert(stringify!($grouped_field_name).to_owned(), serde_json::to_value(&$request.$grouped_field_name).unwrap());
357357
)*
358358
let object = serde_json::Value::Object(map);
359359

@@ -364,9 +364,13 @@ macro_rules! request {
364364
}
365365
};
366366

367-
( @__field as string (request = $request:expr, field = $field:ident) ) => {
368-
$request.$field.to_string().into()
367+
( @__field as string (request = $request:expr, field = $field_name:ident) ) => {
368+
$request.$field_name.to_string().into()
369369
};
370+
371+
( @__field as json (request = $request:expr, field = $field_name:ident) ) => {
372+
serde_json::to_string(&$request.$field_name)?.into()
373+
}
370374
}
371375

372376
// Outgoing Requests
@@ -375,7 +379,7 @@ request!(KeysQueryRequest from OriginalKeysQueryRequest groups fields timeout, d
375379
request!(KeysClaimRequest from OriginalKeysClaimRequest groups fields timeout, one_time_keys);
376380
request!(ToDeviceRequest from OriginalToDeviceRequest extracts fields event_type: string, txn_id: string and groups fields messages);
377381
request!(SignatureUploadRequest from OriginalSignatureUploadRequest groups fields signed_keys);
378-
request!(RoomMessageRequest from OriginalRoomMessageRequest extracts fields room_id: string, txn_id: string and groups fields content);
382+
request!(RoomMessageRequest from OriginalRoomMessageRequest extracts fields room_id: string, txn_id: string, content: json);
379383
request!(KeysBackupRequest from OriginalKeysBackupRequest groups fields rooms);
380384

381385
// Other Requests

0 commit comments

Comments
 (0)