lint + cleanup

This commit is contained in:
Ramon Souza 2021-05-27 15:12:49 -03:00
parent 94436d2630
commit 3c41c6fd83
4 changed files with 94 additions and 82 deletions

View File

@ -1,4 +1,4 @@
import React, { Component, Fragment } from 'react';
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { throttle } from 'lodash';
import { defineMessages, injectIntl } from 'react-intl';
@ -30,7 +30,7 @@ import NewWebcamContainer from '../webcam/container';
import PresentationPodsContainer from '../presentation-pod/container';
import { styles } from './styles';
import {
LAYOUT_TYPE, DEVICE_TYPE, ACTIONS, PANELS,
LAYOUT_TYPE, DEVICE_TYPE, ACTIONS,
} from '../layout/enums';
import {
isMobile, isTablet, isTabletPortrait, isTabletLandscape, isDesktop,
@ -44,7 +44,6 @@ import SidebarNavigationContainer from '../sidebar-navigation/container';
import SidebarContentContainer from '../sidebar-content/container';
import { makeCall } from '/imports/ui/services/api';
import ConnectionStatusService from '/imports/ui/components/connection-status/service';
import { NAVBAR_HEIGHT } from '/imports/ui/components/layout/layout-manager/component';
const MOBILE_MEDIA = 'only screen and (max-width: 40em)';
const APP_CONFIG = Meteor.settings.public.app;
@ -421,7 +420,7 @@ class App extends Component {
sidebarNavigationIsOpen,
sidebarContentIsOpen,
audioAlertEnabled,
pushAlertEnabled
pushAlertEnabled,
} = this.props;
return (
@ -460,7 +459,13 @@ class App extends Component {
<ModalContainer />
<AudioContainer />
<ToastContainer rtl />
{(audioAlertEnabled || pushAlertEnabled) && <ChatAlertContainer audioAlertEnabled={audioAlertEnabled} pushAlertEnabled={pushAlertEnabled} /> }
{(audioAlertEnabled || pushAlertEnabled)
&& (
<ChatAlertContainer
audioAlertEnabled={audioAlertEnabled}
pushAlertEnabled={pushAlertEnabled}
/>
)}
<WaitingNotifierContainer />
<LockNotifier />
<StatusNotifier status="raiseHand" />

View File

@ -1,6 +1,6 @@
import React, { useState, useEffect } from 'react';
import PropTypes from 'prop-types';
import { Meteor } from "meteor/meteor";
import { Meteor } from 'meteor/meteor';
import { defineMessages, injectIntl } from 'react-intl';
import _ from 'lodash';
import AudioService from '/imports/ui/components/audio/service';
@ -54,7 +54,7 @@ const ChatAlert = (props) => {
unreadMessagesCountByChat,
unreadMessagesByChat,
intl,
newLayoutContextDispatch
newLayoutContextDispatch,
} = props;
const [unreadMessagesCount, setUnreadMessagesCount] = useState(0);
@ -97,48 +97,43 @@ const ChatAlert = (props) => {
let timewindowsToAlert = [];
let filteredTimewindows = [];
alertsObject.forEach(chat => {
alertsObject.forEach((chat) => {
filteredTimewindows = filteredTimewindows.concat(
chat.filter(timeWindow => {
return timeWindow.timestamp > alertEnabledTimestamp
})
chat.filter((timeWindow) => timeWindow.timestamp > alertEnabledTimestamp),
);
})
});
filteredTimewindows.forEach(timeWindow => {
filteredTimewindows.forEach((timeWindow) => {
const durationDiff = ALERT_DURATION - (new Date().getTime() - timeWindow.timestamp);
if(timeWindow.lastTimestamp > timeWindow.timestamp){
// é update de uma timewindow ja enviada
// verifica se lasttimestamp é maior que ultimo alert exibido desse chat
if(durationDiff > 0 && timeWindow.lastTimestamp > (lastAlertTimestampByChat[timeWindow.chatId] || 0)){
//remover outros timewindows com mesmo key
timewindowsToAlert = timewindowsToAlert.filter(item => item.chatId !== timeWindow.chatId);
const newTimeWindow = {...timeWindow};
if (timeWindow.lastTimestamp > timeWindow.timestamp) {
if (durationDiff > 0
&& timeWindow.lastTimestamp > (lastAlertTimestampByChat[timeWindow.chatId] || 0)) {
timewindowsToAlert = timewindowsToAlert
.filter((item) => item.chatId !== timeWindow.chatId);
const newTimeWindow = { ...timeWindow };
newTimeWindow.durationDiff = durationDiff;
timewindowsToAlert.push(newTimeWindow);
const newLastAlertTimestampByChat = {...lastAlertTimestampByChat};
if(timeWindow.timestamp > (lastAlertTimestampByChat[timeWindow.chatId] || 0)){
const newLastAlertTimestampByChat = { ...lastAlertTimestampByChat };
if (timeWindow.timestamp > (lastAlertTimestampByChat[timeWindow.chatId] || 0)) {
newLastAlertTimestampByChat[timeWindow.chatId] = timeWindow.timestamp;
setLastAlertTimestampByChat(newLastAlertTimestampByChat);
}
}
}else{
// new timeWindow, display if newer than last alert + alert interval
if(timeWindow.timestamp > (lastAlertTimestampByChat[timeWindow.chatId] || 0) + ALERT_INTERVAL){
timewindowsToAlert = timewindowsToAlert.filter(item => item.chatId !== timeWindow.chatId);
} else if (timeWindow.timestamp
> (lastAlertTimestampByChat[timeWindow.chatId] || 0) + ALERT_INTERVAL) {
timewindowsToAlert = timewindowsToAlert
.filter((item) => item.chatId !== timeWindow.chatId);
timewindowsToAlert.push(timeWindow);
const newLastAlertTimestampByChat = {...lastAlertTimestampByChat};
if(timeWindow.timestamp > (lastAlertTimestampByChat[timeWindow.chatId] || 0)){
const newLastAlertTimestampByChat = { ...lastAlertTimestampByChat };
if (timeWindow.timestamp > (lastAlertTimestampByChat[timeWindow.chatId] || 0)) {
newLastAlertTimestampByChat[timeWindow.chatId] = timeWindow.timestamp;
setLastAlertTimestampByChat(newLastAlertTimestampByChat);
}
}
}
})
});
setUnreadMessages(timewindowsToAlert);
}
}, [unreadMessagesByChat]);
@ -155,10 +150,9 @@ const ChatAlert = (props) => {
});
return contentMessage;
}
};
const createMessage = (name, message) => {
return (
const createMessage = (name, message) => (
<div className={styles.pushMessageContent}>
<h3 className={styles.userNameMessage}>{name}</h3>
<div className={styles.contentMessage}>
@ -169,14 +163,17 @@ const ChatAlert = (props) => {
</div>
</div>
);
}
return pushAlertEnabled
? unreadMessages.map(timeWindow => {
? unreadMessages.map((timeWindow) => {
const mappedMessage = Service.mapGroupMessage(timeWindow);
const content = mappedMessage ? createMessage(mappedMessage.sender.name, mappedMessage.content.slice(-5)) : null;
const content = mappedMessage
? createMessage(mappedMessage.sender.name, mappedMessage.content.slice(-5))
: null;
return content ? <ChatPushAlert
return content
? (
<ChatPushAlert
key={mappedMessage.chatId}
chatId={mappedMessage.chatId}
content={content}
@ -187,13 +184,15 @@ const ChatAlert = (props) => {
}
onOpen={
() => {
const newUnreadMessages = unreadMessages.filter(message => message.key !== mappedMessage.key);
const newUnreadMessages = unreadMessages
.filter((message) => message.key !== mappedMessage.key);
setUnreadMessages(newUnreadMessages);
}
}
alertDuration={timeWindow.durationDiff || ALERT_DURATION}
newLayoutContextDispatch={newLayoutContextDispatch}
/> : null;
/>
) : null;
})
: null;
};

View File

@ -39,14 +39,14 @@ const ChatAlertContainer = (props) => {
// audio alerts
const unreadMessagesCountByChat = audioAlertEnabled
? JSON.stringify(activeChats.map(chat => {
return {chatId: chat.chatId, unreadCounter: chat.unreadCounter};
}))
? JSON.stringify(activeChats.map((chat) => ({
chatId: chat.chatId, unreadCounter: chat.unreadCounter,
})))
: null;
// push alerts
const unreadMessagesByChat = pushAlertEnabled
? JSON.stringify(activeChats.filter((chat) => chat.unreadCounter > 0).map(chat => {
? JSON.stringify(activeChats.filter((chat) => chat.unreadCounter > 0).map((chat) => {
const chatId = (chat.chatId === 'public') ? PUBLIC_CHAT_ID : chat.chatId;
return UnreadMessages.getUnreadMessages(chatId, groupChatsMessages);
}))

View File

@ -28,9 +28,17 @@ export function notify(message, type = 'default', icon, options, content, small)
};
if (!toast.isActive(lastToast.id) || !_.isEqual(lastToastProps, toastProps)) {
if(toast.isActive(lastToast.id) && _.isEqual(lastToastProps.key, toastProps.key) && options?.autoClose > 0){
toast.update(lastToast.id, { render: <Toast {...toastProps} />, autoClose: options.autoClose, ...toastProps });
}else{
if (toast.isActive(lastToast.id)
&& _.isEqual(lastToastProps.key, toastProps.key) && options?.autoClose > 0) {
toast.update(
lastToast.id,
{
render: <Toast {...toastProps} />,
autoClose: options.autoClose,
...toastProps,
},
);
} else {
const id = toast(<Toast {...toastProps} />, settings);
lastToast = { id, ...toastProps };