Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UserProfile should include status that indicates if a Cloud instance is owned by or shared with the local user. #342

Merged
merged 6 commits into from
Jan 6, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/cloud/social/freedom-module.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"inviteUser": {
"type": "method",
"value": ["string"],
"ret": "Object"
"ret": "object"
},

"acceptUserInvitation": {
Expand Down
39 changes: 30 additions & 9 deletions src/cloud/social/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,19 @@ interface SavedContact {
description?: string;
}

// State of remote user's relationship to local user.
// Defined in github.com/uProxy/uproxy/blob/dev/src/interfaces/social.ts
//
// For cloud instances, only CLOUD_INSTANCE_CREATED_BY_LOCAL or
// CLOUD_INSTANCE_SHARED_WITH_LOCAL are possible statuses.
enum UserStatus {
FRIEND = 0,
LOCAL_INVITED_BY_REMOTE = 1,
REMOTE_INVITED_BY_LOCAL = 2,
CLOUD_INSTANCE_CREATED_BY_LOCAL = 3,
CLOUD_INSTANCE_SHARED_WITH_LOCAL = 4
}

// Returns a VersionedPeerMessage, as defined in interfaces/social.ts
// in the uProxy repo.
//
Expand Down Expand Up @@ -112,10 +125,17 @@ function makeClientState(address: string): freedom.Social.ClientState {
// To see how these fields are handled, see
// generic_core/social.ts#handleUserProfile in the uProxy repo. We omit
// the status field since remote-user.ts#update will use FRIEND as a default.
function makeUserProfile(address: string): freedom.Social.UserProfile {
function makeUserProfile(
address: string,
username :string): freedom.Social.UserProfile {
var status = UserStatus.CLOUD_INSTANCE_SHARED_WITH_LOCAL;
if (username === ADMIN_USERNAME) {
status = UserStatus.CLOUD_INSTANCE_CREATED_BY_LOCAL;
}
return {
userId: address,
name: address
name: address,
status: status
};
}

Expand Down Expand Up @@ -153,20 +173,21 @@ export class CloudSocialProvider {

constructor(private dispatchEvent_: (name: string, args: Object) => void) { }

// Emits the messages necessary to make the user appear online
// Emits the messages necessary to make the user appear online
// in the contacts list.
private notifyOfUser_ = (address: string, description?: string) => {
this.dispatchEvent_('onUserProfile', makeUserProfile(address));
private notifyOfUser_ = (invite: Invite, description?: string) => {
this.dispatchEvent_('onUserProfile',
makeUserProfile(invite.host, invite.user));

var clientState = makeClientState(address);
var clientState = makeClientState(invite.host);
this.dispatchEvent_('onClientState', clientState);

// Pretend that we received a message from a remote uProxy client.
this.dispatchEvent_('onMessage', {
from: clientState,
// INSTANCE
message: JSON.stringify(makeVersionedPeerMessage(
3000, makeInstanceMessage(address, description)))
3000, makeInstanceMessage(invite.host, description)))
});
}

Expand Down Expand Up @@ -204,7 +225,7 @@ export class CloudSocialProvider {
log.warn('failed to fetch banner: %1', e);
return '';
}).then((banner: string) => {
this.notifyOfUser_(invite.host, banner);
this.notifyOfUser_(invite, banner);
this.savedContacts_[invite.host] = {
invite: invite,
description: banner
Expand Down Expand Up @@ -234,7 +255,7 @@ export class CloudSocialProvider {
if (savedContacts.contacts) {
for (let contact of savedContacts.contacts) {
this.savedContacts_[contact.invite.host] = contact;
this.notifyOfUser_(contact.invite.host, contact.description);
this.notifyOfUser_(contact.invite, contact.description);
}
}
} catch (e) {
Expand Down
2 changes: 1 addition & 1 deletion third_party/tsd.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"commit": "cb08e83dd87ace1202d1032a8f275b3efacde5c3"
},
"freedom/freedom.d.ts": {
"commit": "af76bf46025371c760d8fe8c03cf874428da6124"
"commit": "be6935555777a6e60fa7188df916cb9975cd4afe"
},
"freedom/freedom-core-env.d.ts": {
"commit": "af76bf46025371c760d8fe8c03cf874428da6124"
Expand Down