@@ -136,14 +136,51 @@ export async function renderMessageRow (channelObject, message, fresh, options,
136136 const colorizeByAuthor =
137137 options . colorizeByAuthor === '1' || options . colorizeByAuthor === true
138138
139+ // const id = store.any(latestVersion, ns.sioc('id'))
140+ // const replies = store.each(latestVersion, ns.sioc('has_reply'))
141+
139142 const creator = store . any ( message , ns . foaf ( 'maker' ) )
140143 const date = store . any ( message , ns . dct ( 'created' ) )
141- const latestVersion = mostRecentVersion ( message )
144+ const latestVersion = await mostRecentVersion ( message )
145+ debug . log ( '@@@@ alain mostRecentVersion' )
146+ debug . log ( message )
147+ debug . log ( latestVersion )
142148 const latestVersionCreator = store . any ( latestVersion , ns . foaf ( 'maker' ) )
143149
144150 // use latest content if same owner, else use original
145- const msgId = creator . uri === latestVersionCreator . uri ? latestVersion : message
151+ // this is may be too strict. Should we find latest valid version if any ?
152+ debug . log ( '@@@@ alain creator' )
153+ debug . log ( creator )
154+ debug . log ( latestVersionCreator )
155+ const msgId = creator . uri === latestVersionCreator ?. uri ? latestVersion : message
146156 const content = store . any ( msgId , ns . sioc ( 'content' ) )
157+
158+ const versions = await allVersions ( msgId )
159+ if ( versions . length > 1 ) {
160+ debug . log ( 'renderMessageRow versions: ' , versions . join ( ', ' ) )
161+ }
162+ // be tolerant in accepting replies on any version of a message
163+ const replies = versions . map ( version => store . each ( version , ns . sioc ( 'has_reply' ) ) ) . flat ( )
164+
165+ let thread = null
166+ const straightReplies = [ ]
167+ for ( const reply of replies ) {
168+ if ( store . holds ( reply , ns . rdf ( 'type' ) , ns . sioc ( 'Thread' ) ) ) {
169+ thread = reply
170+ debug . log ( 'renderMessageRow: found thread: ' + thread )
171+ } else {
172+ straightReplies . push ( reply )
173+ }
174+ }
175+ if ( straightReplies . length > 1 ) {
176+ debug . log ( 'renderMessageRow: found normal replies: ' , straightReplies )
177+ }
178+ debug . log ( '@@@@ alain thread' )
179+ // debug.log(replies)
180+ // debug.log(thread)
181+ thread = store . any ( msgId , ns . sioc ( 'has_reply' ) ) // if (!thread)
182+ debug . log ( thread )
183+ // get signature
147184 const signature = store . any ( msgId , $rdf . sym ( `${ SEC } proofValue` ) )
148185
149186 // set message object
@@ -153,16 +190,14 @@ export async function renderMessageRow (channelObject, message, fresh, options,
153190 msg . content = content . value
154191 msg . maker = creator . uri
155192
156- // unsigned message
157- if ( ! signature ?. value ) {
193+ // verify signature
194+ if ( ! signature ?. value ) { // unsigned message
158195 unsignedMessage = true
159196 debug . warn ( msgId . uri + ' is unsigned' ) // TODO replace with UI (colored message ?)
160197 } else { // signed message, get public key and check signature
161198 getPublicKey ( creator ) . then ( publicKey => {
162199 debug . log ( creator . uri + '\n' + msg . created + '\n' + msg . id + '\n' + publicKey )
163200 if ( ! publicKey ) {
164- // TODO try to recreate the publicKey
165- // if(me.uri === creator.uri) await getPrivateKey(creator)
166201 debug . warn ( 'message is signed but ' + creator . uri + ' is missing publicKey' )
167202 }
168203 // check that publicKey is a valid hex string
@@ -172,28 +207,6 @@ export async function renderMessageRow (channelObject, message, fresh, options,
172207 else if ( signature ?. value && ! verifySignature ( signature ?. value , msg , publicKey ) ) debug . warn ( 'invalid signature\n' + msg . id )
173208 } )
174209 }
175- // const id = store.any(latestVersion, ns.sioc('id'))
176- // const replies = store.each(latestVersion, ns.sioc('has_reply'))
177- const versions = await allVersions ( message )
178- if ( versions . length > 1 ) {
179- debug . log ( 'renderMessageRow versions: ' , versions . join ( ', ' ) )
180- }
181- // be tolerant in accepting replies on any version of a message
182- const replies = versions . map ( version => store . each ( version , ns . sioc ( 'has_reply' ) ) ) . flat ( )
183-
184- let thread = null
185- const straightReplies = [ ]
186- for ( const reply of replies ) {
187- if ( store . holds ( reply , ns . rdf ( 'type' ) , ns . sioc ( 'Thread' ) ) ) {
188- thread = reply
189- debug . log ( 'renderMessageRow: found thread: ' + thread )
190- } else {
191- straightReplies . push ( reply )
192- }
193- }
194- if ( straightReplies . length > 1 ) {
195- debug . log ( 'renderMessageRow: found normal replies: ' , straightReplies )
196- }
197210
198211 const originalMessage = await originalVersion ( message )
199212 const edited = ! message . sameTerm ( originalMessage )
0 commit comments