@ -6,6 +6,7 @@ import { Container } from '../container';
import { Logger } from '../logger' ;
import { VslsGuestService } from './guest' ;
import { VslsHostService } from './host' ;
import { debug } from '../system' ;
export const vslsUriPrefixRegex = /^[/|\\]~(?:\d+?|external)(?:[/|\\]|$)/ ;
export const vslsUriRootRegex = /^[/|\\]~(?:\d+?|external)$/ ;
@ -16,6 +17,21 @@ export interface ContactPresence {
}
export type ContactPresenceStatus = 'online' | 'away' | 'busy' | 'dnd' | 'offline' ;
function contactStatusToPresence ( status : string | undefined ) : ContactPresence {
switch ( status ) {
case 'available' :
return { status : 'online' , statusText : 'Available' } ;
case 'away' :
return { status : 'away' , statusText : 'Away' } ;
case 'busy' :
return { status : 'busy' , statusText : 'Busy' } ;
case 'doNotDisturb' :
return { status : 'dnd' , statusText : 'DND' } ;
default :
return { status : 'offline' , statusText : 'Offline' } ;
}
}
export class VslsController implements Disposable {
private _disposable : Disposable | undefined ;
private _guest : VslsGuestService | undefined ;
@ -88,6 +104,7 @@ export class VslsController implements Disposable {
setCommandContext ( CommandContext . Readonly , value ? true : undefined ) ;
}
@debug ( )
async getContact ( email : string | undefined ) {
if ( email === undefined ) return undefined ;
@ -98,22 +115,39 @@ export class VslsController implements Disposable {
return contacts . contacts [ email ] ;
}
@debug ( {
args : {
0 : ( emails : string [ ] ) = > ` length= ${ emails . length } `
}
} )
async getContacts ( emails : string [ ] ) {
const api = await this . _api ;
if ( api == null ) return undefined ;
const contacts = await api . getContacts ( emails ) ;
return Object . values ( contacts . contacts ) ;
}
@debug ( )
async getContactPresence ( email : string | undefined ) : Promise < ContactPresence | undefined > {
const contact = await this . getContact ( email ) ;
if ( contact == null ) return undefined ;
switch ( contact . status ) {
case 'available' :
return { status : 'online' , statusText : 'Available' } ;
case 'away' :
return { status : 'away' , statusText : 'Away' } ;
case 'busy' :
return { status : 'busy' , statusText : 'Busy' } ;
case 'doNotDisturb' :
return { status : 'dnd' , statusText : 'DND' } ;
default :
return { status : 'offline' , statusText : 'Offline' } ;
return contactStatusToPresence ( contact . status ) ;
}
@debug ( {
args : {
0 : ( emails : string [ ] ) = > ` length= ${ emails . length } `
}
} )
async getContactsPresence ( emails : string [ ] ) : Promise < Map < string , ContactPresence > | undefined > {
const contacts = await this . getContacts ( emails ) ;
if ( contacts == null ) return undefined ;
return new Map < string , ContactPresence > (
Object . values ( contacts ) . map ( c = > [ c . email , contactStatusToPresence ( c . status ) ] )
) ;
}
async invite ( email : string | undefined ) {