Skip to content

Commit 56eca7f

Browse files
committed
(props) add RoomId prop to load a specifc room
1 parent 2f033d9 commit 56eca7f

File tree

3 files changed

+36
-18
lines changed

3 files changed

+36
-18
lines changed

README.md

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -87,27 +87,30 @@ You can import it as a custom component:
8787
| currentUserId (1) | [String, Number] | true | - |
8888
| rooms | Array | - | [ ] |
8989
| loadingRooms (2) | Boolean | - | false |
90+
| roomId (3) | [String, Number] | - | null |
9091
| messages | Array | - | [ ] |
91-
| messagesLoaded (3) | Boolean | - | false |
92-
| menuActions (4) | Array | - | [ ] |
93-
| messageActions (5) | Array | - | (4) |
92+
| messagesLoaded (4) | Boolean | - | false |
93+
| menuActions (5) | Array | - | [ ] |
94+
| messageActions (6) | Array | - | (4) |
9495
| showAddRoom | Boolean | - | true |
9596
| showFiles | Boolean | - | true |
9697
| showEmojis | Boolean | - | true |
9798
| showReactionEmojis | Boolean | - | true |
98-
| textMessages (6) | Object | - | null |
99-
| responsiveBreakpoint (7) | Number | - | 900 |
100-
| singleRoom (8) | Number | - | false |
101-
| theme (9) | Sring | - | light |
102-
| styles (10) | Object | - | (10) |
99+
| textMessages (7) | Object | - | null |
100+
| responsiveBreakpoint (8) | Number | - | 900 |
101+
| singleRoom (9) | Number | - | false |
102+
| theme (10) | Sring | - | light |
103+
| styles (11) | Object | - | (10) |
103104

104105
(1) `currentUserId` is required to display UI and trigger actions according to the user using the chat (ex: messages position on the right, etc.)
105106

106107
(2) `loadingRooms` can be used to show/hide a spinner icon while rooms are loading
107108

108-
(3) `messagesLoaded` must be manually set to `true` when all messages of a conversation have been loaded. Meaning the user cannot scroll on top anymore
109+
(3) `roomId` can be used to load a specific room at any time
109110

110-
(4) `menuActions` can be used to display your own buttons when clicking the vertical dots icon inside a room.<br>
111+
(4) `messagesLoaded` must be manually set to `true` when all messages of a conversation have been loaded. Meaning the user cannot scroll on top anymore
112+
113+
(5) `menuActions` can be used to display your own buttons when clicking the vertical dots icon inside a room.<br>
111114
You can then use the [menuActionHandler](#events-api) event to call your own action after clicking a button. Ex:
112115

113116
```javascript
@@ -127,7 +130,7 @@ menuActions="[
127130
]"
128131
```
129132

130-
(5) `messageActions` can be used to display your own buttons when clicking the dropdown icon inside a message.<br>
133+
(6) `messageActions` can be used to display your own buttons when clicking the dropdown icon inside a message.<br>
131134
You can then use the [messageActionHandler](#events-api) event to call your own action after clicking a button. Ex:
132135

133136
```javascript
@@ -167,7 +170,7 @@ messageActions="[
167170
]"
168171
```
169172

170-
(6) `textMessages` can be used to replace default texts. Ex:
173+
(7) `textMessages` can be used to replace default texts. Ex:
171174

172175
```javascript
173176
textMessages="{
@@ -180,13 +183,13 @@ textMessages="{
180183
}"
181184
```
182185

183-
(7) `responsiveBreakpoint` can be used to collapse the rooms list on the left when then viewport size goes below the specified width.
186+
(8) `responsiveBreakpoint` can be used to collapse the rooms list on the left when then viewport size goes below the specified width.
184187

185-
(8) `singleRoom` can be used if you never want to show the rooms list on the left. You still need to pass the `rooms` prop as an array with a single element.
188+
(9) `singleRoom` can be used if you never want to show the rooms list on the left. You still need to pass the `rooms` prop as an array with a single element.
186189

187-
(9) `theme` can be used to change the chat theme. Currently, only `light` and `dark` are available.
190+
(10) `theme` can be used to change the chat theme. Currently, only `light` and `dark` are available.
188191

189-
(10) `styles` can be used to customize your own theme. Ex:
192+
(11) `styles` can be used to customize your own theme. Ex:
190193

191194
```javascript
192195
styles="{

src/ChatWindow/ChatWindow.vue

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ export default {
7575
currentUserId: { type: [String, Number], default: '' },
7676
rooms: { type: Array, default: () => [] },
7777
loadingRooms: { type: Boolean, default: false },
78+
roomId: { type: [String, Number], default: null },
7879
messages: { type: Array, default: () => [] },
7980
messagesLoaded: { type: Boolean, default: false },
8081
menuActions: { type: Array, default: () => [] },
@@ -104,7 +105,19 @@ export default {
104105
watch: {
105106
rooms(newVal, oldVal) {
106107
if (newVal[0] && newVal.length !== oldVal.length) {
107-
this.fetchRoom({ room: newVal[0] })
108+
if (this.roomId) {
109+
const room = newVal.find(r => r.roomId === this.roomId)
110+
this.fetchRoom({ room })
111+
} else {
112+
this.fetchRoom({ room: newVal[0] })
113+
}
114+
}
115+
},
116+
117+
roomId(val) {
118+
if (!this.loadingRooms && this.rooms && this.rooms.length) {
119+
const room = this.rooms.find(r => r.roomId === val)
120+
this.fetchRoom({ room })
108121
}
109122
},
110123

src/ChatWindow/RoomsList.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,10 @@ export default {
9999
100100
watch: {
101101
rooms(val) {
102-
if (val[0]) this.selectedRoomId = val[0].roomId
103102
this.filteredRooms = val
103+
},
104+
room(val) {
105+
if (val) this.selectedRoomId = val.roomId
104106
}
105107
},
106108

0 commit comments

Comments
 (0)