You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

94 lines
3.3 KiB

6 years ago
  1. // Copyright (c) 2016-present, Facebook, Inc. All rights reserved.
  2. //
  3. // You are hereby granted a non-exclusive, worldwide, royalty-free license to use,
  4. // copy, modify, and distribute this software in source code or binary form for use
  5. // in connection with the web services and APIs provided by Facebook.
  6. //
  7. // As with any software that integrates with the Facebook platform, your use of
  8. // this software is subject to the Facebook Developer Principles and Policies
  9. // [http://developers.facebook.com/policy/]. This copyright notice shall be
  10. // included in all copies or substantial portions of the software.
  11. //
  12. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  14. // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  15. // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  16. // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  17. // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  18. import Foundation
  19. import FBSDKShareKit
  20. /**
  21. A model for photo content to be shared.
  22. */
  23. public struct PhotoShareContent: ContentProtocol {
  24. public typealias Result = PostSharingResult
  25. /// Photos to be shared.
  26. public var photos: [Photo]
  27. /**
  28. Create a `PhotoShareContent` with a list of of photos to share.
  29. - parameter photos: The list of photos to share.
  30. */
  31. public init(photos: [Photo] = []) {
  32. self.photos = photos
  33. }
  34. //--------------------------------------
  35. // MARK - ContentProtocol
  36. //--------------------------------------
  37. /**
  38. URL for the content being shared.
  39. This URL will be checked for all link meta tags for linking in platform specific ways.
  40. See documentation for [App Links](https://developers.facebook.com/docs/applinks/)
  41. */
  42. public var url: URL?
  43. /// Hashtag for the content being shared.
  44. public var hashtag: Hashtag?
  45. /**
  46. List of IDs for taggable people to tag with this content.
  47. See documentation for [Taggable Friends](https://developers.facebook.com/docs/graph-api/reference/user/taggable_friends)
  48. */
  49. public var taggedPeopleIds: [String]?
  50. /// The ID for a place to tag with this content.
  51. public var placeId: String?
  52. /// A value to be added to the referrer URL when a person follows a link from this shared content on feed.
  53. public var referer: String?
  54. }
  55. extension PhotoShareContent: Equatable {
  56. /**
  57. Compare two `PhotoShareContent`s for equality.
  58. - parameter lhs: The first `PhotoShareContent` to compare.
  59. - parameter rhs: The second `PhotoShareContent` to compare.
  60. - returns: Whether or not the content are equal.
  61. */
  62. public static func == (lhs: PhotoShareContent, rhs: PhotoShareContent) -> Bool {
  63. return lhs.sdkSharingContentRepresentation.isEqual(rhs.sdkSharingContentRepresentation)
  64. }
  65. }
  66. extension PhotoShareContent: SDKBridgedContent {
  67. var sdkSharingContentRepresentation: FBSDKSharingContent {
  68. let sdkPhotoContent = FBSDKSharePhotoContent()
  69. sdkPhotoContent.photos = photos.map { $0.sdkPhotoRepresentation }
  70. sdkPhotoContent.contentURL = url
  71. sdkPhotoContent.hashtag = hashtag?.sdkHashtagRepresentation
  72. sdkPhotoContent.peopleIDs = taggedPeopleIds
  73. sdkPhotoContent.placeID = placeId
  74. sdkPhotoContent.ref = referer
  75. return sdkPhotoContent
  76. }
  77. }