Send a group message (text and/or voice) without forcing a page refresh when called via AJAX. Stability: - Commit the group message + voice attachment atomically (single transaction) so polling clients never see a blank placeholder voice row.
(gid: int)
| 14885 | conn.commit() |
| 14886 | conn.close() |
| 14887 | return jsonify({"ok": True}) |
| 14888 | |
| 14889 | # --------------------------- |
| 14890 | # Video call signaling (WebRTC) |
| 14891 | # --------------------------- |
| 14892 | |
| 14893 | @app.route("/api/call/start/<peer>", methods=["POST"]) |
| 14894 | @login_required |
| 14895 | def api_call_start(peer: str): |
| 14896 | """api_call_start. |
| 14897 | |
| 14898 | Route handler or application helper. |
| 14899 | |
| 14900 | This docstring was expanded to make future maintenance easier. |
| 14901 | |
| 14902 | Args: |
| 14903 | peer: Parameter. |
| 14904 | |
| 14905 | Returns: |
| 14906 | Varies. |
| 14907 | """ |
| 14908 | if not ENABLE_CALLS: |
| 14909 | return jsonify({"ok": False, "error": "Calls disabled"}), 404 |
| 14910 | me = current_user() |
| 14911 | peer = peer.strip() |
| 14912 | if peer == me: |
| 14913 | return jsonify({"ok": False, "error": "Invalid peer"}), 400 |
| 14914 | conn = db_connect() |
| 14915 | exists = conn.execute("SELECT 1 FROM users WHERE username=?", (peer,)).fetchone() |
| 14916 | if not exists: |
| 14917 | conn.close() |
| 14918 | return jsonify({"ok": False, "error": "User not found"}), 404 |
| 14919 | |
| 14920 | # Reuse any active call between the two users |
| 14921 | row = conn.execute(""" |
| 14922 | SELECT id FROM dm_calls |
| 14923 | WHERE status='active' AND ((a=? AND b=?) OR (a=? AND b=?)) |
| 14924 | ORDER BY id DESC LIMIT 1 |
| 14925 | """, (me, peer, peer, me)).fetchone() |
| 14926 | if row: |
| 14927 | call_id = row["id"] |
| 14928 | else: |
| 14929 | cur = conn.cursor() |
| 14930 | cur.execute("INSERT INTO dm_calls(a,b,status,created_at) VALUES(?,?, 'active', ?)", (me, peer, now_z())) |
| 14931 | call_id = cur.lastrowid |
| 14932 | conn.commit() |
| 14933 | conn.close() |
| 14934 | return jsonify({"ok": True, "call_id": call_id}) |
| 14935 | |
| 14936 | @app.route("/api/call/peek/<peer>") |
| 14937 | @login_required |
| 14938 | def api_call_peek(peer: str): |
| 14939 | """If there is an active call between me and peer, return call_id (used to start polling).""" |
| 14940 | if not ENABLE_CALLS: |
| 14941 | return jsonify({"ok": False, "error": "Calls disabled"}), 404 |
| 14942 | me = current_user() |
| 14943 | peer = peer.strip() |
| 14944 | conn = db_connect() |
nothing calls this directly
no test coverage detected