-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Tenor integration #13949
Tenor integration #13949
Changes from 91 commits
e857e35
4a33eb3
7bae58f
8ec416b
6b19638
30a06f9
37ca6ba
b0e7160
bb32ab4
aa199f2
5f50901
1e56339
f0fbfd1
f5dbe08
b46ccde
53fd5fa
ae01693
29a5a23
8dbadf5
0773f8d
8e47b28
579fa89
95c6f4f
b9c58d2
e2b30ea
5a243d2
c4b336c
eecacb8
fe9884b
d81e424
56b7b44
859f457
5d021d4
40bab0c
731dfa5
da261a0
1961c99
eb59a69
9c7f00c
97ec082
d230006
bd99c14
f55adae
0425612
dc81e1c
422f53c
f884b0b
1adbdab
2230ba5
a9249b8
b30652e
dc5bdf2
90e2260
38dd814
9fad122
e3c965f
82f7a7d
b063dc7
441db93
647d61a
6cd90d3
ea3af7f
7a92257
dfa77e4
12c5b9e
6ae0331
5fa137d
249c2da
6db76db
c65a385
9eeb0f3
7c701e7
964aae4
d052c5a
2b13e0f
f8671c8
df4a5de
6490dd6
1a1484d
3a0e107
30c286d
cc29595
61d1c39
a848a0e
1db8728
6a1b672
1deccc8
f0f11a5
7abe7db
69aecc1
6e31736
125be33
5258dec
2e90a13
1a96c43
ae4e567
1d9fdf6
65e3a9b
73494fd
1bcf08a
71573b7
e4139be
25c6d0a
a8aab30
d35ce72
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 |
---|---|---|
|
@@ -59,10 +59,16 @@ public struct MediaAnalyticsInfo { | |
self.selectionMethod = selectionMethod | ||
} | ||
|
||
func eventForMediaType(_ mediaType: MediaType) -> WPAnalyticsStat? { | ||
func eventForMediaType(_ mediaType: MediaType) -> WPAnalyticsEvent? { | ||
return origin.eventForMediaType(mediaType) | ||
} | ||
|
||
// Old tracking events via WPShared | ||
// Ref: https://iosp2.wordpress.com/2020/03/16/adding-tracks-forget-wordpress-shared/ | ||
func wpsharedEventForMediaType(_ mediaType: MediaType) -> WPAnalyticsStat? { | ||
return origin.wpsharedEventForMediaType(mediaType) | ||
} | ||
|
||
var retryEvent: WPAnalyticsStat? { | ||
switch origin { | ||
case .mediaLibrary: | ||
|
@@ -107,8 +113,28 @@ enum MediaUploadOrigin { | |
case mediaLibrary(MediaSource) | ||
case editor(MediaSource) | ||
|
||
func eventForMediaType(_ mediaType: MediaType) -> WPAnalyticsStat? { | ||
// All new media tracking events will be added into WPAnalyticsEvent | ||
// Ref: https://iosp2.wordpress.com/2020/03/16/adding-tracks-forget-wordpress-shared/ | ||
func eventForMediaType(_ mediaType: MediaType) -> WPAnalyticsEvent? { | ||
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'm not entirely sure why these definitions need to be split out from the existing definitions below? 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. Hey @frosty because the old tracking method uses |
||
switch (self, mediaType) { | ||
// Media Library | ||
case (.mediaLibrary(let source), .image) where source == .tenor: | ||
return .mediaLibraryAddedPhotoViaTenor | ||
|
||
// Editor | ||
case (.editor(let source), .image) where source == .tenor: | ||
return .editorAddedPhotoViaTenor | ||
|
||
default: | ||
return nil | ||
} | ||
} | ||
|
||
// This is for the previous events created within WordPressShared | ||
// Ref: https://iosp2.wordpress.com/2020/03/16/adding-tracks-forget-wordpress-shared/ | ||
func wpsharedEventForMediaType(_ mediaType: MediaType) -> WPAnalyticsStat? { | ||
switch (self, mediaType) { | ||
// Media Library | ||
case (.mediaLibrary(let source), .image) where source == .deviceLibrary: | ||
return .mediaLibraryAddedPhotoViaDeviceLibrary | ||
case (.mediaLibrary(let source), .image) where source == .giphy: | ||
|
@@ -125,6 +151,7 @@ enum MediaUploadOrigin { | |
return .mediaLibraryAddedVideoViaOtherApps | ||
case (.mediaLibrary(let source), .video) where source == .camera: | ||
return .mediaLibraryAddedVideoViaCamera | ||
// Editor | ||
case (.editor(let source), .image) where source == .giphy : | ||
return .editorAddedPhotoViaGiphy | ||
case (.editor(let source), .image) where source == .deviceLibrary: | ||
|
@@ -159,4 +186,5 @@ enum MediaSource { | |
case camera | ||
case giphy | ||
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. Note for a future PR: we should remove all the existing Giphy references 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. There is already a task for this #13803 ;-) 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. Great, thanks! |
||
case mediaEditor | ||
case tenor | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import Gutenberg | ||
|
||
class GutenbergTenorMediaPicker { | ||
private var tenor: TenorPicker? | ||
private var mediaPickerCallback: MediaPickerDidPickMediaCallback? | ||
private let mediaInserter: GutenbergMediaInserterHelper | ||
private unowned var gutenberg: Gutenberg | ||
private var multipleSelection = false | ||
|
||
init(gutenberg: Gutenberg, mediaInserter: GutenbergMediaInserterHelper) { | ||
self.mediaInserter = mediaInserter | ||
self.gutenberg = gutenberg | ||
} | ||
|
||
func presentPicker(origin: UIViewController, post: AbstractPost, multipleSelection: Bool, callback: @escaping MediaPickerDidPickMediaCallback) { | ||
let picker = TenorPicker() | ||
tenor = picker | ||
picker.allowMultipleSelection = true | ||
picker.delegate = self | ||
mediaPickerCallback = callback | ||
picker.presentPicker(origin: origin, blog: post.blog) | ||
self.multipleSelection = multipleSelection | ||
} | ||
} | ||
|
||
extension GutenbergTenorMediaPicker: TenorPickerDelegate { | ||
func tenorPicker(_ picker: TenorPicker, didFinishPicking assets: [TenorMedia]) { | ||
defer { | ||
mediaPickerCallback = nil | ||
tenor = nil | ||
} | ||
guard assets.isEmpty == false else { | ||
mediaPickerCallback?(nil) | ||
return | ||
} | ||
|
||
// For blocks that support multiple uploads this will upload all images. | ||
// If multiple uploads are not supported then it will seperate them out to Image Blocks. | ||
multipleSelection ? insertOnBlock(with: assets) : insertSingleImages(assets) | ||
} | ||
|
||
/// Adds the given image object to the requesting block and seperates multiple images to seperate image blocks | ||
/// - Parameter asset: Tenor Media object to add. | ||
func insertSingleImages(_ assets: [TenorMedia]) { | ||
// Append the first item via callback given by Gutenberg. | ||
if let firstItem = assets.first { | ||
insertOnBlock(with: [firstItem]) | ||
} | ||
// Append the rest of images via `.appendMedia` event. | ||
// Ideally we would send all picked images via the given callback, but that seems to not be possible yet. | ||
appendOnNewBlocks(assets: assets.dropFirst()) | ||
} | ||
|
||
/// Adds the given images to the requesting block | ||
/// - Parameter assets: Tenor Media objects to add. | ||
func insertOnBlock(with assets: [TenorMedia]) { | ||
guard let callback = mediaPickerCallback else { | ||
return assertionFailure("Image picked without callback") | ||
} | ||
|
||
let mediaInfo = assets.compactMap { (asset) -> MediaInfo? in | ||
guard let media = self.mediaInserter.insert(exportableAsset: asset, source: .tenor) else { | ||
return nil | ||
} | ||
let mediaUploadID = media.gutenbergUploadID | ||
return MediaInfo(id: mediaUploadID, url: asset.URL.absoluteString, type: media.mediaTypeString) | ||
} | ||
|
||
callback(mediaInfo) | ||
} | ||
|
||
/// Create a new image block for each of the image objects in the slice. | ||
/// - Parameter assets: Tenor Media objects to append. | ||
func appendOnNewBlocks(assets: ArraySlice<TenorMedia>) { | ||
assets.forEach { | ||
if let media = self.mediaInserter.insert(exportableAsset: $0, source: .tenor) { | ||
self.gutenberg.appendMedia(id: media.gutenbergUploadID, url: $0.URL, type: .image) | ||
} | ||
} | ||
} | ||
} |
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.
Probably shouldn't include a p2 reference here
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.
Two more of these below too
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.
Done thanks @frosty