Minor fixes. Users become online momentarily

This commit is contained in:
Pavel Murygin 2021-01-16 19:32:26 +03:00
parent 47aad98639
commit e1574427a5
5 changed files with 30 additions and 24 deletions

View File

@ -42,6 +42,8 @@ const throwIfError = (result: ServiceResult) => {
} }
}; };
export type PeerId = string;
export const updateOnlineStatuses = async (client: FluenceClient) => { export const updateOnlineStatuses = async (client: FluenceClient) => {
const particle = new Particle( const particle = new Particle(
` `
@ -59,7 +61,7 @@ export const updateOnlineStatuses = async (client: FluenceClient) => {
(call u.$.relay_id ("op" "identity") []) (call u.$.relay_id ("op" "identity") [])
(seq (seq
(call myRelay ("op" "identity") []) (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(), myPeerId: client.selfPeerId.toB58String(),
fluentPadServiceId: fluentPadServiceId, fluentPadServiceId: fluentPadServiceId,
notifyOnline: notifyOnlineFnName, notifyOnline: notifyOnlineFnName,
immediately: false,
}, },
); );
@ -95,7 +96,7 @@ export const notifySelfAdded = (client: FluenceClient, name: string) => {
(par (par
(seq (seq
(call u.$.relay_id ("op" "identity") []) (call u.$.relay_id ("op" "identity") [])
(call u.$.peer_id (fluentPadServiceId notifyUserAdded) [myUser]) (call u.$.peer_id (fluentPadServiceId notifyUserAdded) [myUser setOnline])
) )
(next u) (next u)
) )
@ -110,11 +111,14 @@ export const notifySelfAdded = (client: FluenceClient, name: string) => {
myPeerId: client.selfPeerId.toB58String(), myPeerId: client.selfPeerId.toB58String(),
fluentPadServiceId: fluentPadServiceId, fluentPadServiceId: fluentPadServiceId,
notifyUserAdded: notifyUserAddedFnName, notifyUserAdded: notifyUserAddedFnName,
myUser: { myUser: [
{
name: name, name: name,
peer_id: client.selfPeerId.toB58String(), peer_id: client.selfPeerId.toB58String(),
relay_id: client.relayPeerID.toB58String(), relay_id: client.relayPeerID.toB58String(),
}, },
],
setOnline: true,
}, },
); );

View File

@ -61,7 +61,6 @@ export class SyncClient<T = TextDoc> {
private doHandleDocUpdate(docId: string, doc: Doc<T>) { private doHandleDocUpdate(docId: string, doc: Doc<T>) {
if (docId === SyncClient.globalDocId && this.handleDocUpdate) { if (docId === SyncClient.globalDocId && this.handleDocUpdate) {
console.log(docId, doc);
this.handleDocUpdate(doc); this.handleDocUpdate(doc);
} }
} }

View File

@ -200,12 +200,18 @@ body {
text-transform: uppercase; text-transform: uppercase;
background: none; background: none;
border: none; border-top: none;
border-right: none;
border-left: none;
border-bottom: 1px solid $accent-color;
text-decoration: none; text-decoration: none;
outline: none;
&:hover, &:hover,
&:focus { &:focus {
color: $accent-color; color: $accent-color;
border-bottom: 2px solid $accent-color;
} }
} }
} }

View File

@ -23,17 +23,15 @@ export const CollaborativeEditor = () => {
useEffect(() => { useEffect(() => {
syncClient.syncDoc(initDoc()); syncClient.syncDoc(initDoc());
syncClient.handleDocUpdate = (doc) => { syncClient.handleDocUpdate = (doc) => {
console.log('syncClient.handleDocUpdate');
setText(doc.text.toString()); setText(doc.text.toString());
}; };
syncClient.handleSendChanges = (changes: string) => { syncClient.handleSendChanges = (changes: string) => {
console.log('syncClient.handleSendChanges');
api.addEntry(client, changes); api.addEntry(client, changes);
}; };
const unsub = subscribeToEvent(client, fluentPadServiceId, notifyTextUpdateFnName, (args, tetraplets) => { 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()) { if (authorPeerId === client.selfPeerId.toB58String()) {
return; return;
} }

View File

@ -8,8 +8,7 @@ import {
import { useFluenceClient } from '../app/FluenceClientContext'; import { useFluenceClient } from '../app/FluenceClientContext';
import * as api from 'src/app/api'; import * as api from 'src/app/api';
import { subscribeToEvent } from '@fluencelabs/fluence'; import { subscribeToEvent } from '@fluencelabs/fluence';
import { PeerId } from 'src/app/api';
type PeerId = string;
interface User { interface User {
id: PeerId; id: PeerId;
@ -46,7 +45,7 @@ export const UserList = (props: { selfName: string }) => {
}, refreshTimeoutMs); }, refreshTimeoutMs);
const unsub1 = subscribeToEvent(client, fluentPadServiceId, notifyUserAddedFnName, (args, _) => { 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) => { setUsers((prev) => {
const result = new Map(prev); const result = new Map(prev);
for (let u of users) { for (let u of users) {
@ -59,8 +58,8 @@ export const UserList = (props: { selfName: string }) => {
result.set(u.peer_id, { result.set(u.peer_id, {
name: u.name, name: u.name,
id: u.peer_id, id: u.peer_id,
isOnline: isCurrentUser, isOnline: isCurrentUser || setOnline,
shouldBecomeOnline: isCurrentUser, shouldBecomeOnline: isCurrentUser || setOnline,
}); });
} }
return result; return result;
@ -68,7 +67,7 @@ export const UserList = (props: { selfName: string }) => {
}); });
const unsub2 = subscribeToEvent(client, fluentPadServiceId, notifyUserRemovedFnName, (args, _) => { const unsub2 = subscribeToEvent(client, fluentPadServiceId, notifyUserRemovedFnName, (args, _) => {
const users = args.flatMap((x) => x) as PeerId[]; const [users] = args as [PeerId[]];
setUsers((prev) => { setUsers((prev) => {
const result = new Map(prev); const result = new Map(prev);
for (let u of users) { for (let u of users) {
@ -79,14 +78,14 @@ export const UserList = (props: { selfName: string }) => {
}); });
const unsub3 = subscribeToEvent(client, fluentPadServiceId, notifyOnlineFnName, (args, _) => { const unsub3 = subscribeToEvent(client, fluentPadServiceId, notifyOnlineFnName, (args, _) => {
const [[peerId], immediately] = args; const [users] = args as [PeerId[]];
setUsers((prev) => { setUsers((prev) => {
const result = new Map(prev); const result = new Map(prev);
const toSetOnline = result.get(peerId); for (let u of users) {
const toSetOnline = result.get(u);
if (toSetOnline) { if (toSetOnline) {
toSetOnline.shouldBecomeOnline = true; toSetOnline.shouldBecomeOnline = true;
if (immediately) {
toSetOnline.isOnline = true; toSetOnline.isOnline = true;
} }
} }