Skip to content

Commit

Permalink
Merge pull request #115 from NfNitLoop/use-external-client
Browse files Browse the repository at this point in the history
Use external client
  • Loading branch information
NfNitLoop committed Mar 4, 2023
2 parents e8292f6 + 4abe08a commit 57fa655
Show file tree
Hide file tree
Showing 27 changed files with 2,580 additions and 1,687 deletions.
5 changes: 3 additions & 2 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
// use protoc_rust;

fn main() {
// TODO: Specify a rebuild-if
let proto_file = "protobufs/feoblog.proto";
println!("cargo:rerun-if-changed={}", proto_file);
protoc_rust::Codegen::new()
.out_dir("src/protos")
.inputs(&["protobufs/feoblog.proto"])
.inputs(&[proto_file])
.include("protobufs")
.run()
.expect("protoc");
Expand Down
16 changes: 16 additions & 0 deletions protobufs/feoblog.proto
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ message Profile {
// The order of the list is unimportant.
repeated Follow follows = 4;

// Users may collect their follows into groups to make sorting/filtering/syncing them easier.
repeated FollowGroup follow_groups = 5;

// TODO:
// irrevocably_purge_this_user
// Though, maybe that should just be its own type so that you can't specify a Profile with it.
Expand Down Expand Up @@ -176,11 +179,24 @@ message Follow {
// Here you can set a stable name so you always know who's who.
string display_name = 2;

// The (0-indexed) group index that this follow should be grouped under.
optional int32 follow_group = 3;

// Possible future features:
// * quota -- determine how much disk space a particular user may use.
// (i.e.: how much of their content to cache on their behalf)
}

message FollowGroup {
// A display name for this group. ex: "News", or "Friends".
// Names should probably be unique for users' own sanity but at the moment that is not enforced by the protocol.
string name = 1;

// Future possibilities:
// quota settings by group?
// Additional filter options (ex: don't display comments from this group)
}

message UserID {
// A user's public NaCL key/ID. Must be 32 bytes:
bytes bytes = 1;
Expand Down
28 changes: 16 additions & 12 deletions web-client/components/CommentEditor.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@
import { DateTime } from "luxon";
import { getContext } from "svelte";
import type { Writable } from "svelte/store";
import { Item, Comment, ReplyRef, UserID as ProtoUserID, Signature as ProtoSignature} from "../protos/feoblog";
import type { AppState } from "../ts/app";
import type { Signature, UserID } from "../ts/client";
import type { Signature, UserID} from "../ts/client";
import { protobuf as pb} from "../ts/client";
import CommentView from "./CommentView.svelte";
import ExpandingTextarea from "./ExpandingTextarea.svelte";
import SignAndSend from "./SignAndSend.svelte";
Expand Down Expand Up @@ -68,23 +68,27 @@ $: errors = !hasText ? ["Can not submit an empty comment"] : []
$: placeholder = isLoggedIn ? "Leave a Comment" : "Must log in to comment"
$: commentItem = function() {
let item = new Item()
let item = new pb.Item()
let now = DateTime.local()
item.timestamp_ms_utc = now.valueOf()
item.utc_offset_minutes = now.offset
item.timestampMsUtc = BigInt(now.valueOf())
item.utcOffsetMinutes = now.offset
let comment = new Comment()
item.comment = comment
let comment = new pb.Comment()
let ref = new ReplyRef()
ref.user_id = new ProtoUserID()
ref.user_id.bytes = replyToUserID.bytes
ref.signature = new ProtoSignature()
// Nope: item.comment = comment
item.itemType = {case: "comment", value: comment}
let ref = new pb.ReplyRef()
ref.userId = new pb.UserID()
ref.userId.bytes = replyToUserID.bytes
ref.signature = new pb.Signature()
ref.signature.bytes = replyToSignature.bytes
// ref.item_type = // TODO
comment.reply_to = ref
comment.replyTo = ref
comment.text = text
return item
Expand Down
14 changes: 8 additions & 6 deletions web-client/components/CommentView.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
<ItemHeader {showReplyTo} {item} {signature} {userID} bind:viewMode />
<div class="body">
{#if viewMode == "normal"}
{@html markdownToHtml(item.comment.text, {stripImages: true, relativeBase: `/u/${userID}/i/${signature}/`})}
{@html markdownToHtml(comment.text, {stripImages: true, relativeBase: `/u/${userID}/i/${signature}/`})}
{:else if viewMode == "markdown"}
<p>Markdown source:</p>
<code><pre>{item.comment.text}</pre></code>
<code><pre>{comment.text}</pre></code>
{:else}
<p>JSON representation of Protobuf Item:</p>
<code><pre>{JSON.stringify(item.toObject(), null, 4)}</pre></code>
<code><pre>{JSON.stringify(item, null, 4)}</pre></code>
{/if}

</div>
Expand All @@ -21,18 +21,18 @@
<script lang="ts">
import type { Writable } from "svelte/store";
import type { Item } from "../protos/feoblog";
import type { AppState } from "../ts/app";
import type {UserID} from "../ts/client"
import type {UserID, protobuf as pb} from "../ts/client"
import { getInner } from "../ts/client"
import {markdownToHtml, fixLinks} from "../ts/common"
import ItemHeader from "./ItemHeader.svelte"
import type {ViewMode} from "./ItemHeader.svelte"
import { getContext } from "svelte";
let appState: Writable<AppState> = getContext("appStateStore")
export let item: Item
export let item: pb.Item
export let showReplyTo = true
export let userID:UserID
Expand All @@ -43,5 +43,7 @@ let viewMode: ViewMode = "normal"
// If we want to use this as a preview, we must account for an invalid signature:
export let signature: string
$: comment = getInner(item, "comment")!
</script>

27 changes: 14 additions & 13 deletions web-client/components/EditPost.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ type PostData = {
<script lang="ts">
import ExpandingTextarea from "./ExpandingTextarea.svelte"
import TimestampEditor from "./TimestampEditor.svelte"
import { Attachments, File, Item, Post } from "../protos/feoblog";
import FileAttachments from "./FileAttachments.svelte"
import {FileInfo, getMarkdownInfo} from "../ts/common"
import { getContext, onMount } from "svelte";
import type { AppState } from "../ts/app";
import type { Writable } from "svelte/store";
import type { UserID } from "../ts/client";
import {protobuf as pb} from "../ts/client";
import { DateTime } from "luxon";
export let files: FileInfo[] = []
Expand Down Expand Up @@ -152,29 +152,30 @@ function saveDraft(userID: UserID|null, postData: PostData) {
// Exported so that EditorWithPreview can preview, serialize, & send it for us.
export let item: Item
export let item: pb.Item
$: item = function() {
let itm = new Item({
timestamp_ms_utc: timestampMsUTC,
utc_offset_minutes: offsetMinutes,
post: new Post({
title,
body: text,
})
let post = new pb.Post({
title,
body: text,
})
let itm = new pb.Item({
timestampMsUtc: BigInt(timestampMsUTC),
utcOffsetMinutes: offsetMinutes,
itemType: { case: "post", value: post }
})
if (files.length > 0) {
let attachments: File[] = []
let attachments: pb.File[] = []
for (let info of files) {
let file = new File({
let file = new pb.File({
hash: info.hash.bytes,
size: info.size,
size: BigInt(info.size),
name: info.name,
})
attachments.push(file)
}
itm.post.attachments = new Attachments({file: attachments})
post.attachments = new pb.Attachments({file: attachments})
}
return itm
Expand Down
50 changes: 25 additions & 25 deletions web-client/components/EditProfile.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,9 @@
import ExpandingTextarea from "./ExpandingTextarea.svelte"
import FollowBox from "./FollowBox.svelte"
import Button from "./Button.svelte"
import { Follow, Item, Profile, Server, UserID } from "../protos/feoblog";
import type { AppState } from "../ts/app";
import type { Writable } from "svelte/store";
import { UserID as ClientUserID } from "../ts/client";
import { UserID as ClientUserID, protobuf as pb, getInner } from "../ts/client";
import { parseUserID, validateServerURL } from "../ts/common";
import { getContext, tick } from "svelte";
import InputBox from "./InputBox.svelte";
Expand All @@ -48,10 +47,10 @@ import { decodeBase58 } from "../ts/fbBase58";
let appState: Writable<AppState> = getContext("appStateStore")
// Exported so that EditorWithPreview can preview, serialize, & send it for us.
export let item: Item
export let item: pb.Item
// Possibly imported, so we can start editing an existing profile:
export let initialItem: Item|undefined
export let initialItem: pb.Item|undefined
export let validationErrors: string[] = []
$: validationErrors = function(): string[] {
Expand Down Expand Up @@ -137,10 +136,10 @@ class FollowEntry {
this.displayName = displayName
}
toFollow(): Follow {
return new Follow({
display_name: this.displayName,
user: new UserID({
toFollow(): pb.Follow {
return new pb.Follow({
displayName: this.displayName,
user: new pb.UserID({
bytes: this.userIDBytes()
}),
});
Expand All @@ -166,14 +165,14 @@ $: {
}
// This is the inverse of $: itemProto above. Given an Item, load data from it.
function loadFromProto(item: Item) {
let profile = item.profile
displayName = profile.display_name
function loadFromProto(item: pb.Item) {
let profile = getInner(item, "profile")!
displayName = profile.displayName
profileContent = profile.about
let _follows = new Array<FollowEntry>()
profile.follows.forEach((follow) => {
let f = new FollowEntry(ClientUserID.fromBytes(follow.user.bytes).toString(), follow.display_name)
let f = new FollowEntry(ClientUserID.fromBytes(follow.user!.bytes).toString(), follow.displayName)
_follows.push(f)
})
Expand All @@ -187,35 +186,36 @@ if (initialItem) {
}
$: item = function(): Item {
$: item = function(): pb.Item {
// For profiles, we *always* want to save with the latest timestamp possible:
let now = DateTime.local()
let item = new Item({
timestamp_ms_utc: now.valueOf(),
utc_offset_minutes: now.offset,
profile: new Profile({
display_name: displayName,
about: profileContent,
})
let profile = new pb.Profile({
displayName,
about: profileContent,
})
let item = new pb.Item({
timestampMsUtc: BigInt(now.valueOf()),
utcOffsetMinutes: now.offset,
itemType: { case: "profile", value: profile }
})
let profile = item.profile
follows.forEach(entry => {
let userIDBytes = new Uint8Array()
try {
userIDBytes = decodeBase58(entry.userID)
} catch (_ignored) {}
profile.follows.push(new Follow({
user: new UserID({bytes: userIDBytes}),
display_name: entry.displayName,
profile.follows.push(new pb.Follow({
user: new pb.UserID({bytes: userIDBytes}),
displayName: entry.displayName,
}))
})
for (let {url} of servers) {
if (url === "") continue
profile.servers.push(new Server({url}))
profile.servers.push(new pb.Server({url}))
}
return item
Expand Down
7 changes: 3 additions & 4 deletions web-client/components/EditorWithPreview.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,9 @@

<script lang="ts">
import type { Writable } from "svelte/store"
import { Item } from "../protos/feoblog"
import type { UserID as ClientUserID, UserID } from "../ts/client"
import { UserID as ClientUserID, protobuf as pb } from "../ts/client"
import type { AppState } from '../ts/app';
import ItemView from './ItemView.svelte'
import EditProfile from './EditProfile.svelte';
Expand All @@ -76,7 +75,7 @@ let tabs = ["Edit", "Preview"]
let activeTab = "Edit"
// Can provide an initial item for editing.
export let initialItem: Item|undefined = undefined
export let initialItem: pb.Item|undefined = undefined
let fileAttachments: FileInfo[] = []
Expand All @@ -90,7 +89,7 @@ let warnings: string[] = []
// The Item protobuf generated by EditProfile/EditPost.
let item: Item = new Item()
let item: pb.Item = new pb.Item()
let editPost: EditPost|undefined = undefined
let editProfile: EditProfile|undefined = undefined
Expand Down
Loading

0 comments on commit 57fa655

Please sign in to comment.