Skip to content

Commit 3811209

Browse files
committed
refactor: Rename getReadByText to listUsers
1 parent f2fda54 commit 3811209

File tree

6 files changed

+56
-58
lines changed

6 files changed

+56
-58
lines changed

docusaurus/docs/Angular/components/MessageComponent.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ The `Message` component uses the [`parseDate`](https://github.com/GetStream/stre
4646

4747
### Read by
4848

49-
The `Message` component uses the [`getReadByText`](https://github.com/GetStream/stream-chat-angular/tree/master/projects/stream-chat-angular/src/lib/message/read-by-text.ts) utility function to display the list of people who have read a particular message in a user friendly way (for example _Bob, Sophie, Jack, Rose, John and 1 more_).
49+
The `Message` component uses the [`listUsers`](https://github.com/GetStream/stream-chat-angular/tree/master/projects/stream-chat-angular/src/lib/list-users.ts) utility function to display the list of people who have read a particular message in a user friendly way (for example _Bob, Sophie, Jack, Rose, John and 1 more_).
5050

5151
### Loading indicator
5252

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { listUsers } from './list-users';
2+
3+
describe('listUsers', () => {
4+
it('should return the correct result if called with empty array', () => {
5+
expect(listUsers([])).toBe('');
6+
});
7+
8+
it('should return the correct result if called with two users', () => {
9+
expect(
10+
listUsers([
11+
{ id: 'id1', name: 'Sara' },
12+
{ id: 'id2', name: 'Jane' },
13+
])
14+
).toBe('Sara and Jane');
15+
});
16+
17+
it('should return correct result if user has no name, the fallback should be id', () => {
18+
expect(listUsers([{ id: 'id1' }, { id: 'id2', name: 'Jane' }])).toBe(
19+
'id1 and Jane'
20+
);
21+
});
22+
23+
it(`should return the correct result if called with one user`, () => {
24+
expect(listUsers([{ id: 'id2', name: 'Jane' }])).toBe('Jane ');
25+
});
26+
27+
it('should return the correct result if called with more than two users, but less or equal than five', () => {
28+
const readBy = [
29+
{ id: 'id1', name: 'Bob' },
30+
{ id: 'id2', name: 'Sophie' },
31+
{ id: 'id3', name: 'Jack' },
32+
{ id: 'id4', name: 'Rose' },
33+
{ id: 'id5', name: 'John' },
34+
];
35+
36+
expect(listUsers(readBy)).toBe('Bob, Sophie, Jack, John, and Rose');
37+
});
38+
39+
it('should return the correct result if called with more than five users', () => {
40+
const readBy = [
41+
{ id: 'id1', name: 'Bob' },
42+
{ id: 'id2', name: 'Sophie' },
43+
{ id: 'id3', name: 'Jack' },
44+
{ id: 'id4', name: 'Rose' },
45+
{ id: 'id5', name: 'John' },
46+
{ id: 'id6', name: 'Adam' },
47+
];
48+
49+
expect(listUsers(readBy)).toBe('Bob, Sophie, Jack, Rose, John and 1 more');
50+
});
51+
});

projects/stream-chat-angular/src/lib/message/read-by-text.ts renamed to projects/stream-chat-angular/src/lib/list-users.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { UserResponse } from 'stream-chat';
22

3-
export const getReadByText = (users: UserResponse[]) => {
3+
export const listUsers = (users: UserResponse[]) => {
44
let outStr = '';
55

66
const slicedArr = users.map((item) => item.name || item.id).slice(0, 5);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ import {
2323
StreamMessage,
2424
} from '../types';
2525
import { parseDate } from './parse-date';
26-
import { getReadByText } from './read-by-text';
2726
import emojiRegex from 'emoji-regex';
2827
import { Subscription } from 'rxjs';
2928
import { CustomTemplatesService } from '../custom-templates.service';
29+
import { listUsers } from '../list-users';
3030

3131
type MessagePart = {
3232
content: string;
@@ -130,7 +130,7 @@ export class MessageComponent implements OnInit, OnChanges, OnDestroy {
130130
}
131131

132132
get readByText() {
133-
return getReadByText(this.message!.readBy);
133+
return listUsers(this.message!.readBy);
134134
}
135135

136136
get lastReadUser() {

projects/stream-chat-angular/src/lib/message/read-by-text.spec.ts

Lines changed: 0 additions & 53 deletions
This file was deleted.

projects/stream-chat-angular/src/public-api.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export * from './lib/channel-list/channel-list.component';
2121
export * from './lib/channel-list/channel-list-toggle.service';
2222
export * from './lib/message/message.component';
2323
export * from './lib/message/parse-date';
24-
export * from './lib/message/read-by-text';
24+
export * from './lib/list-users';
2525
export * from './lib/message-input/message-input.component';
2626
export * from './lib/message-input/textarea/textarea.component';
2727
export * from './lib/message-input/autocomplete-textarea/autocomplete-textarea.component';

0 commit comments

Comments
 (0)