Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 14576 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 14576 Rev 14580
Línea 1... Línea 1...
1
import React from 'react'
1
import React from 'react'
2
import { useState, useEffect } from 'react'
2
import { useState, useEffect } from 'react'
-
 
3
import { axios } from '../../utils'
3
import Contacts from './contacts/Contacts'
4
import Contacts from './contacts/Contacts'
4
import NotificationAlert from '../../shared/notification/NotificationAlert'
5
import NotificationAlert from '../../shared/notification/NotificationAlert'
5
import Groups from './groups/Groups'
6
import Groups from './groups/Groups'
6
import PersonalChat from './personal-chat/PersonalChat'
7
import PersonalChat from './personal-chat/PersonalChat'
7
import { axios } from '../../utils'
-
 
Línea 8... Línea 8...
8
 
8
 
Línea 9... Línea 9...
9
const notifyAudio = new Audio('/audio/chat.mp3')
9
const notifyAudio = new Audio('/audio/chat.mp3')
10
 
10
 
-
 
11
const Chat = (props) => {
11
const Chat = (props) => {
12
	// states
12
	// states
13
	const [fullChats, setFullChats] = useState([])
13
	const [contacts, setContacts] = useState([])
14
	const [contacts, setContacts] = useState([])
14
	const [groups, setGroups] = useState([])
15
	const [groups, setGroups] = useState([])
15
	const [activeChats, setActiveChats] = useState([])
16
	const [activeChats, setActiveChats] = useState([])
Línea 21... Línea 22...
21
 
22
 
22
	const filtredContacts = contacts.filter(({ name }) => name.toLowerCase().includes(search.toLowerCase()))
23
	const filtredContacts = contacts.filter(({ name }) => name.toLowerCase().includes(search.toLowerCase()))
Línea 23... Línea 24...
23
	const filtredGroups = groups.filter(({ name }) => name.toLowerCase().includes(search.toLowerCase()))
24
	const filtredGroups = groups.filter(({ name }) => name.toLowerCase().includes(search.toLowerCase()))
-
 
25
 
24
 
26
	const handleEntities = entities => {
25
	const handleEntities = entities => {
27
		setFullChats([...entities])
26
		let newUserContacts = []
28
		let newUserContacts = []
27
		let newGroups = []
29
		let newGroups = []
28
		entities.map((entity) => {
30
		entities.map((entity) => {
Línea 88... Línea 90...
88
			}
90
			}
89
		}
91
		}
90
	}
92
	}
Línea 91... Línea 93...
91
 
93
 
92
	const handleNewMessage = async (unseeEntity) => {
94
	const handleNewMessage = async (unseeEntity) => {
-
 
95
		await axios.post(unseeEntity.url_mark_received).then((response) => {
-
 
96
			('')
93
		await axios.post(unseeEntity.url_mark_received)
97
		})
94
		if (!activeChats.some((activeChat) => activeChat.id === unseeEntity.id)) {
98
		if (!activeChats.some((activeChat) => activeChat.id === unseeEntity.id)) {
95
			setActiveChats([...activeChats, { ...unseeEntity, minimized: false }])
99
			setActiveChats([...activeChats, { ...unseeEntity, minimized: false }])
96
			playNotifyAudio()
100
			playNotifyAudio()
97
		} else {
101
		} else {
Línea 111... Línea 115...
111
		if (activeChats.length < 3 && !activeChats.some((el) => el.id === entity.id)) {
115
		if (activeChats.length < 3 && !activeChats.some((el) => el.id === entity.id)) {
112
			setActiveChats([...activeChats, { ...entity, minimized: minimized }])
116
			setActiveChats([...activeChats, { ...entity, minimized: minimized }])
113
		}
117
		}
114
		if (activeChats.length >= 3 && !activeChats.some((el) => el.id === entity.id)) {
118
		if (activeChats.length >= 3 && !activeChats.some((el) => el.id === entity.id)) {
115
			activeChats.map((el, index) => {
119
			activeChats.map((el, index) => {
-
 
120
				if (index === 0) {
116
				if (index === 0) axios.post(el.url_close)
121
					axios.post(el.url_close)
-
 
122
				}
117
			})
123
			})
118
			const newActiveChats = activeChats.filter((el, index) => index !== 0)
124
			const newActiveChats = activeChats.filter((el, index) => index !== 0)
119
			setActiveChats([...newActiveChats, { ...entity, minimized: minimized }])
125
			setActiveChats([...newActiveChats, { ...entity, minimized: minimized }])
120
		}
126
		}
121
	}
127
	}
Línea 153... Línea 159...
153
	}
159
	}
Línea 154... Línea 160...
154
 
160
 
155
	const handleCloseChat = (entityId, url_close) => {
161
	const handleCloseChat = (entityId, url_close) => {
156
		let newActiveChats = []
162
		let newActiveChats = []
157
		setLoading(true)
163
		setLoading(true)
-
 
164
		axios.post(url_close).then((response) => {
-
 
165
			const resData = response.data
158
		axios.post(url_close)
166
		})
159
		newActiveChats = activeChats.filter(
167
		newActiveChats = activeChats.filter(
160
			(activeChat) => activeChat.id !== entityId
168
			(activeChat) => activeChat.id !== entityId
161
		)
169
		)
162
		setActiveChats(newActiveChats)
170
		setActiveChats(newActiveChats)