forked from lavina/lavina
1
0
Fork 0
This commit is contained in:
Nikita Vilunov 2024-05-21 01:52:06 +02:00
parent 6491c8819b
commit 77d159ec24
3 changed files with 30 additions and 16 deletions

View File

@ -107,6 +107,8 @@ impl<'a> XmppConnection<'a> {
resource: Some(self.user.xmpp_resource.clone()),
},
},
self_presence: true,
just_created: false, // TODO we don't know this for sure at this point
}],
..Default::default()
};
@ -166,6 +168,8 @@ mod tests {
resource: Some(conn.user.xmpp_resource.clone()),
},
},
self_presence: true,
just_created: false,
}],
..Default::default()
};
@ -216,6 +220,8 @@ mod tests {
resource: Some(conn.user.xmpp_resource.clone()),
},
},
self_presence: true,
just_created: false,
}],
..Default::default()
};

View File

@ -135,22 +135,16 @@ impl<T: FromXml> Parser for MessageParser<T> {
}
}
}
Event::End(_) => {
if let Some(body) = state.body {
Continuation::Final(Ok(Message {
Event::End(_) => Continuation::Final(Ok(Message {
from: state.from,
id: state.id,
to: state.to,
r#type: state.r#type,
lang: state.lang,
subject: state.subject,
body: Some(body),
body: state.body,
custom: state.custom,
}))
} else {
Continuation::Final(Err(ffail!("Body not found")))
}
}
})),
Event::Empty(_) => {
let parser = T::parse();
match parser.consume(namespace, event) {

View File

@ -148,6 +148,10 @@ impl FromXml for X {
#[derive(Debug, PartialEq, Eq)]
pub struct XUser {
pub item: XUserItem,
/// The receiver is the user referred to in the presence stanza.
pub self_presence: bool,
/// The room from which the presence stanza was sent was just created.
pub just_created: bool,
}
impl ToXml for XUser {
fn serialize(&self, output: &mut Vec<Event<'static>>) {
@ -155,6 +159,16 @@ impl ToXml for XUser {
tag.push_attribute(("xmlns", XMLNS_USER));
output.push(Event::Start(tag));
self.item.serialize(output);
if self.self_presence {
let mut meg = BytesStart::new("status");
meg.push_attribute(("code", "110"));
output.push(Event::Empty(meg));
}
if self.just_created {
let mut meg = BytesStart::new("status");
meg.push_attribute(("code", "201"));
output.push(Event::Empty(meg));
}
output.push(Event::End(BytesEnd::new("x")));
}
}