@@ -418,41 +418,41 @@ fn get_message_preview(
418418 room_secrets : & std:: collections:: HashMap < u32 , [ u8 ; 32 ] > ,
419419) -> String {
420420 use river_core:: room_state:: content:: {
421- ActionContentV1 , ReplyContentV1 , TextContentV1 , ACTION_TYPE_DELETE , ACTION_TYPE_EDIT ,
422- ACTION_TYPE_REACTION , ACTION_TYPE_REMOVE_REACTION , CONTENT_TYPE_ACTION , CONTENT_TYPE_REPLY ,
423- CONTENT_TYPE_TEXT ,
421+ ActionContentV1 , EventContentV1 , ReplyContentV1 , TextContentV1 , ACTION_TYPE_DELETE ,
422+ ACTION_TYPE_EDIT , ACTION_TYPE_REACTION , ACTION_TYPE_REMOVE_REACTION , CONTENT_TYPE_ACTION ,
423+ CONTENT_TYPE_EVENT , CONTENT_TYPE_REPLY , CONTENT_TYPE_TEXT , EVENT_TYPE_JOIN ,
424424 } ;
425425
426426 let text = match content {
427427 RoomMessageBody :: Public {
428428 content_type, data, ..
429- } => {
430- if * content_type == CONTENT_TYPE_TEXT {
431- TextContentV1 :: decode ( data )
432- . map ( |t| t . text )
433- . unwrap_or_else ( |_| "[Failed to decode message]" . to_string ( ) )
434- } else if * content_type == CONTENT_TYPE_ACTION {
435- // Action messages - show action description
436- ActionContentV1 :: decode ( data )
437- . map ( |action| match action. action_type {
438- ACTION_TYPE_EDIT => "[Edited a message]" . to_string ( ) ,
439- ACTION_TYPE_DELETE => "[Deleted a message]" . to_string ( ) ,
440- ACTION_TYPE_REACTION => action
441- . reaction_payload ( )
442- . map ( |p| format ! ( "Reacted with {}" , p . emoji ) )
443- . unwrap_or_else ( || "[Reacted]" . to_string ( ) ) ,
444- ACTION_TYPE_REMOVE_REACTION => "[Removed a reaction ]". to_string ( ) ,
445- _ => "[Unknown action]" . to_string ( ) ,
446- } )
447- . unwrap_or_else ( |_| "[Action ]" . to_string ( ) )
448- } else if * content_type == CONTENT_TYPE_REPLY {
449- ReplyContentV1 :: decode ( data )
450- . map ( |r| r . text )
451- . unwrap_or_else ( |_| "[Failed to decode reply]" . to_string ( ) )
452- } else {
453- "[Unknown message type ]". to_string ( )
454- }
455- }
429+ } => match * content_type {
430+ CONTENT_TYPE_TEXT => TextContentV1 :: decode ( data )
431+ . map ( |t| t . text )
432+ . unwrap_or_else ( |_| "[Failed to decode message]" . to_string ( ) ) ,
433+ CONTENT_TYPE_ACTION => ActionContentV1 :: decode ( data )
434+ . map ( |action| match action . action_type {
435+ ACTION_TYPE_EDIT => "[Edited a message]" . to_string ( ) ,
436+ ACTION_TYPE_DELETE => "[Deleted a message]" . to_string ( ) ,
437+ ACTION_TYPE_REACTION => action
438+ . reaction_payload ( )
439+ . map ( |p| format ! ( "Reacted with {}" , p . emoji ) )
440+ . unwrap_or_else ( || "[Reacted]" . to_string ( ) ) ,
441+ ACTION_TYPE_REMOVE_REACTION => "[Removed a reaction]" . to_string ( ) ,
442+ _ => "[Unknown action]" . to_string ( ) ,
443+ } )
444+ . unwrap_or_else ( |_| "[Action ]". to_string ( ) ) ,
445+ CONTENT_TYPE_REPLY => ReplyContentV1 :: decode ( data )
446+ . map ( |r| r . text )
447+ . unwrap_or_else ( |_| "[Failed to decode reply ]" . to_string ( ) ) ,
448+ CONTENT_TYPE_EVENT => EventContentV1 :: decode ( data )
449+ . map ( |event| match event . event_type {
450+ EVENT_TYPE_JOIN => "joined the room" . to_string ( ) ,
451+ _ => format ! ( "[Event type {}]" , event . event_type ) ,
452+ } )
453+ . unwrap_or_else ( |_| "[Event ]". to_string ( ) ) ,
454+ _ => "[Unknown message type]" . to_string ( ) ,
455+ } ,
456456 RoomMessageBody :: Private {
457457 content_type,
458458 ciphertext,
@@ -463,18 +463,21 @@ fn get_message_preview(
463463 // Look up the secret for this message's version
464464 if let Some ( secret) = room_secrets. get ( secret_version) {
465465 decrypt_with_symmetric_key ( secret, ciphertext. as_slice ( ) , nonce)
466- . map ( |bytes| {
467- if * content_type == CONTENT_TYPE_TEXT {
468- TextContentV1 :: decode ( & bytes)
469- . map ( |t| t. text )
470- . unwrap_or_else ( |_| String :: from_utf8_lossy ( & bytes) . to_string ( ) )
471- } else if * content_type == CONTENT_TYPE_REPLY {
472- ReplyContentV1 :: decode ( & bytes)
473- . map ( |r| r. text )
474- . unwrap_or_else ( |_| String :: from_utf8_lossy ( & bytes) . to_string ( ) )
475- } else {
476- String :: from_utf8_lossy ( & bytes) . to_string ( )
477- }
466+ . map ( |bytes| match * content_type {
467+ CONTENT_TYPE_TEXT => TextContentV1 :: decode ( & bytes)
468+ . map ( |t| t. text )
469+ . unwrap_or_else ( |_| String :: from_utf8_lossy ( & bytes) . to_string ( ) ) ,
470+ CONTENT_TYPE_REPLY => ReplyContentV1 :: decode ( & bytes)
471+ . map ( |r| r. text )
472+ . unwrap_or_else ( |_| String :: from_utf8_lossy ( & bytes) . to_string ( ) ) ,
473+ CONTENT_TYPE_EVENT => EventContentV1 :: decode ( & bytes)
474+ . map ( |event| match event. event_type {
475+ EVENT_TYPE_JOIN => "joined the room" . to_string ( ) ,
476+ _ => format ! ( "[Event type {}]" , event. event_type) ,
477+ } )
478+ . unwrap_or_else ( |_| "[Event]" . to_string ( ) ) ,
479+ CONTENT_TYPE_ACTION => "[Action]" . to_string ( ) ,
480+ _ => String :: from_utf8_lossy ( & bytes) . to_string ( ) ,
478481 } )
479482 . unwrap_or_else ( |_| "[Encrypted message]" . to_string ( ) )
480483 } else {
0 commit comments