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

Commit

Permalink
[NEW] Introduce clearLocalStorageWhenChatEnded setting logic (#666)
Browse files Browse the repository at this point in the history
Co-authored-by: Kevin Aleman <kevin.aleman@rocket.chat>
  • Loading branch information
tiagoevanp and KevLehman committed Dec 3, 2021
1 parent 0b50f73 commit 4c1777f
Show file tree
Hide file tree
Showing 77 changed files with 15 additions and 5 deletions.
2 changes: 2 additions & 0 deletions .loki/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
current
difference
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .loki/reference/chrome_Components_Button_danger.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .loki/reference/chrome_Components_Button_disabled.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .loki/reference/chrome_Components_Button_loading.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .loki/reference/chrome_Components_Button_normal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .loki/reference/chrome_Components_Button_nude.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .loki/reference/chrome_Components_Button_outline.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .loki/reference/chrome_Components_Button_secondary.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .loki/reference/chrome_Components_Button_small.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .loki/reference/chrome_Components_Button_stack.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .loki/reference/chrome_Components_Button_with_badge.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .loki/reference/chrome_Components_Header_for_user_chat.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .loki/reference/chrome_Components_Header_with_custom_field.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .loki/reference/chrome_Components_Header_with_theme.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .loki/reference/chrome_Components_Icons_doc.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .loki/reference/chrome_Components_Icons_file.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .loki/reference/chrome_Components_Icons_pdf.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .loki/reference/chrome_Components_Icons_ppt.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .loki/reference/chrome_Components_Icons_sheet.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .loki/reference/chrome_Components_Icons_zip.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .loki/reference/chrome_Components_Menu_Item_disabled.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .loki/reference/chrome_Components_Menu_Item_with_icon.png
Binary file modified .loki/reference/chrome_Components_Modal_alert.png
Binary file modified .loki/reference/chrome_Components_Modal_animated.png
Binary file modified .loki/reference/chrome_Components_Modal_confirm.png
Binary file modified .loki/reference/chrome_Components_Modal_normal.png
Binary file modified .loki/reference/chrome_Components_Modal_timeout.png
Binary file modified .loki/reference/chrome_Components_Screen_with_agent.png
Binary file modified .loki/reference/chrome_Components_Screen_with_agent_email.png
Binary file modified .loki/reference/chrome_Components_Screen_with_agent_phone.png
Binary file modified .loki/reference/chrome_Forms_DateInput_default.png
Binary file modified .loki/reference/chrome_Forms_DateInput_disabled.png
Binary file modified .loki/reference/chrome_Forms_DateInput_filled.png
Binary file modified .loki/reference/chrome_Forms_DateInput_small.png
Binary file modified .loki/reference/chrome_Forms_DateInput_with_error.png
Binary file modified .loki/reference/chrome_Forms_Form_default.png
Binary file modified .loki/reference/chrome_Forms_PasswordInput_disabled.png
Binary file modified .loki/reference/chrome_Forms_SelectInput_disabled.png
Binary file modified .loki/reference/chrome_Forms_TextInput_disabled.png
Binary file modified .loki/reference/chrome_Messages_MessageBlocks_with_blocks.png
Binary file modified .loki/reference/chrome_Messages_MessageList_normal.png
Binary file modified .loki/reference/chrome_Messages_MessageList_with_typing_users.png
Binary file modified .loki/reference/chrome_Messages_Message_default.png
Binary file modified .loki/reference/chrome_Messages_Message_grouping.png
Binary file modified .loki/reference/chrome_Messages_Message_markdown.png
Binary file modified .loki/reference/chrome_Messages_Message_me.png
Binary file modified .loki/reference/chrome_Messages_Message_with_files_attachments.png
Binary file modified .loki/reference/chrome_Messages_Message_with_image_attachment.png
Binary file modified .loki/reference/chrome_Messages_Message_with_quotation.png
Binary file modified .loki/reference/chrome_Messages_TypingIndicator_with_avatars.png
Binary file modified .loki/reference/chrome_Routes_Chat_loading.png
Binary file modified .loki/reference/chrome_Routes_Chat_normal.png
Binary file modified .loki/reference/chrome_Routes_Chat_with_trigger_messages.png
Binary file modified .loki/reference/chrome_Routes_Chat_with_typing_user.png
Binary file modified .loki/reference/chrome_Routes_Leave_a_message_loading.png
Binary file modified .loki/reference/chrome_Routes_Register_loading.png
Binary file modified .loki/reference/chrome_Routes_SwitchDepartment_loading.png
Binary file modified .loki/reference/chrome_Routes_SwitchDepartment_normal.png
Binary file modified .loki/reference/chrome_Routes_TriggerMessage_multiple.png
Binary file modified .loki/reference/chrome_UiKit_Message_Actions_block_button.png
Binary file modified .loki/reference/chrome_UiKit_Message_Actions_block_datepicker.png
Binary file modified .loki/reference/chrome_UiKit_Message_Button_element_default.png
Binary file modified .loki/reference/chrome_UiKit_Message_Context_block_mrkdwn.png
12 changes: 10 additions & 2 deletions src/lib/room.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Livechat } from '../api';
import { CallStatus, isCallOngoing } from '../components/Calls/CallStatus';
import { setCookies, upsert, canRenderMessage, createToken } from '../components/helpers';
import I18n from '../i18n';
import { store } from '../store';
import { store, initialState } from '../store';
import { normalizeAgent } from './api';
import Commands from './commands';
import constants from './constants';
Expand All @@ -21,6 +21,14 @@ export const closeChat = async ({ transcriptRequested } = {}) => {
await handleTranscript();
}

const { config: { settings: { clearLocalStorageWhenChatEnded } = {} } = {} } = store.state;

if (clearLocalStorageWhenChatEnded) {
// exclude UI-affecting flags
const { minimized, visible, undocked, expanded, ...initial } = initialState();
await store.setState(initial);
}

await loadConfig();
parentCall('callback', 'chat-ended');
route('/chat-finished');
Expand Down Expand Up @@ -127,7 +135,7 @@ const isAgentHidden = () => {

const transformAgentInformationOnMessage = (message) => {
const { user } = store.state;
if (message.u && message.u._id !== user._id && isAgentHidden()) {
if (message && user && message.u && message.u._id !== user._id && isAgentHidden()) {
return { ...message, u: { _id: message.u._id } };
}

Expand Down
6 changes: 3 additions & 3 deletions src/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Store from './Store';

const createToken = () => Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15);

const initialState = {
export const initialState = () => ({
token: createToken(),
typing: [],
config: {
Expand Down Expand Up @@ -36,10 +36,10 @@ const initialState = {
unread: null,
incomingCallAlert: null,
ongoingCall: null, // TODO: store call info like url, startTime, timeout, etc here
};
});

const dontPersist = ['messages', 'typing', 'loading', 'alerts', 'unread', 'noMoreMessages', 'modal', 'incomingCallAlert', 'ongoingCall'];
export const store = new Store(initialState, { dontPersist });
export const store = new Store(initialState(), { dontPersist });

if (process.env.NODE_ENV === 'development') {
store.on('change', ([, , partialState]) => {
Expand Down

0 comments on commit 4c1777f

Please sign in to comment.