Skip to content
This repository has been archived by the owner on Jun 30, 2022. It is now read-only.

Commit

Permalink
remove reloadConfig() call while visitor change
Browse files Browse the repository at this point in the history
  • Loading branch information
murtaza98 committed Aug 18, 2020
1 parent 4471825 commit ccbfc61
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 37 deletions.
2 changes: 1 addition & 1 deletion size-plugin.json

Large diffs are not rendered by default.

34 changes: 0 additions & 34 deletions src/lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,40 +38,6 @@ export const loadConfig = async () => {
});
};

export const reloadConfig = async () => {
const {
token,
room: { _id: roomId = null } = {},
messages,
typing,
} = store.state;

Livechat.credentials.token = token;

const {
agent,
room,
guest: user,
resources: { sound: src = null } = {},
queueInfo,
...config
} = await Livechat.config({
token,
...roomId && { roomId },
});

await store.setState({
config,
agent: agent && agent.hiddenInfo ? { hiddenInfo: true } : agent, // TODO: revert it when the API is updated
room,
user,
queueInfo,
sound: { src, enabled: true, play: false },
messages,
typing,
});
};

export const processUnread = async () => {
const { minimized, visible, messages } = store.state;
if (minimized || !visible) {
Expand Down
8 changes: 6 additions & 2 deletions src/lib/room.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { setCookies, upsert, canRenderMessage } from '../components/helpers';
import { store } from '../store';
import { normalizeAgent } from './api';
import Commands from './commands';
import { loadConfig, processUnread, reloadConfig } from './main';
import { loadConfig, processUnread } from './main';
import { parentCall } from './parentCall';
import { normalizeMessage, normalizeMessages } from './threads';
import { handleTranscript } from './transcript';
Expand Down Expand Up @@ -85,12 +85,15 @@ export const initRoom = async () => {
Livechat.onVisitorChange(rid, async (newVisitor) => {
const { user: { _updatedAt = null } = {}, room } = store.state;
const { _id, token, username } = newVisitor;

Livechat.credentials.token = token;

await store.setState({
user: { _id, token, username, _updatedAt },
token,
room: { ...room, v: { _id, token, username } },
});
await reloadConfig();
parentCall('callback', ['visitor-change', newVisitor]);
});

setCookies(rid, token);
Expand All @@ -111,6 +114,7 @@ const transformAgentInformationOnMessage = (message) => {
return message;
};


Livechat.onTyping((username, isTyping) => {
const { typing, user, agent } = store.state;

Expand Down
2 changes: 2 additions & 0 deletions src/widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export const validCallbacks = [
'agent-status-change',
'queue-position-change',
'no-agent-online',
'visitor-change',
];

const callbacks = mitt();
Expand Down Expand Up @@ -433,6 +434,7 @@ window.RocketChat.livechat = {
onAgentStatusChange(fn) { registerCallback('agent-status-change', fn); },
onQueuePositionChange(fn) { registerCallback('queue-position-change', fn); },
onServiceOffline(fn) { registerCallback('no-agent-online', fn); },
onVisitorChange(fn) { registerCallback('visitor-change', fn); },
};

// proccess queue
Expand Down

0 comments on commit ccbfc61

Please sign in to comment.