Skip to content

Commit ca8a85a

Browse files
committed
Updated Integration section
1 parent fe26d92 commit ca8a85a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+666
-331
lines changed

docs.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2379,7 +2379,10 @@
23792379
"group": "Getting Started",
23802380
"pages": [
23812381
"ui-kit/angular/v5/quickstart",
2382-
"ui-kit/angular/v5/integration"
2382+
"ui-kit/angular/v5/integration",
2383+
"ui-kit/angular/v5/angular-conversation",
2384+
"ui-kit/angular/v5/angular-one-to-one-chat",
2385+
"ui-kit/angular/v5/angular-tab-based-chat"
23832386
]
23842387
},
23852388
{
Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
---
2+
title: "Conversation List + Message View"
3+
sidebarTitle: "Conversation List + Message View"
4+
description: "Build a two-panel conversation list + message view layout in Angular with CometChat UI Kit."
5+
---
6+
7+
<Accordion title="AI Integration Quick Reference">
8+
9+
| Field | Value |
10+
| --- | --- |
11+
| Package | `@cometchat/chat-uikit-angular` |
12+
| Framework | Angular |
13+
| Components | `CometChatConversationsComponent`, `CometChatMessageHeaderComponent`, `CometChatMessageListComponent`, `CometChatMessageComposerComponent` |
14+
| Layout | Two-panel — conversation list (left) + message view (right) |
15+
| Prerequisite | Complete [Angular Integration](/ui-kit/angular/v5/integration) Steps 1–5 first |
16+
| Pattern | WhatsApp Web, Slack, Microsoft Teams |
17+
18+
</Accordion>
19+
20+
This guide builds a two-panel chat layout — conversation list on the left, messages on the right. Users tap a conversation to open it.
21+
22+
This assumes you've already completed [Angular Integration](/ui-kit/angular/v5/integration) (project created, UI Kit installed, init + login working, CSS imported).
23+
24+
<Frame>
25+
<img src="/images/e6411d13-chat_experience_sidebar_message-35c431d8bf694e5690e4e0f3a74165af.png" />
26+
</Frame>
27+
28+
---
29+
30+
## What You're Building
31+
32+
Three sections working together:
33+
34+
1. **Sidebar (conversation list)** — shows all active conversations (users and groups)
35+
2. **Message view** — displays chat messages for the selected conversation in real time
36+
3. **Message composer** — text input with support for media, emojis, and reactions
37+
38+
---
39+
40+
## Step 1 — Update AppComponent
41+
42+
Wire the conversation list and message components together in your root component. The UIKit's `ChatStateService` handles all the wiring — when a user clicks a conversation, `cometchat-conversations` updates the service, and the message components automatically react to the change.
43+
44+
```ts title="src/app/app.component.ts" expandable
45+
import { Component, inject, OnInit } from "@angular/core";
46+
import {
47+
CometChatUIKit,
48+
CometChatConversationsComponent,
49+
CometChatMessageHeaderComponent,
50+
CometChatMessageListComponent,
51+
CometChatMessageComposerComponent,
52+
ChatStateService,
53+
} from "@cometchat/chat-uikit-angular";
54+
import { CometChat } from "@cometchat/chat-sdk-javascript";
55+
56+
@Component({
57+
selector: "app-root",
58+
standalone: true,
59+
imports: [
60+
CometChatConversationsComponent,
61+
CometChatMessageHeaderComponent,
62+
CometChatMessageListComponent,
63+
CometChatMessageComposerComponent,
64+
],
65+
template: `
66+
@if (isLoggedIn) {
67+
<div class="chat-layout">
68+
<div class="sidebar">
69+
<cometchat-conversations></cometchat-conversations>
70+
</div>
71+
@if (chatStateService.activeUser() || chatStateService.activeGroup()) {
72+
<div class="chat-window">
73+
<cometchat-message-header></cometchat-message-header>
74+
<cometchat-message-list></cometchat-message-list>
75+
<cometchat-message-composer></cometchat-message-composer>
76+
</div>
77+
} @else {
78+
<div class="empty-conversation">
79+
Select a conversation to start chatting
80+
</div>
81+
}
82+
</div>
83+
} @else {
84+
<p>Loading...</p>
85+
}
86+
`,
87+
styles: `
88+
:host {
89+
display: flex;
90+
height: 100vh;
91+
width: 100vw;
92+
}
93+
.chat-layout {
94+
display: flex;
95+
width: 100%;
96+
height: 100%;
97+
}
98+
.sidebar {
99+
width: 360px;
100+
border-right: 1px solid #e0e0e0;
101+
}
102+
.chat-window {
103+
flex: 1;
104+
display: flex;
105+
flex-direction: column;
106+
}
107+
.empty-conversation {
108+
height: 100vh;
109+
width: 100%;
110+
display: flex;
111+
justify-content: center;
112+
align-items: center;
113+
background: var(--cometchat-background-color-03, #F5F5F5);
114+
color: var(--cometchat-text-color-secondary, #727272);
115+
font: var(--cometchat-font-body-regular, 400 14px Roboto);
116+
}
117+
`,
118+
})
119+
export class AppComponent implements OnInit {
120+
chatStateService = inject(ChatStateService);
121+
isLoggedIn = false;
122+
123+
ngOnInit(): void {
124+
CometChatUIKit.getLoggedinUser().then((user: CometChat.User | null) => {
125+
if (!user) {
126+
CometChatUIKit.login("cometchat-uid-1")
127+
.then(() => (this.isLoggedIn = true))
128+
.catch(console.log);
129+
} else {
130+
this.isLoggedIn = true;
131+
}
132+
});
133+
}
134+
}
135+
```
136+
137+
How it works:
138+
- `cometchat-conversations` calls `ChatStateService.setActiveConversation()` automatically when a conversation is clicked.
139+
- `setActiveConversation()` extracts the `User` or `Group` and sets it as the active entity, enforcing mutual exclusivity (setting a user clears the group, and vice versa).
140+
- `cometchat-message-header`, `cometchat-message-list`, and `cometchat-message-composer` auto-subscribe to `ChatStateService` — no `[user]` or `[group]` bindings needed.
141+
- The `@if` block reads `chatStateService.activeUser()` and `chatStateService.activeGroup()` signals to show the chat window or the empty state.
142+
143+
<Tip>
144+
This is the recommended approach for most applications. For advanced use cases like multi-panel layouts
145+
where each panel needs independent state, you can pass `[user]` or `[group]` via `@Input()` bindings
146+
to override the service. See the [State Management guide](/ui-kit/angular/v5/guides/state-management) for details.
147+
</Tip>
148+
149+
---
150+
151+
## Step 2 — Run the Project
152+
153+
```bash
154+
ng serve
155+
```
156+
157+
You should see the conversation list on the left. Tap any conversation to load messages on the right.
158+
159+
---
160+
161+
## Next Steps
162+
163+
<CardGroup cols={2}>
164+
<Card title="Theming" icon="paintbrush" href="/ui-kit/angular/v5/customization/theming">
165+
Customize colors, fonts, and styles to match your brand
166+
</Card>
167+
<Card title="Components Overview" icon="grid-2" href="/ui-kit/angular/v5/components/overview">
168+
Browse all prebuilt UI components
169+
</Card>
170+
<Card title="Angular Integration" icon="angular" href="/ui-kit/angular/v5/integration">
171+
Back to the main setup guide
172+
</Card>
173+
<Card title="Core Features" icon="comments" href="/ui-kit/angular/v5/core-features">
174+
Chat features included out of the box
175+
</Card>
176+
</CardGroup>
Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
---
2+
title: "One-to-One / Group Chat"
3+
sidebarTitle: "One-to-One / Group Chat"
4+
description: "Build a focused one-to-one or group chat experience in Angular with CometChat UI Kit."
5+
---
6+
7+
<Accordion title="AI Integration Quick Reference">
8+
9+
| Field | Value |
10+
| --- | --- |
11+
| Package | `@cometchat/chat-uikit-angular` |
12+
| Framework | Angular |
13+
| Components | `CometChatMessageHeaderComponent`, `CometChatMessageListComponent`, `CometChatMessageComposerComponent` |
14+
| Layout | Single chat window — no sidebar, no conversation list |
15+
| Prerequisite | Complete [Angular Integration](/ui-kit/angular/v5/integration) Steps 1–5 first |
16+
| Pattern | Support chat, embedded widgets, focused messaging |
17+
18+
</Accordion>
19+
20+
This guide builds a single chat window — no sidebar, no conversation list. Users go directly into a one-to-one or group chat. Good for support chat, embedded widgets, or any focused messaging experience.
21+
22+
This assumes you've already completed [Angular Integration](/ui-kit/angular/v5/integration) (project created, UI Kit installed, init + login working, CSS imported).
23+
24+
<Frame>
25+
<img src="/images/4d640baf-chat_experience_one_on_one-db9d6d7716241c59bb026625b05019fe.png" />
26+
</Frame>
27+
28+
---
29+
30+
## What You're Building
31+
32+
Three components stacked vertically:
33+
34+
1. **Chat header** — displays recipient name, avatar, online status, and optional call buttons
35+
2. **Message list** — real-time chat history with scrolling
36+
3. **Message composer** — text input with media, emojis, and reactions
37+
38+
Everything goes in `AppComponent` — no extra files needed.
39+
40+
---
41+
42+
## Step 1 — Update AppComponent
43+
44+
The app fetches a user (or group) on mount, sets it as the active entity via `ChatStateService`, and renders the three message components. The components auto-subscribe to the service — no prop passing needed.
45+
46+
```ts title="src/app/app.component.ts" expandable
47+
import { Component, inject, OnInit } from "@angular/core";
48+
import {
49+
CometChatUIKit,
50+
CometChatMessageHeaderComponent,
51+
CometChatMessageListComponent,
52+
CometChatMessageComposerComponent,
53+
ChatStateService,
54+
} from "@cometchat/chat-uikit-angular";
55+
import { CometChat } from "@cometchat/chat-sdk-javascript";
56+
57+
@Component({
58+
selector: "app-root",
59+
standalone: true,
60+
imports: [
61+
CometChatMessageHeaderComponent,
62+
CometChatMessageListComponent,
63+
CometChatMessageComposerComponent,
64+
],
65+
template: `
66+
@if (chatStateService.activeUser() || chatStateService.activeGroup()) {
67+
<div class="chat-window">
68+
<cometchat-message-header></cometchat-message-header>
69+
<cometchat-message-list></cometchat-message-list>
70+
<cometchat-message-composer></cometchat-message-composer>
71+
</div>
72+
} @else {
73+
<div class="empty-conversation">
74+
Loading chat...
75+
</div>
76+
}
77+
`,
78+
styles: `
79+
.chat-window {
80+
display: flex;
81+
flex-direction: column;
82+
height: 100vh;
83+
width: 100vw;
84+
}
85+
.empty-conversation {
86+
height: 100vh;
87+
width: 100%;
88+
display: flex;
89+
justify-content: center;
90+
align-items: center;
91+
background: var(--cometchat-background-color-03, #F5F5F5);
92+
color: var(--cometchat-text-color-secondary, #727272);
93+
font: var(--cometchat-font-body-regular, 400 14px Roboto);
94+
}
95+
.cometchat .cometchat-message-composer {
96+
border-radius: 0px;
97+
}
98+
`,
99+
})
100+
export class AppComponent implements OnInit {
101+
chatStateService = inject(ChatStateService);
102+
103+
ngOnInit(): void {
104+
CometChatUIKit.getLoggedinUser().then((user: CometChat.User | null) => {
105+
if (!user) {
106+
CometChatUIKit.login("cometchat-uid-1")
107+
.then(() => this.loadUser())
108+
.catch(console.log);
109+
} else {
110+
this.loadUser();
111+
}
112+
});
113+
}
114+
115+
private loadUser(): void {
116+
// Fetch the user whose chat you want to load
117+
const UID = "cometchat-uid-2";
118+
119+
CometChat.getUser(UID).then(
120+
(user: CometChat.User) => {
121+
this.chatStateService.setActiveUser(user);
122+
},
123+
(error: CometChat.CometChatException) => {
124+
console.error("User fetch failed:", error);
125+
}
126+
);
127+
128+
// To load a group chat instead, uncomment below:
129+
// const GUID = "GUID";
130+
// CometChat.getGroup(GUID).then(
131+
// (group: CometChat.Group) => {
132+
// this.chatStateService.setActiveGroup(group);
133+
// },
134+
// (error: CometChat.CometChatException) => {
135+
// console.error("Group fetch failed:", error);
136+
// }
137+
// );
138+
}
139+
}
140+
```
141+
142+
Key points:
143+
- `CometChat.getUser(UID)` fetches the user object from the SDK — you need a real user object, not a manually constructed one.
144+
- `chatStateService.setActiveUser(user)` sets the active entity — all message components auto-subscribe and render accordingly.
145+
- Setting a user automatically clears any active group (mutual exclusivity).
146+
147+
---
148+
149+
## Switching Between User and Group Chat
150+
151+
To load a group chat instead of one-to-one, replace the `setActiveUser` call with `setActiveGroup`:
152+
153+
```ts highlight={1}
154+
const GUID = "GUID"; // Replace with your actual Group ID
155+
156+
CometChat.getGroup(GUID).then(
157+
(group: CometChat.Group) => {
158+
this.chatStateService.setActiveGroup(group);
159+
},
160+
(error: CometChat.CometChatException) => {
161+
console.error("Failed to fetch group:", error);
162+
}
163+
);
164+
```
165+
166+
You can also determine this dynamically — for example, based on a route parameter or a selection from another part of your app.
167+
168+
---
169+
170+
## Step 2 — Run the Project
171+
172+
```bash
173+
ng serve
174+
```
175+
176+
You should see the chat window load with the conversation for the UID you set.
177+
178+
---
179+
180+
## Next Steps
181+
182+
<CardGroup cols={2}>
183+
<Card title="Theming" icon="paintbrush" href="/ui-kit/angular/v5/customization/theming">
184+
Customize colors, fonts, and styles to match your brand
185+
</Card>
186+
<Card title="Components Overview" icon="grid-2" href="/ui-kit/angular/v5/components/overview">
187+
Browse all prebuilt UI components
188+
</Card>
189+
<Card title="Angular Integration" icon="angular" href="/ui-kit/angular/v5/integration">
190+
Back to the main setup guide
191+
</Card>
192+
<Card title="Core Features" icon="comments" href="/ui-kit/angular/v5/core-features">
193+
Chat features included out of the box
194+
</Card>
195+
</CardGroup>

0 commit comments

Comments
 (0)