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