Philipp Hörist pushed to branch master at gajim / gajim


Commits:
a97dd86d by lovetox at 2022-03-12T16:45:38+01:00
HistoryExport: Add better solution for storing plaintext files

JIDs can be long, and have characters which are not allowed in the
filesystem. This splits the jid on domain / localpart / resource and
generates a folder structure. Further each part is limited in length.

- - - - -
fa18adc6 by lovetox at 2022-03-12T17:06:14+01:00
Use correct type hints

- - - - -


5 changed files:

- gajim/common/helpers.py
- gajim/gtk/controls/base.py
- gajim/gtk/conversation/view.py
- gajim/gtk/history_export.py
- gajim/gtk/search_view.py


Changes:

=====================================
gajim/common/helpers.py
=====================================
@@ -1399,3 +1399,16 @@ def get_start_of_day(date_time: datetime) -> datetime:
                              minute=0,
                              second=0,
                              microsecond=0)
+
+
+def make_path_from_jid(base_path: Path, jid: JID) -> Path:
+    assert jid.domain is not None
+    domain = jid.domain[:50]
+
+    if jid.localpart is None:
+        return base_path / domain
+
+    path = base_path / domain / jid.localpart[:50]
+    if jid.resource is not None:
+        return path / jid.resource[:30]
+    return path


=====================================
gajim/gtk/controls/base.py
=====================================
@@ -1404,7 +1404,7 @@ def scroll_to_end(self, force: bool = False) -> None:
         self.reset_view()
         self.conversation_view.scroll_to_end(force)
 
-    def scroll_to_message(self, log_line_id: str, timestamp: float) -> None:
+    def scroll_to_message(self, log_line_id: int, timestamp: float) -> None:
         row = self.conversation_view.get_row_by_log_line_id(log_line_id)
         if row is None:
             # Clear view and reload conversation around timestamp


=====================================
gajim/gtk/conversation/view.py
=====================================
@@ -430,7 +430,7 @@ def _reduce_messages_after(self) -> None:
         row = self.get_row_at_index(len(self.get_children()) - 1)
         row.destroy()
 
-    def scroll_to_message_and_highlight(self, log_line_id: str) -> None:
+    def scroll_to_message_and_highlight(self, log_line_id: int) -> None:
         highlight_row = None
         for row in cast(list[BaseRow], self.get_children()):
             row.get_style_context().remove_class(
@@ -447,7 +447,7 @@ def scroll_to_message_and_highlight(self, log_line_id: str) 
-> None:
     def _get_row_by_message_id(self, id_: str) -> Optional[MessageRow]:
         return self._message_id_row_map.get(id_)
 
-    def get_row_by_log_line_id(self, log_line_id: str) -> Optional[MessageRow]:
+    def get_row_by_log_line_id(self, log_line_id: int) -> Optional[MessageRow]:
         for row in cast(list[BaseRow], self.get_children()):
             if not isinstance(row, MessageRow):
                 continue


=====================================
gajim/gtk/history_export.py
=====================================
@@ -27,6 +27,7 @@
 from gajim.common import app
 from gajim.common import configpaths
 from gajim.common.const import KindConstant
+from gajim.common.helpers import make_path_from_jid
 from gajim.common.i18n import _
 from gajim.common.storage.archive import MessageExportRow
 
@@ -106,8 +107,7 @@ def _on_export(self) -> None:
 
         current_time = datetime.now()
         time_str = current_time.strftime('%Y-%m-%d-%H-%M-%S')
-        path = Path(directory) / f'export_{time_str}'
-        path.mkdir()
+        export_dir = Path(directory) / f'export_{time_str}'
 
         jids = app.storage.archive.get_conversation_jids(account)
 
@@ -116,7 +116,10 @@ def _on_export(self) -> None:
             if not messages:
                 continue
 
-            with open(path / f'{jid}.txt', 'w', encoding='utf-8') as file:
+            file_path = make_path_from_jid(export_dir, jid)
+            file_path.mkdir(parents=True, exist_ok=True)
+            with open(file_path / 'history.txt', 'w', encoding='utf-8') as 
file:
+                file.write(f'History for {jid}\n\n')
                 for message in messages:
                     file.write(self._get_export_line(message))
 


=====================================
gajim/gtk/search_view.py
=====================================
@@ -319,7 +319,7 @@ def __init__(self, count: int) -> None:
 
 
 class ResultRow(Gtk.ListBoxRow):
-    def __init__(self, msg: Any, account: str, jid: JID) -> None:
+    def __init__(self, msg: SearchLogRow, account: str, jid: JID) -> None:
         Gtk.ListBoxRow.__init__(self)
         self.account = account
         self.jid = jid



View it on GitLab: 
https://dev.gajim.org/gajim/gajim/-/compare/48e1df4517bdd2f00548c2d27fa181286ad5815e...fa18adc6a211c2af8effbc6f605854821ddb085b

-- 
View it on GitLab: 
https://dev.gajim.org/gajim/gajim/-/compare/48e1df4517bdd2f00548c2d27fa181286ad5815e...fa18adc6a211c2af8effbc6f605854821ddb085b
You're receiving this email because of your account on dev.gajim.org.


_______________________________________________
Commits mailing list
[email protected]
https://lists.gajim.org/cgi-bin/listinfo/commits

Reply via email to