mirror of
https://github.com/chatmail/core.git
synced 2026-05-12 03:16:29 +03:00
Turn get_[fresh_]msg_cnt() into ChatId members
This commit is contained in:
@@ -966,7 +966,7 @@ pub unsafe extern "C" fn dc_get_msg_cnt(context: *mut dc_context_t, chat_id: u32
|
|||||||
}
|
}
|
||||||
let ffi_context = &*context;
|
let ffi_context = &*context;
|
||||||
ffi_context
|
ffi_context
|
||||||
.with_inner(|ctx| chat::get_msg_cnt(ctx, ChatId::new(chat_id)) as libc::c_int)
|
.with_inner(|ctx| ChatId::new(chat_id).get_msg_cnt(ctx) as libc::c_int)
|
||||||
.unwrap_or(0)
|
.unwrap_or(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -981,7 +981,7 @@ pub unsafe extern "C" fn dc_get_fresh_msg_cnt(
|
|||||||
}
|
}
|
||||||
let ffi_context = &*context;
|
let ffi_context = &*context;
|
||||||
ffi_context
|
ffi_context
|
||||||
.with_inner(|ctx| chat::get_fresh_msg_cnt(ctx, ChatId::new(chat_id)) as libc::c_int)
|
.with_inner(|ctx| ChatId::new(chat_id).get_fresh_msg_cnt(ctx) as libc::c_int)
|
||||||
.unwrap_or(0)
|
.unwrap_or(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -514,7 +514,7 @@ pub fn dc_cmdline(context: &Context, line: &str) -> Result<(), failure::Error> {
|
|||||||
chat_prefix(&chat),
|
chat_prefix(&chat),
|
||||||
chat.get_id(),
|
chat.get_id(),
|
||||||
chat.get_name(),
|
chat.get_name(),
|
||||||
chat::get_fresh_msg_cnt(context, chat.get_id()),
|
chat.get_id().get_fresh_msg_cnt(context),
|
||||||
);
|
);
|
||||||
let lot = chatlist.get_summary(context, i, Some(&chat));
|
let lot = chatlist.get_summary(context, i, Some(&chat));
|
||||||
let statestr = if chat.is_archived() {
|
let statestr = if chat.is_archived() {
|
||||||
@@ -602,10 +602,7 @@ pub fn dc_cmdline(context: &Context, line: &str) -> Result<(), failure::Error> {
|
|||||||
log_msg(context, "Draft", &draft);
|
log_msg(context, "Draft", &draft);
|
||||||
}
|
}
|
||||||
|
|
||||||
println!(
|
println!("{} messages.", sel_chat.get_id().get_msg_cnt(context));
|
||||||
"{} messages.",
|
|
||||||
chat::get_msg_cnt(context, sel_chat.get_id())
|
|
||||||
);
|
|
||||||
chat::marknoticed_chat(context, sel_chat.get_id())?;
|
chat::marknoticed_chat(context, sel_chat.get_id())?;
|
||||||
}
|
}
|
||||||
"createchat" => {
|
"createchat" => {
|
||||||
|
|||||||
58
src/chat.rs
58
src/chat.rs
@@ -327,6 +327,33 @@ impl ChatId {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns number of messages in a chat.
|
||||||
|
pub fn get_msg_cnt(self, context: &Context) -> usize {
|
||||||
|
context
|
||||||
|
.sql
|
||||||
|
.query_get_value::<_, i32>(
|
||||||
|
context,
|
||||||
|
"SELECT COUNT(*) FROM msgs WHERE chat_id=?;",
|
||||||
|
params![self],
|
||||||
|
)
|
||||||
|
.unwrap_or_default() as usize
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_fresh_msg_cnt(self, context: &Context) -> usize {
|
||||||
|
context
|
||||||
|
.sql
|
||||||
|
.query_get_value::<_, i32>(
|
||||||
|
context,
|
||||||
|
"SELECT COUNT(*)
|
||||||
|
FROM msgs
|
||||||
|
WHERE state=10
|
||||||
|
AND hidden=0
|
||||||
|
AND chat_id=?;",
|
||||||
|
params![self],
|
||||||
|
)
|
||||||
|
.unwrap_or_default() as usize
|
||||||
|
}
|
||||||
|
|
||||||
/// Bad evil escape hatch.
|
/// Bad evil escape hatch.
|
||||||
///
|
///
|
||||||
/// Avoid using this, eventually types should be cleaned up enough
|
/// Avoid using this, eventually types should be cleaned up enough
|
||||||
@@ -1453,33 +1480,6 @@ pub fn get_chat_msgs(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns number of messages in a chat.
|
|
||||||
pub fn get_msg_cnt(context: &Context, chat_id: ChatId) -> usize {
|
|
||||||
context
|
|
||||||
.sql
|
|
||||||
.query_get_value::<_, i32>(
|
|
||||||
context,
|
|
||||||
"SELECT COUNT(*) FROM msgs WHERE chat_id=?;",
|
|
||||||
params![chat_id],
|
|
||||||
)
|
|
||||||
.unwrap_or_default() as usize
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_fresh_msg_cnt(context: &Context, chat_id: ChatId) -> usize {
|
|
||||||
context
|
|
||||||
.sql
|
|
||||||
.query_get_value::<_, i32>(
|
|
||||||
context,
|
|
||||||
"SELECT COUNT(*)
|
|
||||||
FROM msgs
|
|
||||||
WHERE state=10
|
|
||||||
AND hidden=0
|
|
||||||
AND chat_id=?;",
|
|
||||||
params![chat_id],
|
|
||||||
)
|
|
||||||
.unwrap_or_default() as usize
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn marknoticed_chat(context: &Context, chat_id: ChatId) -> Result<(), Error> {
|
pub fn marknoticed_chat(context: &Context, chat_id: ChatId) -> Result<(), Error> {
|
||||||
if !context.sql.exists(
|
if !context.sql.exists(
|
||||||
"SELECT id FROM msgs WHERE chat_id=? AND state=?;",
|
"SELECT id FROM msgs WHERE chat_id=? AND state=?;",
|
||||||
@@ -2535,7 +2535,7 @@ mod tests {
|
|||||||
assert_eq!(msg2.text.as_ref().unwrap(), "second message");
|
assert_eq!(msg2.text.as_ref().unwrap(), "second message");
|
||||||
|
|
||||||
// check device chat
|
// check device chat
|
||||||
assert_eq!(get_msg_cnt(&t.ctx, msg2.chat_id), 2);
|
assert_eq!(msg2.chat_id.get_msg_cnt(&t.ctx), 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -2568,7 +2568,7 @@ mod tests {
|
|||||||
|
|
||||||
// check device chat
|
// check device chat
|
||||||
let chat_id = msg1.chat_id;
|
let chat_id = msg1.chat_id;
|
||||||
assert_eq!(get_msg_cnt(&t.ctx, chat_id), 1);
|
assert_eq!(chat_id.get_msg_cnt(&t.ctx), 1);
|
||||||
assert!(!chat_id.is_special());
|
assert!(!chat_id.is_special());
|
||||||
let chat = Chat::load_from_db(&t.ctx, chat_id);
|
let chat = Chat::load_from_db(&t.ctx, chat_id);
|
||||||
assert!(chat.is_ok());
|
assert!(chat.is_ok());
|
||||||
|
|||||||
Reference in New Issue
Block a user