refactor get_room_topic
into 1 single function
Signed-off-by: strawberry <strawberry@puppygock.gay>
This commit is contained in:
parent
88d038ffec
commit
fcdf1463ef
3 changed files with 16 additions and 20 deletions
|
@ -15,6 +15,7 @@ use ruma::{
|
|||
history_visibility::{HistoryVisibility, RoomHistoryVisibilityEventContent},
|
||||
member::{MembershipState, RoomMemberEventContent},
|
||||
name::RoomNameEventContent,
|
||||
topic::RoomTopicEventContent,
|
||||
},
|
||||
StateEventType,
|
||||
},
|
||||
|
@ -341,4 +342,17 @@ impl Service {
|
|||
.map_err(|_| Error::bad_database("Invalid canonical alias event in database."))
|
||||
})
|
||||
}
|
||||
|
||||
/// Gets the room topic
|
||||
pub fn get_room_topic(&self, room_id: &RoomId) -> Result<Option<String>, Error> {
|
||||
self.room_state_get(room_id, &StateEventType::RoomTopic, "")?
|
||||
.map_or(Ok(None), |s| {
|
||||
serde_json::from_str(s.content.get())
|
||||
.map(|c: RoomTopicEventContent| Some(c.topic))
|
||||
.map_err(|e| {
|
||||
error!("Invalid room topic event in database for room {room_id}: {e}");
|
||||
Error::bad_database("Invalid room topic event in database.")
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue