Skip to content

Commit 7601116

Browse files
authored
Merge pull request #250 from GetStream/stream-chat-v6
Stream chat v6
2 parents da0ebd1 + 6547640 commit 7601116

30 files changed

+571
-328
lines changed

docusaurus/docs/Angular/basics/upgrade-v2.mdx

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,15 @@ id: upgrade-v2
33
title: Upgrade from v2
44
---
55

6+
## About v3
7+
8+
This version's main focus was to enhance the customizability of the SDK, the two main features are:
9+
10+
- there are many new customization points where you can provide your own template to override the default UI - our [customization guide](../concepts/customization.mdx) covers this topic in detail
11+
- you can take advantage of TypeScript generics to define custom fields for messages, message reactions, attachments, commands, channels or events - our [generics guide](../concepts/generics.mdx) explain this topic in more details
12+
13+
Below you can find the list of breaking changes and instructions on how to update your code.
14+
615
## Peer dependencies
716

817
### stream-chat-css
@@ -19,6 +28,21 @@ Or this if you were using CSS:
1928

2029
It's still possible to individually import stylesheets you just have to replace the `~@stream-io/stream-chat-css/dist` prefix with `~stream-chat-angular/src/assets/styles`.
2130

31+
### stream-chat
32+
33+
Upgrade to stream-chat `^6.2.0`.
34+
35+
You might need to update your code if you created custom components/services that used `stream-chat` in your application.
36+
37+
The biggest change is that generic parameters were refactored into a single generic parameter, this has two major implications:
38+
39+
- If you used generic parameters for handling messages, message reactions, attachments, commands, channels or events you have to change those generic parameters, the SDK uses the [`DefaultStreamChatGenerics`](https://github.com/GetStream/stream-chat-angular/blob/master/projects/stream-chat-angular/src/lib/types.ts) parameter instead of the individual `DefaultAttachmentType`, `DefaultChannelType`, `DefaultCommandType`, `DefaultEventType` `DefaultMessageType`, `DefaultReactionType` and `DefaultUserType` parameters.
40+
- If you are interacting with the `ChannelService` or `ChatClientService` you'll have to provide the [`DefaultStreamChatGenerics`](https://github.com/GetStream/stream-chat-angular/blob/master/projects/stream-chat-angular/src/lib/types.ts) parameter (or a descended) for message reactions, attachments, commands, channels or events (you don't need to provide it for messages as it's already part of the [`StreamMessage`](https://github.com/GetStream/stream-chat-angular/blob/master/projects/stream-chat-angular/src/lib/types.ts) class)
41+
42+
Our [generics guide](../concepts/generics.mdx) explains this topic in more details.
43+
44+
You can find the full list of breaking changes in stream-chat [v5](https://github.com/GetStream/stream-chat-js/releases/tag/v5.0.0) and [v6](https://github.com/GetStream/stream-chat-js/releases/tag/v6.0.0) on GitHub.
45+
2246
## Inputs removed in favor of channel capabilities
2347

2448
The following inputs are removed:
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
---
2+
id: generics
3+
title: Generics
4+
---
5+
6+
The [`stream-chat-js`](https://github.com/GetStream/stream-chat-js) library takes advantage of [TypeScript generics](https://www.typescriptlang.org/docs/handbook/2/generics.html) to make it possible to define custom fileds on the following entities:
7+
8+
1. [`Attachment`](https://github.com/GetStream/stream-chat-js/blob/master/src/types.ts)
9+
2. [`ChannelResponse`](https://github.com/GetStream/stream-chat-js/blob/master/src/types.ts)
10+
3. [`CommandVariants`](https://github.com/GetStream/stream-chat-js/blob/master/src/types.ts)
11+
4. [`Event`](https://github.com/GetStream/stream-chat-js/blob/master/src/types.ts)
12+
5. [`MessageBase`](https://github.com/GetStream/stream-chat-js/blob/master/src/types.ts)
13+
6. [`Reaction`](https://github.com/GetStream/stream-chat-js/blob/master/src/types.ts)
14+
7. [`User`](https://github.com/GetStream/stream-chat-js/blob/master/src/types.ts)
15+
16+
Those 7 overrides are combined to a single generic parameter called [`DefaultGenerics`](https://github.com/GetStream/stream-chat-js/blob/master/src/types.ts).
17+
18+
The Angular SDK extends the `DefaultGenerics` with custom fields creating the [`DefaultStreamChatGenerics`](https://github.com/GetStream/stream-chat-angular/blob/master/projects/stream-chat-angular/src/lib/types.ts) type.
19+
20+
You can further extend the `DefaultStreamChatGenerics` type with your own custom fields, both the [`ChatClientService`](../services/ChatClientService.mdx) and [`ChannelService`](../services/ChannelService.mdx) accepts a generic parameter.
21+
22+
Here is an example about custom fields with generics:
23+
24+
```typescript
25+
import { Component, OnInit } from "@angular/core";
26+
import {
27+
ChatClientService,
28+
ChannelService,
29+
StreamI18nService,
30+
DefaultStreamChatGenerics,
31+
} from "stream-chat-angular";
32+
import { environment } from "../environments/environment";
33+
34+
type MyStreamGenerics = DefaultStreamChatGenerics & {
35+
attachmentType: { lat?: string; lon?: string };
36+
channelType: {
37+
color: string;
38+
topic: "gardening" | "cats" | "f1";
39+
};
40+
userType: {
41+
nickname: string;
42+
};
43+
messageType: {
44+
isSecret: boolean;
45+
};
46+
reactionType: {
47+
onlyVisibleToSender: boolean;
48+
};
49+
};
50+
51+
@Component({
52+
selector: "app-root",
53+
templateUrl: "./app.component.html",
54+
styleUrls: ["./app.component.scss"],
55+
})
56+
export class AppComponent implements OnInit {
57+
constructor(
58+
private chatService: ChatClientService<MyStreamGenerics>,
59+
private channelService: ChannelService<MyStreamGenerics>,
60+
private streamI18nService: StreamI18nService
61+
) {
62+
void this.chatService.init(
63+
environment.apiKey,
64+
{ id: environment.userId, nickname: "Zizi" },
65+
environment.userToken
66+
);
67+
this.streamI18nService.setTranslation();
68+
}
69+
70+
async ngOnInit() {
71+
await this.channelService.init({
72+
type: "messaging",
73+
topic: "cats",
74+
});
75+
const channel = this.chatService.chatClient.channel(
76+
"messaging",
77+
"cat-photos",
78+
{ color: "blue", topic: "cats", name: "The bes cat photos" }
79+
);
80+
81+
await channel.create();
82+
await this.channelService.sendMessage(
83+
"This is a secret message",
84+
[{ type: "geolocation", lat: "40.7128", lon: "74.0060" }],
85+
[],
86+
undefined,
87+
undefined,
88+
{ isSecret: true }
89+
);
90+
const message = channel.state.messages[0];
91+
this.channelService.addReaction(message.id, "like", {
92+
onlyVisibleToSender: true,
93+
});
94+
}
95+
}
96+
```

package-lock.json

Lines changed: 8 additions & 8 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
@@ -101,7 +101,7 @@
101101
"emoji-regex": "^10.0.0",
102102
"pretty-bytes": "^5.6.0",
103103
"rxjs": "~6.6.0",
104-
"stream-chat": "^5.6.0",
104+
"stream-chat": "^6.2.0",
105105
"ts-node": "^10.2.1",
106106
"tslib": "^2.3.0",
107107
"uuidv4": "^6.2.12",

projects/stream-chat-angular/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"@angular/common": "^12.2.0 || ^13.0.0",
1313
"@angular/core": "^12.2.0 || ^13.0.0",
1414
"@ngx-translate/core": "^13.0.0 || ^14.0.0",
15-
"stream-chat": "^4.3.0 || ^5.0.0"
15+
"stream-chat": "^6.2.0"
1616
},
1717
"dependencies": {
1818
"angular-mentions": "^1.4.0",

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import { ChannelService } from '../channel.service';
66
import { ImageLoadService } from '../message-list/image-load.service';
77
import { StreamI18nService } from '../stream-i18n.service';
88
import { AttachmentListComponent } from './attachment-list.component';
9+
import { Attachment } from 'stream-chat';
10+
import { DefaultStreamChatGenerics } from '../types';
911

1012
describe('AttachmentListComponent', () => {
1113
let component: AttachmentListComponent;
@@ -285,7 +287,7 @@ describe('AttachmentListComponent', () => {
285287
frames: '6',
286288
},
287289
},
288-
};
290+
} as any as Attachment<DefaultStreamChatGenerics>;
289291
component.attachments = [attachment];
290292
component.ngOnChanges();
291293
fixture.detectChanges();
@@ -337,7 +339,7 @@ describe('AttachmentListComponent', () => {
337339
frames: '6',
338340
},
339341
},
340-
};
342+
} as any as Attachment<DefaultStreamChatGenerics>;
341343
component.messageId = 'message-id';
342344
component.attachments = [attachment];
343345
component.ngOnChanges();

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
} from '@angular/core';
88
import { Action, Attachment } from 'stream-chat';
99
import { ImageLoadService } from '../message-list/image-load.service';
10-
import { DefaultAttachmentType, ModalContext } from '../types';
10+
import { ModalContext, DefaultStreamChatGenerics } from '../types';
1111
import prettybytes from 'pretty-bytes';
1212
import { isImageAttachment } from '../is-image-attachment';
1313
import { ChannelService } from '../channel.service';
@@ -29,9 +29,9 @@ export class AttachmentListComponent implements OnChanges {
2929
/**
3030
* The attachments to display
3131
*/
32-
@Input() attachments: Attachment<DefaultAttachmentType>[] = [];
33-
orderedAttachments: Attachment<DefaultAttachmentType>[] = [];
34-
imagesToView: Attachment<DefaultAttachmentType>[] = [];
32+
@Input() attachments: Attachment<DefaultStreamChatGenerics>[] = [];
33+
orderedAttachments: Attachment<DefaultStreamChatGenerics>[] = [];
34+
imagesToView: Attachment<DefaultStreamChatGenerics>[] = [];
3535
imagesToViewCurrentIndex = 0;
3636
@ViewChild('modalContent', { static: true })
3737
private modalContent!: TemplateRef<void>;
@@ -80,13 +80,13 @@ export class AttachmentListComponent implements OnChanges {
8080
this.imageLoadService.imageLoad$.next();
8181
}
8282

83-
hasFileSize(attachment: Attachment<DefaultAttachmentType>) {
83+
hasFileSize(attachment: Attachment<DefaultStreamChatGenerics>) {
8484
return (
8585
attachment.file_size && Number.isFinite(Number(attachment.file_size))
8686
);
8787
}
8888

89-
getFileSize(attachment: Attachment<DefaultAttachmentType>) {
89+
getFileSize(attachment: Attachment<DefaultStreamChatGenerics>) {
9090
return prettybytes(Number(attachment.file_size!));
9191
}
9292

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { Channel } from 'stream-chat';
1010
import { ChannelListToggleService } from '../channel-list/channel-list-toggle.service';
1111
import { ChannelService } from '../channel.service';
1212
import { CustomTemplatesService } from '../custom-templates.service';
13-
import { ChannelActionsContext } from '../types';
13+
import { ChannelActionsContext, DefaultStreamChatGenerics } from '../types';
1414

1515
/**
1616
* The `ChannelHeader` component displays the avatar and name of the currently active channel along with member and watcher information. You can read about [the difference between members and watchers](https://getstream.io/chat/docs/javascript/watch_channel/?language=javascript#watchers-vs-members) in the platform documentation. Please note that number of watchers is only displayed if the user has [`connect-events` capability](https://getstream.io/chat/docs/javascript/channel_capabilities/?language=javascript)
@@ -22,7 +22,7 @@ import { ChannelActionsContext } from '../types';
2222
})
2323
export class ChannelHeaderComponent implements OnInit, OnDestroy {
2424
channelActionsTemplate?: TemplateRef<ChannelActionsContext>;
25-
activeChannel: Channel | undefined;
25+
activeChannel: Channel<DefaultStreamChatGenerics> | undefined;
2626
canReceiveConnectEvents: boolean | undefined;
2727
private subscriptions: Subscription[] = [];
2828

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { catchError, map, startWith } from 'rxjs/operators';
1111
import { Channel } from 'stream-chat';
1212
import { ChannelService } from '../channel.service';
1313
import { CustomTemplatesService } from '../custom-templates.service';
14-
import { ChannelPreviewContext } from '../types';
14+
import { ChannelPreviewContext, DefaultStreamChatGenerics } from '../types';
1515
import { ChannelListToggleService } from './channel-list-toggle.service';
1616

1717
/**
@@ -23,7 +23,7 @@ import { ChannelListToggleService } from './channel-list-toggle.service';
2323
styles: [],
2424
})
2525
export class ChannelListComponent implements AfterViewInit, OnDestroy {
26-
channels$: Observable<Channel[] | undefined>;
26+
channels$: Observable<Channel<DefaultStreamChatGenerics>[] | undefined>;
2727
isError$: Observable<boolean>;
2828
isInitializing$: Observable<boolean>;
2929
isLoadingMoreChannels = false;
@@ -70,15 +70,17 @@ export class ChannelListComponent implements AfterViewInit, OnDestroy {
7070
this.isLoadingMoreChannels = false;
7171
}
7272

73-
trackByChannelId(index: number, item: Channel) {
73+
trackByChannelId(index: number, item: Channel<DefaultStreamChatGenerics>) {
7474
return item.cid;
7575
}
7676

7777
channelSelected() {
7878
this.channelListToggleService.channelSelected();
7979
}
8080

81-
getChannelPreviewContext(channel: Channel): ChannelPreviewContext {
81+
getChannelPreviewContext(
82+
channel: Channel<DefaultStreamChatGenerics>
83+
): ChannelPreviewContext<DefaultStreamChatGenerics> {
8284
return {
8385
channel,
8486
};

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
MessageResponse,
88
} from 'stream-chat';
99
import { ChannelService } from '../channel.service';
10+
import { DefaultStreamChatGenerics } from '../types';
1011

1112
/**
1213
* The `ChannelPreview` component displays a channel preview in the channel list, it consists of the image, name and latest message of the channel.
@@ -20,7 +21,7 @@ export class ChannelPreviewComponent implements OnInit, OnDestroy {
2021
/**
2122
* The channel to be displayed
2223
*/
23-
@Input() channel: Channel | undefined;
24+
@Input() channel: Channel<DefaultStreamChatGenerics> | undefined;
2425
isActive = false;
2526
isUnread = false;
2627
latestMessage: string = 'Nothing yet...';

0 commit comments

Comments
 (0)