Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
from typing import Optional, Union
from django.utils.translation import gettext_lazy as _
from celery.result import AsyncResult
from aleksis.apps.matrix.models import MatrixRoom
from aleksis.apps.matrix.tasks import use_group_in_matrix
from aleksis.core.models import Group
@Group.method
def use_in_matrix(self, sync=False) -> Union[MatrixRoom, AsyncResult]:
"""Create and sync a room for this group in Matrix."""
if sync:
return self._use_in_matrix()
else:
return use_group_in_matrix.delay(self.pk)
@Group.method
def _use_in_matrix(self):
"""Create and sync a room for this group in Matrix."""
room = MatrixRoom.from_group(self)
room.sync()
return room
@Group.property_
def matrix_alias(self) -> Optional[str]:
"""Return the alias of the group's room in Matrix."""
if hasattr(self, "matrix_room"):
return self.matrix_room.alias
return None
@Group.property_
def matrix_room_id(self) -> Optional[str]:
"""Return the ID of the group's room in Matrix."""
if hasattr(self, "matrix_room"):
return self.matrix_room.room_id
return None
Group.add_permission("view_matrixroom", _("Can view matrix room of a group"))