mirror of
https://github.com/fluencelabs/fluent-pad
synced 2025-04-24 16:32:13 +00:00
Minor fixes. Users become online momentarily
This commit is contained in:
parent
47aad98639
commit
e1574427a5
@ -42,6 +42,8 @@ const throwIfError = (result: ServiceResult) => {
|
||||
}
|
||||
};
|
||||
|
||||
export type PeerId = string;
|
||||
|
||||
export const updateOnlineStatuses = async (client: FluenceClient) => {
|
||||
const particle = new Particle(
|
||||
`
|
||||
@ -59,7 +61,7 @@ export const updateOnlineStatuses = async (client: FluenceClient) => {
|
||||
(call u.$.relay_id ("op" "identity") [])
|
||||
(seq
|
||||
(call myRelay ("op" "identity") [])
|
||||
(call myPeerId (fluentPadServiceId notifyOnline) [u.$.peer_id immediately])
|
||||
(call myPeerId (fluentPadServiceId notifyOnline) [u.$.peer_id])
|
||||
)
|
||||
)
|
||||
)
|
||||
@ -77,7 +79,6 @@ export const updateOnlineStatuses = async (client: FluenceClient) => {
|
||||
myPeerId: client.selfPeerId.toB58String(),
|
||||
fluentPadServiceId: fluentPadServiceId,
|
||||
notifyOnline: notifyOnlineFnName,
|
||||
immediately: false,
|
||||
},
|
||||
);
|
||||
|
||||
@ -95,7 +96,7 @@ export const notifySelfAdded = (client: FluenceClient, name: string) => {
|
||||
(par
|
||||
(seq
|
||||
(call u.$.relay_id ("op" "identity") [])
|
||||
(call u.$.peer_id (fluentPadServiceId notifyUserAdded) [myUser])
|
||||
(call u.$.peer_id (fluentPadServiceId notifyUserAdded) [myUser setOnline])
|
||||
)
|
||||
(next u)
|
||||
)
|
||||
@ -110,11 +111,14 @@ export const notifySelfAdded = (client: FluenceClient, name: string) => {
|
||||
myPeerId: client.selfPeerId.toB58String(),
|
||||
fluentPadServiceId: fluentPadServiceId,
|
||||
notifyUserAdded: notifyUserAddedFnName,
|
||||
myUser: {
|
||||
name: name,
|
||||
peer_id: client.selfPeerId.toB58String(),
|
||||
relay_id: client.relayPeerID.toB58String(),
|
||||
},
|
||||
myUser: [
|
||||
{
|
||||
name: name,
|
||||
peer_id: client.selfPeerId.toB58String(),
|
||||
relay_id: client.relayPeerID.toB58String(),
|
||||
},
|
||||
],
|
||||
setOnline: true,
|
||||
},
|
||||
);
|
||||
|
||||
|
@ -61,7 +61,6 @@ export class SyncClient<T = TextDoc> {
|
||||
|
||||
private doHandleDocUpdate(docId: string, doc: Doc<T>) {
|
||||
if (docId === SyncClient.globalDocId && this.handleDocUpdate) {
|
||||
console.log(docId, doc);
|
||||
this.handleDocUpdate(doc);
|
||||
}
|
||||
}
|
||||
|
@ -200,12 +200,18 @@ body {
|
||||
text-transform: uppercase;
|
||||
|
||||
background: none;
|
||||
border: none;
|
||||
border-top: none;
|
||||
border-right: none;
|
||||
border-left: none;
|
||||
border-bottom: 1px solid $accent-color;
|
||||
text-decoration: none;
|
||||
|
||||
outline: none;
|
||||
|
||||
&:hover,
|
||||
&:focus {
|
||||
color: $accent-color;
|
||||
border-bottom: 2px solid $accent-color;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -23,17 +23,15 @@ export const CollaborativeEditor = () => {
|
||||
useEffect(() => {
|
||||
syncClient.syncDoc(initDoc());
|
||||
syncClient.handleDocUpdate = (doc) => {
|
||||
console.log('syncClient.handleDocUpdate');
|
||||
setText(doc.text.toString());
|
||||
};
|
||||
|
||||
syncClient.handleSendChanges = (changes: string) => {
|
||||
console.log('syncClient.handleSendChanges');
|
||||
api.addEntry(client, changes);
|
||||
};
|
||||
|
||||
const unsub = subscribeToEvent(client, fluentPadServiceId, notifyTextUpdateFnName, (args, tetraplets) => {
|
||||
const [authorPeerId, changes, isAuthorized] = args;
|
||||
const [authorPeerId, changes, isAuthorized] = args as [api.PeerId, string, boolean];
|
||||
if (authorPeerId === client.selfPeerId.toB58String()) {
|
||||
return;
|
||||
}
|
||||
|
@ -8,8 +8,7 @@ import {
|
||||
import { useFluenceClient } from '../app/FluenceClientContext';
|
||||
import * as api from 'src/app/api';
|
||||
import { subscribeToEvent } from '@fluencelabs/fluence';
|
||||
|
||||
type PeerId = string;
|
||||
import { PeerId } from 'src/app/api';
|
||||
|
||||
interface User {
|
||||
id: PeerId;
|
||||
@ -46,7 +45,7 @@ export const UserList = (props: { selfName: string }) => {
|
||||
}, refreshTimeoutMs);
|
||||
|
||||
const unsub1 = subscribeToEvent(client, fluentPadServiceId, notifyUserAddedFnName, (args, _) => {
|
||||
const users = args.flatMap((x) => x).flatMap((x) => x) as api.User[];
|
||||
const [users, setOnline] = args as [api.User[], boolean];
|
||||
setUsers((prev) => {
|
||||
const result = new Map(prev);
|
||||
for (let u of users) {
|
||||
@ -59,8 +58,8 @@ export const UserList = (props: { selfName: string }) => {
|
||||
result.set(u.peer_id, {
|
||||
name: u.name,
|
||||
id: u.peer_id,
|
||||
isOnline: isCurrentUser,
|
||||
shouldBecomeOnline: isCurrentUser,
|
||||
isOnline: isCurrentUser || setOnline,
|
||||
shouldBecomeOnline: isCurrentUser || setOnline,
|
||||
});
|
||||
}
|
||||
return result;
|
||||
@ -68,7 +67,7 @@ export const UserList = (props: { selfName: string }) => {
|
||||
});
|
||||
|
||||
const unsub2 = subscribeToEvent(client, fluentPadServiceId, notifyUserRemovedFnName, (args, _) => {
|
||||
const users = args.flatMap((x) => x) as PeerId[];
|
||||
const [users] = args as [PeerId[]];
|
||||
setUsers((prev) => {
|
||||
const result = new Map(prev);
|
||||
for (let u of users) {
|
||||
@ -79,14 +78,14 @@ export const UserList = (props: { selfName: string }) => {
|
||||
});
|
||||
|
||||
const unsub3 = subscribeToEvent(client, fluentPadServiceId, notifyOnlineFnName, (args, _) => {
|
||||
const [[peerId], immediately] = args;
|
||||
const [users] = args as [PeerId[]];
|
||||
setUsers((prev) => {
|
||||
const result = new Map(prev);
|
||||
|
||||
const toSetOnline = result.get(peerId);
|
||||
if (toSetOnline) {
|
||||
toSetOnline.shouldBecomeOnline = true;
|
||||
if (immediately) {
|
||||
for (let u of users) {
|
||||
const toSetOnline = result.get(u);
|
||||
if (toSetOnline) {
|
||||
toSetOnline.shouldBecomeOnline = true;
|
||||
toSetOnline.isOnline = true;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user