mirror of
https://github.com/chatmail/core.git
synced 2026-05-02 04:46:29 +03:00
Do not cache gossiped_timestamp
This commit is contained in:
committed by
holger krekel
parent
9d201eb9c6
commit
66adfa074b
14
src/chat.rs
14
src/chat.rs
@@ -35,7 +35,6 @@ pub struct Chat {
|
|||||||
pub grpid: String,
|
pub grpid: String,
|
||||||
blocked: Blocked,
|
blocked: Blocked,
|
||||||
pub param: Params,
|
pub param: Params,
|
||||||
pub gossiped_timestamp: i64,
|
|
||||||
is_sending_locations: bool,
|
is_sending_locations: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -44,7 +43,7 @@ impl Chat {
|
|||||||
pub fn load_from_db(context: &Context, chat_id: u32) -> Result<Self, Error> {
|
pub fn load_from_db(context: &Context, chat_id: u32) -> Result<Self, Error> {
|
||||||
let res = context.sql.query_row(
|
let res = context.sql.query_row(
|
||||||
"SELECT c.id,c.type,c.name, c.grpid,c.param,c.archived, \
|
"SELECT c.id,c.type,c.name, c.grpid,c.param,c.archived, \
|
||||||
c.blocked, c.gossiped_timestamp, c.locations_send_until \
|
c.blocked, c.locations_send_until \
|
||||||
FROM chats c WHERE c.id=?;",
|
FROM chats c WHERE c.id=?;",
|
||||||
params![chat_id as i32],
|
params![chat_id as i32],
|
||||||
|row| {
|
|row| {
|
||||||
@@ -56,8 +55,7 @@ impl Chat {
|
|||||||
param: row.get::<_, String>(4)?.parse().unwrap_or_default(),
|
param: row.get::<_, String>(4)?.parse().unwrap_or_default(),
|
||||||
archived: row.get(5)?,
|
archived: row.get(5)?,
|
||||||
blocked: row.get::<_, Option<_>>(6)?.unwrap_or_default(),
|
blocked: row.get::<_, Option<_>>(6)?.unwrap_or_default(),
|
||||||
gossiped_timestamp: row.get(7)?,
|
is_sending_locations: row.get(7)?,
|
||||||
is_sending_locations: row.get(8)?,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(c)
|
Ok(c)
|
||||||
@@ -216,6 +214,10 @@ impl Chat {
|
|||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_gossiped_timestamp(&self, context: &Context) -> i64 {
|
||||||
|
get_gossiped_timestamp(context, self.id)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn get_color(&self, context: &Context) -> u32 {
|
pub fn get_color(&self, context: &Context) -> u32 {
|
||||||
let mut color = 0;
|
let mut color = 0;
|
||||||
|
|
||||||
@@ -1574,7 +1576,7 @@ pub fn get_gossiped_timestamp(context: &Context, chat_id: u32) -> i64 {
|
|||||||
.sql
|
.sql
|
||||||
.query_get_value::<_, i64>(
|
.query_get_value::<_, i64>(
|
||||||
context,
|
context,
|
||||||
"SELECT gossiped_timestamp FROM chats WHERE chat_id=?;",
|
"SELECT gossiped_timestamp FROM chats WHERE id=?;",
|
||||||
params![chat_id as i32],
|
params![chat_id as i32],
|
||||||
)
|
)
|
||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
@@ -2016,7 +2018,7 @@ pub fn get_info_json(context: &Context, chat_id: u32) -> Result<String, Error> {
|
|||||||
"name": chat.name,
|
"name": chat.name,
|
||||||
"archived": chat.archived,
|
"archived": chat.archived,
|
||||||
"param": chat.param.to_string(),
|
"param": chat.param.to_string(),
|
||||||
"gossiped_timestamp": chat.gossiped_timestamp,
|
"gossiped_timestamp": chat.get_gossiped_timestamp(context),
|
||||||
"is_sending_locations": chat.is_sending_locations,
|
"is_sending_locations": chat.is_sending_locations,
|
||||||
"color": chat.get_color(context),
|
"color": chat.get_color(context),
|
||||||
"profile_image": profile_image,
|
"profile_image": profile_image,
|
||||||
|
|||||||
@@ -304,9 +304,8 @@ impl<'a, 'b> MimeFactory<'a, 'b> {
|
|||||||
Loaded::Message => {
|
Loaded::Message => {
|
||||||
let chat = self.chat.as_ref().unwrap();
|
let chat = self.chat.as_ref().unwrap();
|
||||||
// beside key- and member-changes, force re-gossip every 48 hours
|
// beside key- and member-changes, force re-gossip every 48 hours
|
||||||
if chat.gossiped_timestamp == 0
|
let gossiped_timestamp = chat.get_gossiped_timestamp(self.context);
|
||||||
|| (chat.gossiped_timestamp + (2 * 24 * 60 * 60)) > time()
|
if gossiped_timestamp == 0 || (gossiped_timestamp + (2 * 24 * 60 * 60)) > time() {
|
||||||
{
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user