Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 3618 | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
3719 stevensc 1
import React from 'react';
2
import { Box, styled } from '@mui/material';
3
import { Check } from '@mui/icons-material';
4
 
5
import { parse } from '@utils';
6
 
7
import Options from '@components/UI/Option';
8
 
9
const MessageTemplate = styled(Box)`
10
  box-shadow: var(--light-shadow);
11
  display: inline-flex;
12
  flex-direction: column;
13
  gap: 0.5rem;
14
  margin-bottom: 0.5rem;
15
  max-width: 70%;
16
  min-width: 4rem;
17
  padding: 0.5rem;
18
  position: relative;
19
  p {
20
    color: var(--chat-color);
21
    max-width: 100%;
22
    overflow: hidden;
23
    text-overflow: ellipsis;
24
    word-break: break-word;
25
  }
26
  img,
27
  video {
28
    max-width: 250px;
29
    max-height: 250px;
30
    object-fit: contain;
31
  }
32
  svg,
33
  small {
34
    color: var(--subtitle-color);
35
    font-size: 0.8rem;
36
  }
37
  .time {
38
    display: inline-flex;
39
    gap: 5px;
40
  }
41
  .emojione {
42
    width: 1rem;
43
    height: 1rem;
44
  }
45
`;
46
 
47
export default function Message({ message, reportUrl, onReport }) {
48
  const { u, type, user_name, not_received, seen, id, content, send, contentType, time } = message;
49
 
50
  const showName = type === 'group' && !u === 1;
51
 
52
  const messagesContent = {
53
    text: <p>{parse(window.emojione.shortnameToImage(content))}</p>,
54
    image: <img src={content} alt='chat_image' />,
55
    video: <video src={content} preload='none' controls />,
56
    document: (
57
      <a href={content} download>
58
        <img className='pdf' src='/images/extension/pdf.png' alt='pdf' />
59
      </a>
60
    )
61
  };
62
 
63
  return (
64
    <>
65
      {showName ? <span className='user_name'>{user_name}</span> : null}
66
      <MessageTemplate
67
        sx={
68
          send
69
            ? {
70
                alignSelf: 'flex-end',
71
                backgroundColor: '#eee',
72
                borderRadius: '10px 0px 10px 10px',
73
                marginRight: '0.5rem',
74
                color: '#393939'
75
              }
76
            : {
77
                alignSelf: 'flex-start',
78
                backgroundColor: 'var(--chat-received)',
79
                borderRadius: '0 10px 10px 10px',
80
                marginLeft: '0.5rem'
81
              }
82
        }
83
      >
84
        {messagesContent[contentType]}
85
 
86
        <small className='time'>
87
          <Check
88
            sx={{
89
              color: seen ? 'blue' : 'gray',
90
              display: not_received ? 'none' : 'flex'
91
            }}
92
          />
93
          {time}
94
        </small>
95
 
96
        <Options>
97
          {reportUrl && (
98
            <Options.Item onClick={() => onReport({ url: reportUrl, id })}>Reportar</Options.Item>
99
          )}
100
        </Options>
101
      </MessageTemplate>
102
    </>
103
  );
104
}