chiark / gitweb /
Don't show @mentions in Ego Log post summaries.
authorSimon Tatham <anakin@pobox.com>
Thu, 7 Dec 2023 05:18:52 +0000 (05:18 +0000)
committerSimon Tatham <anakin@pobox.com>
Thu, 7 Dec 2023 05:18:52 +0000 (05:18 +0000)
That way we get in as much as possible of the message _content_, which
should help disambiguate posts that are part of a long conversation
with the same user(s).

text.py

diff --git a/text.py b/text.py
index 307a422ae20359684afb7a575e48dd9890b20f53..dbaebe5715af379fad2cd6edd2aaec6f04d27006 100644 (file)
--- a/text.py
+++ b/text.py
@@ -105,6 +105,9 @@ class ColouredString:
             line += c
         yield line
 
+    def is_colour(self, c):
+        return self.c == c * len(self.c)
+
 class BlankLine:
     def render(self, width):
         yield ColouredString("")
@@ -272,6 +275,14 @@ class Paragraph:
         self.words.extend(para.words)
         self.space_colours.extend(para.space_colours)
 
+    def delete_mention_words_from(self, pos):
+        while pos < len(self.words) and self.words[pos].is_colour('@'):
+            self.words[pos:pos+1] = []
+            self.space_colours[pos:pos+1] = []
+
+    def __len__(self):
+        return len(self.words)
+
     def __repr__(self):
         return f"Paragraph({self.words!r}, unfinished={self.unfinished_word!r})"
 
@@ -299,8 +310,10 @@ class NotificationLog:
         self.para.end_word()
 
         if want_content:
+            currlen = len(self.para)
             for cpara in cparas:
                 self.para.add_para(cpara)
+            self.para.delete_mention_words_from(currlen)
 
     def render(self, width):
         it = self.para.render(width, max(0, width-2))