Skip to content

Commit 129e335

Browse files
authored
Merge pull request #4171 from alfonso-salces/MOBILE-4547
MOBILE-4547 blog: Fix remove offline entries sync
2 parents 00f4e77 + 91588bb commit 129e335

File tree

5 files changed

+15
-5
lines changed

5 files changed

+15
-5
lines changed

scripts/langindex.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@
9191
"addon.blog.associations": "blog",
9292
"addon.blog.blog": "blog",
9393
"addon.blog.blogentries": "blog",
94+
"addon.blog.blogdeleteconfirm": "blog",
9495
"addon.blog.entrybody": "blog",
9596
"addon.blog.entrytitle": "blog",
9697
"addon.blog.errorloadentries": "local_moodlemobileapp",

src/addons/blog/lang.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"associations": "Associations",
66
"blog": "Blog",
77
"blogentries": "Blog entries",
8+
"blogdeleteconfirm": "Delete the blog entry '{{$a}}'?",
89
"entrybody": "Blog entry body",
910
"entrytitle": "Entry title",
1011
"errorloadentries": "Error loading blog entries.",

src/addons/blog/pages/index/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,12 @@ export class AddonBlogIndexPage implements OnInit, OnDestroy {
417417
* @param entryToRemove Entry.
418418
*/
419419
async deleteEntry(entryToRemove: AddonBlogOfflinePostFormatted | AddonBlogPostFormatted): Promise<void> {
420+
try {
421+
await CoreDomUtils.showDeleteConfirm('addon.blog.blogdeleteconfirm', { $a: entryToRemove.subject });
422+
} catch {
423+
return;
424+
}
425+
420426
const loading = await CoreLoadings.show();
421427

422428
try {

src/addons/blog/services/blog-sync.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,9 @@ import { AddonBlogOfflineEntryDBRecord } from './database/blog';
9595
* @returns Syncronization result.
9696
*/
9797
async performEntriesSync(siteId: string): Promise<AddonBlogSyncResult> {
98-
const result: AddonBlogSyncResult = { updated: false, warnings: [] };
99-
const entriesToSync = await this.syncEntriesToRemove(siteId);
98+
const { entries, result } = await this.syncEntriesToRemove(siteId);
10099

101-
for (const entry of entriesToSync.entries) {
100+
for (const entry of entries) {
102101
if (CoreSync.isBlocked(AddonBlogProvider.COMPONENT, entry.id ?? entry.created, siteId)) {
103102
this.logger.debug('Cannot sync entry ' + entry.created + ' because it is blocked.');
104103

@@ -206,7 +205,7 @@ import { AddonBlogOfflineEntryDBRecord } from './database/blog';
206205
* Sync entries to remove.
207206
*
208207
* @param siteId Site ID.
209-
* @returns Entries to remove and result.
208+
* @returns Entries to sync avoiding removed entries and the result of the entries to remove syncronization.
210209
*/
211210
protected async syncEntriesToRemove(siteId?: string): Promise<AddonBlogSyncGetPendingToSyncEntries> {
212211
let entriesToSync = await AddonBlogOffline.getOfflineEntries(undefined, siteId);
@@ -216,10 +215,11 @@ import { AddonBlogOfflineEntryDBRecord } from './database/blog';
216215
await Promise.all(entriesToBeRemoved.map(async (entry) => {
217216
try {
218217
await AddonBlog.deleteEntryOnline({ entryid: entry.id }, siteId);
218+
await AddonBlogOffline.deleteOfflineEntryRecord({ id: entry.id }, siteId);
219+
await AddonBlogOffline.unmarkEntryAsRemoved(entry.id, siteId);
219220
const entriesPendingToSync = entriesToSync.filter(entryToSync => entryToSync.id !== entry.id);
220221

221222
if (entriesPendingToSync.length !== entriesToSync.length) {
222-
await AddonBlogOffline.deleteOfflineEntryRecord({ id: entry.id }, siteId);
223223
entriesToSync = entriesPendingToSync;
224224
}
225225
} catch (error) {

src/addons/blog/tests/behat/entries.feature

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,7 @@ Feature: Blog entries
3030
Then I should find "Blog post one" in the app
3131
When I press "Display options" near "Blog post one" in the app
3232
And I press "Delete" in the app
33+
Then I should find "Delete the blog entry" in the app
34+
And I press "Delete" in the app
3335
And I pull to refresh in the app
3436
And I should not find "Blog post one" in the app

0 commit comments

Comments
 (0)