Skip to content

Commit a4acbf7

Browse files
authored
Merge pull request #138 from throwException/main
Fix json output of messages in listen
2 parents 8ff3aa4 + 62b0710 commit a4acbf7

File tree

1 file changed

+23
-23
lines changed

1 file changed

+23
-23
lines changed

src/listen.rs

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -382,31 +382,31 @@ async fn handle_syncroommessageevent(
382382
debug!("Skipping message from itself because --listen-self is not set.");
383383
return;
384384
}
385-
if !context.output.is_text() {
386-
// Serialize it to a JSON string.
387-
let j = match serde_json::to_string("") {
388-
Ok(jsonstr) => {
389-
// this event does not contain the room_id, other events do.
390-
// People are missing the room_id in output.
391-
// Nasty hack: inserting the room_id into the JSON string.
392-
let mut s = jsonstr;
393-
s.insert_str(s.len() - 1, ",\"event_id\":\"\"");
394-
s.insert_str(s.len() - 2, ev.event_id().as_str());
395-
s.insert_str(s.len() - 1, ",\"sender\":\"\"");
396-
s.insert_str(s.len() - 2, ev.sender().as_str());
397-
s.insert_str(s.len() - 1, ",\"origin_server_ts\":\"\"");
398-
s.insert_str(s.len() - 2, &ev.origin_server_ts().0.to_string());
399-
s.insert_str(s.len() - 1, ",\"room_id\":\"\"");
400-
s.insert_str(s.len() - 2, room.room_id().as_str());
401-
s
402-
}
403-
Err(e) => e.to_string(),
404-
};
405-
println!("{}", j);
406-
return;
407-
}
408385
match ev {
409386
SyncMessageLikeEvent::Original(orginialmessagelikeevent) => {
387+
if !context.output.is_text() {
388+
// Serialize it to a JSON string.
389+
let j = match serde_json::to_string(&orginialmessagelikeevent.content) {
390+
Ok(jsonstr) => {
391+
// this event does not contain the room_id, other events do.
392+
// People are missing the room_id in output.
393+
// Nasty hack: inserting the room_id into the JSON string.
394+
let mut s = jsonstr;
395+
s.insert_str(s.len() - 1, ",\"event_id\":\"\"");
396+
s.insert_str(s.len() - 2, orginialmessagelikeevent.event_id.as_str());
397+
s.insert_str(s.len() - 1, ",\"sender\":\"\"");
398+
s.insert_str(s.len() - 2, orginialmessagelikeevent.sender.as_str());
399+
s.insert_str(s.len() - 1, ",\"origin_server_ts\":\"\"");
400+
s.insert_str(s.len() - 2, &orginialmessagelikeevent.origin_server_ts.0.to_string());
401+
s.insert_str(s.len() - 1, ",\"room_id\":\"\"");
402+
s.insert_str(s.len() - 2, room.room_id().as_str());
403+
s
404+
}
405+
Err(e) => e.to_string(),
406+
};
407+
println!("{}", j);
408+
return;
409+
}
410410
handle_originalsyncmessagelikeevent(
411411
&orginialmessagelikeevent,
412412
&RoomId::parse(room.room_id()).unwrap(),

0 commit comments

Comments
 (0)