8 Commits

Author SHA1 Message Date
Sharon Kennedy
ee30b14cba 2.1.2 2020-10-16 13:43:23 -04:00
Sharon Kennedy
80c00149d2 main file should be chatbox 2020-10-16 13:43:15 -04:00
Sharon Kennedy
a2a48771e1 2.1.1 2020-10-15 12:25:08 -04:00
Sharon Kennedy
7bd6cf2466 package component 2020-10-15 12:24:59 -04:00
Sharon Kennedy
ac9247fecb 2.1.0 2020-10-15 11:40:38 -04:00
Sharon Kennedy
8439a1d100 export chatbox as react component 2020-10-15 11:40:12 -04:00
Sharon Kennedy
b709245b46 2.0.2 2020-09-11 16:32:33 -04:00
Sharon Kennedy
52e30336ad handle chat offline signal 2020-09-11 16:32:20 -04:00
9 changed files with 137 additions and 55 deletions

38
dist/bookmarklet.js vendored

File diff suppressed because one or more lines are too long

38
dist/chatbox.js vendored

File diff suppressed because one or more lines are too long

36
dist/component.js vendored Normal file

File diff suppressed because one or more lines are too long

2
package-lock.json generated
View File

@@ -1,6 +1,6 @@
{
"name": "private-safesupport-chatbox",
"version": "2.0.1",
"version": "2.1.2",
"lockfileVersion": 1,
"requires": true,
"dependencies": {

View File

@@ -1,6 +1,6 @@
{
"name": "private-safesupport-chatbox",
"version": "2.0.1",
"version": "2.1.2",
"description": "A secure and private embeddable chatbox that connects to Riot",
"main": "dist/chatbox.js",
"scripts": {
@@ -118,6 +118,8 @@
"node-sass": "^4.13.1",
"postcss-increase-specificity": "0.6.0",
"postcss-loader": "3.0.0",
"react": "^16.8.6",
"react-dom": "^16.8.6",
"sass-loader": "8.0.0",
"style-loader": "1.1.2",
"wait-for-expect": "^3.0.2",
@@ -137,11 +139,13 @@
"node-localstorage": "^2.1.5",
"olm": "https://packages.matrix.org/npm/olm/olm-3.1.4.tgz",
"prop-types": "^15.6.2",
"react": "^16.8.6",
"react-dom": "^16.8.6",
"react-onclickoutside": "^6.9.0",
"react-test-renderer": "^16.13.0",
"react-transition-group": "^4.0.0",
"uuidv4": "^6.0.2"
},
"peerDependencies": {
"react": "^16.8.6",
"react-dom": "^16.8.6"
}
}

View File

@@ -43,7 +43,7 @@ const DEFAULT_POSITION = 'bottom right'
const DEFAULT_SIZE = 'large'
const DEFAULT_MAX_WAIT_MS = 600000 // 10 minutes
const DEFAULT_WAIT_INTERVAL_MS = 120000 // 2 minutes
const DEFAULT_DOCK_LABEL = 'Start a new chat'
class ChatBox extends React.Component {
constructor(props) {
@@ -461,38 +461,15 @@ class ChatBox extends React.Component {
const decryptionErrors = {...this.state.decryptionErrors}
delete decryptionErrors[message.id]
const isOfflineNotice = message.content.msgtype === "m.notice" && message.content.body === CHAT_IS_OFFLINE_NOTICE
let newMessage = message
// when the bot sends a notice that the chat is offline
// replace the message with the client-configured message
// for now we're treating m.notice and m.text messages the same
if (isOfflineNotice) {
newMessage = {
...message,
content: {
...message.content,
body: this.props.chatOfflineMessage
}
}
this.handleChatOffline()
}
this.setState({
messages: {
...this.state.messages,
[message.id]: newMessage,
[message.id]: message,
},
decryptionErrors
})
}
handleChatOffline = () => {
this.exitChat(false) // close the chat connection but keep chatbox state
this.setState({ ready: true }) // no more loading animation
}
handleKeyDown = (e) => {
switch (e.keyCode) {
case 27:
@@ -584,6 +561,9 @@ class ChatBox extends React.Component {
case 'END_CHAT':
this.displayBotMessage({ body: this.props.exitMessage })
return this.exitChat(false); // keep chat state
case 'CHAT_OFFLINE':
this.displayBotMessage({ body: this.props.chatOfflineMessage })
return this.exitChat(false); // keep chat state
}
}
@@ -776,7 +756,7 @@ class ChatBox extends React.Component {
)}
}
</Transition>
{showDock && !roomId && <Dock handleToggleOpen={this.handleToggleOpen} size={this.props.size} />}
{showDock && !roomId && <Dock handleToggleOpen={this.handleToggleOpen} size={this.props.size} label={this.props.dockLabel} />}
{showDock && roomId && <Header handleToggleOpen={this.handleToggleOpen} opened={opened} handleExitChat={this.handleExitChat} />}
</div>
</div>
@@ -802,6 +782,7 @@ ChatBox.propTypes = {
size: PropTypes.oneOf(['small', 'large']),
maxWaitTime: PropTypes.number,
waitInterval: PropTypes.number,
dockLabel: PropTypes.string,
}
ChatBox.defaultProps = {
@@ -822,6 +803,7 @@ ChatBox.defaultProps = {
size: DEFAULT_SIZE,
maxWaitTime: DEFAULT_MAX_WAIT_MS,
waitInterval: DEFAULT_WAIT_INTERVAL_MS,
dockLabel: DEFAULT_DOCK_LABEL,
}
export default ChatBox;

View File

@@ -1,7 +1,7 @@
import React, { Fragment } from "react"
import PropTypes from "prop-types"
const Dock = ({ handleToggleOpen, size }) => {
const Dock = ({ handleToggleOpen, size, label }) => {
return(
<button
type="button"
@@ -13,11 +13,11 @@ const Dock = ({ handleToggleOpen, size }) => {
{
size === 'small' ?
<div id="open-chatbox-label">
<span>Chat</span><span className="icon">+</span>
<span>{label}</span><span className="icon">+</span>
</div>
:
<Fragment>
<div id="open-chatbox-label">Start a new chat</div>
<div id="open-chatbox-label">{label}</div>
<div className="label-icon">
<div className={`btn-icon`} aria-label={`Open support chat window`}>+</div>
</div>

3
src/outputs/component.js Normal file
View File

@@ -0,0 +1,3 @@
import Chatbox from '../components/chatbox';
export default Chatbox;

View File

@@ -94,4 +94,29 @@ module.exports = [{
publicPath: '/',
filename: 'bookmarklet.js',
},
}, {
...defaultConfig,
entry: './src/outputs/component.js',
output: {
path: distDir,
publicPath: '/',
filename: 'component.js',
library: 'Chatbox',
libraryExport: 'default',
libraryTarget: 'commonjs2',
},
externals: {
react: {
commonjs: "react",
commonjs2: "react",
amd: "React",
root: "React"
},
"react-dom": {
commonjs: "react-dom",
commonjs2: "react-dom",
amd: "ReactDOM",
root: "ReactDOM"
}
}
}];