mirror of
https://github.com/chatmail/core.git
synced 2026-05-07 17:06:35 +03:00
do not add random label for unlabelled device-messages
This commit is contained in:
committed by
holger krekel
parent
5023255ebc
commit
d0ccf28678
48
src/chat.rs
48
src/chat.rs
@@ -1929,33 +1929,42 @@ pub fn get_chat_id_by_grpid(context: &Context, grpid: impl AsRef<str>) -> (u32,
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_device_msg(context: &Context, msg: &mut Message) -> Result<MsgId, Error> {
|
pub fn add_device_msg(context: &Context, msg: &mut Message) -> Result<MsgId, Error> {
|
||||||
let label = format!("info-{}", dc_create_id());
|
add_device_msg_maybe_labelled(context, None, msg)
|
||||||
add_device_msg_once(context, &label, msg)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_device_msg_once(
|
pub fn add_device_msg_once(
|
||||||
context: &Context,
|
context: &Context,
|
||||||
label: &str,
|
label: &str,
|
||||||
msg: &mut Message,
|
msg: &mut Message,
|
||||||
|
) -> Result<MsgId, Error> {
|
||||||
|
add_device_msg_maybe_labelled(context, Some(label), msg)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn add_device_msg_maybe_labelled(
|
||||||
|
context: &Context,
|
||||||
|
label: Option<&str>,
|
||||||
|
msg: &mut Message,
|
||||||
) -> Result<MsgId, Error> {
|
) -> Result<MsgId, Error> {
|
||||||
let (chat_id, _blocked) =
|
let (chat_id, _blocked) =
|
||||||
create_or_lookup_by_contact_id(context, DC_CONTACT_ID_DEVICE, Blocked::Not)?;
|
create_or_lookup_by_contact_id(context, DC_CONTACT_ID_DEVICE, Blocked::Not)?;
|
||||||
let rfc724_mid = dc_create_outgoing_rfc724_mid(None, "@device");
|
let rfc724_mid = dc_create_outgoing_rfc724_mid(None, "@device");
|
||||||
|
|
||||||
// chat_id has an sql-index so it makes sense to add this although redundant
|
// chat_id has an sql-index so it makes sense to add this although redundant
|
||||||
if let Ok(msg_id) = context.sql.query_row(
|
if let Some(label) = label {
|
||||||
"SELECT id FROM msgs WHERE chat_id=? AND label=?",
|
if let Ok(msg_id) = context.sql.query_row(
|
||||||
params![chat_id, label],
|
"SELECT id FROM msgs WHERE chat_id=? AND label=?",
|
||||||
|row| {
|
params![chat_id, label],
|
||||||
let msg_id: MsgId = row.get(0)?;
|
|row| {
|
||||||
Ok(msg_id)
|
let msg_id: MsgId = row.get(0)?;
|
||||||
},
|
Ok(msg_id)
|
||||||
) {
|
},
|
||||||
info!(
|
) {
|
||||||
context,
|
info!(
|
||||||
"device-message {} already exist as {}", label, msg_id
|
context,
|
||||||
);
|
"device-message {} already exist as {}", label, msg_id
|
||||||
return Ok(msg_id);
|
);
|
||||||
|
return Ok(msg_id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
prepare_msg_blob(context, msg)?;
|
prepare_msg_blob(context, msg)?;
|
||||||
@@ -1974,14 +1983,19 @@ pub fn add_device_msg_once(
|
|||||||
msg.text.as_ref().map_or("", String::as_str),
|
msg.text.as_ref().map_or("", String::as_str),
|
||||||
msg.param.to_string(),
|
msg.param.to_string(),
|
||||||
rfc724_mid,
|
rfc724_mid,
|
||||||
label,
|
label.unwrap_or_default(),
|
||||||
],
|
],
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let row_id = sql::get_rowid(context, &context.sql, "msgs", "rfc724_mid", &rfc724_mid);
|
let row_id = sql::get_rowid(context, &context.sql, "msgs", "rfc724_mid", &rfc724_mid);
|
||||||
let msg_id = MsgId::new(row_id);
|
let msg_id = MsgId::new(row_id);
|
||||||
context.call_cb(Event::IncomingMsg { chat_id, msg_id });
|
context.call_cb(Event::IncomingMsg { chat_id, msg_id });
|
||||||
info!(context, "device-message {} added as {}", label, msg_id);
|
info!(
|
||||||
|
context,
|
||||||
|
"device-message {} added as {}",
|
||||||
|
label.unwrap_or("without label"),
|
||||||
|
msg_id
|
||||||
|
);
|
||||||
|
|
||||||
Ok(msg_id)
|
Ok(msg_id)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user