mirror of
https://github.com/chatmail/core.git
synced 2026-05-19 23:06:32 +03:00
Remove bitflags from get_chat_msgs() interface
get_chat_msgs() function is split into new get_chat_msgs() without flags and get_chat_msgs_ex() which accepts booleans instead of bitflags. FFI call dc_get_chat_msgs() is still using bitflags for compatibility. JSON-RPC calls get_message_ids() and get_message_list_items() accept booleans instead of bitflags now.
This commit is contained in:
@@ -14,6 +14,10 @@
|
|||||||
Account.`get_message_by_id` may return `None` in this case.
|
Account.`get_message_by_id` may return `None` in this case.
|
||||||
|
|
||||||
## API-Changes
|
## API-Changes
|
||||||
|
- Remove bitflags from `get_chat_msgs()` interface #4022
|
||||||
|
C interface is not changed.
|
||||||
|
Rust and JSON-RPC API have `flags` integer argument
|
||||||
|
replaced with two boolean flags `info_only` and `add_daymarker`.
|
||||||
|
|
||||||
|
|
||||||
## 1.107.1
|
## 1.107.1
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ async fn get_chat_msgs_benchmark(dbfile: &Path, chats: &[ChatId]) {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
for c in chats.iter().take(10) {
|
for c in chats.iter().take(10) {
|
||||||
black_box(chat::get_chat_msgs(&context, *c, 0).await.ok());
|
black_box(chat::get_chat_msgs(&context, *c).await.ok());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ use std::sync::Arc;
|
|||||||
use std::time::{Duration, SystemTime};
|
use std::time::{Duration, SystemTime};
|
||||||
|
|
||||||
use anyhow::Context as _;
|
use anyhow::Context as _;
|
||||||
use deltachat::chat::{ChatId, ChatVisibility, MuteDuration, ProtectionStatus};
|
use deltachat::chat::{ChatId, ChatVisibility, MessageListOptions, MuteDuration, ProtectionStatus};
|
||||||
use deltachat::constants::DC_MSG_ID_LAST_SPECIAL;
|
use deltachat::constants::DC_MSG_ID_LAST_SPECIAL;
|
||||||
use deltachat::contact::{Contact, ContactId, Origin};
|
use deltachat::contact::{Contact, ContactId, Origin};
|
||||||
use deltachat::context::Context;
|
use deltachat::context::Context;
|
||||||
@@ -60,7 +60,8 @@ use self::string::*;
|
|||||||
// this avoids panics if the ui just forgets to handle a case
|
// this avoids panics if the ui just forgets to handle a case
|
||||||
// - finally, this behaviour matches the old core-c API and UIs already depend on it
|
// - finally, this behaviour matches the old core-c API and UIs already depend on it
|
||||||
|
|
||||||
// TODO: constants
|
const DC_GCM_ADDDAYMARKER: u32 = 0x01;
|
||||||
|
const DC_GCM_INFO_ONLY: u32 = 0x02;
|
||||||
|
|
||||||
// dc_context_t
|
// dc_context_t
|
||||||
|
|
||||||
@@ -1156,12 +1157,21 @@ pub unsafe extern "C" fn dc_get_chat_msgs(
|
|||||||
}
|
}
|
||||||
let ctx = &*context;
|
let ctx = &*context;
|
||||||
|
|
||||||
|
let info_only = (flags & DC_GCM_INFO_ONLY) != 0;
|
||||||
|
let add_daymarker = (flags & DC_GCM_ADDDAYMARKER) != 0;
|
||||||
block_on(async move {
|
block_on(async move {
|
||||||
Box::into_raw(Box::new(
|
Box::into_raw(Box::new(
|
||||||
chat::get_chat_msgs(ctx, ChatId::new(chat_id), flags)
|
chat::get_chat_msgs_ex(
|
||||||
.await
|
ctx,
|
||||||
.unwrap_or_log_default(ctx, "failed to get chat msgs")
|
ChatId::new(chat_id),
|
||||||
.into(),
|
MessageListOptions {
|
||||||
|
info_only,
|
||||||
|
add_daymarker,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.unwrap_or_log_default(ctx, "failed to get chat msgs")
|
||||||
|
.into(),
|
||||||
))
|
))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,8 +6,9 @@ use anyhow::{anyhow, bail, ensure, Context, Result};
|
|||||||
pub use deltachat::accounts::Accounts;
|
pub use deltachat::accounts::Accounts;
|
||||||
use deltachat::{
|
use deltachat::{
|
||||||
chat::{
|
chat::{
|
||||||
self, add_contact_to_chat, forward_msgs, get_chat_media, get_chat_msgs, marknoticed_chat,
|
self, add_contact_to_chat, forward_msgs, get_chat_media, get_chat_msgs, get_chat_msgs_ex,
|
||||||
remove_contact_from_chat, Chat, ChatId, ChatItem, ProtectionStatus,
|
marknoticed_chat, remove_contact_from_chat, Chat, ChatId, ChatItem, MessageListOptions,
|
||||||
|
ProtectionStatus,
|
||||||
},
|
},
|
||||||
chatlist::Chatlist,
|
chatlist::Chatlist,
|
||||||
config::Config,
|
config::Config,
|
||||||
@@ -803,7 +804,7 @@ impl CommandApi {
|
|||||||
let ctx = self.get_context(account_id).await?;
|
let ctx = self.get_context(account_id).await?;
|
||||||
|
|
||||||
// TODO: implement this in core with an SQL query, that will be way faster
|
// TODO: implement this in core with an SQL query, that will be way faster
|
||||||
let messages = get_chat_msgs(&ctx, ChatId::new(chat_id), 0).await?;
|
let messages = get_chat_msgs(&ctx, ChatId::new(chat_id)).await?;
|
||||||
let mut first_unread_message_id = None;
|
let mut first_unread_message_id = None;
|
||||||
for item in messages.into_iter().rev() {
|
for item in messages.into_iter().rev() {
|
||||||
if let ChatItem::Message { msg_id } = item {
|
if let ChatItem::Message { msg_id } = item {
|
||||||
@@ -878,9 +879,23 @@ impl CommandApi {
|
|||||||
markseen_msgs(&ctx, msg_ids.into_iter().map(MsgId::new).collect()).await
|
markseen_msgs(&ctx, msg_ids.into_iter().map(MsgId::new).collect()).await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn get_message_ids(&self, account_id: u32, chat_id: u32, flags: u32) -> Result<Vec<u32>> {
|
async fn get_message_ids(
|
||||||
|
&self,
|
||||||
|
account_id: u32,
|
||||||
|
chat_id: u32,
|
||||||
|
info_only: bool,
|
||||||
|
add_daymarker: bool,
|
||||||
|
) -> Result<Vec<u32>> {
|
||||||
let ctx = self.get_context(account_id).await?;
|
let ctx = self.get_context(account_id).await?;
|
||||||
let msg = get_chat_msgs(&ctx, ChatId::new(chat_id), flags).await?;
|
let msg = get_chat_msgs_ex(
|
||||||
|
&ctx,
|
||||||
|
ChatId::new(chat_id),
|
||||||
|
MessageListOptions {
|
||||||
|
info_only,
|
||||||
|
add_daymarker,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
Ok(msg
|
Ok(msg
|
||||||
.iter()
|
.iter()
|
||||||
.map(|chat_item| -> u32 {
|
.map(|chat_item| -> u32 {
|
||||||
@@ -896,10 +911,19 @@ impl CommandApi {
|
|||||||
&self,
|
&self,
|
||||||
account_id: u32,
|
account_id: u32,
|
||||||
chat_id: u32,
|
chat_id: u32,
|
||||||
flags: u32,
|
info_only: bool,
|
||||||
|
add_daymarker: bool,
|
||||||
) -> Result<Vec<JSONRPCMessageListItem>> {
|
) -> Result<Vec<JSONRPCMessageListItem>> {
|
||||||
let ctx = self.get_context(account_id).await?;
|
let ctx = self.get_context(account_id).await?;
|
||||||
let msg = get_chat_msgs(&ctx, ChatId::new(chat_id), flags).await?;
|
let msg = get_chat_msgs_ex(
|
||||||
|
&ctx,
|
||||||
|
ChatId::new(chat_id),
|
||||||
|
MessageListOptions {
|
||||||
|
info_only,
|
||||||
|
add_daymarker,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
Ok(msg
|
Ok(msg
|
||||||
.iter()
|
.iter()
|
||||||
.map(|chat_item| (*chat_item).into())
|
.map(|chat_item| (*chat_item).into())
|
||||||
|
|||||||
@@ -76,7 +76,8 @@ async function run() {
|
|||||||
const messageIds = await client.rpc.getMessageIds(
|
const messageIds = await client.rpc.getMessageIds(
|
||||||
selectedAccount,
|
selectedAccount,
|
||||||
chatId,
|
chatId,
|
||||||
0
|
false,
|
||||||
|
false
|
||||||
);
|
);
|
||||||
const messages = await client.rpc.getMessages(
|
const messages = await client.rpc.getMessages(
|
||||||
selectedAccount,
|
selectedAccount,
|
||||||
|
|||||||
@@ -97,7 +97,8 @@ describe("online tests", function () {
|
|||||||
const messageList = await dc.rpc.getMessageIds(
|
const messageList = await dc.rpc.getMessageIds(
|
||||||
accountId2,
|
accountId2,
|
||||||
chatIdOnAccountB,
|
chatIdOnAccountB,
|
||||||
0
|
false,
|
||||||
|
false
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(messageList).have.length(1);
|
expect(messageList).have.length(1);
|
||||||
@@ -133,7 +134,8 @@ describe("online tests", function () {
|
|||||||
const messageList = await dc.rpc.getMessageIds(
|
const messageList = await dc.rpc.getMessageIds(
|
||||||
accountId2,
|
accountId2,
|
||||||
chatIdOnAccountB,
|
chatIdOnAccountB,
|
||||||
0
|
false,
|
||||||
|
false
|
||||||
);
|
);
|
||||||
const message = await dc.rpc.getMessage(
|
const message = await dc.rpc.getMessage(
|
||||||
accountId2,
|
accountId2,
|
||||||
@@ -150,7 +152,7 @@ describe("online tests", function () {
|
|||||||
await eventPromise2;
|
await eventPromise2;
|
||||||
|
|
||||||
const messageId = (
|
const messageId = (
|
||||||
await dc.rpc.getMessageIds(accountId1, chatId, 0)
|
await dc.rpc.getMessageIds(accountId1, chatId, false, false)
|
||||||
).reverse()[0];
|
).reverse()[0];
|
||||||
const message2 = await dc.rpc.getMessage(accountId1, messageId);
|
const message2 = await dc.rpc.getMessage(accountId1, messageId);
|
||||||
expect(message2.text).equal("super secret message");
|
expect(message2.text).equal("super secret message");
|
||||||
|
|||||||
@@ -648,8 +648,15 @@ pub async fn cmdline(context: Context, line: &str, chat_id: &mut ChatId) -> Resu
|
|||||||
let sel_chat = sel_chat.as_ref().unwrap();
|
let sel_chat = sel_chat.as_ref().unwrap();
|
||||||
|
|
||||||
let time_start = std::time::SystemTime::now();
|
let time_start = std::time::SystemTime::now();
|
||||||
let msglist =
|
let msglist = chat::get_chat_msgs_ex(
|
||||||
chat::get_chat_msgs(&context, sel_chat.get_id(), DC_GCM_ADDDAYMARKER).await?;
|
&context,
|
||||||
|
sel_chat.get_id(),
|
||||||
|
chat::MessageListOptions {
|
||||||
|
info_only: false,
|
||||||
|
add_daymarker: true,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
let time_needed = time_start.elapsed().unwrap_or_default();
|
let time_needed = time_start.elapsed().unwrap_or_default();
|
||||||
|
|
||||||
let msglist: Vec<MsgId> = msglist
|
let msglist: Vec<MsgId> = msglist
|
||||||
|
|||||||
@@ -174,9 +174,9 @@ class Chat:
|
|||||||
snapshot["message"] = Message(self.account, snapshot.id)
|
snapshot["message"] = Message(self.account, snapshot.id)
|
||||||
return snapshot
|
return snapshot
|
||||||
|
|
||||||
async def get_messages(self, flags: int = 0) -> List[Message]:
|
async def get_messages(self, info_only: bool = False, add_daymarker: bool = False) -> List[Message]:
|
||||||
"""get the list of messages in this chat."""
|
"""get the list of messages in this chat."""
|
||||||
msgs = await self._rpc.get_message_ids(self.account.id, self.id, flags)
|
msgs = await self._rpc.get_message_ids(self.account.id, self.id, info_only, add_daymarker)
|
||||||
return [Message(self.account, msg_id) for msg_id in msgs]
|
return [Message(self.account, msg_id) for msg_id in msgs]
|
||||||
|
|
||||||
async def get_fresh_message_count(self) -> int:
|
async def get_fresh_message_count(self) -> int:
|
||||||
|
|||||||
66
src/chat.rs
66
src/chat.rs
@@ -19,7 +19,7 @@ use crate::color::str_to_color;
|
|||||||
use crate::config::Config;
|
use crate::config::Config;
|
||||||
use crate::constants::{
|
use crate::constants::{
|
||||||
Blocked, Chattype, DC_CHAT_ID_ALLDONE_HINT, DC_CHAT_ID_ARCHIVED_LINK, DC_CHAT_ID_LAST_SPECIAL,
|
Blocked, Chattype, DC_CHAT_ID_ALLDONE_HINT, DC_CHAT_ID_ARCHIVED_LINK, DC_CHAT_ID_LAST_SPECIAL,
|
||||||
DC_CHAT_ID_TRASH, DC_GCM_ADDDAYMARKER, DC_GCM_INFO_ONLY, DC_RESEND_USER_AVATAR_DAYS,
|
DC_CHAT_ID_TRASH, DC_RESEND_USER_AVATAR_DAYS,
|
||||||
};
|
};
|
||||||
use crate::contact::{Contact, ContactId, Origin, VerifiedStatus};
|
use crate::contact::{Contact, ContactId, Origin, VerifiedStatus};
|
||||||
use crate::context::Context;
|
use crate::context::Context;
|
||||||
@@ -2376,12 +2376,40 @@ pub async fn send_videochat_invitation(context: &Context, chat_id: ChatId) -> Re
|
|||||||
send_msg(context, chat_id, &mut msg).await
|
send_msg(context, chat_id, &mut msg).await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_chat_msgs(
|
/// Chat message list request options.
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct MessageListOptions {
|
||||||
|
/// Return only info messages.
|
||||||
|
pub info_only: bool,
|
||||||
|
|
||||||
|
/// Add day markers before each date regarding the local timezone.
|
||||||
|
pub add_daymarker: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns all messages belonging to the chat.
|
||||||
|
pub async fn get_chat_msgs(context: &Context, chat_id: ChatId) -> Result<Vec<ChatItem>> {
|
||||||
|
get_chat_msgs_ex(
|
||||||
|
context,
|
||||||
|
chat_id,
|
||||||
|
MessageListOptions {
|
||||||
|
info_only: false,
|
||||||
|
add_daymarker: false,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns messages belonging to the chat according to the given options.
|
||||||
|
pub async fn get_chat_msgs_ex(
|
||||||
context: &Context,
|
context: &Context,
|
||||||
chat_id: ChatId,
|
chat_id: ChatId,
|
||||||
flags: u32,
|
options: MessageListOptions,
|
||||||
) -> Result<Vec<ChatItem>> {
|
) -> Result<Vec<ChatItem>> {
|
||||||
let process_row = if (flags & DC_GCM_INFO_ONLY) != 0 {
|
let MessageListOptions {
|
||||||
|
info_only,
|
||||||
|
add_daymarker,
|
||||||
|
} = options;
|
||||||
|
let process_row = if info_only {
|
||||||
|row: &rusqlite::Row| {
|
|row: &rusqlite::Row| {
|
||||||
// is_info logic taken from Message.is_info()
|
// is_info logic taken from Message.is_info()
|
||||||
let params = row.get::<_, String>("param")?;
|
let params = row.get::<_, String>("param")?;
|
||||||
@@ -2431,7 +2459,7 @@ pub async fn get_chat_msgs(
|
|||||||
let cnv_to_local = gm2local_offset();
|
let cnv_to_local = gm2local_offset();
|
||||||
|
|
||||||
for (ts, curr_id) in sorted_rows {
|
for (ts, curr_id) in sorted_rows {
|
||||||
if (flags & DC_GCM_ADDDAYMARKER) != 0 {
|
if add_daymarker {
|
||||||
let curr_local_timestamp = ts + cnv_to_local;
|
let curr_local_timestamp = ts + cnv_to_local;
|
||||||
let curr_day = curr_local_timestamp / 86400;
|
let curr_day = curr_local_timestamp / 86400;
|
||||||
if curr_day != last_day {
|
if curr_day != last_day {
|
||||||
@@ -2446,7 +2474,7 @@ pub async fn get_chat_msgs(
|
|||||||
Ok(ret)
|
Ok(ret)
|
||||||
};
|
};
|
||||||
|
|
||||||
let items = if (flags & DC_GCM_INFO_ONLY) != 0 {
|
let items = if info_only {
|
||||||
context
|
context
|
||||||
.sql
|
.sql
|
||||||
.query_map(
|
.query_map(
|
||||||
@@ -4942,7 +4970,7 @@ mod tests {
|
|||||||
assert!(chat.is_protected());
|
assert!(chat.is_protected());
|
||||||
assert!(chat.is_unpromoted());
|
assert!(chat.is_unpromoted());
|
||||||
|
|
||||||
let msgs = get_chat_msgs(&t, chat_id, 0).await?;
|
let msgs = get_chat_msgs(&t, chat_id).await?;
|
||||||
assert_eq!(msgs.len(), 1);
|
assert_eq!(msgs.len(), 1);
|
||||||
|
|
||||||
let msg = t.get_last_msg_in(chat_id).await;
|
let msg = t.get_last_msg_in(chat_id).await;
|
||||||
@@ -4971,7 +4999,7 @@ mod tests {
|
|||||||
assert!(!chat.is_protected());
|
assert!(!chat.is_protected());
|
||||||
assert!(!chat.is_unpromoted());
|
assert!(!chat.is_unpromoted());
|
||||||
|
|
||||||
let msgs = get_chat_msgs(&t, chat_id, 0).await?;
|
let msgs = get_chat_msgs(&t, chat_id).await?;
|
||||||
assert_eq!(msgs.len(), 3);
|
assert_eq!(msgs.len(), 3);
|
||||||
|
|
||||||
// enable protection on promoted chat, the info-message is sent via send_msg() this time
|
// enable protection on promoted chat, the info-message is sent via send_msg() this time
|
||||||
@@ -5069,7 +5097,7 @@ mod tests {
|
|||||||
add_contact_to_chat(&alice, alice_chat_id, contact_id).await?;
|
add_contact_to_chat(&alice, alice_chat_id, contact_id).await?;
|
||||||
assert_eq!(get_chat_contacts(&alice, alice_chat_id).await?.len(), 2);
|
assert_eq!(get_chat_contacts(&alice, alice_chat_id).await?.len(), 2);
|
||||||
send_text_msg(&alice, alice_chat_id, "hi!".to_string()).await?;
|
send_text_msg(&alice, alice_chat_id, "hi!".to_string()).await?;
|
||||||
assert_eq!(get_chat_msgs(&alice, alice_chat_id, 0).await?.len(), 1);
|
assert_eq!(get_chat_msgs(&alice, alice_chat_id).await?.len(), 1);
|
||||||
|
|
||||||
// Alice has an SMTP-server replacing the `Message-ID:`-header (as done eg. by outlook.com).
|
// Alice has an SMTP-server replacing the `Message-ID:`-header (as done eg. by outlook.com).
|
||||||
let sent_msg = alice.pop_sent_msg().await;
|
let sent_msg = alice.pop_sent_msg().await;
|
||||||
@@ -5102,7 +5130,7 @@ mod tests {
|
|||||||
let msg = alice.get_last_msg().await;
|
let msg = alice.get_last_msg().await;
|
||||||
assert_eq!(msg.chat_id, alice_chat_id);
|
assert_eq!(msg.chat_id, alice_chat_id);
|
||||||
assert_eq!(msg.text, Some("ho!".to_string()));
|
assert_eq!(msg.text, Some("ho!".to_string()));
|
||||||
assert_eq!(get_chat_msgs(&alice, alice_chat_id, 0).await?.len(), 2);
|
assert_eq!(get_chat_msgs(&alice, alice_chat_id).await?.len(), 2);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -5130,7 +5158,7 @@ mod tests {
|
|||||||
assert_eq!(chat.id.get_fresh_msg_cnt(&t).await?, 1);
|
assert_eq!(chat.id.get_fresh_msg_cnt(&t).await?, 1);
|
||||||
assert_eq!(t.get_fresh_msgs().await?.len(), 1);
|
assert_eq!(t.get_fresh_msgs().await?.len(), 1);
|
||||||
|
|
||||||
let msgs = get_chat_msgs(&t, chat.id, 0).await?;
|
let msgs = get_chat_msgs(&t, chat.id).await?;
|
||||||
assert_eq!(msgs.len(), 1);
|
assert_eq!(msgs.len(), 1);
|
||||||
let msg_id = match msgs.first().unwrap() {
|
let msg_id = match msgs.first().unwrap() {
|
||||||
ChatItem::Message { msg_id } => *msg_id,
|
ChatItem::Message { msg_id } => *msg_id,
|
||||||
@@ -5180,7 +5208,7 @@ mod tests {
|
|||||||
.is_contact_request());
|
.is_contact_request());
|
||||||
assert_eq!(chat_id.get_msg_cnt(&t).await?, 1);
|
assert_eq!(chat_id.get_msg_cnt(&t).await?, 1);
|
||||||
assert_eq!(chat_id.get_fresh_msg_cnt(&t).await?, 1);
|
assert_eq!(chat_id.get_fresh_msg_cnt(&t).await?, 1);
|
||||||
let msgs = get_chat_msgs(&t, chat_id, 0).await?;
|
let msgs = get_chat_msgs(&t, chat_id).await?;
|
||||||
assert_eq!(msgs.len(), 1);
|
assert_eq!(msgs.len(), 1);
|
||||||
let msg_id = match msgs.first().unwrap() {
|
let msg_id = match msgs.first().unwrap() {
|
||||||
ChatItem::Message { msg_id } => *msg_id,
|
ChatItem::Message { msg_id } => *msg_id,
|
||||||
@@ -5268,7 +5296,7 @@ mod tests {
|
|||||||
let chat_id = msg.chat_id;
|
let chat_id = msg.chat_id;
|
||||||
assert_eq!(chat_id.get_fresh_msg_cnt(&alice).await?, 1);
|
assert_eq!(chat_id.get_fresh_msg_cnt(&alice).await?, 1);
|
||||||
|
|
||||||
let msgs = get_chat_msgs(&alice, chat_id, 0).await?;
|
let msgs = get_chat_msgs(&alice, chat_id).await?;
|
||||||
assert_eq!(msgs.len(), 1);
|
assert_eq!(msgs.len(), 1);
|
||||||
|
|
||||||
// Alice disables receiving classic emails.
|
// Alice disables receiving classic emails.
|
||||||
@@ -5280,7 +5308,7 @@ mod tests {
|
|||||||
// Already received classic email should still be in the chat.
|
// Already received classic email should still be in the chat.
|
||||||
assert_eq!(chat_id.get_fresh_msg_cnt(&alice).await?, 1);
|
assert_eq!(chat_id.get_fresh_msg_cnt(&alice).await?, 1);
|
||||||
|
|
||||||
let msgs = get_chat_msgs(&alice, chat_id, 0).await?;
|
let msgs = get_chat_msgs(&alice, chat_id).await?;
|
||||||
assert_eq!(msgs.len(), 1);
|
assert_eq!(msgs.len(), 1);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -5427,7 +5455,7 @@ mod tests {
|
|||||||
assert!(msg1.get_text().unwrap().contains("bob@example.net"));
|
assert!(msg1.get_text().unwrap().contains("bob@example.net"));
|
||||||
|
|
||||||
let chat_id2 = ChatId::create_for_contact(&t, bob_id).await?;
|
let chat_id2 = ChatId::create_for_contact(&t, bob_id).await?;
|
||||||
assert_eq!(get_chat_msgs(&t, chat_id2, 0).await?.len(), 0);
|
assert_eq!(get_chat_msgs(&t, chat_id2).await?.len(), 0);
|
||||||
forward_msgs(&t, &[msg1.id], chat_id2).await?;
|
forward_msgs(&t, &[msg1.id], chat_id2).await?;
|
||||||
let msg2 = t.get_last_msg_in(chat_id2).await;
|
let msg2 = t.get_last_msg_in(chat_id2).await;
|
||||||
assert!(!msg2.is_info()); // forwarded info-messages lose their info-state
|
assert!(!msg2.is_info()); // forwarded info-messages lose their info-state
|
||||||
@@ -5596,15 +5624,15 @@ mod tests {
|
|||||||
let msg = bob.recv_msg(&sent1).await;
|
let msg = bob.recv_msg(&sent1).await;
|
||||||
assert_eq!(msg.get_text().unwrap(), "alice->bob");
|
assert_eq!(msg.get_text().unwrap(), "alice->bob");
|
||||||
assert_eq!(get_chat_contacts(&bob, msg.chat_id).await?.len(), 2);
|
assert_eq!(get_chat_contacts(&bob, msg.chat_id).await?.len(), 2);
|
||||||
assert_eq!(get_chat_msgs(&bob, msg.chat_id, 0).await?.len(), 1);
|
assert_eq!(get_chat_msgs(&bob, msg.chat_id).await?.len(), 1);
|
||||||
bob.recv_msg(&sent2).await;
|
bob.recv_msg(&sent2).await;
|
||||||
assert_eq!(get_chat_contacts(&bob, msg.chat_id).await?.len(), 3);
|
assert_eq!(get_chat_contacts(&bob, msg.chat_id).await?.len(), 3);
|
||||||
assert_eq!(get_chat_msgs(&bob, msg.chat_id, 0).await?.len(), 2);
|
assert_eq!(get_chat_msgs(&bob, msg.chat_id).await?.len(), 2);
|
||||||
let received = bob.recv_msg_opt(&sent3).await;
|
let received = bob.recv_msg_opt(&sent3).await;
|
||||||
// No message should actually be added since we already know this message:
|
// No message should actually be added since we already know this message:
|
||||||
assert!(received.is_none());
|
assert!(received.is_none());
|
||||||
assert_eq!(get_chat_contacts(&bob, msg.chat_id).await?.len(), 3);
|
assert_eq!(get_chat_contacts(&bob, msg.chat_id).await?.len(), 3);
|
||||||
assert_eq!(get_chat_msgs(&bob, msg.chat_id, 0).await?.len(), 2);
|
assert_eq!(get_chat_msgs(&bob, msg.chat_id).await?.len(), 2);
|
||||||
|
|
||||||
// Claire does not receive the first message, however, due to resending, she has a similar view as Alice and Bob
|
// Claire does not receive the first message, however, due to resending, she has a similar view as Alice and Bob
|
||||||
let claire = TestContext::new().await;
|
let claire = TestContext::new().await;
|
||||||
@@ -5613,7 +5641,7 @@ mod tests {
|
|||||||
let msg = claire.recv_msg(&sent3).await;
|
let msg = claire.recv_msg(&sent3).await;
|
||||||
assert_eq!(msg.get_text().unwrap(), "alice->bob");
|
assert_eq!(msg.get_text().unwrap(), "alice->bob");
|
||||||
assert_eq!(get_chat_contacts(&claire, msg.chat_id).await?.len(), 3);
|
assert_eq!(get_chat_contacts(&claire, msg.chat_id).await?.len(), 3);
|
||||||
assert_eq!(get_chat_msgs(&claire, msg.chat_id, 0).await?.len(), 2);
|
assert_eq!(get_chat_msgs(&claire, msg.chat_id).await?.len(), 2);
|
||||||
let msg_from = Contact::get_by_id(&claire, msg.get_from_id()).await?;
|
let msg_from = Contact::get_by_id(&claire, msg.get_from_id()).await?;
|
||||||
assert_eq!(msg_from.get_addr(), "alice@example.org");
|
assert_eq!(msg_from.get_addr(), "alice@example.org");
|
||||||
|
|
||||||
|
|||||||
@@ -112,9 +112,6 @@ pub const DC_GCL_NO_SPECIALS: usize = 0x02;
|
|||||||
pub const DC_GCL_ADD_ALLDONE_HINT: usize = 0x04;
|
pub const DC_GCL_ADD_ALLDONE_HINT: usize = 0x04;
|
||||||
pub const DC_GCL_FOR_FORWARDING: usize = 0x08;
|
pub const DC_GCL_FOR_FORWARDING: usize = 0x08;
|
||||||
|
|
||||||
pub const DC_GCM_ADDDAYMARKER: u32 = 0x01;
|
|
||||||
pub const DC_GCM_INFO_ONLY: u32 = 0x02;
|
|
||||||
|
|
||||||
pub const DC_GCL_VERIFIED_ONLY: u32 = 0x01;
|
pub const DC_GCL_VERIFIED_ONLY: u32 = 0x01;
|
||||||
pub const DC_GCL_ADD_SELF: u32 = 0x02;
|
pub const DC_GCL_ADD_SELF: u32 = 0x02;
|
||||||
|
|
||||||
|
|||||||
@@ -978,20 +978,20 @@ mod tests {
|
|||||||
assert_eq!(t.get_fresh_msgs().await.unwrap().len(), 0);
|
assert_eq!(t.get_fresh_msgs().await.unwrap().len(), 0);
|
||||||
|
|
||||||
receive_msg(&t, &bob).await;
|
receive_msg(&t, &bob).await;
|
||||||
assert_eq!(get_chat_msgs(&t, bob.id, 0).await.unwrap().len(), 1);
|
assert_eq!(get_chat_msgs(&t, bob.id).await.unwrap().len(), 1);
|
||||||
assert_eq!(bob.id.get_fresh_msg_cnt(&t).await.unwrap(), 1);
|
assert_eq!(bob.id.get_fresh_msg_cnt(&t).await.unwrap(), 1);
|
||||||
assert_eq!(t.get_fresh_msgs().await.unwrap().len(), 1);
|
assert_eq!(t.get_fresh_msgs().await.unwrap().len(), 1);
|
||||||
|
|
||||||
receive_msg(&t, &claire).await;
|
receive_msg(&t, &claire).await;
|
||||||
receive_msg(&t, &claire).await;
|
receive_msg(&t, &claire).await;
|
||||||
assert_eq!(get_chat_msgs(&t, claire.id, 0).await.unwrap().len(), 2);
|
assert_eq!(get_chat_msgs(&t, claire.id).await.unwrap().len(), 2);
|
||||||
assert_eq!(claire.id.get_fresh_msg_cnt(&t).await.unwrap(), 2);
|
assert_eq!(claire.id.get_fresh_msg_cnt(&t).await.unwrap(), 2);
|
||||||
assert_eq!(t.get_fresh_msgs().await.unwrap().len(), 3);
|
assert_eq!(t.get_fresh_msgs().await.unwrap().len(), 3);
|
||||||
|
|
||||||
receive_msg(&t, &dave).await;
|
receive_msg(&t, &dave).await;
|
||||||
receive_msg(&t, &dave).await;
|
receive_msg(&t, &dave).await;
|
||||||
receive_msg(&t, &dave).await;
|
receive_msg(&t, &dave).await;
|
||||||
assert_eq!(get_chat_msgs(&t, dave.id, 0).await.unwrap().len(), 3);
|
assert_eq!(get_chat_msgs(&t, dave.id).await.unwrap().len(), 3);
|
||||||
assert_eq!(dave.id.get_fresh_msg_cnt(&t).await.unwrap(), 3);
|
assert_eq!(dave.id.get_fresh_msg_cnt(&t).await.unwrap(), 3);
|
||||||
assert_eq!(t.get_fresh_msgs().await.unwrap().len(), 6);
|
assert_eq!(t.get_fresh_msgs().await.unwrap().len(), 6);
|
||||||
|
|
||||||
@@ -1006,7 +1006,7 @@ mod tests {
|
|||||||
receive_msg(&t, &bob).await;
|
receive_msg(&t, &bob).await;
|
||||||
receive_msg(&t, &claire).await;
|
receive_msg(&t, &claire).await;
|
||||||
receive_msg(&t, &dave).await;
|
receive_msg(&t, &dave).await;
|
||||||
assert_eq!(get_chat_msgs(&t, claire.id, 0).await.unwrap().len(), 3);
|
assert_eq!(get_chat_msgs(&t, claire.id).await.unwrap().len(), 3);
|
||||||
assert_eq!(claire.id.get_fresh_msg_cnt(&t).await.unwrap(), 3);
|
assert_eq!(claire.id.get_fresh_msg_cnt(&t).await.unwrap(), 3);
|
||||||
assert_eq!(t.get_fresh_msgs().await.unwrap().len(), 6); // muted claire is not counted
|
assert_eq!(t.get_fresh_msgs().await.unwrap().len(), 6); // muted claire is not counted
|
||||||
|
|
||||||
@@ -1023,7 +1023,7 @@ mod tests {
|
|||||||
let t = TestContext::new_alice().await;
|
let t = TestContext::new_alice().await;
|
||||||
let bob = t.create_chat_with_contact("", "bob@g.it").await;
|
let bob = t.create_chat_with_contact("", "bob@g.it").await;
|
||||||
receive_msg(&t, &bob).await;
|
receive_msg(&t, &bob).await;
|
||||||
assert_eq!(get_chat_msgs(&t, bob.id, 0).await.unwrap().len(), 1);
|
assert_eq!(get_chat_msgs(&t, bob.id).await.unwrap().len(), 1);
|
||||||
|
|
||||||
// chat is unmuted by default, here and in the following assert(),
|
// chat is unmuted by default, here and in the following assert(),
|
||||||
// we check mainly that the SQL-statements in is_muted() and get_fresh_msgs()
|
// we check mainly that the SQL-statements in is_muted() and get_fresh_msgs()
|
||||||
|
|||||||
@@ -450,7 +450,7 @@ mod tests {
|
|||||||
.await?;
|
.await?;
|
||||||
let msg = bob.get_last_msg().await;
|
let msg = bob.get_last_msg().await;
|
||||||
let chat_id = msg.chat_id;
|
let chat_id = msg.chat_id;
|
||||||
assert_eq!(get_chat_msgs(&bob, chat_id, 0).await?.len(), 1);
|
assert_eq!(get_chat_msgs(&bob, chat_id).await?.len(), 1);
|
||||||
assert_eq!(msg.download_state(), DownloadState::Available);
|
assert_eq!(msg.download_state(), DownloadState::Available);
|
||||||
|
|
||||||
// downloading the status update afterwards expands to nothing and moves the placeholder to trash-chat
|
// downloading the status update afterwards expands to nothing and moves the placeholder to trash-chat
|
||||||
@@ -464,7 +464,7 @@ mod tests {
|
|||||||
false,
|
false,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
assert_eq!(get_chat_msgs(&bob, chat_id, 0).await?.len(), 0);
|
assert_eq!(get_chat_msgs(&bob, chat_id).await?.len(), 0);
|
||||||
assert!(Message::load_from_db(&bob, msg.id)
|
assert!(Message::load_from_db(&bob, msg.id)
|
||||||
.await?
|
.await?
|
||||||
.chat_id
|
.chat_id
|
||||||
@@ -517,13 +517,13 @@ mod tests {
|
|||||||
.await?;
|
.await?;
|
||||||
let msg = bob.get_last_msg().await;
|
let msg = bob.get_last_msg().await;
|
||||||
let chat_id = msg.chat_id;
|
let chat_id = msg.chat_id;
|
||||||
assert_eq!(get_chat_msgs(&bob, chat_id, 0).await?.len(), 1);
|
assert_eq!(get_chat_msgs(&bob, chat_id).await?.len(), 1);
|
||||||
assert_eq!(msg.download_state(), DownloadState::Available);
|
assert_eq!(msg.download_state(), DownloadState::Available);
|
||||||
|
|
||||||
// downloading the mdn afterwards expands to nothing and deletes the placeholder directly
|
// downloading the mdn afterwards expands to nothing and deletes the placeholder directly
|
||||||
// (usually mdn are too small for not being downloaded directly)
|
// (usually mdn are too small for not being downloaded directly)
|
||||||
receive_imf_inner(&bob, "bar@example.org", raw, false, None, false).await?;
|
receive_imf_inner(&bob, "bar@example.org", raw, false, None, false).await?;
|
||||||
assert_eq!(get_chat_msgs(&bob, chat_id, 0).await?.len(), 0);
|
assert_eq!(get_chat_msgs(&bob, chat_id).await?.len(), 0);
|
||||||
assert!(Message::load_from_db(&bob, msg.id)
|
assert!(Message::load_from_db(&bob, msg.id)
|
||||||
.await?
|
.await?
|
||||||
.chat_id
|
.chat_id
|
||||||
|
|||||||
@@ -1080,7 +1080,7 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn check_msg_is_deleted(t: &TestContext, chat: &Chat, msg_id: MsgId) {
|
async fn check_msg_is_deleted(t: &TestContext, chat: &Chat, msg_id: MsgId) {
|
||||||
let chat_items = chat::get_chat_msgs(t, chat.id, 0).await.unwrap();
|
let chat_items = chat::get_chat_msgs(t, chat.id).await.unwrap();
|
||||||
// Check that the chat is empty except for possibly info messages:
|
// Check that the chat is empty except for possibly info messages:
|
||||||
for item in &chat_items {
|
for item in &chat_items {
|
||||||
if let ChatItem::Message { msg_id } = item {
|
if let ChatItem::Message { msg_id } = item {
|
||||||
|
|||||||
@@ -2144,7 +2144,7 @@ mod tests {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let mut has_image = false;
|
let mut has_image = false;
|
||||||
let chatitems = chat::get_chat_msgs(&t, device_chat_id, 0).await.unwrap();
|
let chatitems = chat::get_chat_msgs(&t, device_chat_id).await.unwrap();
|
||||||
for chatitem in chatitems {
|
for chatitem in chatitems {
|
||||||
if let ChatItem::Message { msg_id } = chatitem {
|
if let ChatItem::Message { msg_id } = chatitem {
|
||||||
if let Ok(msg) = Message::load_from_db(&t, msg_id).await {
|
if let Ok(msg) = Message::load_from_db(&t, msg_id).await {
|
||||||
@@ -2288,7 +2288,7 @@ mod tests {
|
|||||||
assert_eq!(msg1.chat_id, msg2.chat_id);
|
assert_eq!(msg1.chat_id, msg2.chat_id);
|
||||||
let chats = Chatlist::try_load(&bob, 0, None, None).await?;
|
let chats = Chatlist::try_load(&bob, 0, None, None).await?;
|
||||||
assert_eq!(chats.len(), 1);
|
assert_eq!(chats.len(), 1);
|
||||||
let msgs = chat::get_chat_msgs(&bob, bob_chat_id, 0).await?;
|
let msgs = chat::get_chat_msgs(&bob, bob_chat_id).await?;
|
||||||
assert_eq!(msgs.len(), 2);
|
assert_eq!(msgs.len(), 2);
|
||||||
assert_eq!(bob.get_fresh_msgs().await?.len(), 0);
|
assert_eq!(bob.get_fresh_msgs().await?.len(), 0);
|
||||||
|
|
||||||
@@ -2299,7 +2299,7 @@ mod tests {
|
|||||||
let bob_chat = Chat::load_from_db(&bob, bob_chat_id).await?;
|
let bob_chat = Chat::load_from_db(&bob, bob_chat_id).await?;
|
||||||
assert_eq!(bob_chat.blocked, Blocked::Request);
|
assert_eq!(bob_chat.blocked, Blocked::Request);
|
||||||
|
|
||||||
let msgs = chat::get_chat_msgs(&bob, bob_chat_id, 0).await?;
|
let msgs = chat::get_chat_msgs(&bob, bob_chat_id).await?;
|
||||||
assert_eq!(msgs.len(), 2);
|
assert_eq!(msgs.len(), 2);
|
||||||
bob_chat_id.accept(&bob).await.unwrap();
|
bob_chat_id.accept(&bob).await.unwrap();
|
||||||
|
|
||||||
|
|||||||
@@ -443,24 +443,24 @@ Content-Disposition: reaction\n\
|
|||||||
let chat_alice = alice.create_chat(&bob).await;
|
let chat_alice = alice.create_chat(&bob).await;
|
||||||
let alice_msg = alice.send_text(chat_alice.id, "Hi!").await;
|
let alice_msg = alice.send_text(chat_alice.id, "Hi!").await;
|
||||||
let bob_msg = bob.recv_msg(&alice_msg).await;
|
let bob_msg = bob.recv_msg(&alice_msg).await;
|
||||||
assert_eq!(get_chat_msgs(&alice, chat_alice.id, 0).await?.len(), 1);
|
assert_eq!(get_chat_msgs(&alice, chat_alice.id).await?.len(), 1);
|
||||||
assert_eq!(get_chat_msgs(&bob, bob_msg.chat_id, 0).await?.len(), 1);
|
assert_eq!(get_chat_msgs(&bob, bob_msg.chat_id).await?.len(), 1);
|
||||||
|
|
||||||
let alice_msg2 = alice.send_text(chat_alice.id, "Hi again!").await;
|
let alice_msg2 = alice.send_text(chat_alice.id, "Hi again!").await;
|
||||||
bob.recv_msg(&alice_msg2).await;
|
bob.recv_msg(&alice_msg2).await;
|
||||||
assert_eq!(get_chat_msgs(&alice, chat_alice.id, 0).await?.len(), 2);
|
assert_eq!(get_chat_msgs(&alice, chat_alice.id).await?.len(), 2);
|
||||||
assert_eq!(get_chat_msgs(&bob, bob_msg.chat_id, 0).await?.len(), 2);
|
assert_eq!(get_chat_msgs(&bob, bob_msg.chat_id).await?.len(), 2);
|
||||||
|
|
||||||
bob_msg.chat_id.accept(&bob).await?;
|
bob_msg.chat_id.accept(&bob).await?;
|
||||||
|
|
||||||
send_reaction(&bob, bob_msg.id, "👍").await.unwrap();
|
send_reaction(&bob, bob_msg.id, "👍").await.unwrap();
|
||||||
expect_reactions_changed_event(&bob, bob_msg.chat_id, bob_msg.id, ContactId::SELF).await?;
|
expect_reactions_changed_event(&bob, bob_msg.chat_id, bob_msg.id, ContactId::SELF).await?;
|
||||||
assert_eq!(get_chat_msgs(&bob, bob_msg.chat_id, 0).await?.len(), 2);
|
assert_eq!(get_chat_msgs(&bob, bob_msg.chat_id).await?.len(), 2);
|
||||||
|
|
||||||
let bob_reaction_msg = bob.pop_sent_msg().await;
|
let bob_reaction_msg = bob.pop_sent_msg().await;
|
||||||
let alice_reaction_msg = alice.recv_msg_opt(&bob_reaction_msg).await.unwrap();
|
let alice_reaction_msg = alice.recv_msg_opt(&bob_reaction_msg).await.unwrap();
|
||||||
assert_eq!(alice_reaction_msg.chat_id, DC_CHAT_ID_TRASH);
|
assert_eq!(alice_reaction_msg.chat_id, DC_CHAT_ID_TRASH);
|
||||||
assert_eq!(get_chat_msgs(&alice, chat_alice.id, 0).await?.len(), 2);
|
assert_eq!(get_chat_msgs(&alice, chat_alice.id).await?.len(), 2);
|
||||||
|
|
||||||
let reactions = get_msg_reactions(&alice, alice_msg.sender_msg_id).await?;
|
let reactions = get_msg_reactions(&alice, alice_msg.sender_msg_id).await?;
|
||||||
assert_eq!(reactions.to_string(), "👍1");
|
assert_eq!(reactions.to_string(), "👍1");
|
||||||
|
|||||||
@@ -154,12 +154,12 @@ async fn test_adhoc_group_show_accepted_contact_accepted() {
|
|||||||
assert_eq!(chat.typ, Chattype::Single);
|
assert_eq!(chat.typ, Chattype::Single);
|
||||||
assert_eq!(chat.name, "Bob");
|
assert_eq!(chat.name, "Bob");
|
||||||
assert_eq!(chat::get_chat_contacts(&t, chat_id).await.unwrap().len(), 1);
|
assert_eq!(chat::get_chat_contacts(&t, chat_id).await.unwrap().len(), 1);
|
||||||
assert_eq!(chat::get_chat_msgs(&t, chat_id, 0).await.unwrap().len(), 1);
|
assert_eq!(chat::get_chat_msgs(&t, chat_id).await.unwrap().len(), 1);
|
||||||
|
|
||||||
// receive a non-delta-message from Bob, shows up because of the show_emails setting
|
// receive a non-delta-message from Bob, shows up because of the show_emails setting
|
||||||
receive_imf(&t, ONETOONE_NOREPLY_MAIL, false).await.unwrap();
|
receive_imf(&t, ONETOONE_NOREPLY_MAIL, false).await.unwrap();
|
||||||
|
|
||||||
assert_eq!(chat::get_chat_msgs(&t, chat_id, 0).await.unwrap().len(), 2);
|
assert_eq!(chat::get_chat_msgs(&t, chat_id).await.unwrap().len(), 2);
|
||||||
|
|
||||||
// let Bob create an adhoc-group by a non-delta-message, shows up because of the show_emails setting
|
// let Bob create an adhoc-group by a non-delta-message, shows up because of the show_emails setting
|
||||||
receive_imf(&t, GRP_MAIL, false).await.unwrap();
|
receive_imf(&t, GRP_MAIL, false).await.unwrap();
|
||||||
@@ -208,7 +208,7 @@ async fn test_read_receipt_and_unarchive() -> Result<()> {
|
|||||||
// create a group with bob, archive group
|
// create a group with bob, archive group
|
||||||
let group_id = chat::create_group_chat(&t, ProtectionStatus::Unprotected, "foo").await?;
|
let group_id = chat::create_group_chat(&t, ProtectionStatus::Unprotected, "foo").await?;
|
||||||
chat::add_contact_to_chat(&t, group_id, bob_id).await?;
|
chat::add_contact_to_chat(&t, group_id, bob_id).await?;
|
||||||
assert_eq!(chat::get_chat_msgs(&t, group_id, 0).await.unwrap().len(), 0);
|
assert_eq!(chat::get_chat_msgs(&t, group_id).await.unwrap().len(), 0);
|
||||||
group_id
|
group_id
|
||||||
.set_visibility(&t, ChatVisibility::Archived)
|
.set_visibility(&t, ChatVisibility::Archived)
|
||||||
.await?;
|
.await?;
|
||||||
@@ -289,7 +289,7 @@ async fn test_read_receipt_and_unarchive() -> Result<()> {
|
|||||||
false,
|
false,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
assert_eq!(chat::get_chat_msgs(&t, group_id, 0).await?.len(), 1);
|
assert_eq!(chat::get_chat_msgs(&t, group_id).await?.len(), 1);
|
||||||
let msg = message::Message::load_from_db(&t, msg.id).await?;
|
let msg = message::Message::load_from_db(&t, msg.id).await?;
|
||||||
assert_eq!(msg.state, MessageState::OutMdnRcvd);
|
assert_eq!(msg.state, MessageState::OutMdnRcvd);
|
||||||
|
|
||||||
@@ -705,7 +705,7 @@ async fn test_parse_ndn_group_msg() -> Result<()> {
|
|||||||
|
|
||||||
assert_eq!(msg.state, MessageState::OutFailed);
|
assert_eq!(msg.state, MessageState::OutFailed);
|
||||||
|
|
||||||
let msgs = chat::get_chat_msgs(&t, msg.chat_id, 0).await?;
|
let msgs = chat::get_chat_msgs(&t, msg.chat_id).await?;
|
||||||
let msg_id = if let ChatItem::Message { msg_id } = msgs.last().unwrap() {
|
let msg_id = if let ChatItem::Message { msg_id } = msgs.last().unwrap() {
|
||||||
msg_id
|
msg_id
|
||||||
} else {
|
} else {
|
||||||
@@ -966,7 +966,7 @@ async fn test_block_mailing_list() {
|
|||||||
assert_eq!(chats.len(), 0); // Test that the message is not shown
|
assert_eq!(chats.len(), 0); // Test that the message is not shown
|
||||||
|
|
||||||
// Both messages are in the same blocked chat.
|
// Both messages are in the same blocked chat.
|
||||||
let msgs = chat::get_chat_msgs(&t.ctx, chat_id, 0).await.unwrap();
|
let msgs = chat::get_chat_msgs(&t.ctx, chat_id).await.unwrap();
|
||||||
assert_eq!(msgs.len(), 2);
|
assert_eq!(msgs.len(), 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -997,7 +997,7 @@ async fn test_mailing_list_decide_block_then_unblock() {
|
|||||||
|
|
||||||
receive_imf(&t.ctx, DC_MAILINGLIST2, false).await.unwrap();
|
receive_imf(&t.ctx, DC_MAILINGLIST2, false).await.unwrap();
|
||||||
let msg = t.get_last_msg().await;
|
let msg = t.get_last_msg().await;
|
||||||
let msgs = chat::get_chat_msgs(&t, msg.chat_id, 0).await.unwrap();
|
let msgs = chat::get_chat_msgs(&t, msg.chat_id).await.unwrap();
|
||||||
assert_eq!(msgs.len(), 2);
|
assert_eq!(msgs.len(), 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1019,14 +1019,14 @@ async fn test_mailing_list_decide_not_now() {
|
|||||||
|
|
||||||
let chats = Chatlist::try_load(&t.ctx, 0, None, None).await.unwrap();
|
let chats = Chatlist::try_load(&t.ctx, 0, None, None).await.unwrap();
|
||||||
assert_eq!(chats.len(), 1); // Test that chat is still in the chatlist
|
assert_eq!(chats.len(), 1); // Test that chat is still in the chatlist
|
||||||
let msgs = chat::get_chat_msgs(&t.ctx, chat_id, 0).await.unwrap();
|
let msgs = chat::get_chat_msgs(&t.ctx, chat_id).await.unwrap();
|
||||||
assert_eq!(msgs.len(), 1); // ...and contains 1 message
|
assert_eq!(msgs.len(), 1); // ...and contains 1 message
|
||||||
|
|
||||||
receive_imf(&t.ctx, DC_MAILINGLIST2, false).await.unwrap();
|
receive_imf(&t.ctx, DC_MAILINGLIST2, false).await.unwrap();
|
||||||
|
|
||||||
let chats = Chatlist::try_load(&t.ctx, 0, None, None).await.unwrap();
|
let chats = Chatlist::try_load(&t.ctx, 0, None, None).await.unwrap();
|
||||||
assert_eq!(chats.len(), 1); // Test that the new mailing list message got into the same chat
|
assert_eq!(chats.len(), 1); // Test that the new mailing list message got into the same chat
|
||||||
let msgs = chat::get_chat_msgs(&t.ctx, chat_id, 0).await.unwrap();
|
let msgs = chat::get_chat_msgs(&t.ctx, chat_id).await.unwrap();
|
||||||
assert_eq!(msgs.len(), 2);
|
assert_eq!(msgs.len(), 2);
|
||||||
let chat = Chat::load_from_db(&t.ctx, chat_id).await.unwrap();
|
let chat = Chat::load_from_db(&t.ctx, chat_id).await.unwrap();
|
||||||
assert!(chat.is_contact_request());
|
assert!(chat.is_contact_request());
|
||||||
@@ -1052,7 +1052,7 @@ async fn test_mailing_list_decide_accept() {
|
|||||||
|
|
||||||
receive_imf(&t.ctx, DC_MAILINGLIST2, false).await.unwrap();
|
receive_imf(&t.ctx, DC_MAILINGLIST2, false).await.unwrap();
|
||||||
|
|
||||||
let msgs = chat::get_chat_msgs(&t.ctx, chat_id, 0).await.unwrap();
|
let msgs = chat::get_chat_msgs(&t.ctx, chat_id).await.unwrap();
|
||||||
assert_eq!(msgs.len(), 2);
|
assert_eq!(msgs.len(), 2);
|
||||||
let chat = chat::Chat::load_from_db(&t.ctx, chat_id).await.unwrap();
|
let chat = chat::Chat::load_from_db(&t.ctx, chat_id).await.unwrap();
|
||||||
assert!(chat.can_send(&t.ctx).await.unwrap());
|
assert!(chat.can_send(&t.ctx).await.unwrap());
|
||||||
@@ -1110,7 +1110,7 @@ async fn test_majordomo_mailing_list() -> Result<()> {
|
|||||||
assert_eq!(chat.typ, Chattype::Mailinglist);
|
assert_eq!(chat.typ, Chattype::Mailinglist);
|
||||||
assert_eq!(chat.grpid, "mylist@bar.org");
|
assert_eq!(chat.grpid, "mylist@bar.org");
|
||||||
assert_eq!(chat.name, "ola");
|
assert_eq!(chat.name, "ola");
|
||||||
assert_eq!(chat::get_chat_msgs(&t, chat.id, 0).await.unwrap().len(), 1);
|
assert_eq!(chat::get_chat_msgs(&t, chat.id).await.unwrap().len(), 1);
|
||||||
assert!(!chat.can_send(&t).await?);
|
assert!(!chat.can_send(&t).await?);
|
||||||
assert_eq!(chat.get_mailinglist_addr(), None);
|
assert_eq!(chat.get_mailinglist_addr(), None);
|
||||||
|
|
||||||
@@ -1131,7 +1131,7 @@ async fn test_majordomo_mailing_list() -> Result<()> {
|
|||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(chat::get_chat_msgs(&t, chat.id, 0).await.unwrap().len(), 2);
|
assert_eq!(chat::get_chat_msgs(&t, chat.id).await.unwrap().len(), 2);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -1330,7 +1330,7 @@ async fn test_mailing_list_with_mimepart_footer() {
|
|||||||
);
|
);
|
||||||
assert!(msg.has_html());
|
assert!(msg.has_html());
|
||||||
let chat = Chat::load_from_db(&t, msg.chat_id).await.unwrap();
|
let chat = Chat::load_from_db(&t, msg.chat_id).await.unwrap();
|
||||||
assert_eq!(get_chat_msgs(&t, msg.chat_id, 0).await.unwrap().len(), 1);
|
assert_eq!(get_chat_msgs(&t, msg.chat_id).await.unwrap().len(), 1);
|
||||||
assert_eq!(chat.typ, Chattype::Mailinglist);
|
assert_eq!(chat.typ, Chattype::Mailinglist);
|
||||||
assert_eq!(chat.blocked, Blocked::Request);
|
assert_eq!(chat.blocked, Blocked::Request);
|
||||||
assert_eq!(chat.grpid, "intern.lists.abc.de");
|
assert_eq!(chat.grpid, "intern.lists.abc.de");
|
||||||
@@ -1350,7 +1350,7 @@ async fn test_mailing_list_with_mimepart_footer_signed() {
|
|||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let msg = t.get_last_msg().await;
|
let msg = t.get_last_msg().await;
|
||||||
assert_eq!(get_chat_msgs(&t, msg.chat_id, 0).await.unwrap().len(), 1);
|
assert_eq!(get_chat_msgs(&t, msg.chat_id).await.unwrap().len(), 1);
|
||||||
let text = msg.text.clone().unwrap();
|
let text = msg.text.clone().unwrap();
|
||||||
assert!(text.contains("content text"));
|
assert!(text.contains("content text"));
|
||||||
assert!(!text.contains("footer text"));
|
assert!(!text.contains("footer text"));
|
||||||
@@ -1547,7 +1547,7 @@ async fn test_many_images() {
|
|||||||
assert_eq!(msg.viewtype, Viewtype::Image);
|
assert_eq!(msg.viewtype, Viewtype::Image);
|
||||||
assert!(msg.has_html());
|
assert!(msg.has_html());
|
||||||
let chat = Chat::load_from_db(&t, msg.chat_id).await.unwrap();
|
let chat = Chat::load_from_db(&t, msg.chat_id).await.unwrap();
|
||||||
assert_eq!(get_chat_msgs(&t, chat.id, 0).await.unwrap().len(), 1);
|
assert_eq!(get_chat_msgs(&t, chat.id).await.unwrap().len(), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Test that classical MUA messages are assigned to group chats based on the `In-Reply-To`
|
/// Test that classical MUA messages are assigned to group chats based on the `In-Reply-To`
|
||||||
@@ -1597,7 +1597,7 @@ async fn test_in_reply_to() {
|
|||||||
assert_eq!(msg.get_text().unwrap(), "reply foo");
|
assert_eq!(msg.get_text().unwrap(), "reply foo");
|
||||||
|
|
||||||
// Load the first message from the same chat.
|
// Load the first message from the same chat.
|
||||||
let msgs = chat::get_chat_msgs(&t, msg.chat_id, 0).await.unwrap();
|
let msgs = chat::get_chat_msgs(&t, msg.chat_id).await.unwrap();
|
||||||
let msg_id = if let ChatItem::Message { msg_id } = msgs.first().unwrap() {
|
let msg_id = if let ChatItem::Message { msg_id } = msgs.first().unwrap() {
|
||||||
msg_id
|
msg_id
|
||||||
} else {
|
} else {
|
||||||
@@ -1824,7 +1824,7 @@ async fn create_test_alias(chat_request: bool, group_request: bool) -> (TestCont
|
|||||||
assert!(msg.get_text().unwrap().contains("hi support!"));
|
assert!(msg.get_text().unwrap().contains("hi support!"));
|
||||||
let chat = Chat::load_from_db(&alice, msg.chat_id).await.unwrap();
|
let chat = Chat::load_from_db(&alice, msg.chat_id).await.unwrap();
|
||||||
assert_eq!(chat.typ, Chattype::Group);
|
assert_eq!(chat.typ, Chattype::Group);
|
||||||
assert_eq!(get_chat_msgs(&alice, chat.id, 0).await.unwrap().len(), 1);
|
assert_eq!(get_chat_msgs(&alice, chat.id).await.unwrap().len(), 1);
|
||||||
if group_request {
|
if group_request {
|
||||||
assert_eq!(get_chat_contacts(&alice, chat.id).await.unwrap().len(), 4);
|
assert_eq!(get_chat_contacts(&alice, chat.id).await.unwrap().len(), 4);
|
||||||
} else {
|
} else {
|
||||||
@@ -1857,7 +1857,7 @@ async fn create_test_alias(chat_request: bool, group_request: bool) -> (TestCont
|
|||||||
} else {
|
} else {
|
||||||
assert_eq!(chat.typ, Chattype::Single);
|
assert_eq!(chat.typ, Chattype::Single);
|
||||||
}
|
}
|
||||||
assert_eq!(get_chat_msgs(&claire, chat.id, 0).await.unwrap().len(), 1);
|
assert_eq!(get_chat_msgs(&claire, chat.id).await.unwrap().len(), 1);
|
||||||
assert_eq!(msg.get_override_sender_name(), None);
|
assert_eq!(msg.get_override_sender_name(), None);
|
||||||
|
|
||||||
(claire, alice)
|
(claire, alice)
|
||||||
@@ -1972,7 +1972,7 @@ async fn test_dont_assign_to_trash_by_parent() {
|
|||||||
println!("\n========= Delete the message ==========");
|
println!("\n========= Delete the message ==========");
|
||||||
msg.id.trash(&t).await.unwrap();
|
msg.id.trash(&t).await.unwrap();
|
||||||
|
|
||||||
let msgs = chat::get_chat_msgs(&t.ctx, chat_id, 0).await.unwrap();
|
let msgs = chat::get_chat_msgs(&t.ctx, chat_id).await.unwrap();
|
||||||
assert_eq!(msgs.len(), 0);
|
assert_eq!(msgs.len(), 0);
|
||||||
|
|
||||||
println!("\n========= Receive a message that is a reply to the deleted message ==========");
|
println!("\n========= Receive a message that is a reply to the deleted message ==========");
|
||||||
@@ -2182,8 +2182,8 @@ Original signature updated",
|
|||||||
.await?;
|
.await?;
|
||||||
let bob = Contact::load_from_db(&t, bob_id).await?;
|
let bob = Contact::load_from_db(&t, bob_id).await?;
|
||||||
assert_eq!(bob.get_status(), "Original signature updated");
|
assert_eq!(bob.get_status(), "Original signature updated");
|
||||||
assert_eq!(get_chat_msgs(&t, one2one_chat_id, 0).await?.len(), 2);
|
assert_eq!(get_chat_msgs(&t, one2one_chat_id).await?.len(), 2);
|
||||||
assert_eq!(get_chat_msgs(&t, ml_chat_id, 0).await?.len(), 1);
|
assert_eq!(get_chat_msgs(&t, ml_chat_id).await?.len(), 1);
|
||||||
assert_eq!(Chatlist::try_load(&t, 0, None, None).await?.len(), 2);
|
assert_eq!(Chatlist::try_load(&t, 0, None, None).await?.len(), 2);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -779,7 +779,7 @@ mod tests {
|
|||||||
use crate::chat;
|
use crate::chat;
|
||||||
use crate::chat::ProtectionStatus;
|
use crate::chat::ProtectionStatus;
|
||||||
use crate::chatlist::Chatlist;
|
use crate::chatlist::Chatlist;
|
||||||
use crate::constants::{Chattype, DC_GCM_ADDDAYMARKER};
|
use crate::constants::Chattype;
|
||||||
use crate::contact::ContactAddress;
|
use crate::contact::ContactAddress;
|
||||||
use crate::contact::VerifiedStatus;
|
use crate::contact::VerifiedStatus;
|
||||||
use crate::peerstate::Peerstate;
|
use crate::peerstate::Peerstate;
|
||||||
@@ -922,7 +922,7 @@ mod tests {
|
|||||||
// Check Alice got the verified message in her 1:1 chat.
|
// Check Alice got the verified message in her 1:1 chat.
|
||||||
{
|
{
|
||||||
let chat = alice.create_chat(&bob).await;
|
let chat = alice.create_chat(&bob).await;
|
||||||
let msg_id = chat::get_chat_msgs(&alice.ctx, chat.get_id(), DC_GCM_ADDDAYMARKER)
|
let msg_id = chat::get_chat_msgs(&alice.ctx, chat.get_id())
|
||||||
.await
|
.await
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.into_iter()
|
.into_iter()
|
||||||
@@ -971,7 +971,7 @@ mod tests {
|
|||||||
// Check Bob got the verified message in his 1:1 chat.
|
// Check Bob got the verified message in his 1:1 chat.
|
||||||
{
|
{
|
||||||
let chat = bob.create_chat(&alice).await;
|
let chat = bob.create_chat(&alice).await;
|
||||||
let msg_id = chat::get_chat_msgs(&bob.ctx, chat.get_id(), DC_GCM_ADDDAYMARKER)
|
let msg_id = chat::get_chat_msgs(&bob.ctx, chat.get_id())
|
||||||
.await
|
.await
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.into_iter()
|
.into_iter()
|
||||||
@@ -1281,7 +1281,7 @@ mod tests {
|
|||||||
Blocked::Yes,
|
Blocked::Yes,
|
||||||
"Alice's 1:1 chat with Bob is not hidden"
|
"Alice's 1:1 chat with Bob is not hidden"
|
||||||
);
|
);
|
||||||
let msg_id = chat::get_chat_msgs(&alice.ctx, alice_chatid, DC_GCM_ADDDAYMARKER)
|
let msg_id = chat::get_chat_msgs(&alice.ctx, alice_chatid)
|
||||||
.await
|
.await
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.into_iter()
|
.into_iter()
|
||||||
@@ -1326,17 +1326,14 @@ mod tests {
|
|||||||
Blocked::Yes,
|
Blocked::Yes,
|
||||||
"Bob's 1:1 chat with Alice is not hidden"
|
"Bob's 1:1 chat with Alice is not hidden"
|
||||||
);
|
);
|
||||||
for item in chat::get_chat_msgs(&bob.ctx, bob_chatid, DC_GCM_ADDDAYMARKER)
|
for item in chat::get_chat_msgs(&bob.ctx, bob_chatid).await.unwrap() {
|
||||||
.await
|
|
||||||
.unwrap()
|
|
||||||
{
|
|
||||||
if let chat::ChatItem::Message { msg_id } = item {
|
if let chat::ChatItem::Message { msg_id } = item {
|
||||||
let msg = Message::load_from_db(&bob.ctx, msg_id).await.unwrap();
|
let msg = Message::load_from_db(&bob.ctx, msg_id).await.unwrap();
|
||||||
let text = msg.get_text().unwrap();
|
let text = msg.get_text().unwrap();
|
||||||
println!("msg {msg_id} text: {text}");
|
println!("msg {msg_id} text: {text}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let mut msg_iter = chat::get_chat_msgs(&bob.ctx, bob_chatid, DC_GCM_ADDDAYMARKER)
|
let mut msg_iter = chat::get_chat_msgs(&bob.ctx, bob_chatid)
|
||||||
.await
|
.await
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.into_iter();
|
.into_iter();
|
||||||
|
|||||||
@@ -1449,16 +1449,10 @@ mod tests {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// delete self-talk first; this adds a message to device-chat about how self-talk can be restored
|
// delete self-talk first; this adds a message to device-chat about how self-talk can be restored
|
||||||
let device_chat_msgs_before = chat::get_chat_msgs(&t, device_chat_id, 0)
|
let device_chat_msgs_before = chat::get_chat_msgs(&t, device_chat_id).await.unwrap().len();
|
||||||
.await
|
|
||||||
.unwrap()
|
|
||||||
.len();
|
|
||||||
self_talk_id.delete(&t).await.ok();
|
self_talk_id.delete(&t).await.ok();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
chat::get_chat_msgs(&t, device_chat_id, 0)
|
chat::get_chat_msgs(&t, device_chat_id).await.unwrap().len(),
|
||||||
.await
|
|
||||||
.unwrap()
|
|
||||||
.len(),
|
|
||||||
device_chat_msgs_before + 1
|
device_chat_msgs_before + 1
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -476,7 +476,7 @@ mod tests {
|
|||||||
let chat = Chat::load_from_db(&alice, chat_id).await?;
|
let chat = Chat::load_from_db(&alice, chat_id).await?;
|
||||||
assert!(chat.is_self_talk());
|
assert!(chat.is_self_talk());
|
||||||
assert_eq!(Chatlist::try_load(&alice, 0, None, None).await?.len(), 1);
|
assert_eq!(Chatlist::try_load(&alice, 0, None, None).await?.len(), 1);
|
||||||
let msgs = chat::get_chat_msgs(&alice, chat_id, 0).await?;
|
let msgs = chat::get_chat_msgs(&alice, chat_id).await?;
|
||||||
assert_eq!(msgs.len(), 0);
|
assert_eq!(msgs.len(), 0);
|
||||||
|
|
||||||
// let alice's other device receive and execute the sync message,
|
// let alice's other device receive and execute the sync message,
|
||||||
|
|||||||
@@ -18,11 +18,11 @@ use tokio::runtime::Handle;
|
|||||||
use tokio::sync::RwLock;
|
use tokio::sync::RwLock;
|
||||||
use tokio::task;
|
use tokio::task;
|
||||||
|
|
||||||
use crate::chat::{self, Chat, ChatId};
|
use crate::chat::{self, Chat, ChatId, MessageListOptions};
|
||||||
use crate::chatlist::Chatlist;
|
use crate::chatlist::Chatlist;
|
||||||
use crate::config::Config;
|
use crate::config::Config;
|
||||||
use crate::constants::Chattype;
|
use crate::constants::Chattype;
|
||||||
use crate::constants::{DC_GCL_NO_SPECIALS, DC_GCM_ADDDAYMARKER, DC_MSG_ID_DAYMARKER};
|
use crate::constants::{DC_GCL_NO_SPECIALS, DC_MSG_ID_DAYMARKER};
|
||||||
use crate::contact::{Contact, ContactAddress, ContactId, Modifier, Origin};
|
use crate::contact::{Contact, ContactAddress, ContactId, Modifier, Origin};
|
||||||
use crate::context::Context;
|
use crate::context::Context;
|
||||||
use crate::events::{Event, EventType, Events};
|
use crate::events::{Event, EventType, Events};
|
||||||
@@ -464,9 +464,7 @@ impl TestContext {
|
|||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let chat_msgs = chat::get_chat_msgs(self, received.chat_id, 0)
|
let chat_msgs = chat::get_chat_msgs(self, received.chat_id).await.unwrap();
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
assert!(
|
assert!(
|
||||||
chat_msgs.contains(&ChatItem::Message { msg_id: msg.id }),
|
chat_msgs.contains(&ChatItem::Message { msg_id: msg.id }),
|
||||||
"received message is not shown in chat, maybe it's hidden (you may have \
|
"received message is not shown in chat, maybe it's hidden (you may have \
|
||||||
@@ -491,7 +489,7 @@ impl TestContext {
|
|||||||
///
|
///
|
||||||
/// Panics on errors or if the most recent message is a marker.
|
/// Panics on errors or if the most recent message is a marker.
|
||||||
pub async fn get_last_msg_in(&self, chat_id: ChatId) -> Message {
|
pub async fn get_last_msg_in(&self, chat_id: ChatId) -> Message {
|
||||||
let msgs = chat::get_chat_msgs(&self.ctx, chat_id, 0).await.unwrap();
|
let msgs = chat::get_chat_msgs(&self.ctx, chat_id).await.unwrap();
|
||||||
let msg_id = if let ChatItem::Message { msg_id } = msgs.last().unwrap() {
|
let msg_id = if let ChatItem::Message { msg_id } = msgs.last().unwrap() {
|
||||||
msg_id
|
msg_id
|
||||||
} else {
|
} else {
|
||||||
@@ -619,9 +617,16 @@ impl TestContext {
|
|||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
#[allow(clippy::indexing_slicing)]
|
#[allow(clippy::indexing_slicing)]
|
||||||
pub async fn print_chat(&self, chat_id: ChatId) {
|
pub async fn print_chat(&self, chat_id: ChatId) {
|
||||||
let msglist = chat::get_chat_msgs(self, chat_id, DC_GCM_ADDDAYMARKER)
|
let msglist = chat::get_chat_msgs_ex(
|
||||||
.await
|
self,
|
||||||
.unwrap();
|
chat_id,
|
||||||
|
MessageListOptions {
|
||||||
|
info_only: false,
|
||||||
|
add_daymarker: true,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
let msglist: Vec<MsgId> = msglist
|
let msglist: Vec<MsgId> = msglist
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|x| match x {
|
.map(|x| match x {
|
||||||
@@ -918,7 +923,7 @@ pub(crate) async fn get_chat_msg(
|
|||||||
index: usize,
|
index: usize,
|
||||||
asserted_msgs_count: usize,
|
asserted_msgs_count: usize,
|
||||||
) -> Message {
|
) -> Message {
|
||||||
let msgs = chat::get_chat_msgs(&t.ctx, chat_id, 0).await.unwrap();
|
let msgs = chat::get_chat_msgs(&t.ctx, chat_id).await.unwrap();
|
||||||
assert_eq!(msgs.len(), asserted_msgs_count);
|
assert_eq!(msgs.len(), asserted_msgs_count);
|
||||||
let msg_id = if let ChatItem::Message { msg_id } = msgs[index] {
|
let msg_id = if let ChatItem::Message { msg_id } = msgs[index] {
|
||||||
msg_id
|
msg_id
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ use anyhow::Result;
|
|||||||
|
|
||||||
use crate::chat;
|
use crate::chat;
|
||||||
use crate::chat::ChatId;
|
use crate::chat::ChatId;
|
||||||
use crate::constants;
|
|
||||||
use crate::contact;
|
use crate::contact;
|
||||||
use crate::contact::Contact;
|
use crate::contact::Contact;
|
||||||
use crate::contact::ContactId;
|
use crate::contact::ContactId;
|
||||||
@@ -345,9 +344,16 @@ async fn mark_as_verified(this: &TestContext, other: &TestContext) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn get_last_info_msg(t: &TestContext, chat_id: ChatId) -> Option<Message> {
|
async fn get_last_info_msg(t: &TestContext, chat_id: ChatId) -> Option<Message> {
|
||||||
let msgs = chat::get_chat_msgs(&t.ctx, chat_id, constants::DC_GCM_INFO_ONLY)
|
let msgs = chat::get_chat_msgs_ex(
|
||||||
.await
|
&t.ctx,
|
||||||
.unwrap();
|
chat_id,
|
||||||
|
chat::MessageListOptions {
|
||||||
|
info_only: true,
|
||||||
|
add_daymarker: false,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
let msg_id = if let chat::ChatItem::Message { msg_id } = msgs.last()? {
|
let msg_id = if let chat::ChatItem::Message { msg_id } = msgs.last()? {
|
||||||
msg_id
|
msg_id
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
14
src/tools.rs
14
src/tools.rs
@@ -1180,7 +1180,7 @@ DKIM Results: Passed=true, Works=true, Allow_Keychange=true";
|
|||||||
let chats = Chatlist::try_load(&t, 0, None, None).await.unwrap();
|
let chats = Chatlist::try_load(&t, 0, None, None).await.unwrap();
|
||||||
assert_eq!(chats.len(), 1);
|
assert_eq!(chats.len(), 1);
|
||||||
let device_chat_id = chats.get_chat_id(0).unwrap();
|
let device_chat_id = chats.get_chat_id(0).unwrap();
|
||||||
let msgs = chat::get_chat_msgs(&t, device_chat_id, 0).await.unwrap();
|
let msgs = chat::get_chat_msgs(&t, device_chat_id).await.unwrap();
|
||||||
assert_eq!(msgs.len(), 1);
|
assert_eq!(msgs.len(), 1);
|
||||||
|
|
||||||
// the message should be added only once a day - test that an hour later and nearly a day later
|
// the message should be added only once a day - test that an hour later and nearly a day later
|
||||||
@@ -1190,7 +1190,7 @@ DKIM Results: Passed=true, Works=true, Allow_Keychange=true";
|
|||||||
get_provider_update_timestamp(),
|
get_provider_update_timestamp(),
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
let msgs = chat::get_chat_msgs(&t, device_chat_id, 0).await.unwrap();
|
let msgs = chat::get_chat_msgs(&t, device_chat_id).await.unwrap();
|
||||||
assert_eq!(msgs.len(), 1);
|
assert_eq!(msgs.len(), 1);
|
||||||
|
|
||||||
maybe_warn_on_bad_time(
|
maybe_warn_on_bad_time(
|
||||||
@@ -1199,7 +1199,7 @@ DKIM Results: Passed=true, Works=true, Allow_Keychange=true";
|
|||||||
get_provider_update_timestamp(),
|
get_provider_update_timestamp(),
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
let msgs = chat::get_chat_msgs(&t, device_chat_id, 0).await.unwrap();
|
let msgs = chat::get_chat_msgs(&t, device_chat_id).await.unwrap();
|
||||||
assert_eq!(msgs.len(), 1);
|
assert_eq!(msgs.len(), 1);
|
||||||
|
|
||||||
// next day, there should be another device message
|
// next day, there should be another device message
|
||||||
@@ -1212,7 +1212,7 @@ DKIM Results: Passed=true, Works=true, Allow_Keychange=true";
|
|||||||
let chats = Chatlist::try_load(&t, 0, None, None).await.unwrap();
|
let chats = Chatlist::try_load(&t, 0, None, None).await.unwrap();
|
||||||
assert_eq!(chats.len(), 1);
|
assert_eq!(chats.len(), 1);
|
||||||
assert_eq!(device_chat_id, chats.get_chat_id(0).unwrap());
|
assert_eq!(device_chat_id, chats.get_chat_id(0).unwrap());
|
||||||
let msgs = chat::get_chat_msgs(&t, device_chat_id, 0).await.unwrap();
|
let msgs = chat::get_chat_msgs(&t, device_chat_id).await.unwrap();
|
||||||
assert_eq!(msgs.len(), 2);
|
assert_eq!(msgs.len(), 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1242,7 +1242,7 @@ DKIM Results: Passed=true, Works=true, Allow_Keychange=true";
|
|||||||
let chats = Chatlist::try_load(&t, 0, None, None).await.unwrap();
|
let chats = Chatlist::try_load(&t, 0, None, None).await.unwrap();
|
||||||
assert_eq!(chats.len(), 1);
|
assert_eq!(chats.len(), 1);
|
||||||
let device_chat_id = chats.get_chat_id(0).unwrap();
|
let device_chat_id = chats.get_chat_id(0).unwrap();
|
||||||
let msgs = chat::get_chat_msgs(&t, device_chat_id, 0).await.unwrap();
|
let msgs = chat::get_chat_msgs(&t, device_chat_id).await.unwrap();
|
||||||
assert_eq!(msgs.len(), 1);
|
assert_eq!(msgs.len(), 1);
|
||||||
|
|
||||||
// do not repeat the warning every day ...
|
// do not repeat the warning every day ...
|
||||||
@@ -1262,7 +1262,7 @@ DKIM Results: Passed=true, Works=true, Allow_Keychange=true";
|
|||||||
let chats = Chatlist::try_load(&t, 0, None, None).await.unwrap();
|
let chats = Chatlist::try_load(&t, 0, None, None).await.unwrap();
|
||||||
assert_eq!(chats.len(), 1);
|
assert_eq!(chats.len(), 1);
|
||||||
let device_chat_id = chats.get_chat_id(0).unwrap();
|
let device_chat_id = chats.get_chat_id(0).unwrap();
|
||||||
let msgs = chat::get_chat_msgs(&t, device_chat_id, 0).await.unwrap();
|
let msgs = chat::get_chat_msgs(&t, device_chat_id).await.unwrap();
|
||||||
let test_len = msgs.len();
|
let test_len = msgs.len();
|
||||||
assert!(test_len == 1 || test_len == 2);
|
assert!(test_len == 1 || test_len == 2);
|
||||||
|
|
||||||
@@ -1277,7 +1277,7 @@ DKIM Results: Passed=true, Works=true, Allow_Keychange=true";
|
|||||||
let chats = Chatlist::try_load(&t, 0, None, None).await.unwrap();
|
let chats = Chatlist::try_load(&t, 0, None, None).await.unwrap();
|
||||||
assert_eq!(chats.len(), 1);
|
assert_eq!(chats.len(), 1);
|
||||||
let device_chat_id = chats.get_chat_id(0).unwrap();
|
let device_chat_id = chats.get_chat_id(0).unwrap();
|
||||||
let msgs = chat::get_chat_msgs(&t, device_chat_id, 0).await.unwrap();
|
let msgs = chat::get_chat_msgs(&t, device_chat_id).await.unwrap();
|
||||||
assert_eq!(msgs.len(), test_len + 1);
|
assert_eq!(msgs.len(), test_len + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user