clean up config and remove unneccessary constants
This commit is contained in:
parent
b82ba3da3f
commit
eae9c737d7
|
@ -10,7 +10,7 @@ Built on:
|
|||
|
||||
## Usage
|
||||
```
|
||||
<script src="https://unpkg.com/private-safesupport-chatbox" type="text/javascript"></script>
|
||||
<script src="https://safesupport.chat/chatbox.js" type="text/javascript"></script>
|
||||
<script>
|
||||
var config = {
|
||||
matrixServerUrl: 'https://matrix-client.matrix.org',
|
||||
|
@ -74,7 +74,7 @@ This chatbox is meant to be used with a bot account that handles a number of fun
|
|||
|
||||
The bot account is invited to the chatroom when a support request is initiated.
|
||||
|
||||
You can find the code for the bot at [ocrcc-bot](https://github.com/Safe-Support-Labs/ocrcc-bot).
|
||||
You can find the code for the bot at [ocrcc-bot](https://github.com/Safe-Support-Chat/ocrcc-bot).
|
||||
|
||||
## Bookmarklet
|
||||
|
||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name": "private-safesupport-chatbox",
|
||||
"name": "ocrcc-chatbox",
|
||||
"version": "2.3.2",
|
||||
"description": "A secure and private embeddable chatbox that connects to Riot",
|
||||
"description": "A secure and private embeddable chatbox that connects to Matrix",
|
||||
"main": "dist/chatbox.js",
|
||||
"scripts": {
|
||||
"build": "NODE_ENV=production webpack-cli --mode production",
|
||||
|
|
|
@ -1,16 +1,14 @@
|
|||
import React, { useState, useEffect } from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import Chatbox from './chatbox';
|
||||
import { DEFAULT_SETTINGS_ENDPOINT } from '../utils/constants';
|
||||
|
||||
const ChatboxWithSettings = ({ settingsEndpoint = null, matrixServerUrl, ...rest }) => {
|
||||
const [settings, setSettings] = useState({});
|
||||
const [shifts, setShifts] = useState();
|
||||
const [isAvailable, setAvailability] = useState(false);
|
||||
const [isAvailable, setAvailability] = useState(true);
|
||||
|
||||
const getSettings = async () => {
|
||||
const endpoint = settingsEndpoint || DEFAULT_SETTINGS_ENDPOINT;
|
||||
const url = `${endpoint}?homeserver=${encodeURIComponent(matrixServerUrl)}`;
|
||||
const url = `${settingsEndpoint}?homeserver=${encodeURIComponent(matrixServerUrl)}`;
|
||||
const res = await fetch(url);
|
||||
const data = await res.json();
|
||||
const { fields, schedule = [] } = data;
|
||||
|
@ -45,10 +43,6 @@ const ChatboxWithSettings = ({ settingsEndpoint = null, matrixServerUrl, ...rest
|
|||
};
|
||||
|
||||
const checkSchedule = () => {
|
||||
if (shifts.length === 0) {
|
||||
setAvailability(true);
|
||||
}
|
||||
|
||||
const weekdays = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
|
||||
|
||||
const now = new Date();
|
||||
|
@ -71,11 +65,13 @@ const ChatboxWithSettings = ({ settingsEndpoint = null, matrixServerUrl, ...rest
|
|||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (settingsEndpoint) {
|
||||
getSettings();
|
||||
}, []);
|
||||
}
|
||||
}, [settingsEndpoint]);
|
||||
|
||||
useEffect(() => {
|
||||
if (shifts) {
|
||||
if (shifts && shifts.length > 0) {
|
||||
checkSchedule();
|
||||
}
|
||||
}, [shifts]);
|
||||
|
|
|
@ -18,32 +18,13 @@ import Header from "./header";
|
|||
import EmojiSelector from './emoji-selector';
|
||||
|
||||
import './styles.scss';
|
||||
import defaultConfig from '../defaultConfig.js';
|
||||
|
||||
|
||||
const ENCRYPTION_CONFIG = { "algorithm": "m.megolm.v1.aes-sha2" };
|
||||
const ENCRYPTION_NOTICE = "Messages in this chat are secured with end-to-end encryption."
|
||||
const UNENCRYPTION_NOTICE = "Messages in this chat are not encrypted."
|
||||
const RESTARTING_UNENCRYPTED_CHAT_MESSAGE = "Restarting chat without encryption."
|
||||
const CHAT_IS_OFFLINE_NOTICE = "CHAT_OFFLINE"
|
||||
|
||||
const DEFAULT_MATRIX_SERVER = "https://matrix.rhok.space/"
|
||||
const DEFAULT_BOT_ID = "@help-bot:rhok.space"
|
||||
const DEFAULT_TERMS_URL = "https://tosdr.org/"
|
||||
const DEFAULT_ROOM_NAME = "Support Chat"
|
||||
const DEFAULT_INTRO_MESSAGE = "This chat application does not collect any of your personal data or any data from your use of this service."
|
||||
const DEFAULT_AGREEMENT_MESSAGE = "Do you want to continue?"
|
||||
const DEFAULT_CONFIRMATION_MESSAGE = "Waiting for a facilitator to join the chat..."
|
||||
const DEFAULT_EXIT_MESSAGE = "The chat is closed. You may close this window."
|
||||
const DEFAULT_DISPLAY_NAME="Anonymous"
|
||||
const DEFAULT_CHAT_UNAVAILABLE_MESSAGE = "The chat service is not available right now. Please try again later."
|
||||
const DEFAULT_CHAT_OFFLINE_MESSAGE = "All of the chat facilitators are currently offline."
|
||||
const DEFAULT_WAIT_MESSAGE = "Please be patient, our online facilitators are currently responding to other support requests."
|
||||
const DEFAULT_ENCRYPTION_DISABLED = false
|
||||
const DEFAULT_POSITION = 'bottom right'
|
||||
const DEFAULT_SIZE = 'large'
|
||||
const DEFAULT_WAIT_INTERVAL_MS = 120000 // 2 minutes
|
||||
const DEFAULT_DOCK_LABEL = 'Start a new chat'
|
||||
const DEFAULT_ENABLED = false
|
||||
|
||||
class ChatBox extends React.Component {
|
||||
constructor(props) {
|
||||
|
@ -565,7 +546,7 @@ class ChatBox extends React.Component {
|
|||
switch (signal) {
|
||||
case 'END_CHAT':
|
||||
this.displayBotMessage({ body: this.props.exitMessage })
|
||||
return this.exitChat(false); // keep chat state
|
||||
return this.exitChat(false); // keepg chat state
|
||||
case 'CHAT_OFFLINE':
|
||||
this.displayBotMessage({ body: this.props.chatOfflineMessage })
|
||||
return this.exitChat(false); // keep chat state
|
||||
|
@ -659,6 +640,7 @@ class ChatBox extends React.Component {
|
|||
}
|
||||
|
||||
render() {
|
||||
console.log(this.props)
|
||||
if (!this.props.enabled || !this.props.isAvailable) {
|
||||
return null
|
||||
}
|
||||
|
@ -791,29 +773,11 @@ ChatBox.propTypes = {
|
|||
size: PropTypes.oneOf(['small', 'large']),
|
||||
waitInterval: PropTypes.number,
|
||||
dockLabel: PropTypes.string,
|
||||
enabled: PropTypes.bool
|
||||
enabled: PropTypes.bool,
|
||||
isAvailable: PropTypes.bool
|
||||
}
|
||||
|
||||
ChatBox.defaultProps = {
|
||||
matrixServerUrl: DEFAULT_MATRIX_SERVER,
|
||||
botId: DEFAULT_BOT_ID,
|
||||
termsUrl: DEFAULT_TERMS_URL,
|
||||
roomName: DEFAULT_ROOM_NAME,
|
||||
introMessage: DEFAULT_INTRO_MESSAGE,
|
||||
agreementMessage: DEFAULT_AGREEMENT_MESSAGE,
|
||||
confirmationMessage: DEFAULT_CONFIRMATION_MESSAGE,
|
||||
exitMessage: DEFAULT_EXIT_MESSAGE,
|
||||
displayName: DEFAULT_DISPLAY_NAME,
|
||||
chatUnavailableMessage: DEFAULT_CHAT_UNAVAILABLE_MESSAGE,
|
||||
waitMessage: DEFAULT_WAIT_MESSAGE,
|
||||
chatOfflineMessage: DEFAULT_CHAT_OFFLINE_MESSAGE,
|
||||
isEncryptionDisabled: DEFAULT_ENCRYPTION_DISABLED,
|
||||
position: DEFAULT_POSITION,
|
||||
size: DEFAULT_SIZE,
|
||||
waitInterval: DEFAULT_WAIT_INTERVAL_MS,
|
||||
dockLabel: DEFAULT_DOCK_LABEL,
|
||||
enabled: DEFAULT_ENABLED,
|
||||
}
|
||||
ChatBox.defaultProps = defaultConfig
|
||||
|
||||
export default ChatBox;
|
||||
|
||||
|
|
|
@ -27,8 +27,8 @@ import waitForExpect from 'wait-for-expect'
|
|||
config.disabled = true
|
||||
|
||||
var testConfig = {
|
||||
matrixServerUrl: 'https://matrix.rhok.space',
|
||||
botId: '@help-bot:rhok.space',
|
||||
matrixServerUrl: 'https://test.matrix.tld',
|
||||
botId: '@help-bot:matrix.tld',
|
||||
roomName: 'Support Chat',
|
||||
termsUrl: 'https://tosdr.org/',
|
||||
introMessage: 'This chat application does not collect any of your personal data or any data from your use of this service.',
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
const DEFAULT_TERMS_URL = 'https://tosdr.org/';
|
||||
const DEFAULT_ROOM_NAME = 'Support Chat';
|
||||
const DEFAULT_INTRO_MESSAGE = 'This chat application does not collect any of your personal data or any data from your use of this service.';
|
||||
const DEFAULT_AGREEMENT_MESSAGE = 'Do you want to continue?';
|
||||
const DEFAULT_CONFIRMATION_MESSAGE = 'Waiting for a facilitator to join the chat...';
|
||||
const DEFAULT_EXIT_MESSAGE = 'The chat is closed. You may close this window.';
|
||||
const DEFAULT_DISPLAY_NAME = 'Anonymous';
|
||||
const DEFAULT_CHAT_UNAVAILABLE_MESSAGE = 'The chat service is not available right now. Please try again later.';
|
||||
const DEFAULT_CHAT_OFFLINE_MESSAGE = 'All of the chat facilitators are currently offline.';
|
||||
const DEFAULT_WAIT_MESSAGE = 'Please be patient, our online facilitators are currently responding to other support requests.';
|
||||
const DEFAULT_ENCRYPTION_DISABLED = false;
|
||||
const DEFAULT_POSITION = 'bottom right';
|
||||
const DEFAULT_SIZE = 'large';
|
||||
const DEFAULT_WAIT_INTERVAL_MS = 120000; // 2 minutes
|
||||
const DEFAULT_DOCK_LABEL = 'Start a new chat';
|
||||
const DEFAULT_ENABLED = true;
|
||||
const DEFAULT_AVAILABLE = true;
|
||||
|
||||
const defaultConfig = {
|
||||
termsUrl: DEFAULT_TERMS_URL,
|
||||
roomName: DEFAULT_ROOM_NAME,
|
||||
introMessage: DEFAULT_INTRO_MESSAGE,
|
||||
agreementMessage: DEFAULT_AGREEMENT_MESSAGE,
|
||||
confirmationMessage: DEFAULT_CONFIRMATION_MESSAGE,
|
||||
exitMessage: DEFAULT_EXIT_MESSAGE,
|
||||
displayName: DEFAULT_DISPLAY_NAME,
|
||||
chatUnavailableMessage: DEFAULT_CHAT_UNAVAILABLE_MESSAGE,
|
||||
waitMessage: DEFAULT_WAIT_MESSAGE,
|
||||
chatOfflineMessage: DEFAULT_CHAT_OFFLINE_MESSAGE,
|
||||
isEncryptionDisabled: DEFAULT_ENCRYPTION_DISABLED,
|
||||
position: DEFAULT_POSITION,
|
||||
size: DEFAULT_SIZE,
|
||||
waitInterval: DEFAULT_WAIT_INTERVAL_MS,
|
||||
dockLabel: DEFAULT_DOCK_LABEL,
|
||||
enabled: DEFAULT_ENABLED,
|
||||
isAvailable: DEFAULT_AVAILABLE,
|
||||
};
|
||||
|
||||
export default defaultConfig;
|
|
@ -1,17 +1,7 @@
|
|||
import EmbeddableChatbox from './embeddable-chatbox';
|
||||
import defaultConfig from '../defaultConfig';
|
||||
|
||||
const config = {
|
||||
matrixServerUrl: 'https://matrix.rhok.space',
|
||||
botId: '@help-bot:rhok.space',
|
||||
roomName: 'Support Chat',
|
||||
termsUrl: 'https://tosdr.org/',
|
||||
introMessage: 'This chat application does not collect any of your personal data or any data from your use of this service.',
|
||||
agreementMessage: 'Do you want to continue?',
|
||||
confirmationMessage: 'Waiting for a facilitator to join the chat...',
|
||||
exitMessage: 'The chat is closed. You may close this window.',
|
||||
chatUnavailableMessage: 'The chat service is not available right now. Please try again later.',
|
||||
anonymousDisplayName: 'Anonymous',
|
||||
};
|
||||
const config = defaultConfig;
|
||||
|
||||
export default function bookmarklet() {
|
||||
if (window.EmbeddableChatbox) {
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
export const DEFAULT_SETTINGS_ENDPOINT = 'https://admin.safesupport.chat/api/get-settings';
|
13
yarn.lock
13
yarn.lock
|
@ -2966,15 +2966,10 @@ camelcase@^5.0.0, camelcase@^5.3.1:
|
|||
resolved "https://registry.yarnpkg.com/camelcase/-/camelcase-5.3.1.tgz#e3c9b31569e106811df242f715725a1f4c494320"
|
||||
integrity sha512-L28STB170nwWS63UjtlEOE3dldQApaJXZkOI1uMFfzf3rRuPegHaHesyee+YxQ+W6SvRDQV6UrdOdRiR153wJg==
|
||||
|
||||
caniuse-lite@^1.0.30001023:
|
||||
version "1.0.30001023"
|
||||
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001023.tgz#b82155827f3f5009077bdd2df3d8968bcbcc6fc4"
|
||||
integrity sha512-C5TDMiYG11EOhVOA62W1p3UsJ2z4DsHtMBQtjzp3ZsUglcQn62WOUgW0y795c7A5uZ+GCEIvzkMatLIlAsbNTA==
|
||||
|
||||
caniuse-lite@^1.0.30001036, caniuse-lite@^1.0.30001038:
|
||||
version "1.0.30001038"
|
||||
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001038.tgz#44da3cbca2ab6cb6aa83d1be5d324e17f141caff"
|
||||
integrity sha512-zii9quPo96XfOiRD4TrfYGs+QsGZpb2cGiMAzPjtf/hpFgB6zCPZgJb7I1+EATeMw/o+lG8FyRAnI+CWStHcaQ==
|
||||
caniuse-lite@^1.0.30001023, caniuse-lite@^1.0.30001036, caniuse-lite@^1.0.30001038:
|
||||
version "1.0.30001300"
|
||||
resolved "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001300.tgz"
|
||||
integrity sha512-cVjiJHWGcNlJi8TZVKNMnvMid3Z3TTdDHmLDzlOdIiZq138Exvo0G+G0wTdVYolxKb4AYwC+38pxodiInVtJSA==
|
||||
|
||||
capture-exit@^2.0.0:
|
||||
version "2.0.0"
|
||||
|
|
Loading…
Reference in New Issue