Ensure msgs are sent in right order, fix echo bug

bug: only one local echo message delegate could be seen because all
echo eventId were the same
This commit is contained in:
miruka 2019-07-04 19:49:55 -04:00
parent 13266303ff
commit 55e14e96bc
3 changed files with 12 additions and 4 deletions

View File

@ -7,7 +7,8 @@ import platform
from contextlib import suppress from contextlib import suppress
from datetime import datetime from datetime import datetime
from types import ModuleType from types import ModuleType
from typing import Dict, Optional, Type from typing import DefaultDict, Dict, Optional, Type
from uuid import uuid4
import nio import nio
from nio.rooms import MatrixRoom from nio.rooms import MatrixRoom
@ -31,6 +32,9 @@ class MatrixClient(nio.AsyncClient):
self.sync_task: Optional[asyncio.Future] = None self.sync_task: Optional[asyncio.Future] = None
self.send_locks: DefaultDict[str, asyncio.Lock] = \
DefaultDict(asyncio.Lock) # {room_id: lock}
super().__init__(homeserver=homeserver, user=user, device_id=device_id) super().__init__(homeserver=homeserver, user=user, device_id=device_id)
self.connect_callbacks() self.connect_callbacks()
@ -131,14 +135,15 @@ class MatrixClient(nio.AsyncClient):
TimelineMessageReceived( TimelineMessageReceived(
event_type = nio.RoomMessageText, event_type = nio.RoomMessageText,
room_id = room_id, room_id = room_id,
event_id = "local_echo", event_id = f"local_echo.{uuid4()}",
sender_id = self.user_id, sender_id = self.user_id,
date = datetime.now(), date = datetime.now(),
content = content["formatted_body"], content = content["formatted_body"],
is_local_echo = True, is_local_echo = True,
) )
await self.room_send(room_id, "m.room.message", content) async with self.send_locks[room_id]:
print(await self.room_send(room_id, "m.room.message", content))
# Callbacks for nio responses # Callbacks for nio responses

View File

@ -37,8 +37,11 @@ HRectangle {
// Declaring this "alias" provides the on... signal // Declaring this "alias" provides the on... signal
property real yPos: visibleArea.yPosition property real yPos: visibleArea.yPosition
property int zz: 0
onYPosChanged: { onYPosChanged: {
if (chatPage.category != "Invites" && yPos <= 0.1) { if (chatPage.category != "Invites" && yPos <= 0.1) {
zz += 1
print(zz)
//Backend.loadPastEvents(chatPage.roomId) //Backend.loadPastEvents(chatPage.roomId)
} }
} }

View File

@ -87,7 +87,7 @@ function onTimelineEventReceived(
timelines.set(found[0], item) timelines.set(found[0], item)
} else { } else {
// Multiple clients will emit duplicate events with the same eventId // Multiple clients will emit duplicate events with the same eventId
timelines.upsert({"eventId": event_id}, item, true, 500) timelines.upsert({"eventId": event_id}, item, true, 500)
} }
} }