Skip to content

Commit

Permalink
Fix transformed annotation user (#1045)
Browse files Browse the repository at this point in the history
* Select username for annotation user if display name is empty

* Limit PDFDatabaseAnnotation logging

* Fix comment typo
  • Loading branch information
mvasilak authored Dec 14, 2024
1 parent 6f8e87d commit fa9a16c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ struct PDFDatabaseAnnotation {
DDLogWarn("PDFDatabaseAnnotation: isAuthor for currentUserId: \(currentUserId) encountered nil user")
return false
}
DDLogInfo("PDFDatabaseAnnotation: isAuthor for currentUserId: \(currentUserId) compared to \(user.identifier)")
return user.identifier == currentUserId
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1369,7 +1369,9 @@ final class PDFReaderActionHandler: ViewModelActionHandler, BackgroundDbProcessi
let finalAnnotations = keptAsIs + toAdd
for annotation in finalAnnotations {
if annotation.key == nil {
annotation.user = viewModel.state.displayName
// We use the displayName, but if this is empty we use the username, which is what would be presented anyway.
// Since a username cannot be empty, we guarantee an non-empty annotation.user field.
annotation.user = viewModel.state.displayName.isEmpty ? viewModel.state.username : viewModel.state.displayName
annotation.customData = [AnnotationsConfig.keyKey: KeyGenerator.newKey]
}
}
Expand All @@ -1393,6 +1395,7 @@ final class PDFReaderActionHandler: ViewModelActionHandler, BackgroundDbProcessi
document.remove(annotations: needRemove, options: [.suppressNotifications: true])
}
// Transformed annotations need to be added, before they are converted, otherwise their document property is nil.
// Caution, if an annotation is added this way, with any empty string user, its user field will be converted to nil!
document.add(annotations: finalAnnotations, options: [.suppressNotifications: true])
}
}
Expand Down

0 comments on commit fa9a16c

Please sign in to comment.