diff --git a/delete_room.sh b/delete_room.sh new file mode 100755 index 0000000..0cf50ae --- /dev/null +++ b/delete_room.sh @@ -0,0 +1,33 @@ +#!/bin/bash +# This script deletes a given room + +if [ -z "$1" ]; then + echo "Usage: $0 " + echo "Environment variables MATRIX_BASE_URL and MATRIX_TOKEN must be set." + exit 1 +fi + +if [ -z "$MATRIX_BASE_URL" ] || [ -z "$MATRIX_TOKEN" ]; then + echo "Error: MATRIX_BASE_URL and MATRIX_TOKEN environment variables must be set." + exit 1 +fi + +ROOM_ID="$1" + +# Config +export BASE_URL="${MATRIX_BASE_URL}" +export TOKEN="${MATRIX_TOKEN}" + +echo "Deleting room $ROOM_ID from server entirely..." + +# Delete the room :D +curl -X DELETE "${BASE_URL}/_synapse/admin/v2/rooms/${ROOM_ID}" \ + -H "Authorization: Bearer ${TOKEN}" \ + -H "Content-Type: application/json" \ + -d '{ + "purge": true, + "force_purge": true, + "block": true + }' + +echo -e "\nDone." diff --git a/notification_purge.sh b/notification_purge.sh new file mode 100755 index 0000000..ec4a1bd --- /dev/null +++ b/notification_purge.sh @@ -0,0 +1,108 @@ +#!/bin/bash +# This script is meant to help deal with several issues with Continuwuity +# 1. Clears all pushers... as of now they do not clear when one signs absolutely +# 2. Sets all notifications to read + +# Config +if [ -z "$MATRIX_BASE_URL" ] || [ -z "$MATRIX_TOKEN" ]; then + echo "Error: MATRIX_BASE_URL and MATRIX_TOKEN environment variables must be set." + exit 1 +fi + +export BASE_URL="${MATRIX_BASE_URL}/_matrix/client/v3" +export TOKEN="${MATRIX_TOKEN}" + +echo "=== Removing dangling pushers ===" +# Fetch pushers +response=$(curl -s -X GET "${BASE_URL}/pushers" \ + -H "Authorization: Bearer ${TOKEN}" \ + -H "Content-Type: application/json") + +# Loop over pushers +if [ -n "$response" ] && echo "$response" | jq -e '.pushers' >/dev/null; then + echo "$response" | jq -c '.pushers[]' | while read -r pusher; do + app_id=$(echo "$pusher" | jq -r '.app_id') + pushkey=$(echo "$pusher" | jq -r '.pushkey') + + echo "Removing pusher: ${app_id}..." + + # Delete pusher + curl -s -X POST "${BASE_URL}/pushers/set" \ + -H "Authorization: Bearer ${TOKEN}" \ + -H "Content-Type: application/json" \ + -d "$(jq -n --arg id "$app_id" --arg key "$pushkey" \ + '{app_id: $id, pushkey: $key, kind: null}')" > /dev/null + + echo " Done." + done +else + echo "No pushers found or failed to fetch pushers." +fi + + +echo "" +echo "=== Clearing all notifications ===" +# Get all rooms +rooms_response=$(curl -s -X GET "${BASE_URL}/joined_rooms" \ + -H "Authorization: Bearer ${TOKEN}" \ + -H "Content-Type: application/json") + +if [ -n "$rooms_response" ] && echo "$rooms_response" | jq -e '.joined_rooms' >/dev/null; then + + export -f process_room || true + + process_room() { + room_id="$1" + ENCODED_ROOM_ID=$(echo -n "$room_id" | jq -sRr @uri) + + echo "Processing room: ${room_id}" + + CURRENT_RULE=$(curl -s -X GET "${BASE_URL}/pushrules/global/room/${ENCODED_ROOM_ID}" \ + -H "Authorization: Bearer ${TOKEN}") + CURRENT_ACTION=$(echo "$CURRENT_RULE" | jq -c '.actions' 2>/dev/null) + if [ -z "$CURRENT_ACTION" ] || [ "$CURRENT_ACTION" = "null" ]; then + CURRENT_ACTION="default (not explicitly set)" + fi + echo " [Before] Current setting: $CURRENT_ACTION" + + PUT_RESULT=$(curl -s -X PUT "${BASE_URL}/pushrules/global/room/${ENCODED_ROOM_ID}" \ + -H "Authorization: Bearer ${TOKEN}" \ + -H "Content-Type: application/json" \ + -d "{\"actions\": [\"dont_notify\"]}") + + ERRCODE=$(echo "$PUT_RESULT" | jq -r '.errcode // empty' 2>/dev/null) + if [ -n "$ERRCODE" ]; then + ERROR_MSG=$(echo "$PUT_RESULT" | jq -r '.error // "Unknown error"' 2>/dev/null) + echo " [Error] FAILED to set rule: $ERRCODE - $ERROR_MSG" + else + NEW_RULE=$(curl -s -X GET "${BASE_URL}/pushrules/global/room/${ENCODED_ROOM_ID}" \ + -H "Authorization: Bearer ${TOKEN}") + NEW_ACTION=$(echo "$NEW_RULE" | jq -c '.actions' 2>/dev/null) + echo " [After] New setting verified: $NEW_ACTION" + fi + + LATEST_EVENT=$(curl -s -X GET "${BASE_URL}/rooms/${ENCODED_ROOM_ID}/messages?dir=b&limit=1" \ + -H "Authorization: Bearer ${TOKEN}" | jq -r ".chunk[0].event_id // empty") + + if [ -n "$LATEST_EVENT" ]; then + curl -s -X POST "${BASE_URL}/rooms/${ENCODED_ROOM_ID}/read_markers" \ + -H "Authorization: Bearer ${TOKEN}" \ + -H "Content-Type: application/json" \ + -d "{\"m.fully_read\": \"${LATEST_EVENT}\", \"m.read\": \"${LATEST_EVENT}\"}" > /dev/null + + ENCODED_LATEST=$(echo -n "$LATEST_EVENT" | jq -sRr @uri) + curl -s -X POST "${BASE_URL}/rooms/${ENCODED_ROOM_ID}/receipt/m.read/${ENCODED_LATEST}" \ + -H "Authorization: Bearer ${TOKEN}" \ + -H "Content-Type: application/json" \ + -d "{}" > /dev/null + fi + } + export -f process_room + + echo "$rooms_response" | jq -r '.joined_rooms[]' | xargs -P 10 -I {} bash -c 'process_room "$@"' _ {} +else + echo "No joined rooms found or failed to fetch rooms." +fi + +echo "" +echo "Process finished."