Skip to content

Commit 0655ef7

Browse files
authored
Merge pull request #652 from GetStream/new-message-component-hooks
New message component hooks
2 parents d65e2db + 46435a9 commit 0655ef7

5 files changed

Lines changed: 56 additions & 11 deletions

File tree

docusaurus/docs/Angular/code-examples/emoji-picker.mdx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ The `emojiSelect` event is fired when a user selects an emoji, we emit the selec
150150
title="Pick your emoji…"
151151
emoji="point_up"
152152
(emojiSelect)="emojiSelected($event)"
153-
[darkMode]="(theme$ | async) === 'dark'"
153+
[isNative]="true"
154154
></emoji-mart>
155155
</div>
156156
```
@@ -304,6 +304,7 @@ And set the `darkMode` input on the `emoji-mart` component:
304304
title="Pick your emoji…"
305305
emoji="point_up"
306306
(emojiSelect)="emojiSelected($event)"
307+
[isNative]="true"
307308
[darkMode]="(theme$ | async) === 'dark'"
308309
></emoji-mart>
309310
```

projects/stream-chat-angular/src/lib/custom-templates.service.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import {
3232
SendingStatusContext,
3333
SystemMessageContext,
3434
ThreadHeaderContext,
35+
ThreadReplyButtonContext,
3536
TypingIndicatorContext,
3637
UnreadMessagesIndicatorContext,
3738
UnreadMessagesNotificationContext,
@@ -343,6 +344,20 @@ export class CustomTemplatesService<
343344
customAttachmentListTemplate$ = new BehaviorSubject<
344345
TemplateRef<CustomAttachmentListContext> | undefined
345346
>(undefined);
347+
/**
348+
* The template used to display the number of thread replies inside the [message component](../../components/MessageComponent.mdx)
349+
*/
350+
threadLinkButton$ = new BehaviorSubject<
351+
TemplateRef<ThreadReplyButtonContext> | undefined
352+
>(undefined);
353+
/**
354+
* Template to display custom metadata inside the message bubble of the [message component](../components/MessageComponent.mdx)
355+
*
356+
* To properly position your template you should override the `grid-template-areas` of the `.str-chat__message-inner` selector
357+
*/
358+
customMessageMetadataInsideBubbleTemplate$ = new BehaviorSubject<
359+
TemplateRef<CustomMetadataContext> | undefined
360+
>(undefined);
346361

347362
constructor() {}
348363
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ export class MessageInputComponent
452452
if (this.configService.customPasteEventHandler) {
453453
this.configService.customPasteEventHandler(event, this);
454454
} else {
455-
if (event.clipboardData?.files) {
455+
if (event.clipboardData?.files && event.clipboardData?.files.length > 0) {
456456
event.preventDefault();
457457
void this.filesSelected(event.clipboardData?.files);
458458
}

projects/stream-chat-angular/src/lib/message/message.component.html

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,20 @@
6969
</div>
7070
</div>
7171
</div>
72+
<ng-container
73+
*ngIf="
74+
customTemplatesService.customMessageMetadataInsideBubbleTemplate$
75+
| async
76+
"
77+
>
78+
<ng-template
79+
*ngTemplateOutlet="
80+
(customTemplatesService.customMessageMetadataInsideBubbleTemplate$
81+
| async)!;
82+
context: { message: message }
83+
"
84+
></ng-template>
85+
</ng-container>
7286
<div class="str-chat__message-reactions-host">
7387
<ng-template
7488
#defaultMessageReactions
@@ -566,15 +580,24 @@
566580
<div
567581
class="str-chat__message-simple-reply-button str-chat__message-replies-count-button-wrapper"
568582
>
569-
<button
570-
*ngIf="shouldDisplayThreadLink"
571-
class="str-chat__message-replies-count-button"
572-
data-testid="reply-count-button"
573-
(click)="setAsActiveParentMessage()"
574-
>
575-
{{message?.reply_count === 1 ? ('streamChat.1 reply' | translate) : ('streamChat.{{ replyCount }}
576-
replies' | translate:replyCountParam)}}
577-
</button>
583+
<ng-container *ngIf="shouldDisplayThreadLink">
584+
<ng-template
585+
*ngTemplateOutlet="
586+
(customTemplatesService.threadLinkButton$ | async) || defaultButton;
587+
context: { message: message }
588+
"
589+
></ng-template>
590+
</ng-container>
591+
<ng-template #defaultButton let-message="message">
592+
<button
593+
class="str-chat__message-replies-count-button"
594+
data-testid="reply-count-button"
595+
(click)="setAsActiveParentMessage()"
596+
>
597+
{{message?.reply_count === 1 ? ('streamChat.1 reply' | translate) : ('streamChat.{{ replyCount }}
598+
replies' | translate:replyCountParam)}}
599+
</button>
600+
</ng-template>
578601
</div>
579602
</ng-template>
580603

projects/stream-chat-angular/src/lib/types.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,3 +494,9 @@ export type CustomAttachmentPreviewListContext<
494494
> = {
495495
attachmentService: AttachmentService<T>;
496496
};
497+
498+
export type ThreadReplyButtonContext<
499+
T extends DefaultStreamChatGenerics = DefaultStreamChatGenerics
500+
> = {
501+
message: StreamMessage<T>;
502+
};

0 commit comments

Comments
 (0)