diff --git a/scripts/langindex.json b/scripts/langindex.json index c741bd67b..f9a8e8b3c 100644 --- a/scripts/langindex.json +++ b/scripts/langindex.json @@ -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", diff --git a/src/addons/blog/lang.json b/src/addons/blog/lang.json index 485f314e6..4799cfa92 100644 --- a/src/addons/blog/lang.json +++ b/src/addons/blog/lang.json @@ -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.", diff --git a/src/addons/blog/pages/index/index.ts b/src/addons/blog/pages/index/index.ts index c1cc8e4fc..874cd4842 100644 --- a/src/addons/blog/pages/index/index.ts +++ b/src/addons/blog/pages/index/index.ts @@ -417,6 +417,12 @@ export class AddonBlogIndexPage implements OnInit, OnDestroy { * @param entryToRemove Entry. */ async deleteEntry(entryToRemove: AddonBlogOfflinePostFormatted | AddonBlogPostFormatted): Promise { + try { + await CoreDomUtils.showDeleteConfirm('addon.blog.blogdeleteconfirm', { $a: entryToRemove.subject }); + } catch { + return; + } + const loading = await CoreLoadings.show(); try { diff --git a/src/addons/blog/services/blog-sync.ts b/src/addons/blog/services/blog-sync.ts index aaa512602..953ab5564 100644 --- a/src/addons/blog/services/blog-sync.ts +++ b/src/addons/blog/services/blog-sync.ts @@ -95,10 +95,9 @@ import { AddonBlogOfflineEntryDBRecord } from './database/blog'; * @returns Syncronization result. */ async performEntriesSync(siteId: string): Promise { - 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 { 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) { diff --git a/src/addons/blog/tests/behat/entries.feature b/src/addons/blog/tests/behat/entries.feature index 3c8d49341..b1096a93e 100644 --- a/src/addons/blog/tests/behat/entries.feature +++ b/src/addons/blog/tests/behat/entries.feature @@ -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