Commit 3645d564 authored by Daniel Garcia Moreno's avatar Daniel Garcia Moreno

Merge branch 'origin_server_ts' into 'master'

Made the code use origin_server_ts instead of age to calculate messages

See merge request World/fractal!235
parents 151edb8f ae2206e6
......@@ -40,7 +40,7 @@ pub fn sync(bk: &Backend) -> Result<(), Error> {
}},
\"presence\": {{ \"types\": [] }},
\"event_format\": \"client\",
\"event_fields\": [\"type\", \"content\", \"sender\", \"event_id\", \"age\", \"unsigned\"]
\"event_fields\": [\"type\", \"content\", \"sender\", \"origin_server_ts\", \"event_id\"]
}}", globals::PAGE_LIMIT);
params.push(("filter", String::from(filter)));
......
extern crate md5;
extern crate chrono;
extern crate serde_json;
extern crate time;
use self::chrono::prelude::*;
use std::cmp::Ordering;
use std::collections::HashMap;
use self::serde_json::Value as JsonValue;
use self::time::Duration;
use self::chrono::Utc;
use self::chrono::TimeZone;
use self::chrono::DateTime;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Message {
......@@ -111,10 +112,9 @@ impl Message {
/// * `msg` - The message event as Json
pub fn parse_room_message(roomid: String, msg: &JsonValue) -> Message {
let sender = msg["sender"].as_str().unwrap_or("");
let mut age = msg["age"].as_i64().unwrap_or(0);
if age == 0 {
age = msg["unsigned"]["age"].as_i64().unwrap_or(0);
}
let timestamp = msg["origin_server_ts"].as_i64().unwrap_or(0) / 1000;
let server_timestamp: DateTime<Local> = Local.timestamp(timestamp, 0);
let id = msg["event_id"].as_str().unwrap_or("");
let type_ = msg["type"].as_str().unwrap_or("");
......@@ -123,7 +123,7 @@ impl Message {
let mut message = Message {
sender: sender.to_string(),
date: Message::age_to_datetime(age),
date: server_timestamp,
room: roomid.clone(),
id: Some(id.to_string()),
mtype: type_.to_string(),
......@@ -212,12 +212,6 @@ impl Message {
ms
}
fn age_to_datetime(age: i64) -> DateTime<Local> {
let now = Local::now();
let diff = Duration::seconds(age / 1000);
now - diff
}
pub fn set_receipt(&mut self, receipt: HashMap<String, i64>) {
self.receipt = receipt;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment