Skip to content

Commit

Permalink
fix(channel-web): fix switching user language (#5753)
Browse files Browse the repository at this point in the history
  • Loading branch information
laurentlp committed Dec 13, 2021
1 parent dac5e3e commit 5ccebcf
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion modules/builtin/src/actions/switchLanguage.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
async function getVisitorId(userId) {
const rows = await bp.database('web_user_map').where({ userId })
if (rows && rows.length) {
return rows[0] && rows[0].visitorId
}
}

/**
* Update user language
* @title Update user language
Expand All @@ -7,7 +14,8 @@
*/
const switchLanguage = async language => {
event.state.user.language = language
bp.realtime.sendPayload(bp.RealTimePayload.forVisitor(event.target, 'webchat.data', { payload: { language } }))
const visitorId = await getVisitorId(event.target)
bp.realtime.sendPayload(bp.RealTimePayload.forVisitor(visitorId, 'webchat.data', { payload: { language } }))
await event.setFlag(bp.IO.WellKnownFlags.FORCE_PERSIST_STATE, true)
}

Expand Down

0 comments on commit 5ccebcf

Please sign in to comment.