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

fix: Get random profile pictures from Unsplash #3081

Merged
merged 2 commits into from Nov 3, 2020
Merged

Conversation

@makingthematrix
Copy link
Contributor

@makingthematrix makingthematrix commented Nov 3, 2020

fixes https://wearezeta.atlassian.net/browse/AN-7047

I'm not exactly sure how long this functionality was broken but it looks like it was for a long time. The previous code
tried to treat an Unsplash URL as if it was a regular asset that was supposed to be downloaded through our backend.
The backend failed because it didn't understand the request.I rewrote AccountManager.addUnsplashPicture() and added
methods to AssetService and AssetClient which download the picture from Unsplash. Then the picture is set as
the profile one and sent to the backend exactly as if it was a regular profile picture.

I also added a button in Dev Settings to test it. From now on it can be used if we want to test any change in code connected to profile pictures.

APK

Download build #2926
Download build #2927

fixes https://wearezeta.atlassian.net/browse/AN-7047

I'm not exactly sure how long this functionality was broken but it looks like it was for a long time. The previous code
tried to treat an Unsplash URL as if it was a regular asset that was supposed to be downloaded through our backend.
The backend failed because it didn't understand the request.I rewrote `AccountManager.addUnsplashPicture()` and added
methods to `AssetService` and `AssetClient` which download the picture from Unsplash. Then the picture is set as
the profile one and sent to the backend exactly as if it was a regular profile picture.

I also added a button in Dev Settings to test it. From now on it can be used if we want to test any change in code connected
to profile pictures.
@@ -39,7 +39,7 @@ class AndroidUriHelper(context: Context) extends UriHelper with DerivedLogTag {
private def cursor(uri: URI): Managed[Cursor] =
Managed.create(
context.getContentResolver.query(androidUri(uri), null, null, null, null)
)(_.close())
) { c => Option(c).foreach(_.close()) }

This comment has been minimized.

@makingthematrix

makingthematrix Nov 3, 2020
Author Contributor

A fix for a potential bug: the cursor can be null and when close() is called on it, it can fail with NullPointerException.

@mejdoo
mejdoo approved these changes Nov 3, 2020
@@ -142,6 +150,7 @@ object AssetClient {
implicit val DefaultExpiryTime: Expiration = 1.hour

val AssetsV3Path = "/assets/v3"
val UnsplashUrl: URL = new URL("https://source.unsplash.com/800x800/?landscape")

This comment has been minimized.

@mejdoo

mejdoo Nov 3, 2020
Contributor

Define "https://source.unsplash.com/800x800/?landscape" as constant

Copy link
Member

@android10 android10 left a comment

👍

@makingthematrix makingthematrix merged commit 07a0a30 into develop Nov 3, 2020
2 checks passed
2 checks passed
default Build finished.
Details
license/cla Contributor License Agreement is signed.
Details
@makingthematrix makingthematrix deleted the unsplash_pic branch Nov 3, 2020
mejdoo added a commit that referenced this pull request Nov 4, 2020
* fix: Get random profile pictures from Unsplash

fixes https://wearezeta.atlassian.net/browse/AN-7047

I'm not exactly sure how long this functionality was broken but it looks like it was for a long time. The previous code
tried to treat an Unsplash URL as if it was a regular asset that was supposed to be downloaded through our backend.
The backend failed because it didn't understand the request.I rewrote `AccountManager.addUnsplashPicture()` and added methods to `AssetService` and `AssetClient` which download the picture from Unsplash. Then the picture is set as the profile one and sent to the backend exactly as if it was a regular profile picture.

I also added a button in Dev Settings to test it. From now on it can be used if we want to test any change in code connected to profile pictures.

* changes requested in the review
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants
You can’t perform that action at this time.