MOBILE-3793 forum: Fix sync not unblocked in offline
It happened when the user clicked to Reply another post while editing an offline replymain
parent
9c3251ec1d
commit
54abd2e0bc
|
@ -54,6 +54,7 @@ import { AddonModForumEditPostComponent } from '../edit-post/edit-post';
|
||||||
import { CoreRatingInfo } from '@features/rating/services/rating';
|
import { CoreRatingInfo } from '@features/rating/services/rating';
|
||||||
import { CoreForms } from '@singletons/form';
|
import { CoreForms } from '@singletons/form';
|
||||||
import { CoreFileEntry } from '@services/file-helper';
|
import { CoreFileEntry } from '@services/file-helper';
|
||||||
|
import { AddonModForumSharedReplyData } from '../../pages/discussion/discussion.page';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Components that shows a discussion post, its attachments and the action buttons allowed (reply, etc.).
|
* Components that shows a discussion post, its attachments and the action buttons allowed (reply, etc.).
|
||||||
|
@ -71,7 +72,7 @@ export class AddonModForumPostComponent implements OnInit, OnDestroy, OnChanges
|
||||||
@Input() discussion?: AddonModForumDiscussion; // Post's' discussion, only for starting posts.
|
@Input() discussion?: AddonModForumDiscussion; // Post's' discussion, only for starting posts.
|
||||||
@Input() component!: string; // Component this post belong to.
|
@Input() component!: string; // Component this post belong to.
|
||||||
@Input() componentId!: number; // Component ID.
|
@Input() componentId!: number; // Component ID.
|
||||||
@Input() replyData!: AddonModForumReply; // Object with the new post data. Usually shared between posts.
|
@Input() replyData!: AddonModForumSharedReplyData; // Object with the new post data. Usually shared between posts.
|
||||||
@Input() originalData!: Omit<AddonModForumReply, 'id'>; // Object with the original post data. Usually shared between posts.
|
@Input() originalData!: Omit<AddonModForumReply, 'id'>; // Object with the original post data. Usually shared between posts.
|
||||||
@Input() trackPosts!: boolean; // True if post is being tracked.
|
@Input() trackPosts!: boolean; // True if post is being tracked.
|
||||||
@Input() forum!: AddonModForumData; // The forum the post belongs to. Required for attachments and offline posts.
|
@Input() forum!: AddonModForumData; // The forum the post belongs to. Required for attachments and offline posts.
|
||||||
|
@ -93,8 +94,6 @@ export class AddonModForumPostComponent implements OnInit, OnDestroy, OnChanges
|
||||||
displaySubject = true;
|
displaySubject = true;
|
||||||
optionsMenuEnabled = false;
|
optionsMenuEnabled = false;
|
||||||
|
|
||||||
protected syncId!: string;
|
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
protected elementRef: ElementRef,
|
protected elementRef: ElementRef,
|
||||||
@Optional() protected content?: IonContent,
|
@Optional() protected content?: IonContent,
|
||||||
|
@ -372,8 +371,8 @@ export class AddonModForumPostComponent implements OnInit, OnDestroy, OnChanges
|
||||||
try {
|
try {
|
||||||
await this.confirmDiscard();
|
await this.confirmDiscard();
|
||||||
|
|
||||||
this.syncId = AddonModForumSync.getDiscussionSyncId(this.discussionId);
|
this.replyData.syncId = AddonModForumSync.getDiscussionSyncId(this.discussionId);
|
||||||
CoreSync.blockOperation(AddonModForumProvider.COMPONENT, this.syncId);
|
CoreSync.blockOperation(AddonModForumProvider.COMPONENT, this.replyData.syncId);
|
||||||
|
|
||||||
this.setReplyFormData(
|
this.setReplyFormData(
|
||||||
this.post.parentid,
|
this.post.parentid,
|
||||||
|
@ -498,9 +497,7 @@ export class AddonModForumPostComponent implements OnInit, OnDestroy, OnChanges
|
||||||
|
|
||||||
CoreForms.triggerFormSubmittedEvent(this.formElement, sent, CoreSites.getCurrentSiteId());
|
CoreForms.triggerFormSubmittedEvent(this.formElement, sent, CoreSites.getCurrentSiteId());
|
||||||
|
|
||||||
if (this.syncId) {
|
this.unblockOperation();
|
||||||
CoreSync.unblockOperation(AddonModForumProvider.COMPONENT, this.syncId);
|
|
||||||
}
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
CoreDomUtils.showErrorModalDefault(error, 'addon.mod_forum.couldnotadd', true);
|
CoreDomUtils.showErrorModalDefault(error, 'addon.mod_forum.couldnotadd', true);
|
||||||
} finally {
|
} finally {
|
||||||
|
@ -520,9 +517,7 @@ export class AddonModForumPostComponent implements OnInit, OnDestroy, OnChanges
|
||||||
|
|
||||||
CoreForms.triggerFormCancelledEvent(this.formElement, CoreSites.getCurrentSiteId());
|
CoreForms.triggerFormCancelledEvent(this.formElement, CoreSites.getCurrentSiteId());
|
||||||
|
|
||||||
if (this.syncId) {
|
this.unblockOperation();
|
||||||
CoreSync.unblockOperation(AddonModForumProvider.COMPONENT, this.syncId);
|
|
||||||
}
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// Cancelled.
|
// Cancelled.
|
||||||
}
|
}
|
||||||
|
@ -552,9 +547,7 @@ export class AddonModForumPostComponent implements OnInit, OnDestroy, OnChanges
|
||||||
|
|
||||||
this.onPostChange.emit();
|
this.onPostChange.emit();
|
||||||
|
|
||||||
if (this.syncId) {
|
this.unblockOperation();
|
||||||
CoreSync.unblockOperation(AddonModForumProvider.COMPONENT, this.syncId);
|
|
||||||
}
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// Cancelled.
|
// Cancelled.
|
||||||
}
|
}
|
||||||
|
@ -578,9 +571,7 @@ export class AddonModForumPostComponent implements OnInit, OnDestroy, OnChanges
|
||||||
* Component being destroyed.
|
* Component being destroyed.
|
||||||
*/
|
*/
|
||||||
ngOnDestroy(): void {
|
ngOnDestroy(): void {
|
||||||
if (this.syncId) {
|
this.unblockOperation();
|
||||||
CoreSync.unblockOperation(AddonModForumProvider.COMPONENT, this.syncId);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -588,13 +579,25 @@ export class AddonModForumPostComponent implements OnInit, OnDestroy, OnChanges
|
||||||
*
|
*
|
||||||
* @return Promise resolved if the user confirms or data was not changed and rejected otherwise.
|
* @return Promise resolved if the user confirms or data was not changed and rejected otherwise.
|
||||||
*/
|
*/
|
||||||
protected confirmDiscard(): Promise<void> {
|
protected async confirmDiscard(): Promise<void> {
|
||||||
if (AddonModForumHelper.hasPostDataChanged(this.replyData, this.originalData)) {
|
if (AddonModForumHelper.hasPostDataChanged(this.replyData, this.originalData)) {
|
||||||
// Show confirmation if some data has been modified.
|
// Show confirmation if some data has been modified.
|
||||||
return CoreDomUtils.showConfirm(Translate.instant('core.confirmloss'));
|
await CoreDomUtils.showConfirm(Translate.instant('core.confirmloss'));
|
||||||
} else {
|
|
||||||
return Promise.resolve();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.unblockOperation();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unblock operation if there's any blocked operation.
|
||||||
|
*/
|
||||||
|
protected unblockOperation(): void {
|
||||||
|
if (!this.replyData.syncId) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
CoreSync.unblockOperation(AddonModForumProvider.COMPONENT, this.replyData.syncId);
|
||||||
|
delete this.replyData.syncId;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,7 +74,7 @@ export class AddonModForumDiscussionPage implements OnInit, AfterViewInit, OnDes
|
||||||
postHasOffline!: boolean;
|
postHasOffline!: boolean;
|
||||||
sort: SortType = 'nested';
|
sort: SortType = 'nested';
|
||||||
trackPosts!: boolean;
|
trackPosts!: boolean;
|
||||||
replyData: Omit<AddonModForumReply, 'id'> = {
|
replyData: AddonModForumSharedReplyData = {
|
||||||
replyingTo: 0,
|
replyingTo: 0,
|
||||||
isEditing: false,
|
isEditing: false,
|
||||||
subject: '',
|
subject: '',
|
||||||
|
@ -795,3 +795,10 @@ export class AddonModForumDiscussionPage implements OnInit, AfterViewInit, OnDes
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reply data shared by post.
|
||||||
|
*/
|
||||||
|
export type AddonModForumSharedReplyData = Omit<AddonModForumReply, 'id'> & {
|
||||||
|
syncId?: string; // Sync ID if some post has blocked synchronization.
|
||||||
|
};
|
||||||
|
|
Loading…
Reference in New Issue