@@ -58,6 +58,19 @@ interface SavedContact {
5858 description ?: string ;
5959}
6060
61+ // State of remote user's relationship to local user.
62+ // Defined in github.com/uProxy/uproxy/blob/dev/src/interfaces/social.ts
63+ //
64+ // For cloud instances, only CLOUD_INSTANCE_CREATED_BY_LOCAL or
65+ // CLOUD_INSTANCE_SHARED_WITH_LOCAL are possible statuses.
66+ enum UserStatus {
67+ FRIEND = 0 ,
68+ LOCAL_INVITED_BY_REMOTE = 1 ,
69+ REMOTE_INVITED_BY_LOCAL = 2 ,
70+ CLOUD_INSTANCE_CREATED_BY_LOCAL = 3 ,
71+ CLOUD_INSTANCE_SHARED_WITH_LOCAL = 4
72+ }
73+
6174// Returns a VersionedPeerMessage, as defined in interfaces/social.ts
6275// in the uProxy repo.
6376//
@@ -112,10 +125,17 @@ function makeClientState(address: string): freedom.Social.ClientState {
112125// To see how these fields are handled, see
113126// generic_core/social.ts#handleUserProfile in the uProxy repo. We omit
114127// the status field since remote-user.ts#update will use FRIEND as a default.
115- function makeUserProfile ( address : string ) : freedom . Social . UserProfile {
128+ function makeUserProfile (
129+ address : string ,
130+ username :string ) : freedom . Social . UserProfile {
131+ var status = UserStatus . CLOUD_INSTANCE_SHARED_WITH_LOCAL ;
132+ if ( username === ADMIN_USERNAME ) {
133+ status = UserStatus . CLOUD_INSTANCE_CREATED_BY_LOCAL ;
134+ }
116135 return {
117136 userId : address ,
118- name : address
137+ name : address ,
138+ status : status
119139 } ;
120140}
121141
@@ -153,20 +173,21 @@ export class CloudSocialProvider {
153173
154174 constructor ( private dispatchEvent_ : ( name : string , args : Object ) => void ) { }
155175
156- // Emits the messages necessary to make the user appear online
176+ // Emits the messages necessary to make the user appear online
157177 // in the contacts list.
158- private notifyOfUser_ = ( address : string , description ?: string ) => {
159- this . dispatchEvent_ ( 'onUserProfile' , makeUserProfile ( address ) ) ;
178+ private notifyOfUser_ = ( invite : Invite , description ?: string ) => {
179+ this . dispatchEvent_ ( 'onUserProfile' ,
180+ makeUserProfile ( invite . host , invite . user ) ) ;
160181
161- var clientState = makeClientState ( address ) ;
182+ var clientState = makeClientState ( invite . host ) ;
162183 this . dispatchEvent_ ( 'onClientState' , clientState ) ;
163184
164185 // Pretend that we received a message from a remote uProxy client.
165186 this . dispatchEvent_ ( 'onMessage' , {
166187 from : clientState ,
167188 // INSTANCE
168189 message : JSON . stringify ( makeVersionedPeerMessage (
169- 3000 , makeInstanceMessage ( address , description ) ) )
190+ 3000 , makeInstanceMessage ( invite . host , description ) ) )
170191 } ) ;
171192 }
172193
@@ -204,7 +225,7 @@ export class CloudSocialProvider {
204225 log . warn ( 'failed to fetch banner: %1' , e ) ;
205226 return '' ;
206227 } ) . then ( ( banner : string ) => {
207- this . notifyOfUser_ ( invite . host , banner ) ;
228+ this . notifyOfUser_ ( invite , banner ) ;
208229 this . savedContacts_ [ invite . host ] = {
209230 invite : invite ,
210231 description : banner
@@ -234,7 +255,7 @@ export class CloudSocialProvider {
234255 if ( savedContacts . contacts ) {
235256 for ( let contact of savedContacts . contacts ) {
236257 this . savedContacts_ [ contact . invite . host ] = contact ;
237- this . notifyOfUser_ ( contact . invite . host , contact . description ) ;
258+ this . notifyOfUser_ ( contact . invite , contact . description ) ;
238259 }
239260 }
240261 } catch ( e ) {
0 commit comments