From 86f0db81087b4d02d4cc11569ace4b49c9ad46db Mon Sep 17 00:00:00 2001 From: Noel De Martin Date: Tue, 26 Nov 2019 09:40:18 +0100 Subject: [PATCH 1/3] MOBILE-3230 forum: Use parent subject in post replies --- src/addon/mod/forum/components/post/post.ts | 21 ++++++++++++++----- .../forum/pages/discussion/discussion.html | 6 +++--- .../mod/forum/pages/discussion/discussion.ts | 14 ++++++------- 3 files changed, 25 insertions(+), 16 deletions(-) diff --git a/src/addon/mod/forum/components/post/post.ts b/src/addon/mod/forum/components/post/post.ts index ced5507c8..97b599cef 100644 --- a/src/addon/mod/forum/components/post/post.ts +++ b/src/addon/mod/forum/components/post/post.ts @@ -48,13 +48,14 @@ export class AddonModForumPostComponent implements OnInit, OnDestroy { @Input() trackPosts: boolean; // True if post is being tracked. @Input() forum: any; // The forum the post belongs to. Required for attachments and offline posts. @Input() accessInfo: any; // Forum access information. - @Input() defaultSubject: string; // Default subject to set to new posts. + @Input() parentSubject?: string; // Subject of parent post. @Input() ratingInfo?: CoreRatingInfo; // Rating info item. @Output() onPostChange: EventEmitter; // Event emitted when a reply is posted or modified. messageControl = new FormControl(); uniqueId: string; + defaultReplySubject: string; advanced = false; // Display all form fields. tagsEnabled: boolean; displaySubject = true; @@ -89,9 +90,17 @@ export class AddonModForumPostComponent implements OnInit, OnDestroy { this.uniqueId = this.post.id ? 'reply' + this.post.id : 'edit' + this.post.parent; const reTranslated = this.translate.instant('addon.mod_forum.re'); - this.displaySubject = this.post.parent == 0 || - (this.post.subject != this.defaultSubject && this.post.subject != 'Re: ' + this.defaultSubject && - this.post.subject != reTranslated + this.defaultSubject); + this.displaySubject = !this.parentSubject || ( + this.post.subject != this.parentSubject && + this.post.subject != `Re: ${this.parentSubject}` && + this.post.subject != `${reTranslated} ${this.parentSubject}` + ); + this.defaultReplySubject = ( + this.post.subject.startsWith('Re: ') || + this.post.subject.startsWith(reTranslated) + ) + ? this.post.subject + : `${reTranslated} ${this.post.subject}`; this.optionsMenuEnabled = !this.post.id || (this.forumProvider.isGetDiscussionPostAvailable() && (this.forumProvider.isDeletePostAvailable() || this.forumProvider.isUpdatePostAvailable())); @@ -145,7 +154,7 @@ export class AddonModForumPostComponent implements OnInit, OnDestroy { this.replyData.replyingTo = replyingTo || 0; this.replyData.isEditing = !!isEditing; - this.replyData.subject = subject || this.defaultSubject || ''; + this.replyData.subject = subject || this.defaultReplySubject || ''; this.replyData.message = message || null; this.replyData.files = files || []; this.replyData.isprivatereply = !!isPrivate; @@ -282,6 +291,8 @@ export class AddonModForumPostComponent implements OnInit, OnDestroy { } else { // The post being replied has changed but the data will be kept. this.replyData.replyingTo = this.post.id; + this.replyData.subject = this.defaultReplySubject; + this.originalData.subject = this.defaultReplySubject; this.messageControl.setValue(this.replyData.message); } diff --git a/src/addon/mod/forum/pages/discussion/discussion.html b/src/addon/mod/forum/pages/discussion/discussion.html index 9615fd88a..577fe6c57 100644 --- a/src/addon/mod/forum/pages/discussion/discussion.html +++ b/src/addon/mod/forum/pages/discussion/discussion.html @@ -42,13 +42,13 @@
- +
- + @@ -60,7 +60,7 @@ - +
diff --git a/src/addon/mod/forum/pages/discussion/discussion.ts b/src/addon/mod/forum/pages/discussion/discussion.ts index 454a0147a..6d47d6db9 100644 --- a/src/addon/mod/forum/pages/discussion/discussion.ts +++ b/src/addon/mod/forum/pages/discussion/discussion.ts @@ -51,7 +51,7 @@ export class AddonModForumDiscussionPage implements OnDestroy { discussion: any; posts: any[]; discussionLoaded = false; - defaultSubject: string; + postSubjects: { [id: string]: string }; isOnline: boolean; isSplitViewOn: boolean; postHasOffline: boolean; @@ -375,10 +375,6 @@ export class AddonModForumDiscussionPage implements OnDestroy { }).catch(() => { // Ignore errors. }).then(() => { - this.defaultSubject = this.translate.instant('addon.mod_forum.re') + ' ' + - (this.discussion ? this.discussion.subject : ''); - this.replyData.subject = this.defaultSubject; - const startingPost = this.forumProvider.extractStartingPost(posts); if (startingPost) { // Update discussion data from first post. @@ -388,9 +384,6 @@ export class AddonModForumDiscussionPage implements OnDestroy { return Promise.reject('Invalid forum discussion.'); } - this.defaultSubject = this.translate.instant('addon.mod_forum.re') + ' ' + this.discussion.subject; - this.replyData.subject = this.defaultSubject; - if (this.discussion.userfullname && this.discussion.parent == 0 && this.forum.type == 'single') { // Hide author for first post and type single. this.discussion.userfullname = null; @@ -398,6 +391,11 @@ export class AddonModForumDiscussionPage implements OnDestroy { this.posts = posts; this.ratingInfo = ratingInfo; + this.postSubjects = this.posts.reduce((postSubjects, post) => { + postSubjects[post.id] = post.subject; + + return postSubjects; + }, { [this.discussion.id]: this.discussion.subject }); }); }).then(() => { if (this.forumProvider.isSetPinStateAvailableForSite()) { From 256c883f57df44766595494c45475588bf00721a Mon Sep 17 00:00:00 2001 From: Noel De Martin Date: Tue, 26 Nov 2019 16:16:13 +0100 Subject: [PATCH 2/3] MOBILE-3230 forum: Avoid updating reply subject if it's been modified --- src/addon/mod/forum/components/post/post.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/addon/mod/forum/components/post/post.ts b/src/addon/mod/forum/components/post/post.ts index 97b599cef..16aedbeb5 100644 --- a/src/addon/mod/forum/components/post/post.ts +++ b/src/addon/mod/forum/components/post/post.ts @@ -291,8 +291,13 @@ export class AddonModForumPostComponent implements OnInit, OnDestroy { } else { // The post being replied has changed but the data will be kept. this.replyData.replyingTo = this.post.id; - this.replyData.subject = this.defaultReplySubject; - this.originalData.subject = this.defaultReplySubject; + + if (this.replyData.subject == this.originalData.subject) { + // Update subject only if it hadn't been modified + this.replyData.subject = this.defaultReplySubject; + this.originalData.subject = this.defaultReplySubject; + } + this.messageControl.setValue(this.replyData.message); } From 9ebf923964491a8cd501ef2109fabee029f6c7b9 Mon Sep 17 00:00:00 2001 From: Noel De Martin Date: Wed, 27 Nov 2019 12:47:18 +0100 Subject: [PATCH 3/3] MOBILE-3230 forum: Update parentheses formatting --- src/addon/mod/forum/components/post/post.ts | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/src/addon/mod/forum/components/post/post.ts b/src/addon/mod/forum/components/post/post.ts index 16aedbeb5..8900dc980 100644 --- a/src/addon/mod/forum/components/post/post.ts +++ b/src/addon/mod/forum/components/post/post.ts @@ -90,17 +90,11 @@ export class AddonModForumPostComponent implements OnInit, OnDestroy { this.uniqueId = this.post.id ? 'reply' + this.post.id : 'edit' + this.post.parent; const reTranslated = this.translate.instant('addon.mod_forum.re'); - this.displaySubject = !this.parentSubject || ( - this.post.subject != this.parentSubject && - this.post.subject != `Re: ${this.parentSubject}` && - this.post.subject != `${reTranslated} ${this.parentSubject}` - ); - this.defaultReplySubject = ( - this.post.subject.startsWith('Re: ') || - this.post.subject.startsWith(reTranslated) - ) - ? this.post.subject - : `${reTranslated} ${this.post.subject}`; + this.displaySubject = !this.parentSubject || + (this.post.subject != this.parentSubject && this.post.subject != `Re: ${this.parentSubject}` && + this.post.subject != `${reTranslated} ${this.parentSubject}`); + this.defaultReplySubject = (this.post.subject.startsWith('Re: ') || this.post.subject.startsWith(reTranslated)) + ? this.post.subject : `${reTranslated} ${this.post.subject}`; this.optionsMenuEnabled = !this.post.id || (this.forumProvider.isGetDiscussionPostAvailable() && (this.forumProvider.isDeletePostAvailable() || this.forumProvider.isUpdatePostAvailable()));