Commit 4c5705381f
Unsigned
Layout: unified · split
src/render.rs +23 −1
| @@ -32,6 +32,28 @@ pub struct RenderedEvent { | |||
| 32 | pub content: RenderedContent, | 32 | pub content: RenderedContent, |
| 33 | } | 33 | } |
| 34 | 34 | ||
| 35 | impl RenderedEvent { | ||
| 36 | const MSG_TAGS: &'static [&'static str] = &["notify_message"]; | ||
| 37 | const SELF_TAGS: &'static [&'static str] = | ||
| 38 | &["notify_none", "no_highlight", "self_msg"]; | ||
| 39 | |||
| 40 | pub fn add_self_tags(self) -> Self { | ||
| 41 | self.add_tags(Self::SELF_TAGS) | ||
| 42 | } | ||
| 43 | |||
| 44 | pub fn add_msg_tags(self) -> Self { | ||
| 45 | self.add_tags(Self::MSG_TAGS) | ||
| 46 | } | ||
| 47 | |||
| 48 | fn add_tags(mut self, tags: &[&str]) -> Self { | ||
| 49 | for line in &mut self.content.lines { | ||
| 50 | line.tags.extend(tags.iter().map(|tag| tag.to_string())) | ||
| 51 | } | ||
| 52 | |||
| 53 | self | ||
| 54 | } | ||
| 55 | } | ||
| 56 | |||
| 35 | pub struct RenderedLine { | 57 | pub struct RenderedLine { |
| 36 | /// The tags of the line. | 58 | /// The tags of the line. |
| 37 | pub tags: Vec<String>, | 59 | pub tags: Vec<String>, |
| @@ -322,7 +344,7 @@ impl Render for EncryptedEventContent { | |||
| 322 | 344 | ||
| 323 | impl Render for RedactedSyncMessageEvent<RedactedMessageEventContent> { | 345 | impl Render for RedactedSyncMessageEvent<RedactedMessageEventContent> { |
| 324 | type RenderContext = WeechatRoomMember; | 346 | type RenderContext = WeechatRoomMember; |
| 325 | const TAGS: &'static [&'static str] = &[&"matrix_redacted"]; | 347 | const TAGS: &'static [&'static str] = &["matrix_redacted"]; |
| 326 | 348 | ||
| 327 | fn render(&self, redacter: &Self::RenderContext) -> RenderedContent { | 349 | fn render(&self, redacter: &Self::RenderContext) -> RenderedContent { |
| 328 | // TODO add the redaction reason. | 350 | // TODO add the redaction reason. |
src/room/mod.rs +10 −2
| @@ -502,7 +502,14 @@ impl MatrixRoom { | |||
| 502 | &sender, | 502 | &sender, |
| 503 | &event.content(), | 503 | &event.content(), |
| 504 | ) | 504 | ) |
| 505 | .await | 505 | .await.map(|r| { |
| 506 | // TODO the tags are different if the room is a DM. | ||
| 507 | if sender.user_id == self.own_user_id { | ||
| 508 | r.add_self_tags() | ||
| 509 | } else { | ||
| 510 | r.add_msg_tags() | ||
| 511 | } | ||
| 512 | }) | ||
| 506 | } | 513 | } |
| 507 | 514 | ||
| 508 | // Add the content of the message to our outgoing messag queue and print out | 515 | // Add the content of the message to our outgoing messag queue and print out |
| @@ -520,7 +527,8 @@ impl MatrixRoom { | |||
| 520 | }); | 527 | }); |
| 521 | 528 | ||
| 522 | let local_echo = | 529 | let local_echo = |
| 523 | c.render_with_prefix_for_echo(&sender, uuid, &()); | 530 | c.render_with_prefix_for_echo(&sender, uuid, &()) |
| 531 | .add_self_tags(); | ||
| 524 | self.print_rendered_event(local_echo); | 532 | self.print_rendered_event(local_echo); |
| 525 | 533 | ||
| 526 | self.outgoing_messages.add_with_echo(uuid, content.clone()); | 534 | self.outgoing_messages.add_with_echo(uuid, content.clone()); |