only remove user once they've left all maps
This commit is contained in:
parent
3759851621
commit
83b58d43d5
2 changed files with 23 additions and 8 deletions
|
@ -16,4 +16,4 @@ signalling(io, stunservers, store)
|
||||||
junto(io, store)
|
junto(io, store)
|
||||||
map(io, store)
|
map(io, store)
|
||||||
|
|
||||||
io.listen(5001)
|
io.listen(8081)
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
const { omit, omitBy, isNil, mapValues } = require('lodash')
|
const { find, omit, isNil, mapValues, values } = require('lodash')
|
||||||
const {
|
const {
|
||||||
JOIN_MAP,
|
JOIN_MAP,
|
||||||
LEAVE_MAP,
|
LEAVE_MAP,
|
||||||
|
@ -9,7 +9,16 @@ const {
|
||||||
const NOT_IN_CONVERSATION = 0
|
const NOT_IN_CONVERSATION = 0
|
||||||
const IN_CONVERSATION = 1
|
const IN_CONVERSATION = 1
|
||||||
|
|
||||||
const addMapperToMap = (map, userId) => { return Object.assign({}, map, { [userId]: NOT_IN_CONVERSATION })}
|
const addMapperToMap = (map, userId) => Object.assign({}, map, { [userId]: NOT_IN_CONVERSATION })
|
||||||
|
const userStillPresent = (userId, liveMaps) => {
|
||||||
|
if (!userId) return false
|
||||||
|
let stillPresent = false
|
||||||
|
const userIdString = userId.toString()
|
||||||
|
values(liveMaps).forEach(presentUsers => {
|
||||||
|
if (find(Object.keys(presentUsers), id => id === userIdString)) stillPresent = true
|
||||||
|
})
|
||||||
|
return stillPresent
|
||||||
|
}
|
||||||
|
|
||||||
const reducer = (state = { connectedPeople: {}, liveMaps: {} }, action) => {
|
const reducer = (state = { connectedPeople: {}, liveMaps: {} }, action) => {
|
||||||
const { type, payload } = action
|
const { type, payload } = action
|
||||||
|
@ -37,10 +46,13 @@ const reducer = (state = { connectedPeople: {}, liveMaps: {} }, action) => {
|
||||||
const newLiveMaps = mapWillEmpty
|
const newLiveMaps = mapWillEmpty
|
||||||
? omit(liveMaps, payload.mapid)
|
? omit(liveMaps, payload.mapid)
|
||||||
: Object.assign({}, liveMaps, { [payload.mapid]: omit(map, payload.userid) })
|
: Object.assign({}, liveMaps, { [payload.mapid]: omit(map, payload.userid) })
|
||||||
|
delete newLiveMaps[undefined]
|
||||||
|
delete newLiveMaps[null]
|
||||||
|
const updateConnectedPeople = userStillPresent(payload.userid, newLiveMaps) ? connectedPeople : omit(connectedPeople, payload.userid)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
connectedPeople: omit(connectedPeople, payload.userid),
|
connectedPeople: updateConnectedPeople,
|
||||||
liveMaps: omitBy(newLiveMaps, isNil)
|
liveMaps: newLiveMaps
|
||||||
}
|
}
|
||||||
case JOIN_CALL:
|
case JOIN_CALL:
|
||||||
// update the user (payload.id is user id) in the given map to be marked in the conversation
|
// update the user (payload.id is user id) in the given map to be marked in the conversation
|
||||||
|
@ -57,15 +69,18 @@ const reducer = (state = { connectedPeople: {}, liveMaps: {} }, action) => {
|
||||||
: Object.assign({}, map, { [payload.userid]: NOT_IN_CONVERSATION })
|
: Object.assign({}, map, { [payload.userid]: NOT_IN_CONVERSATION })
|
||||||
|
|
||||||
return Object.assign({}, state, {
|
return Object.assign({}, state, {
|
||||||
liveMaps: Object.assign({}, liveMaps, { map: newMap })
|
liveMaps: Object.assign({}, liveMaps, { [payload.mapid]: newMap })
|
||||||
})
|
})
|
||||||
case 'DISCONNECT':
|
case 'DISCONNECT':
|
||||||
const mapWithoutUser = omit(map, payload.userid)
|
const mapWithoutUser = omit(map, payload.userid)
|
||||||
const newMapWithoutUser = callWillFinish ? mapValues(mapWithoutUser, () => NOT_IN_CONVERSATION) : mapWithoutUser
|
const newMapWithoutUser = callWillFinish ? mapValues(mapWithoutUser, () => NOT_IN_CONVERSATION) : mapWithoutUser
|
||||||
const newLiveMapsWithoutUser = mapWillEmpty ? omit(liveMaps, payload.mapid) : Object.assign({}, liveMaps, { [payload.mapid]: newMapWithoutUser })
|
const newLiveMapsWithoutUser = mapWillEmpty ? omit(liveMaps, payload.mapid) : Object.assign({}, liveMaps, { [payload.mapid]: newMapWithoutUser })
|
||||||
|
delete newLiveMapsWithoutUser[undefined]
|
||||||
|
delete newLiveMapsWithoutUser[null]
|
||||||
|
const newConnectedPeople = userStillPresent(payload.userid, newLiveMapsWithoutUser) ? connectedPeople : omit(connectedPeople, payload.userid)
|
||||||
return {
|
return {
|
||||||
connectedPeople: omit(connectedPeople, payload.userid),
|
connectedPeople: newConnectedPeople,
|
||||||
liveMaps: omitBy(newLiveMapsWithoutUser, isNil)
|
liveMaps: newLiveMapsWithoutUser
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
return state
|
return state
|
||||||
|
|
Loading…
Reference in a new issue