forked from lavina/lavina
Rename and remove commented
This commit is contained in:
parent
09abdd5346
commit
7e1c4fd939
|
@ -24,12 +24,11 @@ impl<'a> XmppConnection<'a> {
|
|||
// resources in MUCs are members' personas – not implemented (yet?)
|
||||
resource: Some(_),
|
||||
}) if server.0 == self.hostname_rooms => {
|
||||
let muc_join_response = self.muc_presence(&name).await?;
|
||||
muc_join_response.serialize(output);
|
||||
let muc_presence = self.retrieve_muc_presence(&name).await?;
|
||||
muc_presence.serialize(output);
|
||||
|
||||
let history_on_join_response = self.send_history_on_join(&name).await?;
|
||||
|
||||
for message in history_on_join_response {
|
||||
let messages = self.retrieve_message_history(&name).await?;
|
||||
for message in messages {
|
||||
message.serialize(output)
|
||||
}
|
||||
}
|
||||
|
@ -67,7 +66,7 @@ impl<'a> XmppConnection<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
async fn muc_presence(&mut self, name: &Name) -> Result<(Presence<XUser>)> {
|
||||
async fn retrieve_muc_presence(&mut self, name: &Name) -> Result<(Presence<XUser>)> {
|
||||
let a = self.user_handle.join_room(RoomId::try_from(name.0.clone())?).await?;
|
||||
// TODO handle bans
|
||||
let response = Presence {
|
||||
|
@ -86,63 +85,50 @@ impl<'a> XmppConnection<'a> {
|
|||
};
|
||||
Ok(response)
|
||||
}
|
||||
async fn send_history_on_join(&self, room_name: &Name) -> Result<(Vec<XmppHistoryMessage>)> {
|
||||
|
||||
/*
|
||||
Retrieve a room's message history. The output can be serialized into a stream of XML stanzas.
|
||||
|
||||
Example of such a stanza:
|
||||
|
||||
<message from="duqedadi@conference.oflor.me/misha" xml:lang="en" to="misha@oflor.me/tux" type="groupchat" id="7ca7cb14-b2af-49c9-bd90-05dabb1113a5">
|
||||
<delay xmlns="urn:xmpp:delay" stamp="2024-05-17T16:05:28.440337Z" from="duqedadi@conference.oflor.me"/>
|
||||
<body></body>
|
||||
</message>
|
||||
*/
|
||||
async fn retrieve_message_history(&self, room_name: &Name) -> Result<(Vec<XmppHistoryMessage>)> {
|
||||
let room_id = RoomId::try_from(room_name.0.clone())?;
|
||||
let history_messages = self.user_handle.get_room_message_history(room_id).await?;
|
||||
let mut response = vec![];
|
||||
|
||||
for history_message in history_messages.into_iter() {
|
||||
let author_name = Option::from(Name(history_message.author.name.into()));
|
||||
tracing::info!("author_name: {:?}", author_name);
|
||||
|
||||
let author_jid = Jid {
|
||||
name: author_name.clone(),
|
||||
server: Server(self.hostname_rooms.clone()),
|
||||
resource: None, // Option::from(Resource(room_name.0.clone())),
|
||||
};
|
||||
|
||||
response.push(XmppHistoryMessage {
|
||||
id: history_message.id,
|
||||
// sauer@localhost/sauer
|
||||
to: Jid {
|
||||
name: Option::from(Name(self.user.xmpp_muc_name.0.clone().into())), // Option::from(Name("chelik".into())),
|
||||
name: Option::from(Name(self.user.xmpp_muc_name.0.clone().into())),
|
||||
server: Server(self.hostname.clone()),
|
||||
resource: None, // Option::from(Resource("sauer".into())), // Option::from(Resource(room_name.0.clone())),
|
||||
resource: None,
|
||||
},
|
||||
from: Jid {
|
||||
name: Option::from(room_name.clone()), // Option::from(Name("chelik".into())),
|
||||
name: Option::from(room_name.clone()),
|
||||
server: Server(self.hostname_rooms.clone()),
|
||||
resource: Option::from(Resource("sauer".into())), // Option::from(Resource(room_name.0.clone())),
|
||||
resource: Option::from(Resource("sauer".into())),
|
||||
},
|
||||
delay: Delay::new(author_jid.clone(), history_message.created_at.to_rfc3339()),
|
||||
delay: Delay::new(
|
||||
Jid {
|
||||
name: author_name.clone(),
|
||||
server: Server(self.hostname_rooms.clone()),
|
||||
resource: None,
|
||||
},
|
||||
history_message.created_at.to_rfc3339(),
|
||||
),
|
||||
body: history_message.body,
|
||||
});
|
||||
}
|
||||
|
||||
return Ok(response);
|
||||
|
||||
// Ok(HistoryMessage {
|
||||
// id: "kek".to_string(),
|
||||
// to: Jid {
|
||||
// name: Some(Name("sauer@oflor.me".into())),
|
||||
// server: Server("localhost".into()),
|
||||
// resource: Some(Resource("tester".into())),
|
||||
// },
|
||||
// from: Jid {
|
||||
// name: Some(Name("pepe".into())),
|
||||
// server: Server("rooms.localhost".into()),
|
||||
// resource: Some(Resource("sauer".into())),
|
||||
// },
|
||||
// delay: Delay::new(
|
||||
// Jid {
|
||||
// name: Some(Name("pepe".into())),
|
||||
// server: Server("rooms.localhost".into()),
|
||||
// resource: Some(Resource("tester".into())),
|
||||
// },
|
||||
// "2021-10-10T10:10:10Z".to_string(),
|
||||
// ),
|
||||
// body: ,
|
||||
// })
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -175,7 +161,7 @@ mod tests {
|
|||
let mut player_conn = server.core.connect_to_player(&user.player_id).await;
|
||||
let mut conn = expect_user_authenticated(&server, &user, &mut player_conn).await.unwrap();
|
||||
|
||||
let response = conn.muc_presence(&user.xmpp_name).await.unwrap();
|
||||
let response = conn.retrieve_muc_presence(&user.xmpp_name).await.unwrap();
|
||||
let expected = Presence {
|
||||
to: Some(Jid {
|
||||
name: Some(conn.user.xmpp_name.clone()),
|
||||
|
@ -215,7 +201,7 @@ mod tests {
|
|||
let mut player_conn = server.core.connect_to_player(&user.player_id).await;
|
||||
let mut conn = expect_user_authenticated(&server, &user, &mut player_conn).await.unwrap();
|
||||
|
||||
let response = conn.muc_presence(&user.xmpp_name).await.unwrap();
|
||||
let response = conn.retrieve_muc_presence(&user.xmpp_name).await.unwrap();
|
||||
let expected = Presence {
|
||||
to: Some(Jid {
|
||||
name: Some(conn.user.xmpp_name.clone()),
|
||||
|
@ -238,7 +224,7 @@ mod tests {
|
|||
let mut player_conn = server.core.connect_to_player(&user.player_id).await;
|
||||
let mut conn = expect_user_authenticated(&server, &user, &mut player_conn).await.unwrap();
|
||||
|
||||
let response = conn.muc_presence(&user.xmpp_name).await.unwrap();
|
||||
let response = conn.retrieve_muc_presence(&user.xmpp_name).await.unwrap();
|
||||
assert_eq!(expected, response);
|
||||
|
||||
server.shutdown().await.unwrap();
|
||||
|
|
Loading…
Reference in New Issue