equal
deleted
inserted
replaced
33 - a principal identified by it's ID, title, authentication token and principals |
33 - a principal identified by it's ID, title, authentication token and principals |
34 - a set of contexts; each context is defined by a unique key ('*' for a global |
34 - a set of contexts; each context is defined by a unique key ('*' for a global |
35 subscription) for which we subscribe for a list of events types |
35 subscription) for which we subscribe for a list of events types |
36 """ |
36 """ |
37 |
37 |
38 def __init__(self, principal): |
38 def __init__(self, principal, host): |
39 self.principal = principal |
39 self.principal = principal |
|
40 self.host = host |
40 self.contexts = {} |
41 self.contexts = {} |
41 |
42 |
42 def update_contexts(self, new_contexts): |
43 def update_contexts(self, new_contexts): |
43 contexts = self.contexts |
44 contexts = self.contexts |
44 for ctx, events in new_contexts.items(): |
45 for ctx, events in new_contexts.items(): |
79 'message': translate(_("Can't subscribe to notifications!"))})) |
80 'message': translate(_("Can't subscribe to notifications!"))})) |
80 return |
81 return |
81 async with users_lock: |
82 async with users_lock: |
82 subscription = users.get(self.ws) |
83 subscription = users.get(self.ws) |
83 if subscription is None: |
84 if subscription is None: |
84 subscription = WebsocketSubscription(principal) |
85 subscription = WebsocketSubscription(principal, message.get('host')) |
85 subscription.update_contexts(message.get('context')) |
86 subscription.update_contexts(message.get('context')) |
86 users[self.ws] = subscription |
87 users[self.ws] = subscription |
87 |
88 |
88 async def on_close(self): |
89 async def on_close(self): |
89 if self.ws in users: |
90 if self.ws in users: |