From 56ad352e64106689b5b3a5896b0a7d4d12797dcb Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Thu, 21 Jan 2021 17:44:18 +0100 Subject: [PATCH] Integrate BigBlueButton and whiteboard in pool rooms --- .../commands/fix_matrix_channels.py | 12 ++++++ tfjm/matrix.py | 40 +++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/apps/participation/management/commands/fix_matrix_channels.py b/apps/participation/management/commands/fix_matrix_channels.py index b1b1a06..40d5e94 100644 --- a/apps/participation/management/commands/fix_matrix_channels.py +++ b/apps/participation/management/commands/fix_matrix_channels.py @@ -5,6 +5,7 @@ import os from asgiref.sync import async_to_sync from django.core.management import BaseCommand +from django.utils.http import urlencode from django.utils.translation import activate from participation.models import Team, Tournament from registration.models import AdminRegistration, Registration, VolunteerRegistration @@ -320,6 +321,17 @@ class Command(BaseCommand): Matrix.set_room_avatar(f"#poule-{slug}-{pool.id}:tfjm.org", avatar_uri) Matrix.set_room_avatar(f"#poule-{slug}-{pool.id}-jurys:tfjm.org", avatar_uri) + url_params = urlencode(dict(url="https://visio.animath.live/b/XXX-XXX-XXX", + isAudioConf='false', displayName='$matrix_display_name', + avatarUrl='$matrix_avatar_url', userId='$matrix_user_id')) \ + .replace("%24", "$") + Matrix.add_integration(f"#poule-{slug}-{pool.id}:tfjm.org", + f"https://scalar.vector.im/api/widgets/bigbluebutton.html?{url_params}", + f"bbb-{slug}-{pool.id}", "bigbluebutton", "BigBlueButton", str(pool)) + Matrix.add_integration(f"#poule-{slug}-{pool.id}:tfjm.org", + f"https://board.tfjm.org/boards/{slug}-{pool.id}", f"board-{slug}-{pool.id}", + "customwidget", "Tableau", str(pool)) + # Invite admins and give permissions for admin in AdminRegistration.objects.all(): Matrix.invite(f"#poule-{slug}-{pool.id}:tfjm.org", f"@{admin.matrix_username}:tfjm.org") diff --git a/tfjm/matrix.py b/tfjm/matrix.py index 1ae0141..1a65311 100644 --- a/tfjm/matrix.py +++ b/tfjm/matrix.py @@ -263,6 +263,46 @@ class Matrix: content=content, ) + @classmethod + @async_to_sync + async def add_integration(cls, room_id: str, widget_url: str, state_key: str, + widget_type: str = "customwidget", widget_name: str = "Custom widget", + widget_title: str = ""): + client = await cls._get_client() + if room_id.startswith("#"): + room_id = await cls.resolve_room_alias(room_id) + content = { + "type": widget_type, + "url": widget_url, + "name": widget_name, + "data": { + "curl": widget_url, + "title": widget_title, + }, + "creatorUserId": client.user, + "roomId": room_id, + "id": state_key, + } + return await client.room_put_state( + room_id=room_id, + event_type="im.vector.modular.widgets", + content=content, + state_key=state_key, + ) + + @classmethod + @async_to_sync + async def remove_integration(cls, room_id: str, state_key: str): + client = await cls._get_client() + if room_id.startswith("#"): + room_id = await cls.resolve_room_alias(room_id) + return await client.room_put_state( + room_id=room_id, + event_type="im.vector.modular.widgets", + content={}, + state_key=state_key, + ) + @classmethod @async_to_sync async def kick(cls, room_id: str, user_id: str, reason: str = None):