From db0de237e6392f8b48d36da659c68abcf57ff24d Mon Sep 17 00:00:00 2001 From: miruka Date: Sun, 8 Sep 2019 11:40:39 -0400 Subject: [PATCH] Add message context menu entry to clear events --- TODO.md | 1 + src/icons/thin/clear-messages.svg | 1 + src/python/matrix_client.py | 18 ++++++++++++++---- src/qml/Chat/Timeline/EventDelegate.qml | 9 ++++++++- src/qml/Chat/Timeline/EventList.qml | 2 +- 5 files changed, 25 insertions(+), 6 deletions(-) create mode 100644 src/icons/thin/clear-messages.svg diff --git a/TODO.md b/TODO.md index 60d851b5..c8d75c2a 100644 --- a/TODO.md +++ b/TODO.md @@ -11,6 +11,7 @@ - When qml syntax highlighting supports ES6 string interpolation, use that - Fixes + - Quote newline spacing - 256 min width when a non-image link preview is present - Pressing backspace in composer sometimes doesn't work - Message order isn't preserved when sending a first message in a E2E diff --git a/src/icons/thin/clear-messages.svg b/src/icons/thin/clear-messages.svg new file mode 100644 index 00000000..e35c1651 --- /dev/null +++ b/src/icons/thin/clear-messages.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/python/matrix_client.py b/src/python/matrix_client.py index b9207fff..1c85cac6 100644 --- a/src/python/matrix_client.py +++ b/src/python/matrix_client.py @@ -61,9 +61,10 @@ class MatrixClient(nio.AsyncClient): self.send_locks: DefaultDict[str, asyncio.Lock] = \ DefaultDict(asyncio.Lock) # {room_id: lock} - self.past_tokens: Dict[str, str] = {} # {room_id: token} - self.fully_loaded_rooms: Set[str] = set() # {room_id} - self.loaded_once_rooms: Set[str] = set() # {room_id} + self.past_tokens: Dict[str, str] = {} # {room_id: token} + self.fully_loaded_rooms: Set[str] = set() # {room_id} + self.loaded_once_rooms: Set[str] = set() # {room_id} + self.cleared_events_rooms: Set[str] = set() # {room_id} self.local_echoes_uuid: Set[str] = set() self.resolved_echoes: Dict[str, str] = {} # {event_id: echo_uuid} @@ -225,7 +226,9 @@ class MatrixClient(nio.AsyncClient): async def load_past_events(self, room_id: str) -> bool: - if room_id in self.fully_loaded_rooms or room_id in self.invited_rooms: + if room_id in self.fully_loaded_rooms or \ + room_id in self.invited_rooms or \ + room_id in self.cleared_events_rooms: return False await self.first_sync_done.wait() @@ -379,6 +382,13 @@ class MatrixClient(nio.AsyncClient): await asyncio.coroutine(cb.func)(room, decrypted) + async def clear_events(self, room_id: str) -> None: + self.cleared_events_rooms.add(room_id) + model = self.models[Event, self.user_id, room_id] + model.clear() + model.sync_now() + + # Functions to register data into models async def event_is_past(self, ev: Union[nio.Event, Event]) -> bool: diff --git a/src/qml/Chat/Timeline/EventDelegate.qml b/src/qml/Chat/Timeline/EventDelegate.qml index 5becf683..ce144648 100644 --- a/src/qml/Chat/Timeline/EventDelegate.qml +++ b/src/qml/Chat/Timeline/EventDelegate.qml @@ -6,7 +6,6 @@ import "../../utils.js" as Utils Column { id: eventDelegate width: eventList.width - topPadding: model.event_type == "RoomCreateEvent" ? 0 : dayBreak ? theme.spacing * 4 : @@ -125,6 +124,14 @@ Column { Utils.copyToClipboard(selectableLabelContainer.joinedSelection) } + HMenuItem { + icon.name: "clear-messages" + text: qsTr("Clear messages") + onTriggered: py.callClientCoro( + chatPage.userId, "clear_events", [chatPage.roomId], + ) + } + HMenuItem { icon.name: "settings" text: qsTr("Set as debug console target") diff --git a/src/qml/Chat/Timeline/EventList.qml b/src/qml/Chat/Timeline/EventList.qml index 9c008aec..aea494da 100644 --- a/src/qml/Chat/Timeline/EventList.qml +++ b/src/qml/Chat/Timeline/EventList.qml @@ -177,7 +177,7 @@ Rectangle { } HNoticePage { - text: qsTr("No messages visible yet") + text: qsTr("No messages to show yet") visible: eventList.model.count < 1 anchors.fill: parent