-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathcontentHandler.js
53 lines (49 loc) · 1.62 KB
/
contentHandler.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
const staticHandlers = {
descriptionDefault(descriptionElement, message, li, self) {
const now = new Date();
const time = new Date(message.timestamp);
var timeStr = time.getHours() + ":" + time.getMinutes();
// If the difference of the message is more away than 1 day
if (now.getTime() - time > 86400000 || true) {
timeStr = time.getDate() + "." + (time.getMonth() + 1) + "." + time.getFullYear() + ", " + timeStr
}
descriptionElement.append(timeStr);
if (self.messages[message.id - 1] && message.timestamp - self.messages[message.id - 1].timestamp < 60 * 1000) {
//descriptionElement.hidden = true;
}
}
};
module.exports = [
{
type: /^text\/.*$/,
content(contentElement, message, li, self) {
contentElement.append(message.content.source);
},
description: staticHandlers.descriptionDefault
},
{
type: /^image\/.*$/,
content(contentElement, message, li, self) {
const img = document.createElement("img");
img.src = message.content.source;
contentElement.append(img);
li.classList.add("attachment");
},
description: staticHandlers.descriptionDefault
},
{
type: /^audio\/.*$/,
content(contentElement, message, li, self) {
const audio = document.createElement("audio");
audio.controls = true;
audio.src = message.content.source;
contentElement.append(audio);
//console.log(audio);
//audio.play();
//audio.attachShadow({mode: 'open'});
//audio.attachShadow({mode: 'close'});
li.classList.add("attachment");
},
description: staticHandlers.descriptionDefault
}
];