Skip to content

Commit

Permalink
use createCloneCell from WeaveClient
Browse files Browse the repository at this point in the history
  • Loading branch information
matthme committed Dec 14, 2024
1 parent 68ac497 commit c023ce3
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 28 deletions.
46 changes: 28 additions & 18 deletions ui/src/presence-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,9 @@ export class PresenceApp extends LitElement {
};
}
// take room info from cached value if it exists
const maybeRoomInfo = this._groupRooms.find(roomInfo =>
encodeHashToBase64(roomInfo.room.dna_hash) === dnaHashB64
const maybeRoomInfo = this._groupRooms.find(
roomInfo =>
encodeHashToBase64(roomInfo.room.dna_hash) === dnaHashB64
);
if (maybeRoomInfo) {
return {
Expand Down Expand Up @@ -356,12 +357,15 @@ export class PresenceApp extends LitElement {
return;
}
const randomWords = generateSillyPassword({ wordCount: 5 });
const clonedCell = await this.client.createCloneCell({
role_name: 'presence',
modifiers: {
network_seed: `privateRoom#${randomWords}`,
const clonedCell = await this._weaveClient.createCloneCell(
{
role_name: 'presence',
modifiers: {
network_seed: `privateRoom#${randomWords}`,
},
},
});
false // This is a private clone
);
const roomClient = new RoomClient(this.client, clonedCell.clone_id);
await roomClient.setRoomInfo({
name: roomNameInput.value,
Expand Down Expand Up @@ -402,13 +406,16 @@ export class PresenceApp extends LitElement {
const appletNetworkSeed =
this._provisionedCell.dna_modifiers.network_seed;
const networkSeed = groupRoomNetworkSeed(appletNetworkSeed, uuid);
const clonedCell = await this.client.createCloneCell({
role_name: 'presence',
modifiers: {
network_seed: networkSeed,
const clonedCell = await this._weaveClient.createCloneCell(
{
role_name: 'presence',
modifiers: {
network_seed: networkSeed,
},
name: roomNameInput.value,
},
name: roomNameInput.value,
});
true // This is a public clone
);

// register it in the main room
const descendentRoom = {
Expand Down Expand Up @@ -454,12 +461,15 @@ export class PresenceApp extends LitElement {
this.notifyError('Error: Secret words must not be empty.');
throw new Error('Secret words must not be empty.');
}
const clonedCell = await this.client.createCloneCell({
role_name: 'presence',
modifiers: {
network_seed: `privateRoom#${secretWordsInput.value}`,
const clonedCell = await this._weaveClient.createCloneCell(
{
role_name: 'presence',
modifiers: {
network_seed: `privateRoom#${secretWordsInput.value}`,
},
},
});
false // This is a private clone
);
this._personalRooms = [clonedCell, ...this._personalRooms];
secretWordsInput.value = '';
}
Expand Down
30 changes: 20 additions & 10 deletions ui/src/shared-room-card.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { LitElement, PropertyValueMap, css, html } from 'lit';
import { LitElement, css, html } from 'lit';
import { customElement, property, state } from 'lit/decorators.js';
import { AgentPubKey, AppClient, ClonedCell } from '@holochain/client';
import { localized, msg } from '@lit/localize';
import { WeaveClient } from '@theweave/api';

import '@shoelace-style/shoelace/dist/components/input/input';
import '@shoelace-style/shoelace/dist/components/icon/icon';
Expand All @@ -10,7 +11,7 @@ import { consume } from '@lit/context';
import { sharedStyles } from './sharedStyles';
import { clientContext } from './contexts';
import { RoomClient } from './room-client';
import { RoomInfo } from './types';
import { RoomInfo, weaveClientContext } from './types';
import { getCellTypes, groupRoomNetworkSeed } from './utils';
import { GroupRoomInfo } from './presence-app';

Expand All @@ -24,6 +25,10 @@ export class SharedRoomCard extends LitElement {
@state()
client!: AppClient;

@consume({ context: weaveClientContext })
@state()
_weaveClient!: WeaveClient;

@property()
groupRoomInfo!: GroupRoomInfo;

Expand Down Expand Up @@ -140,12 +145,15 @@ export class SharedRoomCard extends LitElement {
console.log('Installing cell.');
// network seed must be defined at this point
if (!this._networkSeed) throw new Error('Network seed undefined.');
this._myCell = await this.client.createCloneCell({
role_name: 'presence',
modifiers: {
network_seed: this._networkSeed,
this._myCell = await this._weaveClient.createCloneCell(
{
role_name: 'presence',
modifiers: {
network_seed: this._networkSeed,
},
},
});
true // This is a public clone
);
const roomClient = new RoomClient(this.client, this._myCell.clone_id);
const roomInfo = await roomClient.getRoomInfo();
if (roomInfo) {
Expand All @@ -164,8 +172,7 @@ export class SharedRoomCard extends LitElement {

renderActiveParticipants() {
if (!this._myCell) {
return html`<span
style="font-size: 18px; opacity: 0.8;"
return html`<span style="font-size: 18px; opacity: 0.8;"
>${msg(
'Join this room at least once to be able to see participants'
)}</span
Expand Down Expand Up @@ -212,7 +219,10 @@ export class SharedRoomCard extends LitElement {
</div>
</button>
</div>
<div class="row" style="flex: 1; width: calc(100% - 4px); justify-content: flex-end;">
<div
class="row"
style="flex: 1; width: calc(100% - 4px); justify-content: flex-end;"
>
${this.renderActiveParticipants()}
</div>
</div>
Expand Down

0 comments on commit c023ce3

Please sign in to comment.