Skip to content

Fix empty username #6209

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

Merged
merged 4 commits into from
Mar 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions app/src/main/java/fr/free/nrw/commons/Media.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
} else {
uploader.visibility = View.GONE
}
uploader.text = context.getString(
R.string.image_uploaded_by,
item.getAuthorOrUser()
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
binding.categoryImageAuthor.text =
containerView.context.getString(R.string.image_uploaded_by, media.getAuthorOrUser())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ private String getTechInfo(final Media media, final String type) {
.append("\n\n");

builder.append("User that you want to report: ")
.append(media.getAuthor())
.append(media.getUser())
.append("\n\n");

if (sessionManager.getUserName() != null) {
Expand Down Expand Up @@ -423,7 +423,7 @@ public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
// 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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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()
}
Expand All @@ -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()
}
Expand All @@ -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()
}
Expand Down Expand Up @@ -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()
}
Expand Down