Skip to content

Commit

Permalink
Hiding my current presence from quickpick and treeview (#907)
Browse files Browse the repository at this point in the history
* Refactor WebExtensionContext to include currentConnectionId property

* enabling co-presence on vscode web
  • Loading branch information
ritikramuka authored Apr 15, 2024
1 parent 7e0d326 commit 62b9984
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 22 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@
"command": "powerPlatform.previewCurrentActiveUsers",
"alt": "current active users",
"group": "navigation",
"when": "never"
"when": "isWeb && virtualWorkspace"
}
],
"commandPalette": [
Expand Down Expand Up @@ -955,7 +955,7 @@
{
"id": "powerpages.collaborationView",
"name": "People On The Site",
"when": "never",
"when": "isWeb && virtualWorkspace",
"contextualTitle": "People On The Site",
"visibility": "visible"
}
Expand Down
9 changes: 9 additions & 0 deletions src/web/client/WebExtensionContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ class WebExtensionContext implements IWebExtensionContext {
private _worker: Worker | undefined;
private _sharedWorkSpaceMap: Map<string, string>;
private _containerId: string;
private _currentConnectionId: string;
private _connectedUsers: UserDataMap;
private _quickPickProvider: QuickPickProvider;
private _userCollaborationProvider: UserCollaborationProvider;
Expand Down Expand Up @@ -216,6 +217,9 @@ class WebExtensionContext implements IWebExtensionContext {
public set containerId(containerId: string) {
this._containerId = containerId;
}
public get currentConnectionId() {
return this._currentConnectionId;
}
public get quickPickProvider() {
return this._quickPickProvider;
}
Expand Down Expand Up @@ -257,6 +261,7 @@ class WebExtensionContext implements IWebExtensionContext {
this._concurrencyHandler = new ConcurrencyHandler();
this._sharedWorkSpaceMap = new Map<string, string>();
this._containerId = "";
this._currentConnectionId = "";
this._connectedUsers = new UserDataMap();
this._quickPickProvider = new QuickPickProvider();
this._userCollaborationProvider = new UserCollaborationProvider();
Expand Down Expand Up @@ -790,6 +795,10 @@ class WebExtensionContext implements IWebExtensionContext {
this.connectedUsers.removeUser(userId, removeConnectionData);
}

public setCurrentConnectionId(connectionId: string) {
this._currentConnectionId = connectionId;
}

public async getMail(userId: string): Promise<string> {
const mail = await this.graphClientService.getUserEmail(userId);
return mail;
Expand Down
1 change: 1 addition & 0 deletions src/web/client/common/worker/webworker.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ async function loadContainer(config, swpId, entityInfo) {
userName: member.userName,
containerId: swpId,
connectionData: userConnectionData,
currentConnectionId: myConnectionId,
});
} catch (error) {
self.postMessage({
Expand Down
5 changes: 5 additions & 0 deletions src/web/client/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,11 @@ export function createWebWorkerInstance(
data.userId,
data.connectionData
);

if (data.currentConnectionId) {
WebExtensionContext.setCurrentConnectionId(data.currentConnectionId);
}

WebExtensionContext.userCollaborationProvider.refresh();
WebExtensionContext.quickPickProvider.refresh();
}
Expand Down
4 changes: 1 addition & 3 deletions src/web/client/utilities/commonUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,7 @@ export function isCoPresenceEnabled() {
);
}

// return isCoPresenceEnabled as boolean;
// Co-presence feature is disabled for now
return false;
return isCoPresenceEnabled;
}

/**
Expand Down
17 changes: 10 additions & 7 deletions src/web/client/webViews/QuickPickProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,16 @@ export class QuickPickProvider {

for (const [, value] of connectedUsersMap.entries()) {
for (const connection of value._connectionData) {
const contentPageId = WebExtensionContext.entityForeignKeyDataMap.getEntityForeignKeyMap.get(`${connection.entityId[0]}`);
// List all the user connections except the current connection
if (connection.connectionId !== WebExtensionContext.currentConnectionId) {
const contentPageId = WebExtensionContext.entityForeignKeyDataMap.getEntityForeignKeyMap.get(`${connection.entityId[0]}`);

if (contentPageId && contentPageId.has(`${entityInfo.entityId}`)) {
userMap.set(value._userId, {
label: value._userName,
id: value._userId,
});
if (contentPageId && contentPageId.has(`${entityInfo.entityId}`)) {
userMap.set(value._userId, {
label: value._userName,
id: value._userId,
});
}
}
}
}
Expand Down Expand Up @@ -89,7 +92,7 @@ export class QuickPickProvider {
];

const collaborationOptionsSelected = await vscode.window.showQuickPick(collaborationOptions, {
title: vscode.l10n.t(Constants.WEB_EXTENSION_COLLABORATION_OPTIONS_CONTACT.toUpperCase() + ` ${selectedOption.label.toUpperCase()}`),
title: vscode.l10n.t(Constants.WEB_EXTENSION_COLLABORATION_OPTIONS_CONTACT.toUpperCase() + ` ${selectedOption.label.toUpperCase()}`),
});

if (collaborationOptionsSelected) {
Expand Down
22 changes: 12 additions & 10 deletions src/web/client/webViews/userCollaborationProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import WebExtensionContext from "../WebExtensionContext";
import * as Constants from "../common/constants";

export class UserCollaborationProvider
implements vscode.TreeDataProvider<UserNode>
{
implements vscode.TreeDataProvider<UserNode> {
private _onDidChangeTreeData: vscode.EventEmitter<
UserNode | undefined | void
> = new vscode.EventEmitter<UserNode | undefined | void>();
Expand All @@ -30,15 +29,18 @@ export class UserCollaborationProvider

getConnectedUsers(): UserNode[] {
const connectedUsersMap = WebExtensionContext.connectedUsers.getUserMap;
const connectedUsers: UserNode[] = Array.from(
connectedUsersMap.entries()
).map(([, value]) => {
return new UserNode(
value._userName,
value._userId,
vscode.TreeItemCollapsibleState.None
const connectedUsers: UserNode[] = Array.from(connectedUsersMap.values())
.filter(value =>
!(value._connectionData.length === 0 ||
(value._connectionData.length === 1 && value._connectionData[0].connectionId === WebExtensionContext.currentConnectionId))
)
.map(value =>
new UserNode(
value._userName,
value._userId,
vscode.TreeItemCollapsibleState.None
)
);
});

return connectedUsers;
}
Expand Down

0 comments on commit 62b9984

Please sign in to comment.