-
Notifications
You must be signed in to change notification settings - Fork 375
/
MessageMonitorMetadata.tsx
116 lines (109 loc) · 3.43 KB
/
MessageMonitorMetadata.tsx
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import React from 'react'
import { View } from 'react-native'
import { Icon, Text } from '@ui-kitten/components'
import { useStyles } from '@berty-tech/styles'
import beapi from '@berty-tech/api'
import { pbDateToNum, timeFormat } from '../../helpers'
import { InteractionMonitorMetadata } from '@berty-tech/store/types.gen'
const eventMonitorTypes = beapi.protocol.MonitorGroup.TypeEventMonitor
export const MessageMonitorMetadata: React.FC<{ inte: InteractionMonitorMetadata }> = ({
inte,
}) => {
const [{ padding, text, margin }] = useStyles()
const sentDate = pbDateToNum(inte?.sentDate)
const me = inte.payload.event
let monitorPayloadTitle: string
let monitorPayloadSubtitle: string[] | undefined
switch (me?.type) {
case eventMonitorTypes.TypeEventMonitorAdvertiseGroup:
const msgAdvertise = `local peer advertised ${me.advertiseGroup?.peerId?.substr(
me.advertiseGroup.peerId.length - 10,
)} on ${me.advertiseGroup?.driverName}, with ${me.advertiseGroup?.maddrs?.length} maddrs:`
monitorPayloadSubtitle = me.advertiseGroup?.maddrs?.map((addr: string) => `--${addr}`)
monitorPayloadTitle = msgAdvertise
break
case eventMonitorTypes.TypeEventMonitorPeerFound:
monitorPayloadTitle = `new peer found ${me.peerFound?.peerId?.substr(
me.peerFound.peerId.length - 10,
)} on ${me.peerFound?.driverName}, with ${me.peerFound?.maddrs?.length} maddrs:`
monitorPayloadSubtitle = me.peerFound?.maddrs?.map((addr: string) => `--${addr}`)
break
case eventMonitorTypes.TypeEventMonitorPeerJoin:
if (me.peerJoin?.isSelf) {
monitorPayloadTitle = 'you just joined this group'
} else {
let activeAddr = '<unknown>'
if (me.peerJoin?.maddrs?.length) {
activeAddr = me.peerJoin?.maddrs[0]
}
monitorPayloadTitle = `peer joined ${me.peerJoin?.peerId?.substr(
me.peerJoin.peerId.length - 10,
)} on: ${activeAddr}`
}
break
case eventMonitorTypes.TypeEventMonitorPeerLeave:
if (me.peerLeave?.isSelf) {
monitorPayloadTitle = 'you just leaved this group'
} else {
monitorPayloadTitle = `peer leaved ${me.peerLeave?.peerId?.substr(
me.peerLeave.peerId.length - 10,
)}`
}
break
default:
console.log('undefined event type', me)
monitorPayloadTitle = 'undefined'
}
return (
<View style={[padding.vertical.tiny, padding.horizontal.medium]}>
<View style={[{ justifyContent: 'center', alignItems: 'flex-start' }, padding.small]}>
<View
style={[
{
alignItems: 'center',
justifyContent: 'center',
width: '100%',
},
margin.bottom.small,
]}
>
<Icon name='monitor-outline' fill='#4E58BF' width={25} height={25} />
</View>
<Text
style={[
{ textAlign: 'left', fontFamily: 'Open Sans', color: '#4E58BF' },
text.bold.small,
text.italic,
text.size.scale(14),
]}
>
{monitorPayloadTitle}
</Text>
{monitorPayloadSubtitle &&
monitorPayloadSubtitle.map((subtitle: string) => (
<Text
style={[
{ textAlign: 'left', fontFamily: 'Open Sans', color: '#4E58BF' },
text.bold.small,
text.italic,
text.size.scale(14),
margin.top.tiny,
]}
>
{subtitle}
</Text>
))}
</View>
<Text
style={[
{ fontFamily: 'Open Sans', alignSelf: 'flex-end', color: '#4E58BF' },
text.bold.small,
text.italic,
text.size.small,
]}
>
{timeFormat.fmtTimestamp3(sentDate)}
</Text>
</View>
)
}