0
0
Fork 1
mirror of https://mau.dev/maunium/synapse.git synced 2024-12-15 05:53:51 +01:00

Merge branch 'client_server_url_rename' into develop

This commit is contained in:
Kegan Dougal 2014-08-26 10:37:31 +01:00
commit f6daa9f170
14 changed files with 117 additions and 170 deletions

View file

@ -61,7 +61,7 @@ class SynapseCmd(cmd.Cmd):
"send_delivery_receipts": "on" "send_delivery_receipts": "on"
} }
self.path_prefix = "/matrix/client/api/v1" self.path_prefix = "/matrix/client/api/v1"
self.event_stream_token = "START" self.event_stream_token = "END"
self.prompt = ">>> " self.prompt = ">>> "
def do_EOF(self, line): # allows CTRL+D quitting def do_EOF(self, line): # allows CTRL+D quitting
@ -402,9 +402,7 @@ class SynapseCmd(cmd.Cmd):
"""Leaves a room: "leave <roomid>" """ """Leaves a room: "leave <roomid>" """
try: try:
args = self._parse(line, ["roomid"], force_keys=True) args = self._parse(line, ["roomid"], force_keys=True)
path = ("/rooms/%s/members/%s/state" % self._do_membership_change(args["roomid"], "leave", self._usr())
(urllib.quote(args["roomid"]), self._usr()))
reactor.callFromThread(self._run_and_pprint, "DELETE", path)
except Exception as e: except Exception as e:
print e print e
@ -567,7 +565,7 @@ class SynapseCmd(cmd.Cmd):
alt_text="Sent receipt for %s" % event["msg_id"]) alt_text="Sent receipt for %s" % event["msg_id"])
def _do_membership_change(self, roomid, membership, userid): def _do_membership_change(self, roomid, membership, userid):
path = "/rooms/%s/members/%s/state" % (urllib.quote(roomid), userid) path = "/rooms/%s/state/m.room.member/%s" % (urllib.quote(roomid), urllib.quote(userid))
data = { data = {
"membership": membership "membership": membership
} }

View file

@ -44,15 +44,15 @@ class Auth(object):
be raised only if raises=True. be raised only if raises=True.
""" """
try: try:
if event.type in [RoomTopicEvent.TYPE, MessageEvent.TYPE, if hasattr(event, "room_id"):
FeedbackEvent.TYPE]: if event.type == RoomMemberEvent.TYPE:
yield self.check_joined_room(event.room_id, event.user_id)
defer.returnValue(True)
elif event.type == RoomMemberEvent.TYPE:
allowed = yield self.is_membership_change_allowed(event) allowed = yield self.is_membership_change_allowed(event)
defer.returnValue(allowed) defer.returnValue(allowed)
else: else:
raise AuthError(500, "Unknown event type %s" % event.type) yield self.check_joined_room(event.room_id, event.user_id)
defer.returnValue(True)
else:
raise AuthError(500, "Unknown event: %s" % event)
except AuthError as e: except AuthError as e:
logger.info("Event auth check failed on event %s with msg: %s", logger.info("Event auth check failed on event %s with msg: %s",
event, e.msg) event, e.msg)
@ -77,6 +77,8 @@ class Auth(object):
@defer.inlineCallbacks @defer.inlineCallbacks
def is_membership_change_allowed(self, event): def is_membership_change_allowed(self, event):
target_user_id = event.state_key
# does this room even exist # does this room even exist
room = yield self.store.get_room(event.room_id) room = yield self.store.get_room(event.room_id)
if not room: if not room:
@ -94,7 +96,7 @@ class Auth(object):
# get info about the target # get info about the target
try: try:
target = yield self.store.get_room_member( target = yield self.store.get_room_member(
user_id=event.target_user_id, user_id=target_user_id,
room_id=event.room_id) room_id=event.room_id)
except: except:
target = None target = None
@ -108,12 +110,12 @@ class Auth(object):
raise AuthError(403, "You are not in room %s." % event.room_id) raise AuthError(403, "You are not in room %s." % event.room_id)
elif target_in_room: # the target is already in the room. elif target_in_room: # the target is already in the room.
raise AuthError(403, "%s is already in the room." % raise AuthError(403, "%s is already in the room." %
event.target_user_id) target_user_id)
elif Membership.JOIN == membership: elif Membership.JOIN == membership:
# Joins are valid iff caller == target and they were: # Joins are valid iff caller == target and they were:
# invited: They are accepting the invitation # invited: They are accepting the invitation
# joined: It's a NOOP # joined: It's a NOOP
if event.user_id != event.target_user_id: if event.user_id != target_user_id:
raise AuthError(403, "Cannot force another user to join.") raise AuthError(403, "Cannot force another user to join.")
elif room.is_public: elif room.is_public:
pass # anyone can join public rooms. pass # anyone can join public rooms.
@ -123,10 +125,10 @@ class Auth(object):
elif Membership.LEAVE == membership: elif Membership.LEAVE == membership:
if not caller_in_room: # trying to leave a room you aren't joined if not caller_in_room: # trying to leave a room you aren't joined
raise AuthError(403, "You are not in room %s." % event.room_id) raise AuthError(403, "You are not in room %s." % event.room_id)
elif event.target_user_id != event.user_id: elif target_user_id != event.user_id:
# trying to force another user to leave # trying to force another user to leave
raise AuthError(403, "Cannot force %s to leave." % raise AuthError(403, "Cannot force %s to leave." %
event.target_user_id) target_user_id)
else: else:
raise AuthError(500, "Unknown membership %s" % membership) raise AuthError(500, "Unknown membership %s" % membership)

View file

@ -23,6 +23,7 @@ class Membership(object):
JOIN = u"join" JOIN = u"join"
KNOCK = u"knock" KNOCK = u"knock"
LEAVE = u"leave" LEAVE = u"leave"
LIST = (INVITE, JOIN, KNOCK, LEAVE)
class Feedback(object): class Feedback(object):

View file

@ -13,6 +13,8 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
from synapse.api.constants import Membership
from synapse.api.errors import SynapseError
from . import SynapseEvent from . import SynapseEvent
@ -59,15 +61,15 @@ class RoomMemberEvent(SynapseEvent):
TYPE = "m.room.member" TYPE = "m.room.member"
valid_keys = SynapseEvent.valid_keys + [ valid_keys = SynapseEvent.valid_keys + [
"target_user_id", # target # target is the state_key
"membership", # action "membership", # action
] ]
def __init__(self, **kwargs): def __init__(self, **kwargs):
if "target_user_id" in kwargs:
kwargs["state_key"] = kwargs["target_user_id"]
if "membership" not in kwargs: if "membership" not in kwargs:
kwargs["membership"] = kwargs.get("content", {}).get("membership") kwargs["membership"] = kwargs.get("content", {}).get("membership")
if not kwargs["membership"] in Membership.LIST:
raise SynapseError(400, "Bad membership value.")
super(RoomMemberEvent, self).__init__(**kwargs) super(RoomMemberEvent, self).__init__(**kwargs)
def get_content_template(self): def get_content_template(self):
@ -108,7 +110,7 @@ class InviteJoinEvent(SynapseEvent):
TYPE = "m.room.invite_join" TYPE = "m.room.invite_join"
valid_keys = SynapseEvent.valid_keys + [ valid_keys = SynapseEvent.valid_keys + [
"target_user_id", # target_user_id is the state_key
"target_host", "target_host",
] ]

View file

@ -56,11 +56,11 @@ class Notifier(object):
# invites MUST prod the person being invited, who won't be in the room. # invites MUST prod the person being invited, who won't be in the room.
if (event.type == RoomMemberEvent.TYPE and if (event.type == RoomMemberEvent.TYPE and
event.content["membership"] == Membership.INVITE): event.content["membership"] == Membership.INVITE):
member_list.append(event.target_user_id) member_list.append(event.state_key)
# similarly, LEAVEs must be sent to the person leaving # similarly, LEAVEs must be sent to the person leaving
if (event.type == RoomMemberEvent.TYPE and if (event.type == RoomMemberEvent.TYPE and
event.content["membership"] == Membership.LEAVE): event.content["membership"] == Membership.LEAVE):
member_list.append(event.target_user_id) member_list.append(event.state_key)
for user_id in member_list: for user_id in member_list:
if user_id in self.stored_event_listeners: if user_id in self.stored_event_listeners:

View file

@ -65,7 +65,7 @@ class FederationHandler(BaseHandler):
content.update({"membership": Membership.JOIN}) content.update({"membership": Membership.JOIN})
new_event = self.event_factory.create_event( new_event = self.event_factory.create_event(
etype=RoomMemberEvent.TYPE, etype=RoomMemberEvent.TYPE,
target_user_id=event.user_id, state_key=event.user_id,
room_id=event.room_id, room_id=event.room_id,
user_id=event.user_id, user_id=event.user_id,
membership=Membership.JOIN, membership=Membership.JOIN,

View file

@ -399,7 +399,7 @@ class RoomCreationHandler(BaseHandler):
content = {"membership": Membership.JOIN} content = {"membership": Membership.JOIN}
join_event = self.event_factory.create_event( join_event = self.event_factory.create_event(
etype=RoomMemberEvent.TYPE, etype=RoomMemberEvent.TYPE,
target_user_id=user_id, state_key=user_id,
room_id=room_id, room_id=room_id,
user_id=user_id, user_id=user_id,
membership=Membership.JOIN, membership=Membership.JOIN,
@ -527,9 +527,10 @@ class RoomMemberHandler(BaseHandler):
Raises: Raises:
SynapseError if there was a problem changing the membership. SynapseError if there was a problem changing the membership.
""" """
target_user_id = event.state_key
prev_state = yield self.store.get_room_member( prev_state = yield self.store.get_room_member(
event.target_user_id, event.room_id target_user_id, event.room_id
) )
if prev_state: if prev_state:
@ -555,7 +556,7 @@ class RoomMemberHandler(BaseHandler):
yield self.auth.check(event, raises=True) yield self.auth.check(event, raises=True)
prev_state = yield self.store.get_room_member( prev_state = yield self.store.get_room_member(
event.target_user_id, event.room_id target_user_id, event.room_id
) )
if prev_state and prev_state.membership == event.membership: if prev_state and prev_state.membership == event.membership:
# double same action, treat this event as a NOOP. # double same action, treat this event as a NOOP.
@ -588,7 +589,7 @@ class RoomMemberHandler(BaseHandler):
content.update({"membership": Membership.JOIN}) content.update({"membership": Membership.JOIN})
new_event = self.event_factory.create_event( new_event = self.event_factory.create_event(
etype=RoomMemberEvent.TYPE, etype=RoomMemberEvent.TYPE,
target_user_id=joinee.to_string(), state_key=joinee.to_string(),
room_id=room_id, room_id=room_id,
user_id=joinee.to_string(), user_id=joinee.to_string(),
membership=Membership.JOIN, membership=Membership.JOIN,
@ -601,7 +602,7 @@ class RoomMemberHandler(BaseHandler):
@defer.inlineCallbacks @defer.inlineCallbacks
def _do_join(self, event, room_host=None, do_auth=True): def _do_join(self, event, room_host=None, do_auth=True):
joinee = self.hs.parse_userid(event.target_user_id) joinee = self.hs.parse_userid(event.state_key)
# room_id = RoomID.from_string(event.room_id, self.hs) # room_id = RoomID.from_string(event.room_id, self.hs)
room_id = event.room_id room_id = event.room_id
@ -710,16 +711,17 @@ class RoomMemberHandler(BaseHandler):
# If we're inviting someone, then we should also send it to that # If we're inviting someone, then we should also send it to that
# HS. # HS.
target_user_id = event.state_key
if membership == Membership.INVITE: if membership == Membership.INVITE:
host = UserID.from_string( host = UserID.from_string(
event.target_user_id, self.hs target_user_id, self.hs
).domain ).domain
destinations.append(host) destinations.append(host)
# If we are joining a remote HS, include that. # If we are joining a remote HS, include that.
if membership == Membership.JOIN: if membership == Membership.JOIN:
host = UserID.from_string( host = UserID.from_string(
event.target_user_id, self.hs target_user_id, self.hs
).domain ).domain
destinations.append(host) destinations.append(host)

View file

@ -18,9 +18,10 @@ from twisted.internet import defer
from base import RestServlet, client_path_pattern from base import RestServlet, client_path_pattern
from synapse.api.errors import SynapseError, Codes from synapse.api.errors import SynapseError, Codes
from synapse.api.events.room import (RoomTopicEvent, MessageEvent, from synapse.api.events.room import (
RoomMemberEvent, FeedbackEvent) MessageEvent, RoomMemberEvent, FeedbackEvent
from synapse.api.constants import Feedback, Membership )
from synapse.api.constants import Feedback
from synapse.api.streams import PaginationConfig from synapse.api.streams import PaginationConfig
import json import json
@ -95,41 +96,71 @@ class RoomCreateRestServlet(RestServlet):
return (200, {}) return (200, {})
class RoomTopicRestServlet(RestServlet): class RoomStateEventRestServlet(RestServlet):
PATTERN = client_path_pattern("/rooms/(?P<room_id>[^/]*)/topic$") def register(self, http_server):
# /room/$roomid/state/$eventtype
no_state_key = "/rooms/(?P<room_id>[^/]*)/state/(?P<event_type>[^/]*)$"
def get_event_type(self): # /room/$roomid/state/$eventtype/$statekey
return RoomTopicEvent.TYPE state_key = ("/rooms/(?P<room_id>[^/]*)/state/" +
"(?P<event_type>[^/]*)/(?P<state_key>[^/]*)$")
http_server.register_path("GET",
client_path_pattern(state_key),
self.on_GET)
http_server.register_path("PUT",
client_path_pattern(state_key),
self.on_PUT)
http_server.register_path("GET",
client_path_pattern(no_state_key),
self.on_GET_no_state_key)
http_server.register_path("PUT",
client_path_pattern(no_state_key),
self.on_PUT_no_state_key)
def on_GET_no_state_key(self, request, room_id, event_type):
return self.on_GET(request, room_id, event_type, "")
def on_PUT_no_state_key(self, request, room_id, event_type):
return self.on_PUT(request, room_id, event_type, "")
@defer.inlineCallbacks @defer.inlineCallbacks
def on_GET(self, request, room_id): def on_GET(self, request, room_id, event_type, state_key):
user = yield self.auth.get_user_by_req(request) user = yield self.auth.get_user_by_req(request)
msg_handler = self.handlers.message_handler msg_handler = self.handlers.message_handler
data = yield msg_handler.get_room_data( data = yield msg_handler.get_room_data(
user_id=user.to_string(), user_id=user.to_string(),
room_id=urllib.unquote(room_id), room_id=urllib.unquote(room_id),
event_type=RoomTopicEvent.TYPE, event_type=urllib.unquote(event_type),
state_key="", state_key=urllib.unquote(state_key),
) )
if not data: if not data:
raise SynapseError(404, "Topic not found.", errcode=Codes.NOT_FOUND) raise SynapseError(404, "Event not found.", errcode=Codes.NOT_FOUND)
defer.returnValue((200, data.content)) defer.returnValue((200, data[0].get_dict()["content"]))
@defer.inlineCallbacks @defer.inlineCallbacks
def on_PUT(self, request, room_id): def on_PUT(self, request, room_id, event_type, state_key):
user = yield self.auth.get_user_by_req(request) user = yield self.auth.get_user_by_req(request)
event_type = urllib.unquote(event_type)
content = _parse_json(request) content = _parse_json(request)
event = self.event_factory.create_event( event = self.event_factory.create_event(
etype=self.get_event_type(), etype=event_type,
content=content, content=content,
room_id=urllib.unquote(room_id), room_id=urllib.unquote(room_id),
user_id=user.to_string(), user_id=user.to_string(),
state_key=urllib.unquote(state_key)
) )
if event_type == RoomMemberEvent.TYPE:
# membership events are special
handler = self.handlers.room_member_handler
yield handler.change_membership(event)
defer.returnValue((200, ""))
else:
# store random bits of state
msg_handler = self.handlers.message_handler msg_handler = self.handlers.message_handler
yield msg_handler.store_room_data( yield msg_handler.store_room_data(
event=event event=event
@ -157,73 +188,6 @@ class JoinRoomAliasServlet(RestServlet):
defer.returnValue((200, ret_dict)) defer.returnValue((200, ret_dict))
class RoomMemberRestServlet(RestServlet):
PATTERN = client_path_pattern("/rooms/(?P<room_id>[^/]*)/members/"
+ "(?P<target_user_id>[^/]*)/state$")
def get_event_type(self):
return RoomMemberEvent.TYPE
@defer.inlineCallbacks
def on_GET(self, request, room_id, target_user_id):
room_id = urllib.unquote(room_id)
user = yield self.auth.get_user_by_req(request)
handler = self.handlers.room_member_handler
member = yield handler.get_room_member(
room_id,
urllib.unquote(target_user_id),
user.to_string())
if not member:
raise SynapseError(404, "Member not found.",
errcode=Codes.NOT_FOUND)
defer.returnValue((200, member.content))
@defer.inlineCallbacks
def on_DELETE(self, request, roomid, target_user_id):
user = yield self.auth.get_user_by_req(request)
event = self.event_factory.create_event(
etype=self.get_event_type(),
target_user_id=urllib.unquote(target_user_id),
room_id=urllib.unquote(roomid),
user_id=user.to_string(),
membership=Membership.LEAVE,
content={"membership": Membership.LEAVE}
)
handler = self.handlers.room_member_handler
yield handler.change_membership(event)
defer.returnValue((200, ""))
@defer.inlineCallbacks
def on_PUT(self, request, roomid, target_user_id):
user = yield self.auth.get_user_by_req(request)
content = _parse_json(request)
if "membership" not in content:
raise SynapseError(400, "No membership key.",
errcode=Codes.BAD_JSON)
valid_membership_values = [Membership.JOIN, Membership.INVITE]
if (content["membership"] not in valid_membership_values):
raise SynapseError(400, "Membership value must be %s." % (
valid_membership_values,), errcode=Codes.BAD_JSON)
event = self.event_factory.create_event(
etype=self.get_event_type(),
target_user_id=urllib.unquote(target_user_id),
room_id=urllib.unquote(roomid),
user_id=user.to_string(),
membership=content["membership"],
content=content
)
handler = self.handlers.room_member_handler
yield handler.change_membership(event)
defer.returnValue((200, ""))
class MessageRestServlet(RestServlet): class MessageRestServlet(RestServlet):
PATTERN = client_path_pattern("/rooms/(?P<room_id>[^/]*)/messages/" PATTERN = client_path_pattern("/rooms/(?P<room_id>[^/]*)/messages/"
+ "(?P<sender_id>[^/]*)/(?P<msg_id>[^/]*)$") + "(?P<sender_id>[^/]*)/(?P<msg_id>[^/]*)$")
@ -354,7 +318,8 @@ class RoomMemberListRestServlet(RestServlet):
user_id=user.to_string()) user_id=user.to_string())
for event in members["chunk"]: for event in members["chunk"]:
target_user = self.hs.parse_userid(event["target_user_id"]) # 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 # Presence is an optional cache; don't fail if we can't fetch it
try: try:
presence_state = yield self.handlers.presence_handler.get_state( presence_state = yield self.handlers.presence_handler.get_state(
@ -400,6 +365,7 @@ class RoomTriggerBackfill(RestServlet):
res = [event.get_dict() for event in events] res = [event.get_dict() for event in events]
defer.returnValue((200, res)) defer.returnValue((200, res))
def _parse_json(request): def _parse_json(request):
try: try:
content = json.loads(request.content.read()) content = json.loads(request.content.read())
@ -412,8 +378,7 @@ def _parse_json(request):
def register_servlets(hs, http_server): def register_servlets(hs, http_server):
RoomTopicRestServlet(hs).register(http_server) RoomStateEventRestServlet(hs).register(http_server)
RoomMemberRestServlet(hs).register(http_server)
MessageRestServlet(hs).register(http_server) MessageRestServlet(hs).register(http_server)
FeedbackRestServlet(hs).register(http_server) FeedbackRestServlet(hs).register(http_server)
RoomCreateRestServlet(hs).register(http_server) RoomCreateRestServlet(hs).register(http_server)

View file

@ -35,13 +35,14 @@ class RoomMemberStore(SQLBaseStore):
def _store_room_member(self, event): def _store_room_member(self, event):
"""Store a room member in the database. """Store a room member in the database.
""" """
domain = self.hs.parse_userid(event.target_user_id).domain target_user_id = event.state_key
domain = self.hs.parse_userid(target_user_id).domain
yield self._simple_insert( yield self._simple_insert(
"room_memberships", "room_memberships",
{ {
"event_id": event.event_id, "event_id": event.event_id,
"user_id": event.target_user_id, "user_id": target_user_id,
"sender": event.user_id, "sender": event.user_id,
"room_id": event.room_id, "room_id": event.room_id,
"membership": event.membership, "membership": event.membership,

View file

@ -54,10 +54,6 @@ angular.module('eventHandlerService', [])
} }
var handleMessage = function(event, isLiveEvent) { var handleMessage = function(event, isLiveEvent) {
if ("membership_target" in event.content) {
event.user_id = event.content.membership_target;
}
initRoom(event.room_id); initRoom(event.room_id);
if (isLiveEvent) { if (isLiveEvent) {

View file

@ -115,19 +115,7 @@ angular.module('matrixService', [])
// Joins a room // Joins a room
join: function(room_id) { join: function(room_id) {
// The REST path spec return this.membershipChange(room_id, config.user_id, "join");
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"
});
}, },
joinAlias: function(room_alias) { joinAlias: function(room_alias) {
@ -141,34 +129,23 @@ angular.module('matrixService', [])
// Invite a user to a room // Invite a user to a room
invite: function(room_id, user_id) { invite: function(room_id, user_id) {
// The REST path spec return this.membershipChange(room_id, user_id, "invite");
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"
});
}, },
// Leaves a room // Leaves a room
leave: function(room_id) { leave: function(room_id) {
return this.membershipChange(room_id, config.user_id, "leave");
},
membershipChange: function(room_id, user_id, membershipValue) {
// The REST path spec // 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 return doRequest("PUT", path, undefined, {
room_id = encodeURIComponent(room_id); membership: membershipValue
});
// Customize it
path = path.replace("$room_id", room_id);
path = path.replace("$user_id", config.user_id);
return doRequest("DELETE", path, undefined, undefined);
}, },
// Retrieves the room ID corresponding to a room alias // Retrieves the room ID corresponding to a room alias

View file

@ -41,7 +41,7 @@ angular.module('HomeController', ['matrixService', 'mFileInput', 'mFileUpload',
$scope.$on(eventHandlerService.MEMBER_EVENT, function(ngEvent, event, isLive) { $scope.$on(eventHandlerService.MEMBER_EVENT, function(ngEvent, event, isLive) {
var config = matrixService.config(); 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); console.log("Invited to room " + event.room_id);
// FIXME push membership to top level key to match /im/sync // FIXME push membership to top level key to match /im/sync
event.membership = event.content.membership; event.membership = event.content.membership;

View file

@ -154,7 +154,10 @@ angular.module('RoomController', ['ngSanitize', 'mUtilities'])
var updateMemberList = function(chunk) { var updateMemberList = function(chunk) {
if (chunk.room_id != $scope.room_id) return; 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) { if (isNewMember) {
// FIXME: why are we copying these fields around inside chunk? // FIXME: why are we copying these fields around inside chunk?
if ("state" in chunk.content) { if ("state" in chunk.content) {
@ -172,7 +175,7 @@ angular.module('RoomController', ['ngSanitize', 'mUtilities'])
if ("avatar_url" in chunk.content) { if ("avatar_url" in chunk.content) {
chunk.avatar_url = chunk.content.avatar_url; 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 // 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) { if (target_user_id in $rootScope.presence) {
updatePresence($rootScope.presence[chunk.target_user_id]); updatePresence($rootScope.presence[target_user_id]);
} }
} }
else { else {
// selectively update membership else it will nuke the picture and displayname too :/ // 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; member.content.membership = chunk.content.membership;
} }
} }

View file

@ -44,7 +44,7 @@
<span ng-hide='msg.type !== "m.room.member"'> <span ng-hide='msg.type !== "m.room.member"'>
{{ members[msg.user_id].displayname || msg.user_id }} {{ members[msg.user_id].displayname || msg.user_id }}
{{ {"join": "joined", "leave": "left", "invite": "invited"}[msg.content.membership] }} {{ {"join": "joined", "leave": "left", "invite": "invited"}[msg.content.membership] }}
{{ msg.content.target_id || '' }} {{ msg.content.membership === "invite" ? (msg.state_key || '') : '' }}
</span> </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.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'"/> <span ng-hide='msg.content.msgtype !== "m.text"' ng-bind-html="((msg.content.msgtype === 'm.text') ? msg.content.body : '') | linky:'_blank'"/>