Add highlight positional info to iOS highlights

This commit is contained in:
Jackson Harper
2023-02-02 15:13:51 +08:00
parent f4d2726db7
commit 08405dbcc2
8 changed files with 38 additions and 5 deletions

View File

@ -29,7 +29,10 @@ final class PDFViewerViewModel: ObservableObject {
highlightID: highlightID,
quote: quote,
patch: patch,
articleId: pdfItem.itemID
articleId: pdfItem.itemID,
// TODO:
positionPercent: nil,
positionAnchorIndex: nil
)
}
@ -48,6 +51,9 @@ final class PDFViewerViewModel: ObservableObject {
quote: quote,
patch: patch,
articleId: pdfItem.itemID,
// TODO:
positionPercent: nil,
positionAnchorIndex: nil,
overlapHighlightIdList: overlapHighlightIdList
)
}

View File

@ -83,6 +83,8 @@ struct SafariWebLink: Identifiable {
quote: messageBody["quote"] as? String ?? "",
patch: messageBody["patch"] as? String ?? "",
articleId: messageBody["articleId"] as? String ?? "",
positionPercent: messageBody["highlightPositionPercent"] as? Double,
positionAnchorIndex: messageBody["highlightPositionAnchorIndex"] as? Int,
annotation: messageBody["annotation"] as? String ?? ""
)
@ -113,7 +115,9 @@ struct SafariWebLink: Identifiable {
let quote = messageBody["quote"] as? String,
let patch = messageBody["patch"] as? String,
let articleId = messageBody["articleId"] as? String,
let overlapHighlightIdList = messageBody["overlapHighlightIdList"] as? [String]
let overlapHighlightIdList = messageBody["overlapHighlightIdList"] as? [String],
let positionPercent = messageBody["highlightPositionPercent"] as? Double,
let positionAnchorIndex = messageBody["highlightPositionAnchorIndex"] as? Int
else {
replyHandler([], "createHighlight: Error encoding response")
return
@ -125,6 +129,8 @@ struct SafariWebLink: Identifiable {
quote: quote,
patch: patch,
articleId: articleId,
positionPercent: positionPercent,
positionAnchorIndex: positionAnchorIndex,
overlapHighlightIdList: overlapHighlightIdList
)

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="21512" systemVersion="21G115" minimumToolsVersion="Automatic" sourceLanguage="Swift" userDefinedModelVersionIdentifier="">
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="21513" systemVersion="21G115" minimumToolsVersion="Automatic" sourceLanguage="Swift" userDefinedModelVersionIdentifier="">
<entity name="Highlight" representedClassName="Highlight" syncable="YES" codeGenerationType="class">
<attribute name="annotation" optional="YES" attributeType="String"/>
<attribute name="createdAt" optional="YES" attributeType="Date" usesScalarValueType="NO"/>
@ -7,6 +7,8 @@
<attribute name="id" attributeType="String"/>
<attribute name="markedForDeletion" attributeType="Boolean" defaultValueString="NO" usesScalarValueType="YES"/>
<attribute name="patch" attributeType="String"/>
<attribute name="positionAnchorIndex" optional="YES" attributeType="Integer 64" defaultValueString="0" usesScalarValueType="YES"/>
<attribute name="positionPercent" optional="YES" attributeType="Double" defaultValueString="0.0" usesScalarValueType="YES"/>
<attribute name="prefix" optional="YES" attributeType="String"/>
<attribute name="quote" attributeType="String"/>
<attribute name="serverSyncStatus" attributeType="Integer 64" defaultValueString="0" usesScalarValueType="YES"/>

View File

@ -10,6 +10,8 @@ extension DataService {
quote: String,
patch: String,
articleId: String,
positionPercent: Double?,
positionAnchorIndex: Int?,
annotation: String? = nil
) -> [String: Any]? {
let internalHighlight = InternalHighlight(
@ -23,6 +25,8 @@ extension DataService {
updatedAt: nil,
createdByMe: true,
createdBy: nil,
positionPercent: positionPercent,
positionAnchorIndex: positionAnchorIndex,
labels: []
)
@ -54,7 +58,8 @@ extension DataService {
input: InputObjects.CreateHighlightInput(
annotation: OptionalArgument(highlight.annotation),
articleId: articleId,
id: highlight.id,
highlightPositionAnchorIndex: OptionalArgument(highlight.positionAnchorIndex),
highlightPositionPercent: OptionalArgument(highlight.positionPercent), id: highlight.id,
patch: highlight.patch,
quote: highlight.quote,
shortId: highlight.shortId

View File

@ -11,6 +11,8 @@ extension DataService {
quote: String,
patch: String,
articleId: String,
positionPercent: Double?,
positionAnchorIndex: Int?,
overlapHighlightIdList: [String]
) -> [String: Any]? {
let internalHighlight = InternalHighlight(
@ -25,6 +27,8 @@ extension DataService {
updatedAt: nil,
createdByMe: true,
createdBy: nil,
positionPercent: positionPercent,
positionAnchorIndex: positionAnchorIndex,
labels: []
)

View File

@ -24,6 +24,8 @@ let highlightSelection = Selection.Highlight {
updatedAt: try $0.updatedAt().value,
createdByMe: try $0.createdByMe(),
createdBy: try $0.user(selection: userProfileSelection),
positionPercent: try $0.highlightPositionPercent(),
positionAnchorIndex: try $0.highlightPositionAnchorIndex(),
labels: try $0.labels(selection: highlightLabelSelection.list.nullable) ?? []
)
}

View File

@ -14,6 +14,8 @@ struct InternalHighlight: Encodable {
let updatedAt: Date?
let createdByMe: Bool
let createdBy: InternalUserProfile?
let positionPercent: Double?
let positionAnchorIndex: Int?
var labels: [InternalLinkedItemLabel]
func asManagedObject(context: NSManagedObjectContext) -> Highlight {
@ -35,6 +37,10 @@ struct InternalHighlight: Encodable {
highlight.createdAt = createdAt
highlight.updatedAt = updatedAt
highlight.createdByMe = createdByMe
highlight.positionPercent = positionPercent ?? -1.0
if let positionAnchorIndex = positionAnchorIndex {
highlight.positionAnchorIndex = Int64(positionAnchorIndex)
}
if let createdBy = createdBy {
highlight.createdBy = createdBy.asManagedObject(inContext: context)
@ -64,6 +70,8 @@ struct InternalHighlight: Encodable {
updatedAt: highlight.updatedAt,
createdByMe: highlight.createdByMe,
createdBy: InternalUserProfile.makeSingle(highlight.createdBy),
positionPercent: highlight.positionPercent,
positionAnchorIndex: Int(highlight.positionAnchorIndex),
labels: InternalLinkedItemLabel.make(highlight.labels)
)
}

File diff suppressed because one or more lines are too long