Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MOBILE-4547 blog: Fix remove offline entries sync #4171

Merged
merged 1 commit into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
2 changes: 2 additions & 0 deletions src/addons/blog/tests/behat/entries.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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