2018-02-25 12:05:29 +00:00
|
|
|
from channels.generic.websocket import JsonWebsocketConsumer
|
2019-03-15 14:52:30 +00:00
|
|
|
|
2018-03-01 20:51:20 +00:00
|
|
|
from funkwhale_api.common import channels
|
2018-02-25 12:05:29 +00:00
|
|
|
|
|
|
|
|
|
|
|
class JsonAuthConsumer(JsonWebsocketConsumer):
|
|
|
|
def connect(self):
|
2019-03-15 14:52:30 +00:00
|
|
|
try:
|
|
|
|
assert self.scope["user"].pk is not None
|
|
|
|
except (AssertionError, AttributeError, KeyError):
|
2019-03-13 15:50:49 +00:00
|
|
|
return self.close()
|
2018-03-01 20:51:20 +00:00
|
|
|
|
2019-03-15 14:52:30 +00:00
|
|
|
return self.accept()
|
|
|
|
|
2018-03-01 20:51:20 +00:00
|
|
|
def accept(self):
|
|
|
|
super().accept()
|
2020-02-18 14:19:51 +00:00
|
|
|
groups = self.scope["user"].get_channels_groups() + self.groups
|
|
|
|
for group in groups:
|
2018-09-06 18:35:02 +00:00
|
|
|
channels.group_add(group, self.channel_name)
|
2020-02-18 14:19:51 +00:00
|
|
|
|
|
|
|
def disconnect(self, close_code):
|
|
|
|
groups = self.scope["user"].get_channels_groups() + self.groups
|
|
|
|
for group in groups:
|
|
|
|
channels.group_discard(group, self.channel_name)
|