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 13, 2024
1 parent d7c3c37 commit 6ef7eb3
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
1 change: 1 addition & 0 deletions scripts/langindex.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions src/addons/blog/lang.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down
6 changes: 6 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,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 {
Expand Down
10 changes: 5 additions & 5 deletions src/addons/blog/services/blog-sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.');

Expand Down Expand Up @@ -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);
Expand All @@ -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) {
Expand Down

0 comments on commit 6ef7eb3

Please sign in to comment.