mirror of
https://github.com/fluencelabs/fluent-pad
synced 2025-04-25 08:52:14 +00:00
Rename message -> entry everywhere
This commit is contained in:
parent
1d83a95460
commit
77d5329ca6
@ -3,7 +3,7 @@ import React, { useEffect, useState } from 'react';
|
|||||||
import { connect } from 'src/fluence';
|
import { connect } from 'src/fluence';
|
||||||
|
|
||||||
import './App.scss';
|
import './App.scss';
|
||||||
import { FluenceClientContext, useFluenceClient } from './FluenceClientContext';
|
import { FluenceClientContext } from './FluenceClientContext';
|
||||||
import { UserList } from './UserList';
|
import { UserList } from './UserList';
|
||||||
import * as calls from 'src/fluence/calls';
|
import * as calls from 'src/fluence/calls';
|
||||||
import { CollaborativeEditor } from './CollaborativeEditor';
|
import { CollaborativeEditor } from './CollaborativeEditor';
|
||||||
@ -70,7 +70,7 @@ const App = () => {
|
|||||||
|
|
||||||
<div className="wrapper">
|
<div className="wrapper">
|
||||||
<div>{isInRoom && client && <CollaborativeEditor />}</div>
|
<div>{isInRoom && client && <CollaborativeEditor />}</div>
|
||||||
{/* <div>{isInRoom && client && <UserList selfName={nickName} />}</div> */}
|
<div>{isInRoom && client && <UserList selfName={nickName} />}</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</FluenceClientContext.Provider>
|
</FluenceClientContext.Provider>
|
@ -42,24 +42,24 @@ const getUpdatedDocFromText = (oldDoc: TextDoc | null, newText: string) => {
|
|||||||
return newDoc;
|
return newDoc;
|
||||||
};
|
};
|
||||||
|
|
||||||
const parseState = (message: calls.Message) => {
|
const parseState = (entry: calls.Entry) => {
|
||||||
try {
|
try {
|
||||||
const obj = JSON.parse(message.body);
|
const obj = JSON.parse(entry.body);
|
||||||
if (obj.fluentPadState) {
|
if (obj.fluentPadState) {
|
||||||
return Automerge.load(obj.fluentPadState) as TextDoc;
|
return Automerge.load(obj.fluentPadState) as TextDoc;
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log('couldnt parse state format: ' + message.body);
|
console.log('couldnt parse state format: ' + entry.body);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const applyStates = (startingDoc: TextDoc | null, messages: calls.Message[]) => {
|
const applyStates = (startingDoc: TextDoc | null, entries: calls.Entry[]) => {
|
||||||
let res = startingDoc;
|
let res = startingDoc;
|
||||||
for (let m of messages) {
|
for (let entry of entries) {
|
||||||
const state = parseState(m) as TextDoc;
|
const state = parseState(entry) as TextDoc;
|
||||||
if (state) {
|
if (state) {
|
||||||
if (!res) {
|
if (!res) {
|
||||||
res = state;
|
res = state;
|
||||||
@ -107,12 +107,12 @@ export const CollaborativeEditor = () => {
|
|||||||
|
|
||||||
// don't block
|
// don't block
|
||||||
setImmediate(async () => {
|
setImmediate(async () => {
|
||||||
const message = {
|
const entry = {
|
||||||
fluentPadState: Automerge.save(newDoc),
|
fluentPadState: Automerge.save(newDoc),
|
||||||
};
|
};
|
||||||
const messageStr = JSON.stringify(message);
|
const entryStr = JSON.stringify(entry);
|
||||||
|
|
||||||
await calls.addMessage(client, messageStr);
|
await calls.addEntry(client, entryStr);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,6 +1,4 @@
|
|||||||
import { FluenceClient } from '@fluencelabs/fluence';
|
import { FluenceClient } from '@fluencelabs/fluence';
|
||||||
import { idText } from 'typescript';
|
|
||||||
import { fluenceClient } from '.';
|
|
||||||
import {
|
import {
|
||||||
fluentPadServiceId,
|
fluentPadServiceId,
|
||||||
historyNodePid,
|
historyNodePid,
|
||||||
@ -25,7 +23,7 @@ export interface User {
|
|||||||
name: string;
|
name: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Message {
|
export interface Entry {
|
||||||
id: number;
|
id: number;
|
||||||
body: string;
|
body: string;
|
||||||
}
|
}
|
||||||
@ -34,8 +32,8 @@ interface GetUsersResult extends ServiceResult {
|
|||||||
users: Array<User>;
|
users: Array<User>;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface GetMessagesResult extends ServiceResult {
|
interface GetEntries extends ServiceResult {
|
||||||
messages: Message[];
|
entries: Entry[];
|
||||||
}
|
}
|
||||||
|
|
||||||
const throwIfError = (result: ServiceResult) => {
|
const throwIfError = (result: ServiceResult) => {
|
||||||
@ -209,7 +207,7 @@ export const getHistory = async (client: FluenceClient) => {
|
|||||||
let getHistoryAir = `
|
let getHistoryAir = `
|
||||||
(seq
|
(seq
|
||||||
(call userlistNode (userlist "is_authenticated") [] token)
|
(call userlistNode (userlist "is_authenticated") [] token)
|
||||||
(call historyNode (history "get_all") [token.$.is_authenticated] messages)
|
(call historyNode (history "get_all") [token.$.is_authenticated] entries)
|
||||||
)
|
)
|
||||||
`;
|
`;
|
||||||
|
|
||||||
@ -219,12 +217,12 @@ export const getHistory = async (client: FluenceClient) => {
|
|||||||
data.set('userlistNode', userListNodePid);
|
data.set('userlistNode', userListNodePid);
|
||||||
data.set('historyNode', historyNodePid);
|
data.set('historyNode', historyNodePid);
|
||||||
|
|
||||||
const [result] = await client.fetch<[GetMessagesResult]>(getHistoryAir, ['messages'], data);
|
const [result] = await client.fetch<[GetEntries]>(getHistoryAir, ['entries'], data);
|
||||||
throwIfError(result);
|
throwIfError(result);
|
||||||
return result.messages;
|
return result.entries;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const addMessage = async (client: FluenceClient, messageBody: string) => {
|
export const addEntry = async (client: FluenceClient, entry: string) => {
|
||||||
const particle = new Particle(
|
const particle = new Particle(
|
||||||
`
|
`
|
||||||
(seq
|
(seq
|
||||||
@ -234,12 +232,12 @@ export const addMessage = async (client: FluenceClient, messageBody: string) =>
|
|||||||
(seq
|
(seq
|
||||||
(call userlistNode (userlist "get_users") [] allUsers)
|
(call userlistNode (userlist "get_users") [] allUsers)
|
||||||
(seq
|
(seq
|
||||||
(call node (history "add") [message token.$.["is_authenticated"]])
|
(call node (history "add") [entry token.$.["is_authenticated"]])
|
||||||
(fold allUsers.$.users! u
|
(fold allUsers.$.users! u
|
||||||
(par
|
(par
|
||||||
(seq
|
(seq
|
||||||
(call u.$.relay_id ("op" "identity") [])
|
(call u.$.relay_id ("op" "identity") [])
|
||||||
(call u.$.peer_id (fluentPadServiceId notifyTextUpdate) [message token.$.["is_authenticated"]])
|
(call u.$.peer_id (fluentPadServiceId notifyTextUpdate) [entry token.$.["is_authenticated"]])
|
||||||
)
|
)
|
||||||
(next u)
|
(next u)
|
||||||
)
|
)
|
||||||
@ -253,7 +251,7 @@ export const addMessage = async (client: FluenceClient, messageBody: string) =>
|
|||||||
{
|
{
|
||||||
userlistNode: userListNodePid,
|
userlistNode: userListNodePid,
|
||||||
historyNode: historyNodePid,
|
historyNode: historyNodePid,
|
||||||
message: messageBody,
|
entry: entry,
|
||||||
userlist: userListServiceId,
|
userlist: userListServiceId,
|
||||||
history: historyServiceId,
|
history: historyServiceId,
|
||||||
myRelay: client.relayPeerID.toB58String(),
|
myRelay: client.relayPeerID.toB58String(),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user