forked from MirrorHub/synapse
Merge branch 'master' of github.com:matrix-org/synapse into sql_refactor
This commit is contained in:
commit
b4a1f2ccb5
5 changed files with 55 additions and 18 deletions
|
@ -155,7 +155,10 @@ class PresenceHandler(BaseHandler):
|
||||||
if allowed_by_subscription:
|
if allowed_by_subscription:
|
||||||
defer.returnValue(True)
|
defer.returnValue(True)
|
||||||
|
|
||||||
# TODO(paul): Check same channel
|
rm_handler = self.homeserver.get_handlers().room_member_handler
|
||||||
|
for room_id in (yield rm_handler.get_rooms_for_user(observer_user)):
|
||||||
|
if observed_user in (yield rm_handler.get_room_members(room_id)):
|
||||||
|
defer.returnValue(True)
|
||||||
|
|
||||||
defer.returnValue(False)
|
defer.returnValue(False)
|
||||||
|
|
||||||
|
@ -166,16 +169,11 @@ class PresenceHandler(BaseHandler):
|
||||||
observed_user=target_user
|
observed_user=target_user
|
||||||
)
|
)
|
||||||
|
|
||||||
if visible or True: # XXX: FIXME: Bodge to unbreak matrix.org. breaks UTs.
|
if visible:
|
||||||
state = yield self.store.get_presence_state(
|
state = yield self.store.get_presence_state(
|
||||||
target_user.localpart
|
target_user.localpart
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
# FIXME: *Surely* we shouldn't be 404ing the whole request, whatever
|
|
||||||
# it is, just because presence info isn't visible?!
|
|
||||||
# This causes client/api/v1/rooms/!cURbafjkfsMDVwdRDQ%3Amatrix.org/members/list
|
|
||||||
# to 404 currently
|
|
||||||
|
|
||||||
raise SynapseError(404, "Presence information not visible")
|
raise SynapseError(404, "Presence information not visible")
|
||||||
else:
|
else:
|
||||||
# TODO(paul): Have remote server send us permissions set
|
# TODO(paul): Have remote server send us permissions set
|
||||||
|
|
|
@ -24,7 +24,7 @@ from synapse.rest.base import RestServlet, client_path_pattern
|
||||||
class EventStreamRestServlet(RestServlet):
|
class EventStreamRestServlet(RestServlet):
|
||||||
PATTERN = client_path_pattern("/events$")
|
PATTERN = client_path_pattern("/events$")
|
||||||
|
|
||||||
DEFAULT_LONGPOLL_TIME_MS = 5000
|
DEFAULT_LONGPOLL_TIME_MS = 30000
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def on_GET(self, request):
|
def on_GET(self, request):
|
||||||
|
|
|
@ -353,10 +353,14 @@ class RoomMemberListRestServlet(RestServlet):
|
||||||
|
|
||||||
for event in members["chunk"]:
|
for event in members["chunk"]:
|
||||||
target_user = self.hs.parse_userid(event["target_user_id"])
|
target_user = self.hs.parse_userid(event["target_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(
|
presence_state = yield self.handlers.presence_handler.get_state(
|
||||||
target_user=target_user, auth_user=user
|
target_user=target_user, auth_user=user
|
||||||
)
|
)
|
||||||
event["content"].update(presence_state)
|
event["content"].update(presence_state)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
defer.returnValue((200, members))
|
defer.returnValue((200, members))
|
||||||
|
|
||||||
|
|
|
@ -80,6 +80,14 @@ class PresenceStateTestCase(unittest.TestCase):
|
||||||
return defer.succeed(allow)
|
return defer.succeed(allow)
|
||||||
self.datastore.is_presence_visible = is_presence_visible
|
self.datastore.is_presence_visible = is_presence_visible
|
||||||
|
|
||||||
|
# Mock the RoomMemberHandler
|
||||||
|
room_member_handler = Mock(spec=[
|
||||||
|
"get_rooms_for_user",
|
||||||
|
"get_room_members",
|
||||||
|
])
|
||||||
|
hs.handlers.room_member_handler = room_member_handler
|
||||||
|
logging.getLogger().debug("Mocking room_member_handler=%r", room_member_handler)
|
||||||
|
|
||||||
# Some local users to test with
|
# Some local users to test with
|
||||||
self.u_apple = hs.parse_userid("@apple:test")
|
self.u_apple = hs.parse_userid("@apple:test")
|
||||||
self.u_banana = hs.parse_userid("@banana:test")
|
self.u_banana = hs.parse_userid("@banana:test")
|
||||||
|
@ -87,11 +95,21 @@ class PresenceStateTestCase(unittest.TestCase):
|
||||||
|
|
||||||
self.handler = hs.get_handlers().presence_handler
|
self.handler = hs.get_handlers().presence_handler
|
||||||
|
|
||||||
hs.handlers.room_member_handler = Mock(spec=[
|
self.room_members = []
|
||||||
"get_rooms_for_user",
|
|
||||||
])
|
def get_rooms_for_user(user):
|
||||||
hs.handlers.room_member_handler.get_rooms_for_user = (
|
if user in self.room_members:
|
||||||
lambda u: defer.succeed([]))
|
return defer.succeed(["a-room"])
|
||||||
|
else:
|
||||||
|
return defer.succeed([])
|
||||||
|
room_member_handler.get_rooms_for_user = get_rooms_for_user
|
||||||
|
|
||||||
|
def get_room_members(room_id):
|
||||||
|
if room_id == "a-room":
|
||||||
|
return defer.succeed(self.room_members)
|
||||||
|
else:
|
||||||
|
return defer.succeed([])
|
||||||
|
room_member_handler.get_room_members = get_room_members
|
||||||
|
|
||||||
self.mock_start = Mock()
|
self.mock_start = Mock()
|
||||||
self.mock_stop = Mock()
|
self.mock_stop = Mock()
|
||||||
|
@ -131,6 +149,21 @@ class PresenceStateTestCase(unittest.TestCase):
|
||||||
)
|
)
|
||||||
mocked_get.assert_called_with("apple")
|
mocked_get.assert_called_with("apple")
|
||||||
|
|
||||||
|
@defer.inlineCallbacks
|
||||||
|
def test_get_same_room_state(self):
|
||||||
|
mocked_get = self.datastore.get_presence_state
|
||||||
|
mocked_get.return_value = defer.succeed(
|
||||||
|
{"state": ONLINE, "status_msg": "Online"}
|
||||||
|
)
|
||||||
|
|
||||||
|
self.room_members = [self.u_apple, self.u_clementine]
|
||||||
|
|
||||||
|
state = yield self.handler.get_state(
|
||||||
|
target_user=self.u_apple, auth_user=self.u_clementine
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertEquals({"state": ONLINE, "status_msg": "Online"}, state)
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def test_get_disallowed_state(self):
|
def test_get_disallowed_state(self):
|
||||||
mocked_get = self.datastore.get_presence_state
|
mocked_get = self.datastore.get_presence_state
|
||||||
|
@ -138,6 +171,8 @@ class PresenceStateTestCase(unittest.TestCase):
|
||||||
{"state": ONLINE, "status_msg": "Online"}
|
{"state": ONLINE, "status_msg": "Online"}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
self.room_members = []
|
||||||
|
|
||||||
yield self.assertFailure(
|
yield self.assertFailure(
|
||||||
self.handler.get_state(
|
self.handler.get_state(
|
||||||
target_user=self.u_apple, auth_user=self.u_clementine
|
target_user=self.u_apple, auth_user=self.u_clementine
|
||||||
|
|
|
@ -26,7 +26,7 @@ angular.module('eventStreamService', [])
|
||||||
.factory('eventStreamService', ['$q', '$timeout', 'matrixService', 'eventHandlerService', function($q, $timeout, matrixService, eventHandlerService) {
|
.factory('eventStreamService', ['$q', '$timeout', 'matrixService', 'eventHandlerService', function($q, $timeout, matrixService, eventHandlerService) {
|
||||||
var END = "END";
|
var END = "END";
|
||||||
var START = "START";
|
var START = "START";
|
||||||
var TIMEOUT_MS = 5000;
|
var TIMEOUT_MS = 30000;
|
||||||
var ERR_TIMEOUT_MS = 5000;
|
var ERR_TIMEOUT_MS = 5000;
|
||||||
|
|
||||||
var settings = {
|
var settings = {
|
||||||
|
|
Loading…
Reference in a new issue