1
-
2
1
const makebuffer = ( raw ) => {
3
2
let b = Uint8Array . from ( window . atob ( raw ) , ( v ) => v . charCodeAt ( 0 ) ) ;
4
3
// This data is padded with a 0x80 delimiter followed by any number of 0x00 bytes, but these are
@@ -50,12 +49,12 @@ const setup = async () => {
50
49
51
50
if ( msgs . length === 0 )
52
51
{
53
- elem . appendChild ( document . createTextNode ( `the ${ window . view_room } room is empty` ) ) ;
52
+ elem . appendChild ( document . createTextNode ( `the ${ window . view_room_token } room is empty` ) ) ;
54
53
}
55
54
56
55
for ( let msg of msgs . reverse ( ) )
57
56
{
58
- let e = document . createElement ( "li" )
57
+ let e = document . createElement ( "li" ) ;
59
58
try
60
59
{
61
60
const data = makebuffer ( msg . data ) ;
@@ -64,41 +63,42 @@ const setup = async () => {
64
63
{
65
64
throw Error ( err ) ;
66
65
}
67
-
66
+
68
67
const plain = Message . decode ( data ) . dataMessage ;
69
68
70
69
// reply
71
- if ( plain . quote ) {
72
- originalMsg = document . createElement ( 'p' ) ;
70
+ if ( plain . quote )
71
+ {
72
+ let originalMsg = document . createElement ( 'p' ) ;
73
73
originalMsg . classList . add ( 'text-sm' , 'italic' , 'border-l-2' , 'border-accent' , 'pl-2' ) ;
74
74
75
- authorId = plain . quote . author
75
+ let authorId = plain . quote . author ;
76
76
authorId = authorId . substr ( authorId . length - 8 ) ;
77
77
originalMsg . appendChild ( document . createTextNode ( "..." + authorId + ": " + plain . quote . text ) ) ;
78
78
e . appendChild ( originalMsg ) ;
79
79
}
80
-
80
+
81
81
// message body
82
82
e . appendChild ( document . createTextNode ( plain . profile . displayName + ": " + plain . body ) ) ;
83
83
e . classList . add ( 'bg-gray-300' , 'dark:bg-lightGray' , 'w-fit' , 'rounded-lg' , 'p-2' , 'my-2' )
84
84
elem . appendChild ( e ) ;
85
-
86
- // attachments
87
- if ( plain . attachments . length > 0 ) {
88
- plain . attachments . forEach ( attachment => {
89
- console . log ( attachment ) ;
90
- attachmentElement = document . createElement ( 'p' ) ;
91
- attachmentElement . appendChild ( document . createTextNode ( "📎\xa0\xa0\xa0" ) ) ;
92
-
93
- attachmentLink = document . createElement ( 'a' ) ;
94
- attachmentLink . appendChild ( document . createTextNode ( ( attachment . fileName || attachment . contentType ) + ` (${ formatBytes ( attachment . size ) } )` ) ) ;
95
- attachmentLink . href = attachment . url ;
96
- attachmentLink . download = ( attachment . fileName || "" ) ;
97
-
98
- attachmentElement . appendChild ( attachmentLink ) ;
99
- attachmentElement . classList . add ( 'text-sm' , 'italic' , 'pl-1' ) ;
100
- e . appendChild ( attachmentElement ) ;
101
- } ) ;
85
+
86
+ // show attachments
87
+ for ( let attachment of plain . attachments )
88
+ {
89
+
90
+ let attachmentElement = document . createElement ( 'p' ) ;
91
+ attachmentElement . appendChild ( document . createTextNode ( "📎\xa0\xa0\xa0" ) ) ;
92
+
93
+ let attachmentLink = document . createElement ( 'a' ) ;
94
+ attachmentLink . appendChild ( document . createTextNode ( ( attachment . fileName || attachment . contentType ) + ` (${ formatBytes ( attachment . size ) } )` ) ) ;
95
+ attachmentLink . href = attachment . url ;
96
+ attachmentLink . download = ( attachment . fileName || "" ) ;
97
+
98
+ attachmentElement . appendChild ( attachmentLink ) ;
99
+ attachmentElement . classList . add ( 'text-sm' , 'italic' , 'pl-1' ) ;
100
+ e . appendChild ( attachmentElement ) ;
101
+
102
102
}
103
103
104
104
}
0 commit comments