11import lodash from 'lodash'
2+ import sanitizeHtml from 'sanitize-html'
23import { DevtoArticle , DevtoComment , DevtoUser } from '../usecases/devto/types'
34import { single } from '../../../utils/arrays'
4- import { getUser } from '../usecases/devto/getUser'
5+ import { getUserById } from '../usecases/devto/getUser'
56import IntegrationRepository from '../../../database/repositories/integrationRepository'
67import { IRepositoryOptions } from '../../../database/repositories/IRepositoryOptions'
78import Operations from '../../dbOperations/operations'
@@ -96,8 +97,10 @@ export default class DevtoIterator extends BaseIterator {
9697 // does not contain all the user information we can get full profile and set it to comments
9798 const userIds : number [ ] = DevtoIterator . getUserIdsFromComments ( comments )
9899 for ( const userId of userIds ) {
99- const fullUser = await getUser ( userId )
100- DevtoIterator . setFullUser ( comments , fullUser )
100+ const fullUser = await getUserById ( userId )
101+ if ( fullUser !== null ) {
102+ DevtoIterator . setFullUser ( comments , fullUser )
103+ }
101104 }
102105
103106 return {
@@ -195,30 +198,33 @@ export default class DevtoIterator extends BaseIterator {
195198
196199 const communityMember : CommunityMember = {
197200 username : {
198- [ PlatformType . DEVTO ] : comment . fullUser . username ,
201+ [ PlatformType . DEVTO ] : comment . user . username ,
199202 } ,
200203 crowdInfo : {
201204 [ PlatformType . DEVTO ] : {
202- id : comment . fullUser . id ,
205+ url : `https://dev.to/ ${ encodeURIComponent ( comment . fullUser . username ) } ` ,
203206 } ,
204207 } ,
205- bio : comment . fullUser ?. summary || '' ,
206- location : comment . fullUser ?. location || '' ,
207208 }
208209
209- if ( comment . fullUser . twitter_username ) {
210+ if ( comment . user . twitter_username ) {
210211 communityMember . crowdInfo . twitter = {
211- url : `https://twitter.com/${ comment . fullUser . twitter_username } ` ,
212+ url : `https://twitter.com/${ comment . user . twitter_username } ` ,
212213 }
213- communityMember . username . twitter = comment . fullUser . twitter_username
214+ communityMember . username . twitter = comment . user . twitter_username
214215 }
215216
216- if ( comment . fullUser . github_username ) {
217+ if ( comment . user . github_username ) {
217218 communityMember . crowdInfo . github = {
218- name : comment . fullUser . name ,
219- url : `https://github.com/${ comment . fullUser . github_username } ` ,
219+ name : comment . user . name ,
220+ url : `https://github.com/${ comment . user . github_username } ` ,
220221 }
221- communityMember . username . github = comment . fullUser . github_username
222+ communityMember . username . github = comment . user . github_username
223+ }
224+
225+ if ( comment . fullUser ) {
226+ communityMember . bio = comment . fullUser ?. summary || ''
227+ communityMember . location = comment . fullUser ?. location || ''
222228 }
223229
224230 activities . push ( {
@@ -229,12 +235,15 @@ export default class DevtoIterator extends BaseIterator {
229235 sourceId : comment . id_code ,
230236 sourceParentId : parentCommentId ,
231237 crowdInfo : {
232- bodyHtml : comment . body_html ,
233- userUrl : `https://dev.to/${ encodeURIComponent ( comment . fullUser . username ) } ` ,
234- commentUrl : `https://dev.to/${ encodeURIComponent ( comment . fullUser . username ) } /comment/${
238+ body : sanitizeHtml ( comment . body_html ) ,
239+ url : `https://dev.to/${ encodeURIComponent ( comment . fullUser . username ) } /comment/${
235240 comment . id_code
236241 } `,
242+ thread : parentCommentId !== undefined ,
243+
244+ userUrl : `https://dev.to/${ encodeURIComponent ( comment . fullUser . username ) } ` ,
237245 articleUrl : article . url ,
246+ articleTitle : article . title ,
238247 } ,
239248 communityMember,
240249
0 commit comments