Skip to content

Commit 4dc3ce9

Browse files
committed
Merge pull request #342 from uProxy/lucyhe-cloud_user_status
UserProfile should include status that indicates if a Cloud instance is owned by or shared with the local user.
2 parents 8cc65a2 + e033827 commit 4dc3ce9

File tree

3 files changed

+32
-11
lines changed

3 files changed

+32
-11
lines changed

src/cloud/social/freedom-module.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
"inviteUser": {
6060
"type": "method",
6161
"value": ["string"],
62-
"ret": "Object"
62+
"ret": "object"
6363
},
6464

6565
"acceptUserInvitation": {

src/cloud/social/provider.ts

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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) {

third_party/tsd.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"commit": "cb08e83dd87ace1202d1032a8f275b3efacde5c3"
2525
},
2626
"freedom/freedom.d.ts": {
27-
"commit": "af76bf46025371c760d8fe8c03cf874428da6124"
27+
"commit": "be6935555777a6e60fa7188df916cb9975cd4afe"
2828
},
2929
"freedom/freedom-core-env.d.ts": {
3030
"commit": "af76bf46025371c760d8fe8c03cf874428da6124"

0 commit comments

Comments
 (0)