Commit 98d8a82e authored by Alexandre Franke's avatar Alexandre Franke Committed by Alexandre Franke

api: don’t unwrap blindly for left rooms

The Option can be None in some cases.
parent 289a4e33
Pipeline #87402 passed with stages
in 23 minutes and 16 seconds
......@@ -170,22 +170,26 @@ impl Room {
});
let left_rooms = response.rooms.leave.iter().map(|(k, room)| {
let leave_id = &room.timeline.events.last().unwrap()["sender"];
if leave_id != userid {
let kick_reason = &room.timeline.events.last().unwrap()["content"]["reason"];
if let Some((kicker_alias, kicker_avatar)) =
get_user_avatar(baseu, leave_id.as_str().unwrap_or_default()).ok()
{
let kicker = Member {
alias: Some(kicker_alias),
avatar: Some(kicker_avatar),
uid: String::from(leave_id.as_str().unwrap_or_default()),
};
let reason = Reason::Kicked(
String::from(kick_reason.as_str().unwrap_or_default()),
kicker,
);
Self::new(k.clone(), RoomMembership::Left(reason))
if let Some(last_event) = room.timeline.events.last() {
let leave_id = &last_event["sender"];
if leave_id != userid {
let kick_reason = &last_event["content"]["reason"];
if let Some((kicker_alias, kicker_avatar)) =
get_user_avatar(baseu, leave_id.as_str().unwrap_or_default()).ok()
{
let kicker = Member {
alias: Some(kicker_alias),
avatar: Some(kicker_avatar),
uid: String::from(leave_id.as_str().unwrap_or_default()),
};
let reason = Reason::Kicked(
String::from(kick_reason.as_str().unwrap_or_default()),
kicker,
);
Self::new(k.clone(), RoomMembership::Left(reason))
} else {
Self::new(k.clone(), RoomMembership::Left(Reason::None))
}
} else {
Self::new(k.clone(), RoomMembership::Left(Reason::None))
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment