Skip to content

Commit

Permalink
Merge pull request #138 from throwException/main
Browse files Browse the repository at this point in the history
Fix json output of messages in listen
  • Loading branch information
8go authored Nov 21, 2024
2 parents 8ff3aa4 + 62b0710 commit a4acbf7
Showing 1 changed file with 23 additions and 23 deletions.
46 changes: 23 additions & 23 deletions src/listen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,31 +382,31 @@ async fn handle_syncroommessageevent(
debug!("Skipping message from itself because --listen-self is not set.");
return;
}
if !context.output.is_text() {
// Serialize it to a JSON string.
let j = match serde_json::to_string("") {
Ok(jsonstr) => {
// this event does not contain the room_id, other events do.
// People are missing the room_id in output.
// Nasty hack: inserting the room_id into the JSON string.
let mut s = jsonstr;
s.insert_str(s.len() - 1, ",\"event_id\":\"\"");
s.insert_str(s.len() - 2, ev.event_id().as_str());
s.insert_str(s.len() - 1, ",\"sender\":\"\"");
s.insert_str(s.len() - 2, ev.sender().as_str());
s.insert_str(s.len() - 1, ",\"origin_server_ts\":\"\"");
s.insert_str(s.len() - 2, &ev.origin_server_ts().0.to_string());
s.insert_str(s.len() - 1, ",\"room_id\":\"\"");
s.insert_str(s.len() - 2, room.room_id().as_str());
s
}
Err(e) => e.to_string(),
};
println!("{}", j);
return;
}
match ev {
SyncMessageLikeEvent::Original(orginialmessagelikeevent) => {
if !context.output.is_text() {
// Serialize it to a JSON string.
let j = match serde_json::to_string(&orginialmessagelikeevent.content) {
Ok(jsonstr) => {
// this event does not contain the room_id, other events do.
// People are missing the room_id in output.
// Nasty hack: inserting the room_id into the JSON string.
let mut s = jsonstr;
s.insert_str(s.len() - 1, ",\"event_id\":\"\"");
s.insert_str(s.len() - 2, orginialmessagelikeevent.event_id.as_str());
s.insert_str(s.len() - 1, ",\"sender\":\"\"");
s.insert_str(s.len() - 2, orginialmessagelikeevent.sender.as_str());
s.insert_str(s.len() - 1, ",\"origin_server_ts\":\"\"");
s.insert_str(s.len() - 2, &orginialmessagelikeevent.origin_server_ts.0.to_string());
s.insert_str(s.len() - 1, ",\"room_id\":\"\"");
s.insert_str(s.len() - 2, room.room_id().as_str());
s
}
Err(e) => e.to_string(),
};
println!("{}", j);
return;
}
handle_originalsyncmessagelikeevent(
&orginialmessagelikeevent,
&RoomId::parse(room.room_id()).unwrap(),
Expand Down

0 comments on commit a4acbf7

Please sign in to comment.