Skip to content

Commit

Permalink
MOBILE-4547 blog: Fix remove offline entries sync
Browse files Browse the repository at this point in the history
  • Loading branch information
alfonso-salces committed Sep 10, 2024
1 parent d7c3c37 commit f65b707
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
10 changes: 10 additions & 0 deletions src/addons/blog/pages/index/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,16 @@ export class AddonBlogIndexPage implements OnInit, OnDestroy {
* @param entryToRemove Entry.
*/
async deleteEntry(entryToRemove: AddonBlogOfflinePostFormatted | AddonBlogPostFormatted): Promise<void> {
try {
await CoreDomUtils.showDeleteConfirm('addon.mod_data.confirmdeleterecord');
} catch (error) {
if (!CoreDomUtils.isCanceledError(error)) {
throw error;
}

return;
}

const loading = await CoreLoadings.show();

try {
Expand Down
7 changes: 4 additions & 3 deletions src/addons/blog/services/blog-sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ 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 result: AddonBlogSyncResult = entriesToSync.result;

for (const entry of entriesToSync.entries) {
if (CoreSync.isBlocked(AddonBlogProvider.COMPONENT, entry.id ?? entry.created, siteId)) {
Expand Down Expand Up @@ -206,7 +206,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);
Expand All @@ -216,10 +216,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) {
Expand Down

0 comments on commit f65b707

Please sign in to comment.