cleanup series of webxdc info messages (#3395)

* clarify webxdc reference wrt info-messages

* add from_id parameter to add_info_msg_with_cmd()

* flag webxdc-info-messages as such

* set from_id to sender for webxdc-info-messages

* test additional webxdc info properties

* do not add series of similar info messages

instead, if on adding the last info message
is already from the same webxdc and sender,
just update the text

* test cleanup of webxdc info messages series

* update changelog

* make clippy happy

there is no real complexity in the args,
so allowing one more arg is probably fine.

if really wanted, we can refactor the function in another pr;
this pr is already complex enough :)

* use cleaner function names and comments

* clarify CHANGELOG
This commit is contained in:
bjoern
2022-06-04 11:12:09 +02:00
committed by GitHub
parent 303c4f1f6d
commit fcded63653
7 changed files with 211 additions and 25 deletions

View File

@@ -438,6 +438,7 @@ impl ChatId {
dc_create_smeared_timestamp(context).await,
None,
None,
None,
)
.await?;
}
@@ -3380,6 +3381,7 @@ pub(crate) async fn delete_and_reset_all_device_msgs(context: &Context) -> Resul
/// Adds an informational message to chat.
///
/// For example, it can be a message showing that a member was added to a group.
#[allow(clippy::too_many_arguments)]
pub(crate) async fn add_info_msg_with_cmd(
context: &Context,
chat_id: ChatId,
@@ -3389,6 +3391,7 @@ pub(crate) async fn add_info_msg_with_cmd(
// Timestamp to show to the user (if this is None, `timestamp_sort` will be shown to the user)
timestamp_sent_rcvd: Option<i64>,
parent: Option<&Message>,
from_id: Option<ContactId>,
) -> Result<MsgId> {
let rfc724_mid = dc_create_outgoing_rfc724_mid(None, "@device");
let ephemeral_timer = chat_id.get_ephemeral_timer(context).await?;
@@ -3404,7 +3407,7 @@ pub(crate) async fn add_info_msg_with_cmd(
VALUES (?,?,?, ?,?,?,?,?, ?,?,?, ?,?);",
paramsv![
chat_id,
ContactId::INFO,
from_id.unwrap_or(ContactId::INFO),
ContactId::INFO,
timestamp_sort,
timestamp_sent_rcvd.unwrap_or(0),
@@ -3440,10 +3443,29 @@ pub(crate) async fn add_info_msg(
timestamp,
None,
None,
None,
)
.await
}
pub(crate) async fn update_msg_text_and_timestamp(
context: &Context,
chat_id: ChatId,
msg_id: MsgId,
text: &str,
timestamp: i64,
) -> Result<()> {
context
.sql
.execute(
"UPDATE msgs SET txt=?, timestamp=? WHERE id=?;",
paramsv![text, timestamp, msg_id],
)
.await?;
context.emit_msgs_changed(chat_id, msg_id);
Ok(())
}
#[cfg(test)]
mod tests {
use super::*;
@@ -4520,6 +4542,7 @@ mod tests {
10000,
None,
None,
None,
)
.await?;