diff --git a/Containers/nextcloud/notify-all.sh b/Containers/nextcloud/notify-all.sh index 5f32bb47..00b3ce9b 100644 --- a/Containers/nextcloud/notify-all.sh +++ b/Containers/nextcloud/notify-all.sh @@ -13,6 +13,10 @@ fi SUBJECT="$1" MESSAGE="$2" +# The object-id is limited to 64 characters, so hash the subject to get a +# stable identifier of fixed length that is unique per subject. +OBJECT_ID="$(printf '%s' "$SUBJECT" | sha256sum | cut -c1-64)" + if [ "$("${COMMAND[@]}" config:app:get notifications enabled)" = "no" ]; then echo "Cannot send notification as notification app is not enabled." exit 1 @@ -24,7 +28,7 @@ mapfile -t NC_USERS <<< "$NC_USERS" for user in "${NC_USERS[@]}" do echo "Posting '$SUBJECT' to: $user" - "${COMMAND[@]}" notification:generate "$user" "$NC_DOMAIN: $SUBJECT" -l "$MESSAGE" --object-type='update' --object-id="$SUBJECT" + "${COMMAND[@]}" notification:generate "$user" "$NC_DOMAIN: $SUBJECT" -l "$MESSAGE" --object-type='update' --object-id="$OBJECT_ID" done echo "Done!" diff --git a/Containers/nextcloud/notify.sh b/Containers/nextcloud/notify.sh index d540865e..c94ed2ae 100644 --- a/Containers/nextcloud/notify.sh +++ b/Containers/nextcloud/notify.sh @@ -13,6 +13,10 @@ fi SUBJECT="$1" MESSAGE="$2" +# The object-id is limited to 64 characters, so hash the subject to get a +# stable identifier of fixed length that is unique per subject. +OBJECT_ID="$(printf '%s' "$SUBJECT" | sha256sum | cut -c1-64)" + if [ "$("${COMMAND[@]}" config:app:get notifications enabled)" = "no" ]; then echo "Cannot send notification as notification app is not enabled." exit 1 @@ -32,7 +36,7 @@ done for admin in "${NC_ADMIN_USER[@]}" do echo "Posting '$SUBJECT' to: $admin" - "${COMMAND[@]}" notification:generate "$admin" "$NC_DOMAIN: $SUBJECT" -l "$MESSAGE" --object-type='update' --object-id="$SUBJECT" + "${COMMAND[@]}" notification:generate "$admin" "$NC_DOMAIN: $SUBJECT" -l "$MESSAGE" --object-type='update' --object-id="$OBJECT_ID" done echo "Done!"