Skip to content
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

Image recommendations - Add feedback API calls #4796

Merged
merged 8 commits into from
Mar 29, 2024
Merged

Image recommendations - Add feedback API calls #4796

merged 8 commits into from
Mar 29, 2024

Conversation

tonisevener
Copy link
Collaborator

@tonisevener tonisevener commented Mar 27, 2024

Phabricator:
https://phabricator.wikimedia.org/T360574

Notes

This PR adds the ability to send feedback API calls when approving or rejecting an image suggestion. This is the first WKData API call against the MediaWiki Rest API. I wasn't able to lean on some of the existing calls in MediaWikiFetcher, so I had to extend it a bit to support PUT and these new url styles.

There's not really an easy way to test this without the connections to the survey and edit summary views, so we can skip testing until that connection is made. I tested these calls by updating this method in ExploreViewController, tapping Yes to the toolbar button and watching the http traffic:

    func imageRecommendationsUserDidTapInsertImage(with imageData: WKImageRecommendationsViewModel.WKImageRecommendationData) {

//        let image = UIImage() // TODO: fetch image properly
//        if let imageURL = URL(string: imageData.descriptionURL),
//           let thumbURL = URL(string: imageData.thumbUrl) {
//            let searchResult = InsertMediaSearchResult(fileTitle: imageData.filename, displayTitle: imageData.filename, thumbnailURL: thumbURL, imageDescription: imageData.description,  filePageURL: imageURL)
//            let insertMediaViewController = InsertMediaSettingsViewController(image: image, searchResult: searchResult, fromImageRecommendations: true)
//            navigationController?.pushViewController(insertMediaViewController, animated: true)
//        }

// TEMP CODE
        let language = WKLanguage(languageCode: "en", languageVariantCode: nil)
        let dataController = WKImageRecommendationsDataController()
        dataController.sendFeedback(project: .wikipedia(language), pageTitle: imageData.pageTitle, editRevId: nil, fileName: imageData.filename, accepted: true, caption: nil) { result in
            switch result {
            case .success(let dict):
                print(dict)
            case .failure(let error):
                print(error)
            }
        }
    }

@tonisevener tonisevener requested review from a team and staykids and removed request for a team March 27, 2024 20:50
@staykids staykids self-assigned this Mar 28, 2024
Copy link
Contributor

@staykids staykids left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice – one note below.

var tokenizedParams = request.parameters ?? [:]
tokenizedParams["token"] = token.value

self?.performPut(url: url, parameters: tokenizedParams, completion: completion)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the event that self is nil here, this call could leave the completion block uncalled. Would it make sense to call the completion block with some kind of failure here in the case that self is nil in order to prevent the caller from waiting on a completion that never occurs?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@staykids Good catch - this is done!

@staykids staykids removed their assignment Mar 29, 2024
@staykids staykids merged commit 4db2f9e into main Mar 29, 2024
4 checks passed
@staykids staykids deleted the T360574 branch March 29, 2024 22:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants