diff --git a/CHANGELOG.md b/CHANGELOG.md index 3e9a20a5c..3d5f33320 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed +- Only `DataMessage` that are sent, received, or sent from another device are saved in the local store (#137). + This is a breaking change because clients previously had to introduce calls to filter internal messages themselves. + - Changed (and fixed) the behaviour of the iterator returned by `SledStore::messages` (#119) * The iterator yields elements in chronological order (used to be reversed) * The iterator now implements `DoubleEndedIterator` which means you it can be reversed or consumed from the end diff --git a/src/manager.rs b/src/manager.rs index d3ea6d99c..28d0dd262 100644 --- a/src/manager.rs +++ b/src/manager.rs @@ -809,13 +809,10 @@ impl Manager { } } - if let Ok(thread) = Thread::try_from(&content) { - // TODO: handle reactions here, we should update the original message? - if let Err(e) = - state.config_store.save_message(&thread, content.clone()) - { - log::error!("Error saving message to store: {}", e); - } + if let Err(e) = + save_message(&mut state.config_store, content.clone()) + { + log::error!("Error saving message to store: {}", e); } return Some((content, state)); @@ -859,7 +856,6 @@ impl Manager { .await?; // save the message - let thread = Thread::Contact(recipient.uuid); let content = Content { metadata: Metadata { sender: self.state.uuid.into(), @@ -871,7 +867,7 @@ impl Manager { body: content_body, }; - self.config_store.save_message(&thread, content)?; + save_message(&mut self.config_store, content)?; Ok(()) } @@ -923,8 +919,8 @@ impl Manager { }, body: message.into(), }; - let thread = Thread::try_from(&content)?; - self.config_store.save_message(&thread, content)?; + + save_message(&mut self.config_store, content)?; Ok(()) } @@ -1094,3 +1090,26 @@ async fn upsert_group( config_store.group(master_key_bytes) } + +fn save_message(config_store: &mut C, message: Content) -> Result<(), Error> { + let thread = Thread::try_from(&message)?; + // only save DataMessage and SynchronizeMessage (sent) + match message.body { + ContentBody::DataMessage(_) + | ContentBody::SynchronizeMessage(SyncMessage { sent: Some(_), .. }) + | ContentBody::SynchronizeMessage(SyncMessage { + call_event: Some(_), + .. + }) => { + config_store.save_message(&thread, message)?; + } + ContentBody::SynchronizeMessage(_) => { + debug!("skipping saving sync message without interesting fields") + } + ContentBody::CallMessage(_) => debug!("skipping saving call message"), + ContentBody::ReceiptMessage(_) => debug!("skipping saving receipt message"), + ContentBody::TypingMessage(_) => debug!("skipping saving typing message"), + } + + Ok(()) +} diff --git a/src/store/mod.rs b/src/store/mod.rs index 6b5988897..91867b28f 100644 --- a/src/store/mod.rs +++ b/src/store/mod.rs @@ -159,7 +159,6 @@ pub trait MessageStore { fn clear_messages(&mut self) -> Result<(), Error>; /// Save a message in a [Thread] identified by a timestamp. - /// TODO: deriving the thread happens from the content, so we can also ditch the first parameter fn save_message(&mut self, thread: &Thread, message: Content) -> Result<(), Error>; /// Delete a single message, identified by its received timestamp from a thread. diff --git a/src/store/sled.rs b/src/store/sled.rs index 6792f2e6d..f50d84f9d 100644 --- a/src/store/sled.rs +++ b/src/store/sled.rs @@ -782,7 +782,7 @@ impl MessageStore for SledStore { message.metadata.timestamp, ); - let tree = self.messages_thread_tree_name(thread); + let tree = self.messages_thread_tree_name(&thread); let key = message.metadata.timestamp.to_be_bytes(); let proto: ContentProto = message.into();