Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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

Rev 3111 Rev 3119
Línea 4... Línea 4...
4
import Contacts from "./contacts/Contacts";
4
import Contacts from "./contacts/Contacts";
5
import NotificationAlert from "../../shared/notification/NotificationAlert";
5
import NotificationAlert from "../../shared/notification/NotificationAlert";
6
import Groups from "./groups/Groups";
6
import Groups from "./groups/Groups";
7
import PersonalChat from "./personal-chat/PersonalChat";
7
import PersonalChat from "./personal-chat/PersonalChat";
8
import { FiMaximize2 } from 'react-icons/fi'
8
import { FiMaximize2 } from 'react-icons/fi'
9
import { addNotification } from "../../redux/notification/notification.actions";
-
 
10
import { useDispatch } from "react-redux";
-
 
Línea 11... Línea 9...
11
 
9
 
Línea 12... Línea 10...
12
const notifyAudio = new Audio("/audio/chat.mp3");
10
const notifyAudio = new Audio("/audio/chat.mp3");
Línea 13... Línea -...
13
 
-
 
Línea 14... Línea 11...
14
const Chat = (props) => {
11
 
15
 
-
 
16
  const dispatch = useDispatch()
12
const Chat = (props) => {
17
 
13
 
18
  // states
14
 
19
  const [fullChats, setFullChats] = useState([]);
15
  // states
20
  const [contacts, setContacts] = useState([]);
16
  const [contacts, setContacts] = useState([]);
Línea 28... Línea 24...
28
 
24
 
29
  const filtredContacts = contacts.filter(({ name }) => name.toLowerCase().includes(search.toLowerCase()))
25
  const filtredContacts = contacts.filter(({ name }) => name.toLowerCase().includes(search.toLowerCase()))
Línea 30... Línea 26...
30
  const filtredGroups = groups.filter(({ name }) => name.toLowerCase().includes(search.toLowerCase()))
26
  const filtredGroups = groups.filter(({ name }) => name.toLowerCase().includes(search.toLowerCase()))
31
 
-
 
32
  const handleEntities = entities => {
-
 
33
    setFullChats([...entities]);
27
 
34
    console.log(entities)
28
  const handleEntities = entities => {
35
    let newUserContacts = [];
29
    let newUserContacts = [];
36
    let newGroups = [];
30
    let newGroups = [];
37
    entities.map((entity) => {
31
    entities.map((entity) => {
-
 
32
      if (entity.not_received_messages) handleNewMessage(entity)
38
      if (entity.not_received_messages) handleNewMessage(entity)
33
      if (entity.not_seen_messages) handleNotSeenMessage(entity)
39
      if (entity.not_seen_messages) handleNotSeenMessage(entity)
34
      if (entity.is_open) handleOpenConversation(entity, false);
40
      switch (entity.type) {
35
      switch (entity.type) {
41
        case "user":
36
        case "user":
42
          newUserContacts = [...newUserContacts, entity];
37
          newUserContacts = [...newUserContacts, entity];
Línea 51... Línea 46...
51
    });
46
    });
52
    setContacts(newUserContacts);
47
    setContacts(newUserContacts);
53
    setGroups(newGroups);
48
    setGroups(newGroups);
54
  }
49
  }
Línea 55... Línea -...
55
 
-
 
56
  useEffect(() => {
-
 
57
    axios.get("/chat/heart-beat")
-
 
58
      .then(({ data }) => {
-
 
59
        if (data.success) {
-
 
60
          const entities = data.data
-
 
61
 
-
 
62
 
-
 
63
          entities.map(entity => {
-
 
64
            if (entity.is_open !== 0) handleOpenConversation(entity, false);
-
 
65
          })
-
 
66
        }
-
 
67
      })
-
 
68
  }, [])
-
 
69
 
50
 
70
  const heartBeat = async () => {
51
  const heartBeat = async () => {
71
    try {
52
    try {
72
      const res = await axios.get("/chat/heart-beat")
-
 
73
      let entities = [];
-
 
74
      const resData = res.data;
53
      const { data } = await axios.get("/chat/heart-beat")
75
      if (resData.success) {
-
 
76
        entities = resData.data;
54
      if (data.success) {
77
        handleEntities(entities)
55
        handleEntities(data.data)
78
      }
56
      }
79
      return entities;
57
      return data.data;
80
    } catch (error) {
58
    } catch (error) {
81
      console.log('>>: chat error > ', error)
59
      console.log('>>: chat error > ', error)
82
    }
60
    }
Línea 83... Línea -...
83
  };
-
 
84
 
61
  };
85
 
62
 
86
  const handleUpdateOnline = (entity) => {
63
  const handleUpdateOnline = (entity) => {
87
    const existingChatId = activeChats.findIndex(
64
    const existingChatId = activeChats.findIndex(
88
      (activeChat) => activeChat.id === entity.id
65
      (activeChat) => activeChat.id === entity.id
Línea 165... Línea 142...
165
        break;
142
        break;
166
    }
143
    }
167
    setActiveChats(newActiveChats);
144
    setActiveChats(newActiveChats);
168
  };
145
  };
Línea 169... Línea 146...
169
 
146
 
170
const handleNotSeenMessage = (entity) => {
147
  const handleNotSeenMessage = (entity) => {
Línea 171... Línea 148...
171
    const index = activeChats.findIndex(chat => chat.id === entity.id)
148
    const index = activeChats.findIndex(chat => chat.id === entity.id)
172
 
149
 
173
    if (index !== -1) {
150
    if (index !== -1) {
Línea 179... Línea 156...
179
          }
156
          }
180
        }
157
        }
181
        return chat;
158
        return chat;
182
      }))
159
      }))
183
    }
160
    }
184
  
161
 
185
}
162
  }
186
  
163
 
187
  const handleCloseChat = (entityId, url_close) => {
164
  const handleCloseChat = (entityId, url_close) => {
188
    let newActiveChats = [];
165
    let newActiveChats = [];
189
    setLoading(true)
166
    setLoading(true)
190
    axios.post(url_close).then((response) => {
167
    axios.post(url_close).then((response) => {
191
      const resData = response.data;
168
      const resData = response.data;