Skip to content

Commit 6ba9032

Browse files
authored
Merge pull request #157 from GetStream/fix-message-edit
fix: Message edit
2 parents fd3bb62 + 8c300a2 commit 6ba9032

File tree

3 files changed

+30
-18
lines changed

3 files changed

+30
-18
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

projects/stream-chat-angular/src/lib/message-input/message-input.component.ts

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { OnInit } from '@angular/core';
21
import {
32
AfterViewInit,
43
ChangeDetectorRef,
@@ -40,7 +39,7 @@ import { TextareaInterface } from './textarea.interface';
4039
providers: [AttachmentService],
4140
})
4241
export class MessageInputComponent
43-
implements OnInit, OnChanges, OnDestroy, AfterViewInit
42+
implements OnChanges, OnDestroy, AfterViewInit
4443
{
4544
@Input() isFileUploadEnabled: boolean | undefined;
4645
@Input() areMentionsEnabled: boolean | undefined;
@@ -64,6 +63,7 @@ export class MessageInputComponent
6463
private textareaAnchor!: TextareaDirective;
6564
private subscriptions: Subscription[] = [];
6665
private hideNotification: Function | undefined;
66+
private isViewInited = false;
6767

6868
constructor(
6969
private channelService: ChannelService,
@@ -85,17 +85,6 @@ export class MessageInputComponent
8585
}
8686
)
8787
);
88-
this.attachmentUploads$ = this.attachmentService.attachmentUploads$;
89-
this.isFileUploadEnabled = this.configService.isFileUploadEnabled;
90-
this.acceptedFileTypes = this.configService.acceptedFileTypes;
91-
this.isMultipleFileUploadEnabled =
92-
this.configService.isMultipleFileUploadEnabled;
93-
this.areMentionsEnabled = this.configService.areMentionsEnabled;
94-
this.mentionAutocompleteItemTemplate =
95-
this.configService.mentionAutocompleteItemTemplate;
96-
this.mentionScope = this.configService.mentionScope;
97-
}
98-
ngOnInit(): void {
9988
this.subscriptions.push(
10089
this.channelService.activeChannel$.subscribe((channel) => {
10190
this.textareaValue = '';
@@ -106,14 +95,26 @@ export class MessageInputComponent
10695
capabilities.indexOf('upload-file') !== -1;
10796
this.canSendLinks = capabilities.indexOf('send-links') !== -1;
10897
this.canSendMessages = capabilities.indexOf('send-message') !== -1;
109-
this.cdRef.detectChanges();
110-
this.initTextarea();
98+
if (this.isViewInited) {
99+
this.cdRef.detectChanges();
100+
this.initTextarea();
101+
}
111102
}
112103
})
113104
);
105+
this.attachmentUploads$ = this.attachmentService.attachmentUploads$;
106+
this.isFileUploadEnabled = this.configService.isFileUploadEnabled;
107+
this.acceptedFileTypes = this.configService.acceptedFileTypes;
108+
this.isMultipleFileUploadEnabled =
109+
this.configService.isMultipleFileUploadEnabled;
110+
this.areMentionsEnabled = this.configService.areMentionsEnabled;
111+
this.mentionAutocompleteItemTemplate =
112+
this.configService.mentionAutocompleteItemTemplate;
113+
this.mentionScope = this.configService.mentionScope;
114114
}
115115

116116
ngAfterViewInit(): void {
117+
this.isViewInited = true;
117118
this.initTextarea();
118119
}
119120

projects/stream-chat-angular/src/lib/message-input/textarea.directive.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,11 @@ export class TextareaDirective implements OnChanges {
2929
@Output() readonly send = new EventEmitter<void>();
3030
@Output() readonly userMentions = new EventEmitter<UserResponse[]>();
3131
private subscriptions: Subscription[] = [];
32-
32+
private unpropagatedChanges: SimpleChanges[] = [];
3333
constructor(public viewContainerRef: ViewContainerRef) {}
3434

3535
ngOnChanges(changes: SimpleChanges): void {
36+
this.unpropagatedChanges.push(changes);
3637
if (!this.componentRef) {
3738
return;
3839
}
@@ -56,6 +57,11 @@ export class TextareaDirective implements OnChanges {
5657
)
5758
);
5859
}
60+
this.componentRef.instance.areMentionsEnabled = this.areMentionsEnabled;
61+
this.componentRef.instance.mentionAutocompleteItemTemplate =
62+
this.mentionAutocompleteItemTemplate;
63+
this.componentRef.instance.mentionScope = this.mentionScope;
64+
this.componentRef.instance.value = this.value;
5965
}
6066
}
6167
if (changes.areMentionsEnabled) {
@@ -72,7 +78,12 @@ export class TextareaDirective implements OnChanges {
7278
this.componentRef.instance.value = this.value;
7379
}
7480
// ngOnChanges not called for dynamic components since we don't use template binding
81+
let changesToPropagate = {};
82+
this.unpropagatedChanges.forEach(
83+
(c) => (changesToPropagate = { ...changesToPropagate, ...c })
84+
);
7585
// eslint-disable-next-line @angular-eslint/no-lifecycle-call
76-
this.componentRef.instance.ngOnChanges(changes);
86+
this.componentRef.instance.ngOnChanges(changesToPropagate);
87+
this.unpropagatedChanges = [];
7788
}
7889
}

0 commit comments

Comments
 (0)