//! Exact upstream MUC + muc_mam oracle, with no replacement storage/module API.
use rust_xmpp::{muc::Muc, protocol::ModuleResult};
fn send(muc: &mut Muc, xml: &str) -> ModuleResult {
let doc = roxmltree::Document::parse(xml).unwrap();
muc.handle("alice@example.org/r", doc.root_element())
.unwrap()
.unwrap()
}
#[test]
#[ignore = "requires PROSODY_REFERENCE_SOURCE and PROSODY_REFERENCE_LUA"]
fn actual_prosody_muc_mam_reads_rust_and_writes_native_archive() {
let root = tempfile::tempdir().unwrap();
let mut muc = Muc::new(root.path().into(), "rooms.example.org".into());
muc.set_defaults(serde_json::json!({"persistent":true,"archiving":true,"whois":"moderators"}));
send(
&mut muc,
"",
);
send(
&mut muc,
"",
);
send(
&mut muc,
"Rust archived body",
);
drop(muc);
let bootstrap = std::fs::read_to_string(concat!(
env!("CARGO_MANIFEST_DIR"),
"/scripts/prosody_compat/oracle.lua"
))
.unwrap();
let bootstrap = bootstrap.split("if phase == 'probe' then").next().unwrap();
let script = format!(
"{bootstrap}\n{}",
r#"
config.set('rooms.example.org','component_module','muc');
config.set('rooms.example.org','modules_enabled',{'muc_mam'});
config.set('rooms.example.org','muc_log_expires_after','never');
assert(require('prosody.core.hostmanager').activate('rooms.example.org'));
if not mm.get_module('rooms.example.org','muc_mam') then assert(mm.load('rooms.example.org','muc_mam')); end
local muc=assert(mm.get_module('rooms.example.org','muc'));
local room=assert(muc.get_room_from_jid('room@rooms.example.org'));
assert(room:get_affiliation('alice@example.org')=='owner');
assert(room:get_persistent());assert(room._data.archiving);
local archive=assert(sm.open('rooms.example.org','muc_log','archive'));
local count=0;
for id,item,when,peer in assert(archive:find('room',{with='message",
);
assert!(
result
.replies
.iter()
.any(|s| s.contains("Native archived body")),
"{:?}",
result.replies
);
let disco = send(
&mut muc,
"",
);
assert!(disco.replies[0].contains("Native room name"));
}