MOBILE-4547 blog: Fix remove offline entries sync

main
Alfonso Salces 2024-09-06 14:01:46 +02:00
parent d7c3c37b21
commit 91588bb94c
5 changed files with 15 additions and 5 deletions

View File

@ -91,6 +91,7 @@
"addon.blog.associations": "blog",
"addon.blog.blog": "blog",
"addon.blog.blogentries": "blog",
"addon.blog.blogdeleteconfirm": "blog",
"addon.blog.entrybody": "blog",
"addon.blog.entrytitle": "blog",
"addon.blog.errorloadentries": "local_moodlemobileapp",

View File

@ -5,6 +5,7 @@
"associations": "Associations",
"blog": "Blog",
"blogentries": "Blog entries",
"blogdeleteconfirm": "Delete the blog entry '{{$a}}'?",
"entrybody": "Blog entry body",
"entrytitle": "Entry title",
"errorloadentries": "Error loading blog entries.",

View File

@ -417,6 +417,12 @@ export class AddonBlogIndexPage implements OnInit, OnDestroy {
* @param entryToRemove Entry.
*/
async deleteEntry(entryToRemove: AddonBlogOfflinePostFormatted | AddonBlogPostFormatted): Promise<void> {
try {
await CoreDomUtils.showDeleteConfirm('addon.blog.blogdeleteconfirm', { $a: entryToRemove.subject });
} catch {
return;
}
const loading = await CoreLoadings.show();
try {

View File

@ -95,10 +95,9 @@ import { AddonBlogOfflineEntryDBRecord } from './database/blog';
* @returns Syncronization result.
*/
async performEntriesSync(siteId: string): Promise<AddonBlogSyncResult> {
const result: AddonBlogSyncResult = { updated: false, warnings: [] };
const entriesToSync = await this.syncEntriesToRemove(siteId);
const { entries, result } = await this.syncEntriesToRemove(siteId);
for (const entry of entriesToSync.entries) {
for (const entry of entries) {
if (CoreSync.isBlocked(AddonBlogProvider.COMPONENT, entry.id ?? entry.created, siteId)) {
this.logger.debug('Cannot sync entry ' + entry.created + ' because it is blocked.');
@ -206,7 +205,7 @@ import { AddonBlogOfflineEntryDBRecord } from './database/blog';
* Sync entries to remove.
*
* @param siteId Site ID.
* @returns Entries to remove and result.
* @returns Entries to sync avoiding removed entries and the result of the entries to remove syncronization.
*/
protected async syncEntriesToRemove(siteId?: string): Promise<AddonBlogSyncGetPendingToSyncEntries> {
let entriesToSync = await AddonBlogOffline.getOfflineEntries(undefined, siteId);
@ -216,10 +215,11 @@ import { AddonBlogOfflineEntryDBRecord } from './database/blog';
await Promise.all(entriesToBeRemoved.map(async (entry) => {
try {
await AddonBlog.deleteEntryOnline({ entryid: entry.id }, siteId);
await AddonBlogOffline.deleteOfflineEntryRecord({ id: entry.id }, siteId);
await AddonBlogOffline.unmarkEntryAsRemoved(entry.id, siteId);
const entriesPendingToSync = entriesToSync.filter(entryToSync => entryToSync.id !== entry.id);
if (entriesPendingToSync.length !== entriesToSync.length) {
await AddonBlogOffline.deleteOfflineEntryRecord({ id: entry.id }, siteId);
entriesToSync = entriesPendingToSync;
}
} catch (error) {

View File

@ -30,5 +30,7 @@ Feature: Blog entries
Then I should find "Blog post one" in the app
When I press "Display options" near "Blog post one" in the app
And I press "Delete" in the app
Then I should find "Delete the blog entry" in the app
And I press "Delete" in the app
And I pull to refresh in the app
And I should not find "Blog post one" in the app