Skip to content

Commit b52606c

Browse files
authored
Merge pull request #529 from GetStream/custom-message-reactions-ui
feat: allow customizing the message details modal
2 parents 18795eb + 85b506b commit b52606c

File tree

7 files changed

+58
-10
lines changed

7 files changed

+58
-10
lines changed
363 KB
Loading

docusaurus/docs/Angular/components/MessageReactionsComponent.mdx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import MessageReactionsScreenshot from "../assets/message-reactions-screenshot.png";
2+
import MessageReactionsDetailsScreenshot from "../assets/reaction-details.png";
23
import MessageReactionsSelectorScreenshot from "../assets/message-reactions-selector-screenshot.png";
34

45
The `MessageReactions` component displays the reactions of a message, the current user can add and remove reactions. You can read more about [message reactions](https://getstream.io/chat/docs/javascript/send_reaction/?language=javascript) in the platform documentation.
@@ -7,7 +8,11 @@ The `MessageReactions` component displays the reactions of a message, the curren
78

89
<img src={MessageReactionsScreenshot} width="500" />
910

10-
**Example 2** - adding/removing a reaction:
11+
**Example 2** - displaying the reacting users:
12+
13+
<img src={MessageReactionsDetailsScreenshot} width="500" />
14+
15+
**Example 3** - adding/removing a reaction:
1116

1217
<img src={MessageReactionsSelectorScreenshot} width="500" />
1318

@@ -37,9 +42,11 @@ export class CustomMessageComponent {
3742

3843
## Customization
3944

40-
You can override the default reactions using the [`MessageReactionsService`](../services/MessageReactionsService.mdx)
45+
You can override the default reactions using the [`MessageReactionsService`](../services/MessageReactionsService.mdx).
46+
47+
You can provide your own UI for the reaction details using the [`MessageReactionsService`](../services/MessageReactionsService.mdx).
4148

42-
You can provide your own message reactions component by the [`CustomTemplatesService`](../services/CustomTemplatesService.mdx)
49+
You can provide your own message reactions component by the [`CustomTemplatesService`](../services/CustomTemplatesService.mdx).
4350

4451
[//]: # "Start of generated content"
4552
[//]: # "End of generated content"

projects/stream-chat-angular/src/lib/message-reactions.service.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Injectable } from '@angular/core';
2-
import { MessageReactionType } from './types';
2+
import { MessageReactionClickDetails, MessageReactionType } from './types';
33
import { BehaviorSubject } from 'rxjs';
44

55
/**
@@ -23,6 +23,12 @@ export class MessageReactionsService {
2323
wow: '😮',
2424
sad: '😞',
2525
});
26+
/**
27+
* By default the [`MessageReactionsComponent`](../../components/MessageReactionsComponent) will display the reacting users when a reaction is clicked. You can override this with your own UI by providing a custom event handler.
28+
*
29+
* The event handler can retrieve all reactions of a message inside the active channel using the [`channelService.getMessageReactions` method](../../services/ChannelService/#getmessagereactions)
30+
*/
31+
customReactionClickHandler?: (details: MessageReactionClickDetails) => void;
2632

2733
constructor() {}
2834

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
"
1515
[class.str-chat__message-reaction-own]="isOwnReaction(reactionType)"
1616
data-testclass="emoji"
17-
(click)="reactionSelected($event, reactionType)"
18-
(keyup.enter)="reactionSelected($event, reactionType)"
17+
(click)="reactionSelected(reactionType)"
18+
(keyup.enter)="reactionSelected(reactionType)"
1919
>
2020
<span class="emoji str-chat__message-reaction-emoji">
2121
{{ getEmojiByReaction(reactionType) }}&nbsp;

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,27 @@ describe('MessageReactionsComponent', () => {
279279
expect(users.length).toBe(2);
280280
}));
281281

282+
it(`should call custom reaction details handler if that's provided`, () => {
283+
component.messageReactionCounts = {
284+
wow: 3,
285+
sad: 2,
286+
};
287+
component.messageId = 'id';
288+
component.latestReactions = [];
289+
fixture.detectChanges();
290+
const messageReactionsService = TestBed.inject(MessageReactionsService);
291+
const spy = jasmine.createSpy();
292+
messageReactionsService.customReactionClickHandler = spy;
293+
294+
const wowEmoji = queryEmojis()[0];
295+
wowEmoji.click();
296+
297+
expect(spy).toHaveBeenCalledWith({ messageId: 'id', reactionType: 'wow' });
298+
expect(component.selectedReactionType).toBeUndefined();
299+
300+
messageReactionsService.customReactionClickHandler = undefined;
301+
});
302+
282303
it('should handle if message reaction details not loaded', fakeAsync(() => {
283304
component.messageReactionCounts = {
284305
wow: 3,

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

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,13 +116,22 @@ export class MessageReactionsComponent implements AfterViewChecked, OnChanges {
116116
return this.messageReactionsService.reactions[reactionType];
117117
}
118118

119-
reactionSelected(event: Event, reactionType: string) {
120-
event.stopPropagation();
119+
reactionSelected(reactionType: string) {
121120
if (this.themeService.themeVersion === '1') {
122121
return;
123122
}
124-
this.selectedReactionType = reactionType;
125-
void this.fetchAllReactions();
123+
if (!this.messageId) {
124+
return;
125+
}
126+
if (this.messageReactionsService.customReactionClickHandler) {
127+
this.messageReactionsService.customReactionClickHandler({
128+
messageId: this.messageId,
129+
reactionType: reactionType,
130+
});
131+
} else {
132+
this.selectedReactionType = reactionType;
133+
void this.fetchAllReactions();
134+
}
126135
}
127136

128137
getUsersByReaction(reactionType: MessageReactionType) {

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,3 +384,8 @@ export type FiltertNextPageConfiguration<
384384
export type NextPageConfiguration =
385385
| OffsetNextPageConfiguration
386386
| FiltertNextPageConfiguration;
387+
388+
export type MessageReactionClickDetails = {
389+
messageId: string;
390+
reactionType: string;
391+
};

0 commit comments

Comments
 (0)