Added limited local read/unread tracking

This commit is contained in:
Emi Simpson 2020-04-09 18:03:12 -04:00 committed by miruka
parent b2cfc27ce2
commit 6ee20a2717
7 changed files with 44 additions and 18 deletions

View File

@ -116,6 +116,7 @@ class MatrixClient(nio.AsyncClient):
self.backend: "Backend" = backend
self.models: ModelStore = self.backend.models
self.open_room: str = None
self.profile_task: Optional[asyncio.Future] = None
self.server_config_task: Optional[asyncio.Future] = None
@ -831,6 +832,18 @@ class MatrixClient(nio.AsyncClient):
await super().room_forget(room_id)
async def room_read(self, room_id: str) -> None:
"""Mark all messages in a room as read
Currently, this doesn't handle sending a read receipt to the server,
only cleaning up any unread indicators.
"""
self.open_room = room_id
if self.first_sync_done.is_set():
room = self.models[self.user_id, "rooms"][room_id]
room.mentions = 0
room.unreads = 0
async def room_mass_invite(
self, room_id: str, *user_ids: str,
@ -1153,10 +1166,12 @@ class MatrixClient(nio.AsyncClient):
last_event_date = registered.last_event_date
typing_members = registered.typing_members
mentions = registered.mentions
unreads = registered.unreads
except KeyError:
last_event_date = datetime.fromtimestamp(0)
typing_members = []
mentions = 0
unreads = 0
self.models[self.user_id, "rooms"][room.room_id] = Room(
id = room.room_id,
@ -1191,6 +1206,7 @@ class MatrixClient(nio.AsyncClient):
last_event_date = last_event_date,
mentions = mentions,
unreads = unreads,
)

View File

@ -82,6 +82,7 @@ class Room(ModelItem):
last_event_date: datetime = ZeroDate
mentions: int = 0
unreads: int = 0
def __lt__(self, other: "Room") -> bool:
"""Sort by join state, then descending last event date, then name.

View File

@ -36,7 +36,6 @@ class NioCallbacks:
client: "MatrixClient" = field()
def __post_init__(self) -> None:
"""Register our methods as callbacks."""
@ -109,9 +108,11 @@ class NioCallbacks:
room, ev, content=co, mentions=mention_list,
)
if self.client.first_sync_done.is_set() and self.client.open_room != room.room_id:
room = self.client.models[self.client.user_id, "rooms"][room.room_id]
room.unreads += 1
if HTML_PROCESSOR.user_id_link_in_html(co, self.client.user_id):
rooms = self.client.models[self.client.user_id, "rooms"]
rooms[room.room_id].mentions += 1
room.mentions += 1

View File

@ -44,23 +44,23 @@ HTileDelegate {
color: theme.mainPane.listView.room.name
}
// HLabel {
// text: model.mentions
// font.pixelSize: theme.fontSize.small
// verticalAlignment: Qt.AlignVCenter
// leftPadding: theme.spacing / 4
// rightPadding: leftPadding
HLabel {
text: model.unreads
font.pixelSize: theme.fontSize.small
verticalAlignment: Qt.AlignVCenter
leftPadding: theme.spacing / 4
rightPadding: leftPadding
// scale: model.mentions === 0 ? 0 : 1
// visible: scale > 0
scale: model.unreads === 0 ? 0 : 1
visible: scale > 0
// background: Rectangle {
// color: theme.colors.alertBackground
// radius: theme.radius / 4
// }
background: Rectangle {
color: model.mentions === 0 ? theme.colors.unreadBackground : theme.colors.alertBackground
radius: theme.radius / 4
}
// Behavior on scale { HNumberAnimation {} }
// },
Behavior on scale { HNumberAnimation {} }
}
HIcon {
svgName: "invite-received"

View File

@ -61,6 +61,8 @@ HLoader {
function showRoom(userId, roomId) {
_show("Pages/Chat/Chat.qml", {userId, roomId})
py.callClientCoro(userId, "room_read", [roomId], () => {})
window.uiState.page = "Pages/Chat/Chat.qml"
window.uiState.pageProperties = {userId, roomId}
window.uiStateChanged()

View File

@ -59,6 +59,9 @@ colors:
color negativeBackground:
hsluv(0, saturation * 1.5, intensity * 52, opacity)
color unreadBackground:
hsluv(188, saturation * 1.5, intensity * 52, 1)
color alertBackground: negativeBackground
color brightText: hsluv(0, 0, intensity * 100)

View File

@ -62,6 +62,9 @@ colors:
color negativeBackground:
hsluv(0, saturation * 1.5, intensity * 52, opacity)
color unreadBackground:
hsluv(188, saturation * 1.5, intensity * 52, 1)
color alertBackground: negativeBackground
color brightText: hsluv(0, 0, intensity * 100)