Give setup-changed messages the same timestamp as the previous message (#3188)

This commit is contained in:
Hocuri
2022-04-06 17:05:44 +02:00
committed by GitHub
parent e29d008914
commit 345a4bc504
4 changed files with 43 additions and 7 deletions

View File

@@ -9,6 +9,8 @@ use crate::chatlist::Chatlist;
use crate::context::Context;
use crate::events::EventType;
use crate::key::{DcKey, Fingerprint, SignedPublicKey};
use crate::message::Message;
use crate::mimeparser::SystemMessage;
use crate::sql::Sql;
use crate::stock_str;
use anyhow::{bail, Result};
@@ -275,10 +277,31 @@ impl Peerstate {
.await
.unwrap();
let msg = stock_str::contact_setup_changed(context, self.addr.clone()).await;
for chat_index in 0..chats.len() {
let chat_id = chats.get_chat_id(chat_index).unwrap();
chat::add_info_msg(context, chat_id, &msg, timestamp).await?;
context.emit_event(EventType::ChatModified(chat_id));
for (chat_id, msg_id) in chats.iter() {
let timestamp_sort = if let Some(msg_id) = msg_id {
let lastmsg = Message::load_from_db(context, *msg_id).await?;
lastmsg.timestamp_sort
} else {
context
.sql
.query_get_value(
"SELECT created_timestamp FROM chats WHERE id=?;",
paramsv![chat_id],
)
.await?
.unwrap_or(0)
};
chat::add_info_msg_with_cmd(
context,
*chat_id,
&msg,
SystemMessage::Unknown,
timestamp_sort,
Some(timestamp),
None,
)
.await?;
context.emit_event(EventType::ChatModified(*chat_id));
}
} else {
bail!("contact with peerstate.addr {:?} not found", &self.addr);