Fix empty username (#6209)

* revert changes from #5860

Signed-off-by: parneet-guraya <gurayaparneet@gmail.com>

* read author prop instead

Signed-off-by: parneet-guraya <gurayaparneet@gmail.com>

* Use user prop if author is empty or null

Signed-off-by: parneet-guraya <gurayaparneet@gmail.com>

* fix test

Signed-off-by: parneet-guraya <gurayaparneet@gmail.com>

---------

Signed-off-by: parneet-guraya <gurayaparneet@gmail.com>
This commit is contained in:
Parneet Singh 2025-03-08 18:56:41 +05:30 committed by GitHub
parent 32d485cc51
commit 972bf785f1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 29 additions and 26 deletions

View file

@ -125,6 +125,19 @@ class Media constructor(
categoriesHiddenStatus = categoriesHiddenStatus
)
/**
* Returns Author if it's not null or empty, otherwise
* returns user
* @return Author or User
*/
fun getAuthorOrUser(): String? {
return if (!author.isNullOrEmpty()) {
author
} else{
user
}
}
/**
* Gets media display title
* @return Media title

View file

@ -98,14 +98,9 @@ class GridViewAdapter(
*/
@SuppressLint("StringFormatInvalid")
private fun setUploaderView(item: Media, uploader: TextView) {
if (!item.author.isNullOrEmpty()) {
uploader.visibility = View.VISIBLE
uploader.text = context.getString(
R.string.image_uploaded_by,
item.user
item.getAuthorOrUser()
)
} else {
uploader.visibility = View.GONE
}
}
}

View file

@ -54,7 +54,7 @@ an upload might take a dozen seconds. */
this.contribution = contribution
this.position = position
binding.contributionTitle.text = contribution.media.mostRelevantCaption
binding.authorView.text = contribution.media.author
binding.authorView.text = contribution.media.getAuthorOrUser()
//Removes flicker of loading image.
binding.contributionImage.hierarchy.fadeDuration = 0

View file

@ -111,7 +111,7 @@ class DeleteHelper @Inject constructor(
val userPageString = "\n{{subst:idw|${media.filename}}} ~~~~"
val creator = media.author
val creator = media.getAuthorOrUser()
?: throw RuntimeException("Failed to nominate for deletion")
return pageEditClient.prependEdit(

View file

@ -39,7 +39,7 @@ class MediaConverter
metadata.licenseShortName(),
metadata.prefixedLicenseUrl,
getAuthor(metadata),
getAuthor(metadata),
imageInfo.getUser(),
MediaDataExtractorUtil.extractCategoriesFromList(metadata.categories()),
metadata.latLng,
entity.labels().mapValues { it.value.value() },

View file

@ -52,12 +52,7 @@ class SearchImagesViewHolder(
binding.categoryImageView.setOnClickListener { onImageClicked(item.second) }
binding.categoryImageTitle.text = media.mostRelevantCaption
binding.categoryImageView.setImageURI(media.thumbUrl)
if (media.author?.isNotEmpty() == true) {
binding.categoryImageAuthor.visibility = View.VISIBLE
binding.categoryImageAuthor.text =
containerView.context.getString(R.string.image_uploaded_by, media.user)
} else {
binding.categoryImageAuthor.visibility = View.GONE
}
containerView.context.getString(R.string.image_uploaded_by, media.getAuthorOrUser())
}
}

View file

@ -328,7 +328,7 @@ public class MediaDetailPagerFragment extends CommonsDaggerSupportFragment imple
.append("\n\n");
builder.append("User that you want to report: ")
.append(media.getAuthor())
.append(media.getUser())
.append("\n\n");
if (sessionManager.getUserName() != null) {
@ -423,7 +423,7 @@ public class MediaDetailPagerFragment extends CommonsDaggerSupportFragment imple
// Initialize bookmark object
bookmark = new Bookmark(
m.getFilename(),
m.getAuthor(),
m.getAuthorOrUser(),
BookmarkPicturesContentProvider.uriForName(m.getFilename())
);
updateBookmarkState(menu.findItem(R.id.menu_bookmark_current_image));

View file

@ -96,7 +96,7 @@ class DeleteHelperTest {
).thenReturn("Media successfully deleted: Test Media Title")
val creatorName = "Creator"
whenever(media.author).thenReturn("$creatorName")
whenever(media.getAuthorOrUser()).thenReturn("$creatorName")
whenever(media.filename).thenReturn("Test file.jpg")
val makeDeletion = deleteHelper.makeDeletion(
context,
@ -133,7 +133,7 @@ class DeleteHelperTest {
whenever(media.displayTitle).thenReturn("Test file")
whenever(media.filename).thenReturn("Test file.jpg")
whenever(media.author).thenReturn("Creator (page does not exist)")
whenever(media.getAuthorOrUser()).thenReturn("Creator (page does not exist)")
deleteHelper.makeDeletion(context, media, "Test reason")?.blockingGet()
}
@ -148,7 +148,7 @@ class DeleteHelperTest {
.thenReturn(Observable.just(false))
whenever(media.displayTitle).thenReturn("Test file")
whenever(media.filename).thenReturn("Test file.jpg")
whenever(media.author).thenReturn("Creator (page does not exist)")
whenever(media.getAuthorOrUser()).thenReturn("Creator (page does not exist)")
deleteHelper.makeDeletion(context, media, "Test reason")?.blockingGet()
}
@ -163,7 +163,7 @@ class DeleteHelperTest {
.thenReturn(Observable.just(true))
whenever(media.displayTitle).thenReturn("Test file")
whenever(media.filename).thenReturn("Test file.jpg")
whenever(media.author).thenReturn("Creator (page does not exist)")
whenever(media.getAuthorOrUser()).thenReturn("Creator (page does not exist)")
deleteHelper.makeDeletion(context, media, "Test reason")?.blockingGet()
}
@ -221,7 +221,7 @@ class DeleteHelperTest {
whenever(media.displayTitle).thenReturn("Test file")
whenever(media.filename).thenReturn("Test file.jpg")
whenever(media.author).thenReturn(null)
whenever(media.getAuthorOrUser()).thenReturn(null)
deleteHelper.makeDeletion(context, media, "Test reason")?.blockingGet()
}