MOBILE-4547 blog: Fix remove offline entries sync
parent
d7c3c37b21
commit
91588bb94c
|
@ -91,6 +91,7 @@
|
||||||
"addon.blog.associations": "blog",
|
"addon.blog.associations": "blog",
|
||||||
"addon.blog.blog": "blog",
|
"addon.blog.blog": "blog",
|
||||||
"addon.blog.blogentries": "blog",
|
"addon.blog.blogentries": "blog",
|
||||||
|
"addon.blog.blogdeleteconfirm": "blog",
|
||||||
"addon.blog.entrybody": "blog",
|
"addon.blog.entrybody": "blog",
|
||||||
"addon.blog.entrytitle": "blog",
|
"addon.blog.entrytitle": "blog",
|
||||||
"addon.blog.errorloadentries": "local_moodlemobileapp",
|
"addon.blog.errorloadentries": "local_moodlemobileapp",
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
"associations": "Associations",
|
"associations": "Associations",
|
||||||
"blog": "Blog",
|
"blog": "Blog",
|
||||||
"blogentries": "Blog entries",
|
"blogentries": "Blog entries",
|
||||||
|
"blogdeleteconfirm": "Delete the blog entry '{{$a}}'?",
|
||||||
"entrybody": "Blog entry body",
|
"entrybody": "Blog entry body",
|
||||||
"entrytitle": "Entry title",
|
"entrytitle": "Entry title",
|
||||||
"errorloadentries": "Error loading blog entries.",
|
"errorloadentries": "Error loading blog entries.",
|
||||||
|
|
|
@ -417,6 +417,12 @@ export class AddonBlogIndexPage implements OnInit, OnDestroy {
|
||||||
* @param entryToRemove Entry.
|
* @param entryToRemove Entry.
|
||||||
*/
|
*/
|
||||||
async deleteEntry(entryToRemove: AddonBlogOfflinePostFormatted | AddonBlogPostFormatted): Promise<void> {
|
async deleteEntry(entryToRemove: AddonBlogOfflinePostFormatted | AddonBlogPostFormatted): Promise<void> {
|
||||||
|
try {
|
||||||
|
await CoreDomUtils.showDeleteConfirm('addon.blog.blogdeleteconfirm', { $a: entryToRemove.subject });
|
||||||
|
} catch {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const loading = await CoreLoadings.show();
|
const loading = await CoreLoadings.show();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -95,10 +95,9 @@ import { AddonBlogOfflineEntryDBRecord } from './database/blog';
|
||||||
* @returns Syncronization result.
|
* @returns Syncronization result.
|
||||||
*/
|
*/
|
||||||
async performEntriesSync(siteId: string): Promise<AddonBlogSyncResult> {
|
async performEntriesSync(siteId: string): Promise<AddonBlogSyncResult> {
|
||||||
const result: AddonBlogSyncResult = { updated: false, warnings: [] };
|
const { entries, result } = await this.syncEntriesToRemove(siteId);
|
||||||
const entriesToSync = 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)) {
|
if (CoreSync.isBlocked(AddonBlogProvider.COMPONENT, entry.id ?? entry.created, siteId)) {
|
||||||
this.logger.debug('Cannot sync entry ' + entry.created + ' because it is blocked.');
|
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.
|
* Sync entries to remove.
|
||||||
*
|
*
|
||||||
* @param siteId Site ID.
|
* @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> {
|
protected async syncEntriesToRemove(siteId?: string): Promise<AddonBlogSyncGetPendingToSyncEntries> {
|
||||||
let entriesToSync = await AddonBlogOffline.getOfflineEntries(undefined, siteId);
|
let entriesToSync = await AddonBlogOffline.getOfflineEntries(undefined, siteId);
|
||||||
|
@ -216,10 +215,11 @@ import { AddonBlogOfflineEntryDBRecord } from './database/blog';
|
||||||
await Promise.all(entriesToBeRemoved.map(async (entry) => {
|
await Promise.all(entriesToBeRemoved.map(async (entry) => {
|
||||||
try {
|
try {
|
||||||
await AddonBlog.deleteEntryOnline({ entryid: entry.id }, siteId);
|
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);
|
const entriesPendingToSync = entriesToSync.filter(entryToSync => entryToSync.id !== entry.id);
|
||||||
|
|
||||||
if (entriesPendingToSync.length !== entriesToSync.length) {
|
if (entriesPendingToSync.length !== entriesToSync.length) {
|
||||||
await AddonBlogOffline.deleteOfflineEntryRecord({ id: entry.id }, siteId);
|
|
||||||
entriesToSync = entriesPendingToSync;
|
entriesToSync = entriesPendingToSync;
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
|
@ -30,5 +30,7 @@ Feature: Blog entries
|
||||||
Then I should find "Blog post one" in the app
|
Then I should find "Blog post one" in the app
|
||||||
When I press "Display options" near "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
|
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 pull to refresh in the app
|
||||||
And I should not find "Blog post one" in the app
|
And I should not find "Blog post one" in the app
|
||||||
|
|
Loading…
Reference in New Issue