mirror of
https://mau.dev/maunium/synapse.git
synced 2024-10-01 01:36:05 -04:00
Adjusted webclient to use new state paths. Updated membership msg template to actually show the person invited. Factored out common membership functions in matrix service.
This commit is contained in:
parent
52b64617f9
commit
5796232cb1
@ -318,7 +318,8 @@ class RoomMemberListRestServlet(RestServlet):
|
||||
user_id=user.to_string())
|
||||
|
||||
for event in members["chunk"]:
|
||||
target_user = self.hs.parse_userid(event["state_key"])
|
||||
# FIXME: should probably be state_key here, not user_id
|
||||
target_user = self.hs.parse_userid(event["user_id"])
|
||||
# Presence is an optional cache; don't fail if we can't fetch it
|
||||
try:
|
||||
presence_state = yield self.handlers.presence_handler.get_state(
|
||||
|
@ -54,10 +54,6 @@ angular.module('eventHandlerService', [])
|
||||
}
|
||||
|
||||
var handleMessage = function(event, isLiveEvent) {
|
||||
if ("membership_target" in event.content) {
|
||||
event.user_id = event.content.membership_target;
|
||||
}
|
||||
|
||||
initRoom(event.room_id);
|
||||
|
||||
if (isLiveEvent) {
|
||||
|
@ -115,19 +115,7 @@ angular.module('matrixService', [])
|
||||
|
||||
// Joins a room
|
||||
join: function(room_id) {
|
||||
// The REST path spec
|
||||
var path = "/rooms/$room_id/members/$user_id/state";
|
||||
|
||||
// Like the cmd client, escape room ids
|
||||
room_id = encodeURIComponent(room_id);
|
||||
|
||||
// Customize it
|
||||
path = path.replace("$room_id", room_id);
|
||||
path = path.replace("$user_id", config.user_id);
|
||||
|
||||
return doRequest("PUT", path, undefined, {
|
||||
membership: "join"
|
||||
});
|
||||
return this.membershipChange(room_id, config.user_id, "join");
|
||||
},
|
||||
|
||||
joinAlias: function(room_alias) {
|
||||
@ -141,34 +129,23 @@ angular.module('matrixService', [])
|
||||
|
||||
// Invite a user to a room
|
||||
invite: function(room_id, user_id) {
|
||||
// The REST path spec
|
||||
var path = "/rooms/$room_id/members/$user_id/state";
|
||||
|
||||
// Like the cmd client, escape room ids
|
||||
room_id = encodeURIComponent(room_id);
|
||||
|
||||
// Customize it
|
||||
path = path.replace("$room_id", room_id);
|
||||
path = path.replace("$user_id", user_id);
|
||||
|
||||
return doRequest("PUT", path, undefined, {
|
||||
membership: "invite"
|
||||
});
|
||||
return this.membershipChange(room_id, user_id, "invite");
|
||||
},
|
||||
|
||||
// Leaves a room
|
||||
leave: function(room_id) {
|
||||
return this.membershipChange(room_id, config.user_id, "leave");
|
||||
},
|
||||
|
||||
membershipChange: function(room_id, user_id, membershipValue) {
|
||||
// The REST path spec
|
||||
var path = "/rooms/$room_id/members/$user_id/state";
|
||||
var path = "/rooms/$room_id/state/m.room.member/$user_id";
|
||||
path = path.replace("$room_id", encodeURIComponent(room_id));
|
||||
path = path.replace("$user_id", encodeURIComponent(user_id));
|
||||
|
||||
// Like the cmd client, escape room ids
|
||||
room_id = encodeURIComponent(room_id);
|
||||
|
||||
// Customize it
|
||||
path = path.replace("$room_id", room_id);
|
||||
path = path.replace("$user_id", config.user_id);
|
||||
|
||||
return doRequest("DELETE", path, undefined, undefined);
|
||||
return doRequest("PUT", path, undefined, {
|
||||
membership: membershipValue
|
||||
});
|
||||
},
|
||||
|
||||
// Retrieves the room ID corresponding to a room alias
|
||||
|
@ -41,7 +41,7 @@ angular.module('HomeController', ['matrixService', 'mFileInput', 'mFileUpload',
|
||||
|
||||
$scope.$on(eventHandlerService.MEMBER_EVENT, function(ngEvent, event, isLive) {
|
||||
var config = matrixService.config();
|
||||
if (event.target_user_id === config.user_id && event.content.membership === "invite") {
|
||||
if (event.state_key === config.user_id && event.content.membership === "invite") {
|
||||
console.log("Invited to room " + event.room_id);
|
||||
// FIXME push membership to top level key to match /im/sync
|
||||
event.membership = event.content.membership;
|
||||
|
@ -154,7 +154,10 @@ angular.module('RoomController', ['ngSanitize', 'mUtilities'])
|
||||
var updateMemberList = function(chunk) {
|
||||
if (chunk.room_id != $scope.room_id) return;
|
||||
|
||||
var isNewMember = !(chunk.target_user_id in $scope.members);
|
||||
// set target_user_id to keep things clear
|
||||
var target_user_id = chunk.state_key;
|
||||
|
||||
var isNewMember = !(target_user_id in $scope.members);
|
||||
if (isNewMember) {
|
||||
// FIXME: why are we copying these fields around inside chunk?
|
||||
if ("state" in chunk.content) {
|
||||
@ -172,7 +175,7 @@ angular.module('RoomController', ['ngSanitize', 'mUtilities'])
|
||||
if ("avatar_url" in chunk.content) {
|
||||
chunk.avatar_url = chunk.content.avatar_url;
|
||||
}
|
||||
$scope.members[chunk.target_user_id] = chunk;
|
||||
$scope.members[target_user_id] = chunk;
|
||||
|
||||
/*
|
||||
// Stale code for explicitly hammering the homeserver for every displayname & avatar_url
|
||||
@ -202,13 +205,13 @@ angular.module('RoomController', ['ngSanitize', 'mUtilities'])
|
||||
});
|
||||
*/
|
||||
|
||||
if (chunk.target_user_id in $rootScope.presence) {
|
||||
updatePresence($rootScope.presence[chunk.target_user_id]);
|
||||
if (target_user_id in $rootScope.presence) {
|
||||
updatePresence($rootScope.presence[target_user_id]);
|
||||
}
|
||||
}
|
||||
else {
|
||||
// selectively update membership else it will nuke the picture and displayname too :/
|
||||
var member = $scope.members[chunk.target_user_id];
|
||||
var member = $scope.members[target_user_id];
|
||||
member.content.membership = chunk.content.membership;
|
||||
}
|
||||
}
|
||||
|
@ -44,7 +44,7 @@
|
||||
<span ng-hide='msg.type !== "m.room.member"'>
|
||||
{{ members[msg.user_id].displayname || msg.user_id }}
|
||||
{{ {"join": "joined", "leave": "left", "invite": "invited"}[msg.content.membership] }}
|
||||
{{ msg.content.target_id || '' }}
|
||||
{{ msg.content.membership === "invite" ? (msg.state_key || '') : '' }}
|
||||
</span>
|
||||
<span ng-hide='msg.content.msgtype !== "m.emote"' ng-bind-html="'* ' + (members[msg.user_id].displayname || msg.user_id) + ' ' + msg.content.body | linky:'_blank'"/>
|
||||
<span ng-hide='msg.content.msgtype !== "m.text"' ng-bind-html="((msg.content.msgtype === 'm.text') ? msg.content.body : '') | linky:'_blank'"/>
|
||||
|
Loading…
Reference in New Issue
Block a user