Add inviter account informations to room invites
This commit is contained in:
parent
bbf29e29b1
commit
9602608b87
|
@ -10,6 +10,7 @@ from PyQt5.QtCore import QObject, pyqtProperty, pyqtSignal, pyqtSlot
|
|||
|
||||
import nio
|
||||
import nio.responses as nr
|
||||
import nio.events as ne
|
||||
|
||||
from .network_manager import NetworkManager
|
||||
from .pyqt_future import futurize
|
||||
|
@ -22,6 +23,7 @@ _POOLS: DefaultDict[str, ThreadPoolExecutor] = \
|
|||
|
||||
class Client(QObject):
|
||||
roomInvited = pyqtSignal(str)
|
||||
roomInvited = pyqtSignal(str, dict)
|
||||
roomJoined = pyqtSignal(str)
|
||||
roomLeft = pyqtSignal(str)
|
||||
roomSyncPrevBatchTokenReceived = pyqtSignal(str, str)
|
||||
|
@ -117,6 +119,13 @@ class Client(QObject):
|
|||
self.nio.receive_response(response)
|
||||
|
||||
for room_id, room_info in response.rooms.invite.items():
|
||||
for ev in room_info.invite_state:
|
||||
member_event = isinstance(ev, ne.InviteMemberEvent)
|
||||
|
||||
if member_event and ev.content["membership"] == "join":
|
||||
self.roomInvited.emit(room_id, ev.content)
|
||||
break
|
||||
else:
|
||||
self.roomInvited.emit(room_id)
|
||||
|
||||
for room_id, room_info in response.rooms.join.items():
|
||||
|
|
|
@ -62,7 +62,8 @@ class User(ListItem):
|
|||
|
||||
|
||||
class Room(ListItem):
|
||||
roles = ("roomId", "category", "displayName", "topic", "typingUsers")
|
||||
roles = ("roomId", "category", "displayName", "topic", "typingUsers",
|
||||
"inviter")
|
||||
|
||||
categoryChanged = pyqtSignal(str)
|
||||
displayNameChanged = pyqtSignal("QVariant")
|
||||
|
@ -74,6 +75,7 @@ class Room(ListItem):
|
|||
displayName = prop(str, "displayName", displayNameChanged)
|
||||
topic = prop(str, "topic", topicChanged, "")
|
||||
typingUsers = prop(list, "typingUsers", typingUsersChanged, [])
|
||||
inviter = prop("QVariantMap", "inviter")
|
||||
|
||||
|
||||
class RoomEvent(ListItem):
|
||||
|
|
|
@ -13,6 +13,8 @@ from .backend import Backend
|
|||
from .client import Client
|
||||
from .model.items import Room, RoomEvent, User
|
||||
|
||||
Inviter = Optional[Dict[str, str]]
|
||||
|
||||
|
||||
class SignalManager(QObject):
|
||||
_event_handling_lock: Lock = Lock()
|
||||
|
@ -54,16 +56,24 @@ class SignalManager(QObject):
|
|||
attr.connect(onSignal)
|
||||
|
||||
|
||||
def onRoomInvited(self, client: Client, room_id: str) -> None:
|
||||
self._add_room(client, client.nio.invited_rooms[room_id], "Invites")
|
||||
def onRoomInvited(self,
|
||||
client: Client,
|
||||
room_id: str,
|
||||
inviter: Inviter = None) -> None:
|
||||
self._add_room(
|
||||
client, client.nio.invited_rooms[room_id], "Invites", inviter
|
||||
)
|
||||
|
||||
|
||||
def onRoomJoined(self, client: Client, room_id: str) -> None:
|
||||
self._add_room(client, client.nio.rooms[room_id], "Rooms")
|
||||
|
||||
|
||||
def _add_room(self, client: Client, room: MatrixRoom, category: str
|
||||
) -> None:
|
||||
def _add_room(self,
|
||||
client: Client,
|
||||
room: MatrixRoom,
|
||||
category: str,
|
||||
inviter: Inviter = None) -> None:
|
||||
model = self.backend.models.rooms[client.userId]
|
||||
|
||||
def group_name() -> Optional[str]:
|
||||
|
@ -75,6 +85,7 @@ class SignalManager(QObject):
|
|||
category = category,
|
||||
displayName = room.name or room.canonical_alias or group_name(),
|
||||
topic = room.topic,
|
||||
inviter = inviter,
|
||||
)
|
||||
|
||||
model.updateOrAppendWhere("roomId", room.room_id, item)
|
||||
|
|
|
@ -9,20 +9,24 @@ Rectangle {
|
|||
Layout.preferredHeight: 32
|
||||
color: "#BBB"
|
||||
|
||||
property var inviter: null
|
||||
|
||||
Base.HRowLayout {
|
||||
id: inviteRow
|
||||
anchors.fill: parent
|
||||
|
||||
Base.Avatar {
|
||||
id: inviteAvatar
|
||||
name: ""
|
||||
name: inviter ? inviter.displayname : ""
|
||||
dimmension: inviteOffer.Layout.preferredHeight
|
||||
//imageSource: inviter ? inviter.avatar_url : ""
|
||||
}
|
||||
|
||||
Base.HLabel {
|
||||
id: inviteLabel
|
||||
text: "<b>" + "Person" + "</b> " +
|
||||
qsTr("invited you to join the room.")
|
||||
text: (inviter ?
|
||||
("<b>" + inviter.displayname + "</b>") : qsTr("Someone")) +
|
||||
" " + qsTr("invited you to join the room.")
|
||||
textFormat: Text.StyledText
|
||||
maximumLineCount: 1
|
||||
elide: Text.ElideRight
|
||||
|
|
|
@ -28,6 +28,7 @@ ColumnLayout {
|
|||
|
||||
InviteOffer {
|
||||
visible: isInvite
|
||||
inviter: roomInfo.inviter
|
||||
}
|
||||
|
||||
SendBox {
|
||||
|
|
Loading…
Reference in New Issue
Block a user