Skip to content

Commit 78e2e09

Browse files
committed
feat: allow displaying custom metadata template inside message component
1 parent cc738e9 commit 78e2e09

File tree

7 files changed

+53
-33
lines changed

7 files changed

+53
-33
lines changed

docusaurus/docs/Angular/components/MessageListComponent.mdx

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -19,30 +19,7 @@ If you want to customize how messages are displayed in the list, head over to th
1919

2020
### Custom message list
2121

22-
The message list contains a lot of low-level logic related to scrolling, we don't advise to create your own message list component, however it's possible: see [our customization guide](../concepts/customization.mdx) on how to provide your own message list component.
23-
24-
:::note
25-
If you want to create your own message list, you can use the [`ChannelService`](../services/ChannelService.mdx) to receive the necessary messages and interact with the Stream API.
26-
27-
Other building blocks, that you might find useful:
28-
29-
### Message group styles
30-
31-
Message group styles makes the message list more readable, by grouping messages from the same author on the same day together. The grouping assigns a CSS class to every message, if you want to take advantage of this functionality, you can use the [`getGroupStyles`](https://github.com/GetStream/stream-chat-angular/tree/master/projects/stream-chat-angular/src/lib/message-list/group-styles.ts) utility function.
32-
33-
**Example 1** - Messages with group styles
34-
35-
<img src={MessagesWithGroupingsScreenhot} width="500" />
36-
37-
**Example 2** - Messages without group styles
38-
39-
<img src={MessagesWithoutGroupingsScreenhot} width="500" />
40-
41-
:::
42-
43-
**Example 2** - Using a custom message component
44-
45-
If you only want to customize the messages (not the whole list), see the [message customization guide](./MessageComponent.mdx/#customization).
22+
The message list contains a lot of low-level logic related to scrolling, we don't advise to create your own message list component
4623

4724
[//]: # "Start of generated content"
4825
[//]: # "End of generated content"

package-lock.json

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@
117117
"@ngx-translate/core": "^13.0.0",
118118
"@ngx-translate/http-loader": "^6.0.0",
119119
"@popperjs/core": "^2.11.5",
120-
"@stream-io/stream-chat-css": "4.3.0",
120+
"@stream-io/stream-chat-css": "4.5.0",
121121
"@stream-io/transliterate": "^1.5.2",
122122
"angular-mentions": "^1.4.0",
123123
"dayjs": "^1.10.7",

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

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ import {
1010
ChannelPreviewContext,
1111
CommandAutocompleteListItemContext,
1212
CustomAttachmentUploadContext,
13+
CustomMetadataContext,
1314
DateSeparatorContext,
15+
DefaultStreamChatGenerics,
1416
DeliveredStatusContext,
1517
EmojiPickerContext,
1618
IconContext,
@@ -39,7 +41,9 @@ import {
3941
@Injectable({
4042
providedIn: 'root',
4143
})
42-
export class CustomTemplatesService {
44+
export class CustomTemplatesService<
45+
T extends DefaultStreamChatGenerics = DefaultStreamChatGenerics
46+
> {
4347
/**
4448
* The autocomplete list item template for mentioning users (used in the [`AutocompleteTextareaComponent`](../components/AutocompleteTextareaComponent.mdx))
4549
*/
@@ -201,6 +205,8 @@ export class CustomTemplatesService {
201205
/**
202206
* The template used for displaying the delivered state of the message inside the [message component](../components/MessageComponent.mdx)
203207
*
208+
* Displayed for the last message sent by the current user, if the message isn't yet read by anyone
209+
*
204210
* For code examples to the different customizations see our [customizations example application](https://github.com/GetStream/stream-chat-angular/tree/master/projects/customizations-example), specifically the [AppComponent](https://github.com/GetStream/stream-chat-angular/tree/master/projects/customizations-example/src/app) (see [README](https://github.com/GetStream/stream-chat-angular/blob/master/README.md#customization-examples) for instructions on how to start the application).
205211
*/
206212
deliveredStatusTemplate$ = new BehaviorSubject<
@@ -209,6 +215,8 @@ export class CustomTemplatesService {
209215
/**
210216
* The template used for displaying the sending state of the message inside the [message component](../components/MessageComponent.mdx)
211217
*
218+
* Displayed for the last message sent by the current user, if the message is currently being sent
219+
*
212220
* For code examples to the different customizations see our [customizations example application](https://github.com/GetStream/stream-chat-angular/tree/master/projects/customizations-example), specifically the [AppComponent](https://github.com/GetStream/stream-chat-angular/tree/master/projects/customizations-example/src/app) (see [README](https://github.com/GetStream/stream-chat-angular/blob/master/README.md#customization-examples) for instructions on how to start the application).
213221
*/
214222
sendingStatusTemplate$ = new BehaviorSubject<
@@ -217,11 +225,21 @@ export class CustomTemplatesService {
217225
/**
218226
* The template used for displaying the sent state of the message inside the [message component](../components/MessageComponent.mdx)
219227
*
228+
* Displayed for the last message sent by the current user, if the message is read at least by one user
229+
*
220230
* For code examples to the different customizations see our [customizations example application](https://github.com/GetStream/stream-chat-angular/tree/master/projects/customizations-example), specifically the [AppComponent](https://github.com/GetStream/stream-chat-angular/tree/master/projects/customizations-example/src/app) (see [README](https://github.com/GetStream/stream-chat-angular/blob/master/README.md#customization-examples) for instructions on how to start the application).
221231
*/
222232
readStatusTemplate$ = new BehaviorSubject<
223233
TemplateRef<ReadStatusContext> | undefined
224234
>(undefined);
235+
/**
236+
* Template to display custom metadata inside [message component](../components/MessageComponent.mdx)
237+
*
238+
* For code examples to the different customizations see our [customizations example application](https://github.com/GetStream/stream-chat-angular/tree/master/projects/customizations-example), specifically the [AppComponent](https://github.com/GetStream/stream-chat-angular/tree/master/projects/customizations-example/src/app) (see [README](https://github.com/GetStream/stream-chat-angular/blob/master/README.md#customization-examples) for instructions on how to start the application).
239+
*/
240+
customMessageMetadataTemplate$ = new BehaviorSubject<
241+
TemplateRef<CustomMetadataContext<T>> | undefined
242+
>(undefined);
225243
/**
226244
* The template used to display additional information about a channel under the channel name inside the [channel header component](../components/ChannelHeaderComponent.mdx)
227245
*

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,18 @@
440440
streamChat.See translation
441441
</button>
442442
</div>
443+
<ng-container
444+
*ngIf="customTemplatesService.customMessageMetadataTemplate$ | async"
445+
>
446+
<div class="str-chat__custom-message-metadata">
447+
<ng-container
448+
*ngTemplateOutlet="
449+
(customTemplatesService.customMessageMetadataTemplate$ | async)!;
450+
context: getMessageMetadataContext()
451+
"
452+
></ng-container>
453+
</div>
454+
</ng-container>
443455
<div
444456
class="
445457
str-chat__message-data

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import {
2727
ReadStatusContext,
2828
CustomMessageActionItem,
2929
SystemMessageContext,
30+
CustomMetadataContext,
3031
} from '../types';
3132
import emojiRegex from 'emoji-regex';
3233
import { Subscription } from 'rxjs';
@@ -367,6 +368,12 @@ export class MessageComponent
367368
};
368369
}
369370

371+
getMessageMetadataContext(): CustomMetadataContext {
372+
return {
373+
message: this.message!,
374+
};
375+
}
376+
370377
jumpToMessage(messageId: string, parentMessageId?: string) {
371378
void this.channelService.jumpToMessage(messageId, parentMessageId);
372379
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,12 @@ export type SendingStatusContext = {
339339
message: StreamMessage;
340340
};
341341

342+
export type CustomMetadataContext<
343+
T extends DefaultStreamChatGenerics = DefaultStreamChatGenerics
344+
> = {
345+
message: StreamMessage<T>;
346+
};
347+
342348
export type ReadStatusContext = {
343349
message: StreamMessage;
344350
readByText: string;

0 commit comments

Comments
 (0)