Upgraded Clive to new room user ID data.
This commit is contained in:
parent
a45d00c105
commit
b9be447dba
21
src/schat.js
21
src/schat.js
|
@ -60,8 +60,27 @@ async function onRooms({ rooms }, bot) {
|
||||||
const usersRes = await bhttp.get(`${config.api}/room/${rooms.map((room) => room.id).join(',')}/users`);
|
const usersRes = await bhttp.get(`${config.api}/room/${rooms.map((room) => room.id).join(',')}/users`);
|
||||||
const users = usersRes.body;
|
const users = usersRes.body;
|
||||||
|
|
||||||
|
const userIdsByRoom = Object.values(users).reduce((acc, user) => {
|
||||||
|
user.sharedRooms.forEach((roomId) => {
|
||||||
|
if (!acc[roomId]) {
|
||||||
|
acc[roomId] = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
acc[roomId].push(user.id);
|
||||||
|
});
|
||||||
|
|
||||||
|
return acc;
|
||||||
|
}, {});
|
||||||
|
|
||||||
/* eslint-disable no-param-reassign */
|
/* eslint-disable no-param-reassign */
|
||||||
bot.rooms = rooms.reduce((acc, room) => ({ ...acc, [room.id]: room }), {});
|
bot.rooms = rooms.reduce((acc, room) => ({
|
||||||
|
...acc,
|
||||||
|
[room.id]: {
|
||||||
|
...room,
|
||||||
|
userIds: userIdsByRoom[room.id],
|
||||||
|
},
|
||||||
|
}), {});
|
||||||
|
|
||||||
bot.users = { ...bot.users, ...users };
|
bot.users = { ...bot.users, ...users };
|
||||||
/* eslint-enable no-param-reassign */
|
/* eslint-enable no-param-reassign */
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue