c9effeac326a | atagen | 2026-10-25 10:32 UTC | 1 | use std::collections::{HashSet, VecDeque}; |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 2 | |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 3 | use ruma::events::room::message::sanitize::remove_plain_reply_fallback; |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 4 | use serde_json::Value; |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 5 | |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 6 | use super::{MessageIndex, index::Doc}; |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 7 | use crate::normalise::poll_question; |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 8 | |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 9 | const REMEMBERED_REDACTIONS: usize = 10_000; |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 10 | |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 11 | #[derive(Clone, Debug, Eq, PartialEq)] |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 12 | pub(crate) struct Edit { |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 13 | pub(crate) id: String, |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 14 | pub(crate) target: String, |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 15 | pub(crate) sender: String, |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 16 | pub(crate) ts: u64, |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 17 | pub(crate) text: String, |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 18 | } |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 19 | |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 20 | #[derive(Clone, Debug, Eq, PartialEq)] |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 21 | pub(crate) enum Observed { |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 22 | Message { |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 23 | key: String, |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 24 | sender: String, |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 25 | ts: u64, |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 26 | text: String, |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 27 | bundled: Option<Edit>, |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 28 | }, |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 29 | Edit(Edit), |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 30 | Redaction { |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 31 | target: String, |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 32 | }, |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 33 | Redacted { |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 34 | key: String, |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 35 | }, |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 36 | Encrypted { |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 37 | key: String, |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 38 | session_id: String, |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 39 | ts: u64, |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 40 | }, |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 41 | Other, |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 42 | } |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 43 | |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 44 | #[derive(Debug, Eq, PartialEq)] |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 45 | pub(crate) enum Effect { |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 46 | Indexed(u64), |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 47 | Removed, |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 48 | /// an edit was redacted out from under its original, which has to be read again |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 49 | Refetch(String), |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 50 | Nothing, |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 51 | } |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 52 | |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 53 | /// redactions seen lately, so a stale copy of what they removed can't come back |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 54 | #[derive(Default)] |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 55 | pub(crate) struct Redactions { |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 56 | order: VecDeque<String>, |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 57 | seen: HashSet<String>, |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 58 | } |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 59 | |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 60 | impl Redactions { |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 61 | fn insert(&mut self, key: String) { |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 62 | if self.seen.insert(key.clone()) { |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 63 | self.order.push_back(key); |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 64 | if self.order.len() > REMEMBERED_REDACTIONS |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 65 | && let Some(oldest) = self.order.pop_front() |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 66 | { |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 67 | self.seen.remove(&oldest); |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 68 | } |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 69 | } |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 70 | } |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 71 | |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 72 | fn contains(&self, key: &str) -> bool { |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 73 | self.seen.contains(key) |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 74 | } |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 75 | } |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 76 | |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 77 | fn text_of(event_type: &str, content: &Value) -> Option<String> { |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 78 | let text = match event_type { |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 79 | "m.room.message" => { |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 80 | let msgtype = content.get("msgtype")?.as_str()?; |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 81 | if msgtype == "m.key.verification.request" { |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 82 | return None; |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 83 | } |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 84 | let mut body = content.get("body")?.as_str()?.to_owned(); |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 85 | if content.pointer("/m.relates_to/m.in_reply_to").is_some() { |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 86 | body = remove_plain_reply_fallback(&body).to_owned(); |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 87 | } |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 88 | match content.get("filename").and_then(Value::as_str) { |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 89 | Some(filename) if filename != body => format!("{body}\n{filename}"), |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 90 | _ => body, |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 91 | } |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 92 | } |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 93 | "m.sticker" => content.get("body")?.as_str()?.to_owned(), |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 94 | "m.poll.start" | "org.matrix.msc3381.poll.start" => poll_question(content, event_type)?, |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 95 | _ => return None, |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 96 | }; |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 97 | (!text.trim().is_empty()).then_some(text) |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 98 | } |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 99 | |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 100 | fn edit_of(value: &Value, event_type: &str) -> Option<Edit> { |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 101 | let content = value.get("content")?; |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 102 | if content.pointer("/m.relates_to/rel_type")?.as_str()? != "m.replace" { |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 103 | return None; |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 104 | } |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 105 | Some(Edit { |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 106 | id: value.get("event_id")?.as_str()?.to_owned(), |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 107 | target: content |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 108 | .pointer("/m.relates_to/event_id")? |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 109 | .as_str()? |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 110 | .to_owned(), |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 111 | sender: value.get("sender")?.as_str()?.to_owned(), |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 112 | ts: value.get("origin_server_ts")?.as_u64()?, |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 113 | text: text_of(event_type, content.get("m.new_content")?)?, |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 114 | }) |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 115 | } |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 116 | |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 117 | pub(crate) fn observe(value: &Value) -> Observed { |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 118 | observe_inner(value).unwrap_or(Observed::Other) |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 119 | } |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 120 | |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 121 | fn observe_inner(value: &Value) -> Option<Observed> { |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 122 | let event_type = value.get("type")?.as_str()?; |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 123 | let key = value.get("event_id")?.as_str()?.to_owned(); |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 124 | if event_type == "m.room.redaction" { |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 125 | let target = value |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 126 | .get("redacts") |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 127 | .or_else(|| value.pointer("/content/redacts"))? |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 128 | .as_str()? |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 129 | .to_owned(); |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 130 | return Some(Observed::Redaction { target }); |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 131 | } |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 132 | if value.pointer("/unsigned/redacted_because").is_some() { |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 133 | return Some(Observed::Redacted { key }); |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 134 | } |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 135 | let ts = value.get("origin_server_ts")?.as_u64()?; |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 136 | if event_type == "m.room.encrypted" { |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 137 | let session_id = value.pointer("/content/session_id")?.as_str()?.to_owned(); |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 138 | return Some(Observed::Encrypted { |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 139 | key, |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 140 | session_id, |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 141 | ts, |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 142 | }); |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 143 | } |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 144 | if value |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 145 | .pointer("/content/m.relates_to/rel_type") |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 146 | .and_then(Value::as_str) |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 147 | == Some("m.replace") |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 148 | { |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 149 | return edit_of(value, event_type).map(Observed::Edit); |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 150 | } |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 151 | let content = value.get("content")?; |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 152 | let text = text_of(event_type, content)?; |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 153 | let sender = value.get("sender")?.as_str()?.to_owned(); |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 154 | let bundled = value |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 155 | .pointer("/unsigned/m.relations/m.replace") |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 156 | .and_then(|edit| edit_of(edit, event_type)) |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 157 | .filter(|edit| edit.target == key); |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 158 | Some(Observed::Message { |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 159 | key, |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 160 | sender, |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 161 | ts, |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 162 | text, |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 163 | bundled, |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 164 | }) |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 165 | } |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 166 | |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 167 | fn newer(ts: u64, id: &str, than: &Doc) -> bool { |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 168 | (ts, id) > (than.content_ts, than.content.as_str()) |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 169 | } |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 170 | |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 171 | /// what `observed` does to `room`'s part of the index. edits land on their original under |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 172 | /// its key, the latest by its own sender wins, and one arriving first holds the key |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 173 | /// provisionally until the original turns up |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 174 | pub(crate) fn apply( |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 175 | index: &mut dyn MessageIndex, |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 176 | redactions: &mut Redactions, |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 177 | room: &str, |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 178 | observed: Observed, |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 179 | ) -> Effect { |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 180 | match observed { |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 181 | Observed::Message { |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 182 | key, |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 183 | sender, |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 184 | ts, |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 185 | text, |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 186 | bundled, |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 187 | } => { |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 188 | if redactions.contains(&key) { |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 189 | return Effect::Nothing; |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 190 | } |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 191 | let mut doc = Doc { |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 192 | key: key.clone(), |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 193 | room: room.to_owned(), |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 194 | sender: sender.clone(), |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 195 | ts, |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 196 | content: key.clone(), |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 197 | content_ts: ts, |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 198 | text, |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 199 | provisional: false, |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 200 | }; |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 201 | if let Some(edit) = |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 202 | bundled.filter(|edit| edit.sender == sender && !redactions.contains(&edit.id)) |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 203 | { |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 204 | doc.content = edit.id; |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 205 | doc.content_ts = edit.ts; |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 206 | doc.text = edit.text; |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 207 | } |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 208 | match index.get(&key) { |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 209 | Some(existing) if !existing.provisional => { |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 210 | if !newer(doc.content_ts, &doc.content, &existing) { |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 211 | return Effect::Nothing; |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 212 | } |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 213 | } |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 214 | Some(existing) => { |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 215 | if existing.sender == sender && !newer(doc.content_ts, &doc.content, &existing) |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 216 | { |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 217 | doc.content = existing.content; |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 218 | doc.content_ts = existing.content_ts; |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 219 | doc.text = existing.text; |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 220 | } |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 221 | } |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 222 | None => {} |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 223 | } |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 224 | index.put(doc); |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 225 | Effect::Indexed(ts) |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 226 | } |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 227 | Observed::Edit(edit) => { |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 228 | if redactions.contains(&edit.target) || redactions.contains(&edit.id) { |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 229 | return Effect::Nothing; |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 230 | } |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 231 | let doc = match index.get(&edit.target) { |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 232 | Some(existing) => { |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 233 | if existing.sender != edit.sender || !newer(edit.ts, &edit.id, &existing) { |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 234 | return Effect::Nothing; |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 235 | } |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 236 | Doc { |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 237 | content: edit.id, |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 238 | content_ts: edit.ts, |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 239 | text: edit.text, |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 240 | ..existing |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 241 | } |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 242 | } |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 243 | None => Doc { |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 244 | key: edit.target, |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 245 | room: room.to_owned(), |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 246 | sender: edit.sender, |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 247 | ts: edit.ts, |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 248 | content: edit.id, |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 249 | content_ts: edit.ts, |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 250 | text: edit.text, |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 251 | provisional: true, |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 252 | }, |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 253 | }; |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 254 | let ts = doc.ts; |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 255 | index.put(doc); |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 256 | Effect::Indexed(ts) |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 257 | } |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 258 | Observed::Redaction { target } => { |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 259 | redactions.insert(target.clone()); |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 260 | if index.remove(&target) { |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 261 | return Effect::Removed; |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 262 | } |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 263 | match index.by_content(&target) { |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 264 | Some(doc) => { |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 265 | index.remove(&doc.key); |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 266 | if doc.provisional { |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 267 | Effect::Removed |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 268 | } else { |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 269 | Effect::Refetch(doc.key) |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 270 | } |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 271 | } |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 272 | None => Effect::Nothing, |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 273 | } |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 274 | } |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 275 | Observed::Redacted { key } => { |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 276 | redactions.insert(key.clone()); |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 277 | if index.remove(&key) { |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 278 | Effect::Removed |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 279 | } else { |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 280 | Effect::Nothing |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 281 | } |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 282 | } |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 283 | Observed::Encrypted { .. } | Observed::Other => Effect::Nothing, |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 284 | } |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 285 | } |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 286 | |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 287 | #[cfg(test)] |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 288 | #[path = "feed_tests.rs"] |
c9effeac326a | atagen | 2026-10-25 10:32 UTC | 289 | mod tests; |