Commit 4c5705381f

4c5705381fa7cb50fb653e954e1587c8913f18c8

parent: 3e46c921f9

Unsigned

Damir Jelić <poljar@termina.org.uk> · 2020-12-01 20:25 UTC

render: Add notify and highlight tags.

Layout: unified · split

src/render.rs +23 −1
@@ -32,6 +32,28 @@ pub struct RenderedEvent {
3232 pub content: RenderedContent,
3333}
3434
35impl 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
3557pub struct RenderedLine {
3658 /// The tags of the line.
3759 pub tags: Vec<String>,
@@ -322,7 +344,7 @@ impl Render for EncryptedEventContent {
322344
323345impl Render for RedactedSyncMessageEvent<RedactedMessageEventContent> {
324346 type RenderContext = WeechatRoomMember;
325 const TAGS: &'static [&'static str] = &[&"matrix_redacted"];
347 const TAGS: &'static [&'static str] = &["matrix_redacted"];
326348
327349 fn render(&self, redacter: &Self::RenderContext) -> RenderedContent {
328350 // TODO add the redaction reason.
src/room/mod.rs +10 −2
@@ -502,7 +502,14 @@ impl MatrixRoom {
502502 &sender,
503503 &event.content(),
504504 )
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 })
506513 }
507514
508515 // Add the content of the message to our outgoing messag queue and print out
@@ -520,7 +527,8 @@ impl MatrixRoom {
520527 });
521528
522529 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();
524532 self.print_rendered_event(local_echo);
525533
526534 self.outgoing_messages.add_with_echo(uuid, content.clone());