mirror of
https://mau.dev/maunium/synapse.git
synced 2024-08-25 03:35:28 +00: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(
|
notificationService.showNotification(
|
||||||
displayname + " (" + roomTitle + ")",
|
displayname + " (" + roomTitle + ")",
|
||||||
message,
|
message,
|
||||||
member ? member.avatar_url : undefined,
|
member ? member.event.content.avatar_url : undefined,
|
||||||
function() {
|
function() {
|
||||||
console.log("notification.onclick() room=" + event.room_id);
|
console.log("notification.onclick() room=" + event.room_id);
|
||||||
$rootScope.goToPage('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
|
// Get the user display name from the member list of the room
|
||||||
var member = modelService.getMember(room_id, user_id);
|
var member = modelService.getMember(room_id, user_id);
|
||||||
|
if (member) {
|
||||||
|
member = member.event;
|
||||||
|
}
|
||||||
if (member && member.content.displayname) { // Do not consider null displayname
|
if (member && member.content.displayname) { // Do not consider null displayname
|
||||||
displayName = member.content.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) {
|
for (var member_id in room.current_room_state.members) {
|
||||||
if (room.current_room_state.members.hasOwnProperty(member_id) && member_id !== user_id) {
|
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) {
|
if (member2.content.displayname && member2.content.displayname === displayName) {
|
||||||
displayName = displayName + " (" + user_id + ")";
|
displayName = displayName + " (" + user_id + ")";
|
||||||
break;
|
break;
|
||||||
@ -551,7 +554,7 @@ function(matrixService, $rootScope, $q, $timeout, $filter, mPresence, notificati
|
|||||||
for (var i in room.current_room_state.members) {
|
for (var i in room.current_room_state.members) {
|
||||||
if (!room.current_room_state.members.hasOwnProperty(i)) continue;
|
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) {
|
if ("join" === member.content.membership) {
|
||||||
memberCount = memberCount + 1;
|
memberCount = memberCount + 1;
|
||||||
|
@ -214,7 +214,7 @@ angular.module('MatrixCall', [])
|
|||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
var roomMembers = modelService.getRoom(this.room_id).current_room_state.members;
|
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");
|
console.log("We need to join the room before we can accept this call");
|
||||||
matrixService.join(this.room_id).then(function() {
|
matrixService.join(this.room_id).then(function() {
|
||||||
self.answer();
|
self.answer();
|
||||||
|
@ -53,7 +53,7 @@ function($rootScope, matrixService, eventHandlerService, modelService) {
|
|||||||
for (var i in room.members) {
|
for (var i in room.members) {
|
||||||
if (!room.members.hasOwnProperty(i)) continue;
|
if (!room.members.hasOwnProperty(i)) continue;
|
||||||
|
|
||||||
var member = room.members[i];
|
var member = room.members[i].event;
|
||||||
if (member.state_key !== user_id) {
|
if (member.state_key !== user_id) {
|
||||||
roomName = eventHandlerService.getUserDisplayName(room_id, member.state_key);
|
roomName = eventHandlerService.getUserDisplayName(room_id, member.state_key);
|
||||||
if (!roomName) {
|
if (!roomName) {
|
||||||
@ -70,11 +70,11 @@ function($rootScope, matrixService, eventHandlerService, modelService) {
|
|||||||
if (otherUserId === user_id) {
|
if (otherUserId === user_id) {
|
||||||
// it's us, we may have been invited to this room or it could
|
// it's us, we may have been invited to this room or it could
|
||||||
// be a self chat.
|
// 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.
|
// 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) {
|
if (!roomName) {
|
||||||
roomName = room.members[otherUserId].user_id;
|
roomName = room.members[otherUserId].event.user_id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -106,7 +106,9 @@ angular.module('modelService', [])
|
|||||||
storeStateEvent: function storeState(event) {
|
storeStateEvent: function storeState(event) {
|
||||||
this.state_events[event.type + event.state_key] = event;
|
this.state_events[event.type + event.state_key] = event;
|
||||||
if (event.type === "m.room.member") {
|
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
|
// Show the room only if the user has joined it or has been invited
|
||||||
// (ie, do not show it if he has been banned)
|
// (ie, do not show it if he has been banned)
|
||||||
var member = modelService.getMember(room_id, user_id);
|
var member = modelService.getMember(room_id, user_id);
|
||||||
|
if (member) {
|
||||||
|
member = member.event;
|
||||||
|
}
|
||||||
room.recent.me = member;
|
room.recent.me = member;
|
||||||
if (member && ("invite" === member.content.membership || "join" === member.content.membership)) {
|
if (member && ("invite" === member.content.membership || "join" === member.content.membership)) {
|
||||||
if ("invite" === member.content.membership) {
|
if ("invite" === member.content.membership) {
|
||||||
|
@ -754,13 +754,13 @@ angular.module('RoomController', ['ngSanitize', 'matrixFilter', 'mFileInput'])
|
|||||||
for (var i in members) {
|
for (var i in members) {
|
||||||
if (!members.hasOwnProperty(i)) continue;
|
if (!members.hasOwnProperty(i)) continue;
|
||||||
|
|
||||||
var member = members[i];
|
var member = members[i].event;
|
||||||
updateMemberList(member);
|
updateMemberList(member);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if the user has already join the room
|
// Check if the user has already join the room
|
||||||
if ($scope.state.user_id in members) {
|
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;
|
needsToJoin = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -36,20 +36,28 @@ describe('EventHandlerService', function() {
|
|||||||
current_room_state: {
|
current_room_state: {
|
||||||
members: {
|
members: {
|
||||||
"@adam:matrix.org": {
|
"@adam:matrix.org": {
|
||||||
content: { membership: "join" },
|
event: {
|
||||||
user_id: "@adam:matrix.org"
|
content: { membership: "join" },
|
||||||
|
user_id: "@adam:matrix.org"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"@beth:matrix.org": {
|
"@beth:matrix.org": {
|
||||||
content: { membership: "invite" },
|
event: {
|
||||||
user_id: "@beth:matrix.org"
|
content: { membership: "invite" },
|
||||||
|
user_id: "@beth:matrix.org"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"@charlie:matrix.org": {
|
"@charlie:matrix.org": {
|
||||||
content: { membership: "join" },
|
event: {
|
||||||
user_id: "@charlie:matrix.org"
|
content: { membership: "join" },
|
||||||
|
user_id: "@charlie:matrix.org"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"@danice:matrix.org": {
|
"@danice:matrix.org": {
|
||||||
content: { membership: "leave" },
|
event: {
|
||||||
user_id: "@danice:matrix.org"
|
content: { membership: "leave" },
|
||||||
|
user_id: "@danice:matrix.org"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -70,12 +78,16 @@ describe('EventHandlerService', function() {
|
|||||||
current_room_state: {
|
current_room_state: {
|
||||||
members: {
|
members: {
|
||||||
"@adam:matrix.org": {
|
"@adam:matrix.org": {
|
||||||
content: { membership: "join" },
|
event: {
|
||||||
user_id: "@adam:matrix.org"
|
content: { membership: "join" },
|
||||||
|
user_id: "@adam:matrix.org"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"@beth:matrix.org": {
|
"@beth:matrix.org": {
|
||||||
content: { membership: "join" },
|
event: {
|
||||||
user_id: "@beth:matrix.org"
|
content: { membership: "join" },
|
||||||
|
user_id: "@beth:matrix.org"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
s: {
|
s: {
|
||||||
@ -102,4 +114,4 @@ describe('EventHandlerService', function() {
|
|||||||
num = eventHandlerService.getUserPowerLevel(roomId, "@unknown:matrix.org");
|
num = eventHandlerService.getUserPowerLevel(roomId, "@unknown:matrix.org");
|
||||||
expect(num).toEqual(50);
|
expect(num).toEqual(50);
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
|
@ -86,11 +86,13 @@ describe('mRoomName filter', function() {
|
|||||||
inviter_user_id = user_id;
|
inviter_user_id = user_id;
|
||||||
}
|
}
|
||||||
this.s["m.room.member" + user_id] = {
|
this.s["m.room.member" + user_id] = {
|
||||||
content: {
|
event: {
|
||||||
membership: membership
|
content: {
|
||||||
},
|
membership: membership
|
||||||
state_key: user_id,
|
},
|
||||||
user_id: inviter_user_id
|
state_key: user_id,
|
||||||
|
user_id: inviter_user_id
|
||||||
|
}
|
||||||
};
|
};
|
||||||
this.members[user_id] = this.s["m.room.member" + 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);
|
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