Skip to content
This repository was archived by the owner on Jun 30, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 18 additions & 13 deletions src/components/Messages/MessageList/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,17 +164,22 @@ export class MessageList extends MemoizedComponent {

render = ({
className,
style = {},
}) => (
<div
onScroll={this.handleScroll}
className={createClassName(styles, 'message-list', {}, [className])}
onClick={this.handleClick}
style={style}
>
<ol className={createClassName(styles, 'message-list__content')}>
{this.renderItems(this.props)}
</ol>
</div>
)
style = {}
}) => {
if (this.props.loading) {
return <span className={createClassName(styles, 'many-request-error')}>{this.props.loadingMessage}</span>
}
else {
return <div
onScroll={this.handleScroll}
className={createClassName(styles, 'message-list', {}, [className])}
onClick={this.handleClick}
style={style}
>
<ol className={createClassName(styles, 'message-list__content')}>
{this.renderItems(this.props)}
</ol>
</div>
}
}
}
12 changes: 12 additions & 0 deletions src/components/Messages/MessageList/styles.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
@import '../../../styles/colors';
@import '../../../styles/variables';

$alert-error-background-color: $color-red;

.message-list {
display: flex;
overflow-y: scroll;
Expand Down Expand Up @@ -33,3 +35,13 @@
list-style: none;
}
}

.many-request-error{
background-color: $alert-error-background-color;
width:100%;
height:28px;
color: #FFFFFF;
font-family: Helvetica Neue,arial,sans-serif;
font-size: 12px;
padding:5px;
}
41 changes: 32 additions & 9 deletions src/lib/room.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,15 +162,38 @@ export const loadMessages = async () => {
}

await store.setState({ loading: true });
const rawMessages = (await Livechat.loadMessages(rid)).concat(previousMessages);
const messages = (await normalizeMessages(rawMessages)).map(transformAgentInformationOnMessage);

await initRoom();
await store.setState({ messages: (messages || []).reverse(), noMoreMessages: false, loading: false });

if (messages && messages.length) {
const lastMessage = messages[messages.length - 1];
await store.setState({ lastReadMessageId: lastMessage && lastMessage._id });
try {
const rawMessages = (await Livechat.loadMessages(rid)).concat(previousMessages);
const messages = (await normalizeMessages(rawMessages)).map(transformAgentInformationOnMessage);
await initRoom();
await store.setState({ messages: (messages || []).reverse(), noMoreMessages: false, loading: false });

if (messages && messages.length) {
const lastMessage = messages[messages.length - 1];
await store.setState({ lastReadMessageId: lastMessage && lastMessage._id });
}
}
catch(e) {
const waitTime = parseInt(e.data.error.match(/^.*You must wait ([0-9]*) seconds.*$/)[1]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please set this message on i18n files.

const decrementCounter = async () => {
if(window.loadMessagesTimeout) {
clearInterval(window.loadMessagesTimeout);
}
window.loadMessagesTimeout = setInterval(() => {
let tmpWaitTime = store.state.loadWaitTime;
if(tmpWaitTime) {
store.setState({loadWaitTime: tmpWaitTime - 1, loadingMessage: `Error, too many requests. Please slow down. You must wait for ${tmpWaitTime} seconds.` });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please set this message on i18n files.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

according to your comment, does I need to set that message in all i18n files. Like I have to translate that message to all other languages and set it to respective i18n json files. Right? And if this is the case how I can identify which i18n json file belong to which language. Is there any fast way to do this or I have to manually check each i18n json file to check which language it belongs to. Looking forward to your response. Thanks.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please check the i18n command on package.json files.

You'll use with I18n.t('YOUR TEXT') and run the command, that command will create the line on i18n files.

}
else {
if(window.loadMessagesTimeout) {
clearInterval(window.loadMessagesTimeout);
}
window.location.reload();
}
}, 1000)
}
await store.setState({ loading: true, loadWaitTime: waitTime });
await decrementCounter();
}
};

Expand Down
3 changes: 3 additions & 0 deletions src/routes/Chat/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ export default class Chat extends Component {
avatarResolver,
conversationFinishedMessage,
loading,
loadingMessage,
onUpload,
messages,
uploads = false,
Expand Down Expand Up @@ -149,6 +150,8 @@ export default class Chat extends Component {
ref={this.handleMessagesContainerRef}
avatarResolver={avatarResolver}
uid={uid}
loading={loading}
loadingMessage={loadingMessage}
messages={messages}
typingUsernames={typingUsernames}
conversationFinishedMessage={conversationFinishedMessage}
Expand Down
2 changes: 2 additions & 0 deletions src/routes/Chat/container.js
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,7 @@ export const ChatConnector = ({ ref, ...props }) => (
lastReadMessageId,
triggerAgent,
queueInfo,
loadingMessage,
}) => (
<ChatContainer
ref={ref}
Expand Down Expand Up @@ -434,6 +435,7 @@ export const ChatConnector = ({ ref, ...props }) => (
uploads={uploads}
typingUsernames={Array.isArray(typing) ? typing : []}
loading={loading}
loadingMessage={loadingMessage}
showConnecting={showConnecting} // setting from server that tells if app needs to show "connecting" sometimes
connecting={!!(room && !agent && (showConnecting || queueInfo))}
dispatch={dispatch}
Expand Down
1 change: 1 addition & 0 deletions src/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const initialState = {
visible: true,
minimized: true,
unread: null,
loadingMessage: null,
};

const dontPersist = ['messages', 'typing', 'loading', 'alerts', 'unread', 'noMoreMessages', 'modal'];
Expand Down