clear messages
This commit is contained in:
+33
-2
@@ -70,8 +70,29 @@ pub async fn call(ctx: &Ctx, func: &str, p: &P<'_>) -> bool {
|
||||
"ajaxClearHistoryConfirm" => {
|
||||
let jid = p.str(0);
|
||||
if utils::validate_jid(&jid) {
|
||||
let _ = db::messages_clear(ctx.db(), &ctx.jid(), &jid).await;
|
||||
let muc = ctx.st(|st| st.conferences.contains_key(&jid)).unwrap_or(false);
|
||||
let archive_key = if muc { format!("muc:{jid}") } else { jid.clone() };
|
||||
if let Err(e) = db::messages_clear(ctx.db(), &ctx.jid(), &jid, &archive_key).await {
|
||||
tracing::warn!("clear history of {jid}: {e}");
|
||||
}
|
||||
if muc {
|
||||
get_room(ctx, &jid, true).await;
|
||||
} else {
|
||||
get(ctx, Some(&jid), false).await;
|
||||
}
|
||||
}
|
||||
}
|
||||
"ajaxRestoreHistory" => {
|
||||
let jid = p.str(0);
|
||||
if utils::validate_jid(&jid) {
|
||||
let muc = ctx.st(|st| st.conferences.contains_key(&jid)).unwrap_or(false);
|
||||
let archive_key = if muc { format!("muc:{jid}") } else { jid.clone() };
|
||||
if let Err(e) = db::history_restore(ctx.db(), &ctx.jid(), &archive_key).await {
|
||||
tracing::warn!("restore history of {jid}: {e}");
|
||||
return true;
|
||||
}
|
||||
ctx.toast(&ctx.t("chat.history_restored", &[]));
|
||||
// Reopening fetches from MAM, scrolling up fetches older pages
|
||||
if muc {
|
||||
get_room(ctx, &jid, true).await;
|
||||
} else {
|
||||
@@ -105,11 +126,20 @@ pub async fn call(ctx: &Ctx, func: &str, p: &P<'_>) -> bool {
|
||||
|
||||
pub async fn prepare_header(ctx: &Ctx, jid: &str, muc: bool) -> String {
|
||||
let counter = notif::unreads(ctx).await;
|
||||
let archive_key = if muc { format!("muc:{jid}") } else { jid.to_string() };
|
||||
let cleared = db::history_cleared_at(ctx.db(), &ctx.jid(), &archive_key).await.ok().flatten().is_some();
|
||||
if muc {
|
||||
let conference = rooms::conference_view(ctx, jid).await;
|
||||
ctx.render(
|
||||
"Chat/_chat_header.html",
|
||||
json!({ "jid": jid, "muc": true, "counter": counter, "conference": conference, "in_call": super::visio::has_call(ctx) }),
|
||||
json!({
|
||||
"jid": jid,
|
||||
"muc": true,
|
||||
"counter": counter,
|
||||
"conference": conference,
|
||||
"in_call": super::visio::has_call(ctx),
|
||||
"cleared": cleared,
|
||||
}),
|
||||
)
|
||||
} else {
|
||||
let contact = contact_view(ctx, jid).await;
|
||||
@@ -129,6 +159,7 @@ pub async fn prepare_header(ctx: &Ctx, jid: &str, muc: bool) -> String {
|
||||
"call_video": video,
|
||||
"in_call": in_call,
|
||||
"omemo": omemo,
|
||||
"cleared": cleared,
|
||||
}),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ use minidom::Element;
|
||||
use serde_json::{json, Value};
|
||||
|
||||
use super::{contact_view, P};
|
||||
use crate::{app::Ctx, proto, rpc, utils, xmpp};
|
||||
use crate::{app::Ctx, db, proto, rpc, utils, xmpp};
|
||||
|
||||
pub fn fingerprint(b64: &str) -> String {
|
||||
let Ok(bytes) = B64.decode(b64) else { return String::new() };
|
||||
@@ -46,6 +46,7 @@ pub async fn get_drawer(ctx: &Ctx, jid: &str) {
|
||||
|
||||
let (audio, video) = super::visio::call_targets(ctx, jid);
|
||||
let omemo = ctx.me().is_some_and(|u| u.omemoenabled) && jid != me;
|
||||
let cleared = db::history_cleared_at(ctx.db(), &me, jid).await.ok().flatten().is_some();
|
||||
|
||||
let html = ctx.render(
|
||||
"ContactActions/_contactactions_drawer.html",
|
||||
@@ -57,6 +58,7 @@ pub async fn get_drawer(ctx: &Ctx, jid: &str) {
|
||||
"call_audio": audio,
|
||||
"call_video": video,
|
||||
"omemo": omemo,
|
||||
"cleared": cleared,
|
||||
}),
|
||||
);
|
||||
super::drawer(ctx, "contact_drawer", &html, false, false);
|
||||
|
||||
@@ -494,10 +494,10 @@ pub async fn join(ctx: &Ctx, room: &str, nick: Option<&str>) {
|
||||
// History comes from MAM
|
||||
proto::muc_join(room, &nick, None, Some(0))
|
||||
} else {
|
||||
let since = db::latest_muc_message_date(ctx.db(), &ctx.jid(), room)
|
||||
.await
|
||||
.ok()
|
||||
.flatten()
|
||||
let latest = db::latest_muc_message_date(ctx.db(), &ctx.jid(), room).await.ok().flatten();
|
||||
let cleared = db::history_cleared_at(ctx.db(), &ctx.jid(), &format!("muc:{room}")).await.ok().flatten();
|
||||
let since = latest
|
||||
.max(cleared)
|
||||
.and_then(|d| crate::dates::parse(&d))
|
||||
.map(|d| d.to_rfc3339_opts(chrono::SecondsFormat::Secs, true));
|
||||
match since {
|
||||
|
||||
Reference in New Issue
Block a user