MOBILE-3230 forum: Use parent subject in post replies

main
Noel De Martin 2019-11-26 09:40:18 +01:00
parent 9846e40c8c
commit 86f0db8108
3 changed files with 25 additions and 16 deletions

View File

@ -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<void>; // 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);
}

View File

@ -42,13 +42,13 @@
</ion-card>
<div *ngIf="discussion" margin-bottom class="highlight">
<addon-mod-forum-post [post]="discussion" [courseId]="courseId" [discussionId]="discussionId" [component]="component" [componentId]="cmId" [replyData]="replyData" [originalData]="originalData" [defaultSubject]="defaultSubject" [forum]="forum" [accessInfo]="accessInfo" [trackPosts]="trackPosts" [ratingInfo]="ratingInfo" (onPostChange)="postListChanged()"></addon-mod-forum-post>
<addon-mod-forum-post [post]="discussion" [courseId]="courseId" [discussionId]="discussionId" [component]="component" [componentId]="cmId" [replyData]="replyData" [originalData]="originalData" [forum]="forum" [accessInfo]="accessInfo" [trackPosts]="trackPosts" [ratingInfo]="ratingInfo" (onPostChange)="postListChanged()"></addon-mod-forum-post>
</div>
<ion-card *ngIf="sort != 'nested'">
<ng-container *ngFor="let post of posts; first as first">
<ion-item-divider *ngIf="!first"></ion-item-divider>
<addon-mod-forum-post [post]="post" [courseId]="courseId" [discussionId]="discussionId" [component]="component" [componentId]="cmId" [replyData]="replyData" [originalData]="originalData" [defaultSubject]="defaultSubject" [forum]="forum" [accessInfo]="accessInfo" [trackPosts]="trackPosts" [ratingInfo]="ratingInfo" (onPostChange)="postListChanged()"></addon-mod-forum-post>
<addon-mod-forum-post [post]="post" [courseId]="courseId" [discussionId]="discussionId" [component]="component" [componentId]="cmId" [replyData]="replyData" [originalData]="originalData" [parentSubject]="postSubjects[post.parent]" [forum]="forum" [accessInfo]="accessInfo" [trackPosts]="trackPosts" [ratingInfo]="ratingInfo" (onPostChange)="postListChanged()"></addon-mod-forum-post>
</ng-container>
</ion-card>
@ -60,7 +60,7 @@
<ng-template #nestedPosts let-post="post">
<ion-card>
<addon-mod-forum-post [post]="post" [courseId]="courseId" [discussionId]="discussionId" [component]="component" [componentId]="cmId" [replyData]="replyData" [originalData]="originalData" [defaultSubject]="defaultSubject" [forum]="forum" [accessInfo]="accessInfo" [trackPosts]="trackPosts" [ratingInfo]="ratingInfo" (onPostChange)="postListChanged()"></addon-mod-forum-post>
<addon-mod-forum-post [post]="post" [courseId]="courseId" [discussionId]="discussionId" [component]="component" [componentId]="cmId" [replyData]="replyData" [originalData]="originalData" [parentSubject]="postSubjects[post.parent]" [forum]="forum" [accessInfo]="accessInfo" [trackPosts]="trackPosts" [ratingInfo]="ratingInfo" (onPostChange)="postListChanged()"></addon-mod-forum-post>
</ion-card>
<div padding-left *ngIf="post.children.length && post.children[0].subject">
<ng-container *ngFor="let child of post.children">

View File

@ -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()) {