@@ -269,6 +269,8 @@ class AppView extends Tonic {
269
269
await sub . join ( )
270
270
}
271
271
} )
272
+
273
+ socket . on ( '#data' , ( ...args ) => console . log )
272
274
} else {
273
275
// If the user has changed the clusterId and or subclusterId, we need to tell the peer about it
274
276
// TODO(@heapwolf): we need a nice way to send config updates to the peer worker.
@@ -277,12 +279,13 @@ class AppView extends Tonic {
277
279
const { data : dataProjects } = await this . db . projects . readAll ( )
278
280
279
281
for ( const [ projectId , project ] of dataProjects . entries ( ) ) {
280
- if ( socket . subclusters . get ( project . subclusterId ) ) continue
282
+ if ( socket . subclusters . get ( project . subclusterId ) ) {
283
+ continue
284
+ }
281
285
282
286
const subcluster = await socket . subcluster ( { sharedKey : project . sharedKey } )
283
287
284
288
subcluster . on ( 'patch' , async ( value , packet ) => {
285
- console . log ( 'GOT PATCH!' , value , packet )
286
289
if ( ! packet . verified ) return // gtfoa
287
290
if ( packet . index !== - 1 ) return // not interested
288
291
@@ -293,6 +296,14 @@ class AppView extends Tonic {
293
296
const { data : hasPacket } = await this . db . patches . has ( key )
294
297
if ( hasPacket ) return
295
298
299
+ const patch = Buffer . from ( value . data ) . toString ( )
300
+ const headers = patch . split ( '---' ) [ 0 ]
301
+ const subjectHeader = headers . find ( s => s . includes ( 'Subject:' ) )
302
+ const branchingHash = subjectHeader . split ( / \[ P A T C H ] \s * / ) [ 0 ]
303
+
304
+ if ( branchingHash ) {
305
+ await this . db . patches . put ( branchingHash . trim ( ) , patch )
306
+ }
296
307
} )
297
308
298
309
subcluster . on ( 'clone' , async ( value , packet ) => {
0 commit comments