mirror of
https://github.com/fluencelabs/fluent-pad
synced 2025-04-24 16:32:13 +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 './App.scss';
|
||||
import { FluenceClientContext, useFluenceClient } from './FluenceClientContext';
|
||||
import { FluenceClientContext } from './FluenceClientContext';
|
||||
import { UserList } from './UserList';
|
||||
import * as calls from 'src/fluence/calls';
|
||||
import { CollaborativeEditor } from './CollaborativeEditor';
|
||||
@ -70,7 +70,7 @@ const App = () => {
|
||||
|
||||
<div className="wrapper">
|
||||
<div>{isInRoom && client && <CollaborativeEditor />}</div>
|
||||
{/* <div>{isInRoom && client && <UserList selfName={nickName} />}</div> */}
|
||||
<div>{isInRoom && client && <UserList selfName={nickName} />}</div>
|
||||
</div>
|
||||
</div>
|
||||
</FluenceClientContext.Provider>
|
@ -42,24 +42,24 @@ const getUpdatedDocFromText = (oldDoc: TextDoc | null, newText: string) => {
|
||||
return newDoc;
|
||||
};
|
||||
|
||||
const parseState = (message: calls.Message) => {
|
||||
const parseState = (entry: calls.Entry) => {
|
||||
try {
|
||||
const obj = JSON.parse(message.body);
|
||||
const obj = JSON.parse(entry.body);
|
||||
if (obj.fluentPadState) {
|
||||
return Automerge.load(obj.fluentPadState) as TextDoc;
|
||||
}
|
||||
|
||||
return null;
|
||||
} catch (e) {
|
||||
console.log('couldnt parse state format: ' + message.body);
|
||||
console.log('couldnt parse state format: ' + entry.body);
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
const applyStates = (startingDoc: TextDoc | null, messages: calls.Message[]) => {
|
||||
const applyStates = (startingDoc: TextDoc | null, entries: calls.Entry[]) => {
|
||||
let res = startingDoc;
|
||||
for (let m of messages) {
|
||||
const state = parseState(m) as TextDoc;
|
||||
for (let entry of entries) {
|
||||
const state = parseState(entry) as TextDoc;
|
||||
if (state) {
|
||||
if (!res) {
|
||||
res = state;
|
||||
@ -107,12 +107,12 @@ export const CollaborativeEditor = () => {
|
||||
|
||||
// don't block
|
||||
setImmediate(async () => {
|
||||
const message = {
|
||||
const entry = {
|
||||
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 { idText } from 'typescript';
|
||||
import { fluenceClient } from '.';
|
||||
import {
|
||||
fluentPadServiceId,
|
||||
historyNodePid,
|
||||
@ -25,7 +23,7 @@ export interface User {
|
||||
name: string;
|
||||
}
|
||||
|
||||
export interface Message {
|
||||
export interface Entry {
|
||||
id: number;
|
||||
body: string;
|
||||
}
|
||||
@ -34,8 +32,8 @@ interface GetUsersResult extends ServiceResult {
|
||||
users: Array<User>;
|
||||
}
|
||||
|
||||
interface GetMessagesResult extends ServiceResult {
|
||||
messages: Message[];
|
||||
interface GetEntries extends ServiceResult {
|
||||
entries: Entry[];
|
||||
}
|
||||
|
||||
const throwIfError = (result: ServiceResult) => {
|
||||
@ -209,7 +207,7 @@ export const getHistory = async (client: FluenceClient) => {
|
||||
let getHistoryAir = `
|
||||
(seq
|
||||
(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('historyNode', historyNodePid);
|
||||
|
||||
const [result] = await client.fetch<[GetMessagesResult]>(getHistoryAir, ['messages'], data);
|
||||
const [result] = await client.fetch<[GetEntries]>(getHistoryAir, ['entries'], data);
|
||||
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(
|
||||
`
|
||||
(seq
|
||||
@ -234,12 +232,12 @@ export const addMessage = async (client: FluenceClient, messageBody: string) =>
|
||||
(seq
|
||||
(call userlistNode (userlist "get_users") [] allUsers)
|
||||
(seq
|
||||
(call node (history "add") [message token.$.["is_authenticated"]])
|
||||
(call node (history "add") [entry token.$.["is_authenticated"]])
|
||||
(fold allUsers.$.users! u
|
||||
(par
|
||||
(seq
|
||||
(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)
|
||||
)
|
||||
@ -253,7 +251,7 @@ export const addMessage = async (client: FluenceClient, messageBody: string) =>
|
||||
{
|
||||
userlistNode: userListNodePid,
|
||||
historyNode: historyNodePid,
|
||||
message: messageBody,
|
||||
entry: entry,
|
||||
userlist: userListServiceId,
|
||||
history: historyServiceId,
|
||||
myRelay: client.relayPeerID.toB58String(),
|
||||
|
Loading…
x
Reference in New Issue
Block a user