@@ -61,28 +61,20 @@ abstract class EventProcessor {
6161 return event && typeof event === 'object' && 'kind' in event && 'content' in event ;
6262 }
6363
64- // Shared method to extract basic data
65- protected extractBasicData ( event : any ) : Partial < ProcessedData > {
66- return {
67- timestamp : event . created_at || Date . now ( ) ,
68- kind : event . kind ,
69- user : {
70- id : event . pubkey || '' ,
71- name : 'Anonymous'
72- } ,
73- features : [ ]
74- } ;
75- }
76-
7764 // Extract location from event tags
7865 protected extractLocation (
7966 event : any
8067 ) : { lngLat : [ number , number ] ; geohash : string | null } | null {
81- const gTags = event . tags . filter ( ( tag : any ) => tag [ 0 ] === 'g' && tag [ 1 ] ) ;
82- const longestGTag = gTags . reduce (
83- ( longest : string , tag : any ) => ( tag [ 1 ] . length > ( longest ?. length ?? 0 ) ? tag [ 1 ] : longest ) ,
84- ''
85- ) ;
68+ if ( ! event ?. tags ?. length ) return null ;
69+
70+ const longestGTag = event . tags
71+ . filter ( ( tag : any ) => tag [ 0 ] === 'g' && typeof tag [ 1 ] === 'string' && tag [ 1 ] . length )
72+ . reduce (
73+ ( longest : string , tag : any ) => ( tag [ 1 ] . length > longest . length ? tag [ 1 ] : longest ) ,
74+ ''
75+ ) ;
76+
77+ if ( ! longestGTag ) return null ;
8678
8779 // Check if longestGTag is in "lat,lng" format
8880 const latLngMatch = longestGTag . match ( / ^ ( - ? \d + ( \. \d + ) ? ) , \s * ( - ? \d + ( \. \d + ) ? ) $ / ) ;
@@ -113,13 +105,10 @@ class Kind36820Processor extends EventProcessor {
113105 if ( ! coordinates ) return null ;
114106
115107 let username : string | null = null ;
116- let content = event . content ;
117- let time = event . created_at ;
118- let rating = event . rating ;
108+ let { content, created_at : time , rating } = event ;
119109
120110 try {
121111 const data = JSON . parse ( content ) ;
122-
123112 username = data ?. hitchhikers ?. [ 0 ] ?. nickname ?? null ;
124113 content = data . comment || content ;
125114 if ( data . submission_time ) {
@@ -191,7 +180,7 @@ class DefaultProcessor extends EventProcessor {
191180 properties : {
192181 id : event . id ,
193182 pubkey : event . pubkey ,
194- user : null , // profile,
183+ user : profile ,
195184 time,
196185 username : username || undefined ,
197186 content,
@@ -225,14 +214,12 @@ class EventProcessorFactory {
225214EventProcessorFactory . register ( 36820 , Kind36820Processor ) ;
226215
227216export {
228- DefaultProcessor ,
229- EventProcessor ,
230- EventProcessorFactory ,
231- Kind36820Processor ,
232- type Feature ,
233- type LocationData ,
234- type ProcessedContent ,
235- type ProcessedData ,
236- type UserProfile
217+ DefaultProcessor ,
218+ EventProcessor ,
219+ EventProcessorFactory ,
220+ Kind36820Processor ,
221+ type LocationData ,
222+ type ProcessedContent ,
223+ type ProcessedData ,
224+ type UserProfile
237225} ;
238-
0 commit comments