diff options
| author | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
|---|---|---|
| committer | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
| commit | 3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch) | |
| tree | a44932296ef4a9b71d5f010906253d8c53727726 /addons/website_jitsi/controllers/main.py | |
| parent | 0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff) | |
initial commit 2
Diffstat (limited to 'addons/website_jitsi/controllers/main.py')
| -rw-r--r-- | addons/website_jitsi/controllers/main.py | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/addons/website_jitsi/controllers/main.py b/addons/website_jitsi/controllers/main.py new file mode 100644 index 00000000..b7c91ea7 --- /dev/null +++ b/addons/website_jitsi/controllers/main.py @@ -0,0 +1,59 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from werkzeug.exceptions import NotFound + +from odoo import http +from odoo.http import request + + +class WebsiteJitsiController(http.Controller): + + @http.route(["/jitsi/update_status"], type="json", auth="public") + def jitsi_update_status(self, room_name, participant_count, joined): + """ Update room status: participant count, max reached + + Use the SQL keywords "FOR UPDATE SKIP LOCKED" in order to skip if the row + is locked (instead of raising an exception, wait for a moment and retry). + This endpoint may be called multiple times and we don't care having small + errors in participant count compared to performance issues. + + :raise ValueError: wrong participant count + :raise NotFound: wrong room name + """ + if participant_count < 0: + raise ValueError() + + chat_room = self._chat_room_exists(room_name) + if not chat_room: + raise NotFound() + + request.env.cr.execute( + """ + WITH req AS ( + SELECT id + FROM chat_room + -- Can not update the chat room if we do not have its name + WHERE name = %s + FOR UPDATE SKIP LOCKED + ) + UPDATE chat_room AS wcr + SET participant_count = %s, + last_activity = NOW(), + max_participant_reached = GREATEST(max_participant_reached, %s) + FROM req + WHERE wcr.id = req.id; + """, + [room_name, participant_count, participant_count] + ) + + @http.route(["/jitsi/is_full"], type="json", auth="public") + def jitsi_is_full(self, room_name): + return self._chat_room_exists(room_name).is_full + + # ------------------------------------------------------------ + # TOOLS + # ------------------------------------------------------------ + + def _chat_room_exists(self, room_name): + return request.env["chat.room"].sudo().search([("name", "=", room_name)], limit=1) |
