aboutsummaryrefslogtreecommitdiffstats
path: root/luz/src/connection/read.rs
diff options
context:
space:
mode:
Diffstat (limited to 'luz/src/connection/read.rs')
-rw-r--r--luz/src/connection/read.rs27
1 files changed, 23 insertions, 4 deletions
diff --git a/luz/src/connection/read.rs b/luz/src/connection/read.rs
index 80322ce..d510c5d 100644
--- a/luz/src/connection/read.rs
+++ b/luz/src/connection/read.rs
@@ -20,7 +20,7 @@ use crate::{
chat::{Body, Message},
db::Db,
error::{Error, IqError, MessageRecvError, PresenceError, ReadError, RosterError},
- presence::{Offline, Online, Presence, Show},
+ presence::{Offline, Online, Presence, PresenceType, Show},
roster::Contact,
UpdateMessage,
};
@@ -181,6 +181,11 @@ async fn handle_stanza(
match stanza {
Stanza::Message(stanza_message) => {
if let Some(mut from) = stanza_message.from {
+ // TODO: don't ignore delay from. xep says SHOULD send error if incorrect.
+ let timestamp = stanza_message
+ .delay
+ .map(|delay| delay.stamp)
+ .unwrap_or_else(|| Utc::now());
// TODO: group chat messages
let mut message = Message {
id: stanza_message
@@ -189,7 +194,7 @@ async fn handle_stanza(
.map(|id| Uuid::from_str(&id).unwrap_or_else(|_| Uuid::new_v4()))
.unwrap_or_else(|| Uuid::new_v4()),
from: from.clone(),
- timestamp: Utc::now(),
+ timestamp,
body: Body {
// TODO: should this be an option?
body: stanza_message
@@ -263,10 +268,17 @@ async fn handle_stanza(
let offline = Offline {
status: presence.status.map(|status| status.status.0),
};
+ let timestamp = presence
+ .delay
+ .map(|delay| delay.stamp)
+ .unwrap_or_else(|| Utc::now());
let _ = update_sender
.send(UpdateMessage::Presence {
from,
- presence: Presence::Offline(offline),
+ presence: Presence {
+ timestamp,
+ presence: PresenceType::Offline(offline),
+ },
})
.await;
}
@@ -286,10 +298,17 @@ async fn handle_stanza(
status: presence.status.map(|status| status.status.0),
priority: presence.priority.map(|priority| priority.0),
};
+ let timestamp = presence
+ .delay
+ .map(|delay| delay.stamp)
+ .unwrap_or_else(|| Utc::now());
let _ = update_sender
.send(UpdateMessage::Presence {
from,
- presence: Presence::Online(online),
+ presence: Presence {
+ timestamp,
+ presence: PresenceType::Online(online),
+ },
})
.await;
}