← All repositories

crossmate

A collaborative crossword app for iPhone and iPad

git clone https://code.inqk.net/crossmate.git


commit 688f4c0b03dce53a7150fef51f1ee994cd7f15d6
parent 769d18e27ef8ee1a2afd0573720b8febc5ed0b14
Author: Michael Camilleri <[email protected]>
Date:   Mon, 15 Jun 2026 08:43:07 +0900

Add logging to notification rewriting

Diffstat

MNotificationService/NotificationService.swift | 49++++++++++++++++++++++++++++++++++++++++---------

1 file changed, 40 insertions(+), 9 deletions(-)

diff --git a/NotificationService/NotificationService.swift b/NotificationService/NotificationService.swift

@@ -50,16 +50,47 @@ final class NotificationService: UNNotificationServiceExtension {
         // nickname) into the App Group, and `fromAuthorID` identifies the
         // sender. No match (stale mirror, renamed sender) shows the original
         // body — never broken text.
-        if let fromAuthorID = userInfo["fromAuthorID"] as? String,
-           !bestAttemptContent.body.isEmpty,
-           let entry = NicknameDirectory.entry(for: fromAuthorID),
-           let displayName = entry.displayName {
-            bestAttemptContent.body = NicknameDirectory.rewritten(
-                bestAttemptContent.body,
-                replacing: displayName,
-                with: entry.nickname
-            )
+        // Record *why* the rewrite did or didn't happen as a diagnostics
+        // receipt. The substitution is a silent no-op in several distinct cases
+        // (no sender identity, no nickname for this friend, the friend's name
+        // not yet synced, or a stored name that doesn't match the embedded one
+        // — e.g. a stale rename or a whitespace/Unicode mismatch). Without this
+        // line they're indistinguishable after the fact; with it, the next
+        // occurrence names the cause and surfaces the stored name to compare
+        // against the visible body.
+        let fromAuthorID = (userInfo["fromAuthorID"] as? String)
+            .flatMap { $0.isEmpty ? nil : $0 }
+        let rewriteOutcome: String
+        if bestAttemptContent.body.isEmpty {
+            rewriteOutcome = "skipped=empty-body"
+        } else if let fromAuthorID {
+            let fromPrefix = String(fromAuthorID.prefix(8))
+            if let entry = NicknameDirectory.entry(for: fromAuthorID) {
+                if let displayName = entry.displayName {
+                    let rewritten = NicknameDirectory.rewritten(
+                        bestAttemptContent.body,
+                        replacing: displayName,
+                        with: entry.nickname
+                    )
+                    if rewritten == bestAttemptContent.body {
+                        rewriteOutcome = "skipped=no-match from=\(fromPrefix) stored=\"\(displayName)\""
+                    } else {
+                        bestAttemptContent.body = rewritten
+                        rewriteOutcome = "applied from=\(fromPrefix) stored=\"\(displayName)\""
+                    }
+                } else {
+                    rewriteOutcome = "skipped=nil-stored-name from=\(fromPrefix)"
+                }
+            } else {
+                rewriteOutcome = "skipped=no-entry from=\(fromPrefix)"
+            }
+        } else {
+            rewriteOutcome = "skipped=no-from-author"
         }
+        VisibleNotificationReceiptLog.record(
+            body: rewriteOutcome,
+            source: "nickname-rewrite"
+        )
 
         VisibleNotificationReceiptLog.record(
             body: bestAttemptContent.body,