Return new group messages after a given message id (AJAX polling).
(gid: int)
| 15001 | |
| 15002 | This docstring was expanded to make future maintenance easier. |
| 15003 | |
| 15004 | Args: |
| 15005 | call_id: Parameter. |
| 15006 | |
| 15007 | Returns: |
| 15008 | Varies. |
| 15009 | """ |
| 15010 | if not ENABLE_CALLS: |
| 15011 | return jsonify({"ok": False, "error": "Calls disabled"}), 404 |
| 15012 | me = current_user() |
| 15013 | try: |
| 15014 | since = int(request.args.get("since") or 0) |
| 15015 | except Exception: |
| 15016 | since = 0 |
| 15017 | conn = db_connect() |
| 15018 | call = conn.execute("SELECT a,b,status FROM dm_calls WHERE id=?", (call_id,)).fetchone() |
| 15019 | if not call or call["status"] != "active" or (me != call["a"] and me != call["b"]): |
| 15020 | conn.close() |
| 15021 | return jsonify({"ok": False, "error": "Not allowed"}), 403 |
| 15022 | |
| 15023 | rows = conn.execute(""" |
| 15024 | SELECT id, sender, kind, payload, created_at |
| 15025 | FROM dm_call_signals |
| 15026 | WHERE call_id=? AND id > ? |
| 15027 | ORDER BY id ASC |
| 15028 | LIMIT 120 |
| 15029 | """, (call_id, since)).fetchall() |
| 15030 | conn.close() |
| 15031 | return jsonify({"ok": True, "items": [dict(r) for r in rows]}) |
| 15032 | |
| 15033 | @app.route("/api/call/<int:call_id>/end", methods=["POST"]) |
| 15034 | @login_required |
| 15035 | def api_call_end(call_id: int): |
| 15036 | """api_call_end. |
| 15037 | |
| 15038 | Route handler or application helper. |
| 15039 | |
| 15040 | This docstring was expanded to make future maintenance easier. |
| 15041 | |
| 15042 | Args: |
| 15043 | call_id: Parameter. |
| 15044 | |
| 15045 | Returns: |
| 15046 | Varies. |
| 15047 | """ |
| 15048 | if not ENABLE_CALLS: |
| 15049 | return jsonify({"ok": False, "error": "Calls disabled"}), 404 |
| 15050 | me = current_user() |
| 15051 | conn = db_connect() |
| 15052 | call = conn.execute("SELECT a,b,status FROM dm_calls WHERE id=?", (call_id,)).fetchone() |
| 15053 | if not call or call["status"] != "active" or (me != call["a"] and me != call["b"]): |
| 15054 | conn.close() |
| 15055 | return jsonify({"ok": False, "error": "Not allowed"}), 403 |
| 15056 | conn.execute("UPDATE dm_calls SET status='ended', ended_at=? WHERE id=?", (now_z(), call_id)) |
| 15057 | conn.execute("INSERT INTO dm_call_signals(call_id, sender, kind, payload, created_at) VALUES(?,?,?,?,?)", |
| 15058 | (call_id, me, "hangup", "{}", now_z())) |
nothing calls this directly
no test coverage detected