mirror of
https://github.com/chatmail/core.git
synced 2026-05-04 13:56:30 +03:00
Resultify get_chat_id_by_grpid
I want to avoid having to be able to represent a chat_id of 0 in order to more nicely turn chat_id into a ChatId newtype.
This commit is contained in:
committed by
Floris Bruynooghe
parent
213c5df706
commit
7540770dec
28
src/chat.rs
28
src/chat.rs
@@ -2111,21 +2111,21 @@ pub fn get_chat_cnt(context: &Context) -> usize {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_chat_id_by_grpid(context: &Context, grpid: impl AsRef<str>) -> (u32, bool, Blocked) {
|
||||
context
|
||||
.sql
|
||||
.query_row(
|
||||
"SELECT id, blocked, type FROM chats WHERE grpid=?;",
|
||||
params![grpid.as_ref()],
|
||||
|row| {
|
||||
let chat_id = row.get(0)?;
|
||||
pub(crate) fn get_chat_id_by_grpid(
|
||||
context: &Context,
|
||||
grpid: impl AsRef<str>,
|
||||
) -> Result<(u32, bool, Blocked), sql::Error> {
|
||||
context.sql.query_row(
|
||||
"SELECT id, blocked, type FROM chats WHERE grpid=?;",
|
||||
params![grpid.as_ref()],
|
||||
|row| {
|
||||
let chat_id = row.get(0)?;
|
||||
|
||||
let b = row.get::<_, Option<Blocked>>(1)?.unwrap_or_default();
|
||||
let v = row.get::<_, Option<Chattype>>(2)?.unwrap_or_default();
|
||||
Ok((chat_id, v == Chattype::VerifiedGroup, b))
|
||||
},
|
||||
)
|
||||
.unwrap_or((0, false, Blocked::Not))
|
||||
let b = row.get::<_, Option<Blocked>>(1)?.unwrap_or_default();
|
||||
let v = row.get::<_, Option<Chattype>>(2)?.unwrap_or_default();
|
||||
Ok((chat_id, v == Chattype::VerifiedGroup, b))
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
/// Adds a message to device chat.
|
||||
|
||||
Reference in New Issue
Block a user