(activity: Record<string, any>)
| 401 | } |
| 402 | |
| 403 | export function activityToNotification(activity: Record<string, any>): Record<string, any> | null { |
| 404 | const note: Record<string, any> = {}; |
| 405 | |
| 406 | note.id = activity.max_position; |
| 407 | note.created_at = convertTimestamp(activity.created_at); |
| 408 | if (activity.action === 'favorite') { |
| 409 | note.type = 'favourite'; |
| 410 | note.status = tweetToToot(activity.targets[0]); |
| 411 | note.account = userToAccount(activity.sources[0]); |
| 412 | } else if (activity.action === 'reply') { |
| 413 | note.type = 'mention'; |
| 414 | note.status = tweetToToot(activity.targets[0]); |
| 415 | note.account = userToAccount(activity.sources[0]); |
| 416 | } else if (activity.action === 'mention') { |
| 417 | note.type = 'mention'; |
| 418 | note.status = tweetToToot(activity.target_objects[0]); |
| 419 | note.account = userToAccount(activity.sources[0]); |
| 420 | } else if (activity.action === 'retweet') { |
| 421 | note.type = 'reblog'; |
| 422 | note.status = tweetToToot(activity.targets[0]); |
| 423 | note.account = userToAccount(activity.sources[0]); |
| 424 | } else if (activity.action === 'follow') { |
| 425 | note.type = 'follow'; |
| 426 | note.account = userToAccount(activity.sources[0]); |
| 427 | } else { |
| 428 | console.warn('unhandled activity', activity); |
| 429 | note.type = 'invalid'; |
| 430 | return note; |
| 431 | } |
| 432 | |
| 433 | return note; |
| 434 | } |
no test coverage detected