mirror of
https://mau.dev/maunium/synapse.git
synced 2024-10-01 01:36:05 -04:00
Swap from using raw m.room.member events for room members to using actual RoomMember objects, so User objects can be tacked on. Update tests.
This commit is contained in:
parent
d4c20c472b
commit
e3c3f5a6d0
@ -141,7 +141,7 @@ function(matrixService, $rootScope, $q, $timeout, $filter, mPresence, notificati
|
||||
notificationService.showNotification(
|
||||
displayname + " (" + roomTitle + ")",
|
||||
message,
|
||||
member ? member.avatar_url : undefined,
|
||||
member ? member.event.content.avatar_url : undefined,
|
||||
function() {
|
||||
console.log("notification.onclick() room=" + event.room_id);
|
||||
$rootScope.goToPage('room/' + event.room_id);
|
||||
@ -306,6 +306,9 @@ function(matrixService, $rootScope, $q, $timeout, $filter, mPresence, notificati
|
||||
|
||||
// Get the user display name from the member list of the room
|
||||
var member = modelService.getMember(room_id, user_id);
|
||||
if (member) {
|
||||
member = member.event;
|
||||
}
|
||||
if (member && member.content.displayname) { // Do not consider null displayname
|
||||
displayName = member.content.displayname;
|
||||
|
||||
@ -315,7 +318,7 @@ function(matrixService, $rootScope, $q, $timeout, $filter, mPresence, notificati
|
||||
|
||||
for (var member_id in room.current_room_state.members) {
|
||||
if (room.current_room_state.members.hasOwnProperty(member_id) && member_id !== user_id) {
|
||||
var member2 = room.current_room_state.members[member_id];
|
||||
var member2 = room.current_room_state.members[member_id].event;
|
||||
if (member2.content.displayname && member2.content.displayname === displayName) {
|
||||
displayName = displayName + " (" + user_id + ")";
|
||||
break;
|
||||
@ -551,7 +554,7 @@ function(matrixService, $rootScope, $q, $timeout, $filter, mPresence, notificati
|
||||
for (var i in room.current_room_state.members) {
|
||||
if (!room.current_room_state.members.hasOwnProperty(i)) continue;
|
||||
|
||||
var member = room.current_room_state.members[i];
|
||||
var member = room.current_room_state.members[i].event;
|
||||
|
||||
if ("join" === member.content.membership) {
|
||||
memberCount = memberCount + 1;
|
||||
|
@ -214,7 +214,7 @@ angular.module('MatrixCall', [])
|
||||
var self = this;
|
||||
|
||||
var roomMembers = modelService.getRoom(this.room_id).current_room_state.members;
|
||||
if (roomMembers[matrixService.config().user_id].membership != 'join') {
|
||||
if (roomMembers[matrixService.config().user_id].event.content.membership != 'join') {
|
||||
console.log("We need to join the room before we can accept this call");
|
||||
matrixService.join(this.room_id).then(function() {
|
||||
self.answer();
|
||||
|
@ -53,7 +53,7 @@ function($rootScope, matrixService, eventHandlerService, modelService) {
|
||||
for (var i in room.members) {
|
||||
if (!room.members.hasOwnProperty(i)) continue;
|
||||
|
||||
var member = room.members[i];
|
||||
var member = room.members[i].event;
|
||||
if (member.state_key !== user_id) {
|
||||
roomName = eventHandlerService.getUserDisplayName(room_id, member.state_key);
|
||||
if (!roomName) {
|
||||
@ -70,11 +70,11 @@ function($rootScope, matrixService, eventHandlerService, modelService) {
|
||||
if (otherUserId === user_id) {
|
||||
// it's us, we may have been invited to this room or it could
|
||||
// be a self chat.
|
||||
if (room.members[otherUserId].content.membership === "invite") {
|
||||
if (room.members[otherUserId].event.content.membership === "invite") {
|
||||
// someone invited us, use the right ID.
|
||||
roomName = eventHandlerService.getUserDisplayName(room_id, room.members[otherUserId].user_id);
|
||||
roomName = eventHandlerService.getUserDisplayName(room_id, room.members[otherUserId].event.user_id);
|
||||
if (!roomName) {
|
||||
roomName = room.members[otherUserId].user_id;
|
||||
roomName = room.members[otherUserId].event.user_id;
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
@ -106,7 +106,9 @@ angular.module('modelService', [])
|
||||
storeStateEvent: function storeState(event) {
|
||||
this.state_events[event.type + event.state_key] = event;
|
||||
if (event.type === "m.room.member") {
|
||||
this.members[event.state_key] = event;
|
||||
var rm = new RoomMember();
|
||||
rm.event = event;
|
||||
this.members[event.state_key] = rm;
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -30,6 +30,9 @@ angular.module('RecentsController')
|
||||
// Show the room only if the user has joined it or has been invited
|
||||
// (ie, do not show it if he has been banned)
|
||||
var member = modelService.getMember(room_id, user_id);
|
||||
if (member) {
|
||||
member = member.event;
|
||||
}
|
||||
room.recent.me = member;
|
||||
if (member && ("invite" === member.content.membership || "join" === member.content.membership)) {
|
||||
if ("invite" === member.content.membership) {
|
||||
|
@ -754,13 +754,13 @@ angular.module('RoomController', ['ngSanitize', 'matrixFilter', 'mFileInput'])
|
||||
for (var i in members) {
|
||||
if (!members.hasOwnProperty(i)) continue;
|
||||
|
||||
var member = members[i];
|
||||
var member = members[i].event;
|
||||
updateMemberList(member);
|
||||
}
|
||||
|
||||
// Check if the user has already join the room
|
||||
if ($scope.state.user_id in members) {
|
||||
if ("join" === members[$scope.state.user_id].membership) {
|
||||
if ("join" === members[$scope.state.user_id].event.content.membership) {
|
||||
needsToJoin = false;
|
||||
}
|
||||
}
|
||||
|
@ -36,23 +36,31 @@ describe('EventHandlerService', function() {
|
||||
current_room_state: {
|
||||
members: {
|
||||
"@adam:matrix.org": {
|
||||
event: {
|
||||
content: { membership: "join" },
|
||||
user_id: "@adam:matrix.org"
|
||||
}
|
||||
},
|
||||
"@beth:matrix.org": {
|
||||
event: {
|
||||
content: { membership: "invite" },
|
||||
user_id: "@beth:matrix.org"
|
||||
}
|
||||
},
|
||||
"@charlie:matrix.org": {
|
||||
event: {
|
||||
content: { membership: "join" },
|
||||
user_id: "@charlie:matrix.org"
|
||||
}
|
||||
},
|
||||
"@danice:matrix.org": {
|
||||
event: {
|
||||
content: { membership: "leave" },
|
||||
user_id: "@danice:matrix.org"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@ -70,13 +78,17 @@ describe('EventHandlerService', function() {
|
||||
current_room_state: {
|
||||
members: {
|
||||
"@adam:matrix.org": {
|
||||
event: {
|
||||
content: { membership: "join" },
|
||||
user_id: "@adam:matrix.org"
|
||||
}
|
||||
},
|
||||
"@beth:matrix.org": {
|
||||
event: {
|
||||
content: { membership: "join" },
|
||||
user_id: "@beth:matrix.org"
|
||||
}
|
||||
}
|
||||
},
|
||||
s: {
|
||||
"m.room.power_levels": {
|
||||
|
@ -86,11 +86,13 @@ describe('mRoomName filter', function() {
|
||||
inviter_user_id = user_id;
|
||||
}
|
||||
this.s["m.room.member" + user_id] = {
|
||||
event: {
|
||||
content: {
|
||||
membership: membership
|
||||
},
|
||||
state_key: user_id,
|
||||
user_id: inviter_user_id
|
||||
}
|
||||
};
|
||||
this.members[user_id] = this.s["m.room.member" + user_id];
|
||||
}
|
||||
|
@ -25,6 +25,6 @@ describe('ModelService', function() {
|
||||
});
|
||||
|
||||
var user = modelService.getMember(roomId, userId);
|
||||
expect(user.state_key).toEqual(userId);
|
||||
expect(user.event.state_key).toEqual(userId);
|
||||
}));
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user