import { USER_EVENT , UserClientAddEvent , UserClientRemoveEvent , UserConnectionEvent , UserEvent , UserUpdateEvent , } from '@wireapp/api-client/src/event' ; import { PayloadBundle , PayloadBundleSource , PayloadBundleState , PayloadBundleType } from '../conversation' ; import { MessageBuilder } from '../conversation/message/MessageBuilder' ; export class UserMapper { public static mapUserEvent ( event , selfUserId , source ) { switch ( event . type ) { case USER_EVENT . CONNECTION : { const { connection , user } = event as UserConnectionEvent ; return { content : { connection , user } , conversation : connection . conversation , from : connection . from , id : MessageBuilder . createId ( ) , messageTimer : 0 , source , state : PayloadBundleState . INCOMING , timestamp : new Date ( connection . last_update ) . getTime ( ) , type : PayloadBundleType . CONNECTION_REQUEST , } ; } case USER_EVENT . CLIENT_ADD : { const { client } = event as UserClientAddEvent ; return { content : { client } , conversation : selfUserId , from : selfUserId , id : MessageBuilder . createId ( ) , messageTimer : 0 , source , state : PayloadBundleState . INCOMING , timestamp : new Date ( ) . getTime ( ) , type : PayloadBundleType . CLIENT_ADD , } ; } case USER_EVENT . UPDATE : { const { user } = event as UserUpdateEvent ; return { content : { user } , conversation : selfUserId , from : selfUserId , id : MessageBuilder . createId ( ) , source , state : PayloadBundleState . INCOMING , timestamp : new Date ( ) . getTime ( ) , type : PayloadBundleType . USER_UPDATE , } ; } case USER_EVENT . CLIENT_REMOVE : { const { client } = event as UserClientRemoveEvent ; return { content : { client } , conversation : selfUserId , from : selfUserId , id : MessageBuilder . createId ( ) , messageTimer : 0 , source , state : PayloadBundleState . INCOMING , timestamp : new Date ( ) . getTime ( ) , type : PayloadBundleType . CLIENT_REMOVE , } ; } } } }