New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixes #4370 - History metadata enums and struct access #4371
Changes from 1 commit
3186c62
2595b0c
688c8a0
acf1bc3
7094604
59f9762
9c1dd9d
8737c0c
5df754d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,15 @@ import Foundation | |
public enum DocumentType: Int32 { | ||
case regular = 0 | ||
case media = 1 | ||
case unknown = -1 | ||
|
||
public init(rawValue: Int32) { | ||
switch rawValue { | ||
case 0: self = .regular | ||
case 1: self = .media | ||
default: self = .unknown | ||
} | ||
} | ||
} | ||
|
||
/** | ||
|
@@ -19,6 +28,12 @@ public struct HistoryMetadataKey { | |
public let url: String | ||
public let searchTerm: String? | ||
public let referrerUrl: String? | ||
|
||
public init(url: String, searchTerm: String?, referrerUrl: String?) { | ||
self.url = url | ||
self.searchTerm = searchTerm | ||
self.referrerUrl = referrerUrl | ||
} | ||
} | ||
|
||
/** | ||
|
@@ -28,6 +43,16 @@ public enum HistoryMetadataObservation { | |
case titleObservation(String) | ||
case viewTimeObservation(Int32) | ||
case documentTypeObservation(DocumentType) | ||
case unknown | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I really don't need unknown but removing that causes swift errors for our initializers so I added additional case for default as unknonw. Happy to change / rename it as needed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about function overloading? Separate init functions for each data type? Then you can remove unknown, i think. |
||
|
||
public init(value: Any) { | ||
switch value { | ||
case let title as String: self = .titleObservation(title) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What if we have string observations that aren't about There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The major issue is that we need some sort of initializer for using it on Firefox iOS side otherwise structs and enums are inaccessible. This is just something how swift hasn't gotten to or a limitation I would say as all this is extra work 😓 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh wow, so that's actually a thing! https://docs.swift.org/swift-book/LanguageGuide/AccessControl.html#//apple_ref/doc/uid/TP40014097-CH41-ID3 (memberwise init section). That's pretty annoying :) |
||
case let time as Int32: self = .viewTimeObservation(time) | ||
case let document as DocumentType: self = .documentTypeObservation(document) | ||
default: self = .unknown | ||
} | ||
} | ||
} | ||
|
||
/** | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -887,7 +887,7 @@ public class PlacesWriteConnection: PlacesReadConnection { | |
|
||
// MARK: History Metadata | ||
|
||
open func noteHistoryMetadataObservation( | ||
open func noteHistoryMetadataObservation ( | ||
key: HistoryMetadataKey, | ||
observation: HistoryMetadataObservation | ||
) throws { | ||
|
@@ -910,6 +910,8 @@ public class PlacesWriteConnection: PlacesReadConnection { | |
msg.documentType = documentType.rawValue | ||
case let .titleObservation(title): | ||
msg.title = title | ||
case .unknown: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like a bug that may be easy to miss - e.g. somehow you end up Partially why I don't like being able to represent invalid states! E.g. if |
||
break | ||
} | ||
|
||
let data = try! msg.serializedData() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So what's your use case for this? Can't you just do
DocumentType.media
when creating instances? I suppose this may be helpful when deserializing, but I don't think you'd need to persist aDocumentType
yourself manually.Also, these numbers aren't entirely random - they need to align w/ what other platforms are using. And currently we don't have a
-1
present elsewhere. So unless you absolutely need this change, I'd remove at least theunknown
case.