Fix for #5808: Update the cached Place Items on the successful association of Wiki Item (#5864)

* (fixes #5855) fetch item label in nearby based on user configured language.

* implement a method to delete Place entity from database

* clear the cache for a item when a wikiItem is updated.

* fix style issue

* Update placesRepository on successful WikiItemEdit

* Revert the delete operations added to the PlaceDAO

* Set name of the place to avoid race condition with NearbyParentFragment. Update Success Notification to show only after the pin has been updated.

* Clean-up

---------

Co-authored-by: Nicolas Raoul <nicolas.raoul@gmail.com>
This commit is contained in:
Christo Joby Antony 2024-10-20 00:20:35 +11:00 committed by GitHub
parent c77e5abba7
commit 63f1ed8a2d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 17 additions and 3 deletions

View file

@ -4,7 +4,6 @@ import androidx.room.Dao;
import androidx.room.Insert;
import androidx.room.OnConflictStrategy;
import androidx.room.Query;
import fr.free.nrw.commons.location.LatLng;
import io.reactivex.Completable;
/**

View file

@ -1,6 +1,5 @@
package fr.free.nrw.commons.nearby;
import fr.free.nrw.commons.location.LatLng;
import io.reactivex.Completable;
import javax.inject.Inject;

View file

@ -17,6 +17,7 @@ import androidx.work.Data
import androidx.work.ForegroundInfo
import androidx.work.WorkerParameters
import dagger.android.ContributesAndroidInjector
import fr.free.nrw.commons.BuildConfig.HOME_URL
import fr.free.nrw.commons.CommonsApplication
import fr.free.nrw.commons.Media
import fr.free.nrw.commons.R
@ -30,6 +31,7 @@ import fr.free.nrw.commons.customselector.database.UploadedStatus
import fr.free.nrw.commons.customselector.database.UploadedStatusDao
import fr.free.nrw.commons.di.ApplicationlessInjection
import fr.free.nrw.commons.media.MediaClient
import fr.free.nrw.commons.nearby.PlacesRepository
import fr.free.nrw.commons.theme.BaseActivity
import fr.free.nrw.commons.upload.FileUtilsWrapper
import fr.free.nrw.commons.upload.StashUploadResult
@ -38,6 +40,7 @@ import fr.free.nrw.commons.upload.UploadClient
import fr.free.nrw.commons.upload.UploadProgressActivity
import fr.free.nrw.commons.upload.UploadResult
import fr.free.nrw.commons.wikidata.WikidataEditService
import io.reactivex.schedulers.Schedulers
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.MainScope
import kotlinx.coroutines.launch
@ -74,6 +77,9 @@ class UploadWorker(
@Inject
lateinit var fileUtilsWrapper: FileUtilsWrapper
@Inject
lateinit var placesRepository: PlacesRepository
private val processingUploadsNotificationTag = BuildConfig.APPLICATION_ID + " : upload_tag"
private val processingUploadsNotificationId = 101
@ -379,7 +385,7 @@ class UploadWorker(
saveCompletedContribution(contribution, uploadResult)
} else {
Timber.d(
"WikiDataEdit not required, making wikidata edit",
"WikiDataEdit required, making wikidata edit",
)
makeWikiDataEdit(uploadResult, contribution)
}
@ -471,6 +477,16 @@ class UploadWorker(
contribution.media.captions,
)
if (null != revisionID) {
withContext(Dispatchers.IO) {
val place = placesRepository.fetchPlace(wikiDataPlace.id);
place.name = wikiDataPlace.name;
place.pic = HOME_URL + uploadResult.createCanonicalFileName()
placesRepository
.save(place)
.subscribeOn(Schedulers.io())
.blockingAwait()
Timber.d("Updated WikiItem place ${place.name} with image ${place.pic}")
}
showSuccessNotification(contribution)
}
} catch (exception: Exception) {