Skip to content

Commit ce5067b

Browse files
authored
Merge pull request #442 from GetStream/fixes
Fixes
2 parents 8780456 + 93ed2af commit ce5067b

13 files changed

+105
-37
lines changed

projects/stream-chat-angular/src/lib/avatar-placeholder/avatar-placeholder.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,6 @@
2323
<ng-container
2424
*ngTemplateOutlet="
2525
(customTemplatesService.avatarTemplate$ | async) || defaultAvatar;
26-
context: getAvatarContext()
26+
context: context
2727
"
2828
></ng-container>

projects/stream-chat-angular/src/lib/avatar-placeholder/avatar-placeholder.component.spec.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ describe('AvatarPlaceholderComponent', () => {
1919
beforeEach(() => {
2020
fixture = TestBed.createComponent(AvatarPlaceholderComponent);
2121
component = fixture.componentInstance;
22+
component.ngOnChanges();
2223
fixture.detectChanges();
2324
});
2425

@@ -39,6 +40,7 @@ describe('AvatarPlaceholderComponent', () => {
3940
component.location = 'autocomplete-item';
4041
const user = { id: 'user-id' };
4142
component.user = user;
43+
component.ngOnChanges();
4244
fixture.detectChanges();
4345

4446
expect(avatar.imageUrl).toBe('imageUrl');
@@ -51,6 +53,7 @@ describe('AvatarPlaceholderComponent', () => {
5153
component.type = 'channel';
5254
const channel = { id: 'channel-id' } as Channel<DefaultStreamChatGenerics>;
5355
component.channel = channel;
56+
component.ngOnChanges();
5457
fixture.detectChanges();
5558

5659
expect(avatar.type).toEqual('channel');

projects/stream-chat-angular/src/lib/avatar-placeholder/avatar-placeholder.component.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, Input } from '@angular/core';
1+
import { Component, Input, OnChanges } from '@angular/core';
22
import { Channel, User } from 'stream-chat';
33
import { CustomTemplatesService } from '../custom-templates.service';
44
import {
@@ -16,7 +16,7 @@ import {
1616
templateUrl: './avatar-placeholder.component.html',
1717
styles: [],
1818
})
19-
export class AvatarPlaceholderComponent {
19+
export class AvatarPlaceholderComponent implements OnChanges {
2020
/**
2121
* An optional name of the image, used for fallback image or image title (if `imageUrl` is provided)
2222
*/
@@ -51,10 +51,20 @@ export class AvatarPlaceholderComponent {
5151
@Input() initialsType:
5252
| 'first-letter-of-first-word'
5353
| 'first-letter-of-each-word' = 'first-letter-of-first-word';
54+
context: AvatarContext = {
55+
name: undefined,
56+
imageUrl: undefined,
57+
size: undefined,
58+
location: undefined,
59+
channel: undefined,
60+
user: undefined,
61+
type: undefined,
62+
initialsType: undefined,
63+
};
5464
constructor(public customTemplatesService: CustomTemplatesService) {}
5565

56-
getAvatarContext(): AvatarContext {
57-
return {
66+
ngOnChanges(): void {
67+
this.context = {
5868
name: this.name,
5969
imageUrl: this.imageUrl,
6070
size: this.size,

projects/stream-chat-angular/src/lib/channel-list/channel-list.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
<ng-container
4949
*ngTemplateOutlet="
5050
customChannelPreviewTemplate || defaultTemplate;
51-
context: getChannelPreviewContext(channel)
51+
context: { channel: channel }
5252
"
5353
></ng-container>
5454
</div>

projects/stream-chat-angular/src/lib/channel-list/channel-list.component.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,4 @@ export class ChannelListComponent implements AfterViewInit, OnDestroy {
8181
channelSelected() {
8282
this.channelListToggleService.channelSelected();
8383
}
84-
85-
getChannelPreviewContext(
86-
channel: Channel<DefaultStreamChatGenerics>
87-
): ChannelPreviewContext<DefaultStreamChatGenerics> {
88-
return {
89-
channel,
90-
};
91-
}
9284
}

projects/stream-chat-angular/src/lib/icon-placeholder/icon-placeholder.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
<ng-container
55
*ngTemplateOutlet="
66
(customTemplatesService.iconTemplate$ | async) || defaultIcon;
7-
context: getIconContext()
7+
context: iconContext
88
"
99
></ng-container>

projects/stream-chat-angular/src/lib/icon-placeholder/icon-placeholder.component.spec.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ describe('IconPlaceholderComponent', () => {
2727
it('should bind inputs', () => {
2828
component.icon = 'action-icon';
2929
component.size = 30;
30+
component.ngOnChanges();
3031
fixture.detectChanges();
3132

3233
const iconComponent = fixture.debugElement.query(
@@ -36,4 +37,30 @@ describe('IconPlaceholderComponent', () => {
3637
expect(iconComponent.icon).toBe('action-icon');
3738
expect(iconComponent.size).toBe(30);
3839
});
40+
41+
it('should ipdate inputs', () => {
42+
component.icon = 'action-icon';
43+
component.size = 30;
44+
fixture.detectChanges();
45+
46+
component.icon = 'arrow-down';
47+
component.ngOnChanges();
48+
fixture.detectChanges();
49+
50+
let iconComponent = fixture.debugElement.query(By.directive(IconComponent))
51+
.componentInstance as IconComponent;
52+
53+
expect(iconComponent.icon).toBe('arrow-down');
54+
expect(iconComponent.size).toBe(30);
55+
56+
component.size = 25;
57+
component.ngOnChanges();
58+
fixture.detectChanges();
59+
60+
iconComponent = fixture.debugElement.query(By.directive(IconComponent))
61+
.componentInstance as IconComponent;
62+
63+
expect(iconComponent.icon).toBe('arrow-down');
64+
expect(iconComponent.size).toBe(25);
65+
});
3966
});

projects/stream-chat-angular/src/lib/icon-placeholder/icon-placeholder.component.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, Input } from '@angular/core';
1+
import { Component, Input, OnChanges } from '@angular/core';
22
import { CustomTemplatesService } from '../custom-templates.service';
33
import { Icon } from '../icon/icon.component';
44
import { IconContext } from '../types';
@@ -11,7 +11,7 @@ import { IconContext } from '../types';
1111
templateUrl: './icon-placeholder.component.html',
1212
styles: [],
1313
})
14-
export class IconPlaceholderComponent {
14+
export class IconPlaceholderComponent implements OnChanges {
1515
/**
1616
* The icon to display, the list of [supported icons](https://github.com/GetStream/stream-chat-angular/tree/master/projects/stream-chat-angular/src/lib/icon/icon.component.ts) can be found on GitHub.
1717
*/
@@ -20,10 +20,12 @@ export class IconPlaceholderComponent {
2020
* The size of the icon (in pixels)
2121
*/
2222
@Input() size: number | undefined;
23+
iconContext: IconContext = { icon: undefined, size: undefined };
24+
2325
constructor(public customTemplatesService: CustomTemplatesService) {}
2426

25-
getIconContext(): IconContext {
26-
return {
27+
ngOnChanges(): void {
28+
this.iconContext = {
2729
icon: this.icon,
2830
size: this.size,
2931
};

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -998,4 +998,36 @@ describe('MessageInputComponent', () => {
998998

999999
expect(component.messageSent).toHaveBeenCalledWith();
10001000
});
1001+
1002+
it('should trim leading and ending empty lines in message text', () => {
1003+
component.textareaValue =
1004+
'This is a multiline text\nthis should be left unchanged';
1005+
void component.messageSent();
1006+
//eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
1007+
let sentText = sendMessageSpy.calls.mostRecent().args[0];
1008+
1009+
expect(sentText).toEqual(
1010+
'This is a multiline text\nthis should be left unchanged'
1011+
);
1012+
1013+
component.textareaValue =
1014+
'\n\nLeading and trailing empty \nlines should be removed\n\n';
1015+
void component.messageSent();
1016+
//eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
1017+
sentText = sendMessageSpy.calls.mostRecent().args[0];
1018+
1019+
expect(sentText).toEqual(
1020+
'Leading and trailing empty \nlines should be removed'
1021+
);
1022+
1023+
component.textareaValue =
1024+
'Multiple empty line inside the message\n\n\nis allowed';
1025+
void component.messageSent();
1026+
//eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
1027+
sentText = sendMessageSpy.calls.mostRecent().args[0];
1028+
1029+
expect(sentText).toEqual(
1030+
'Multiple empty line inside the message\n\n\nis allowed'
1031+
);
1032+
});
10011033
});

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,8 @@ export class MessageInputComponent
331331
}
332332
const attachments = this.attachmentService.mapToAttachments();
333333
let text = this.textareaValue;
334+
text = text.replace(/^\n+/g, ''); // leading empty lines
335+
text = text.replace(/\n+$/g, ''); // ending empty lines
334336
const textContainsOnlySpaceChars = !text.replace(/ /g, ''); //spcae
335337
if (
336338
(!text || textContainsOnlySpaceChars) &&

0 commit comments

Comments
 (0)