Skip to content

Commit 5e7dfce

Browse files
soapdogstaltz
authored andcommitted
[[ enhancement ]] support for msgs of type blog.
* Added `BlogContent` type. * Added `isBlogMsg()` function.
1 parent 55d03a3 commit 5e7dfce

File tree

2 files changed

+45
-21
lines changed

2 files changed

+45
-21
lines changed

readme.ts

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export type Msg<C = Content> = {
3333
author: FeedId;
3434
sequence: number;
3535
timestamp: number;
36-
hash: 'sha256';
36+
hash: "sha256";
3737
content: C;
3838
signature: string;
3939
};
@@ -44,21 +44,21 @@ export type MsgInThread = Msg<{
4444
root?: MsgId;
4545
fork?: MsgId;
4646
branch?: MsgId;
47-
}>
47+
}>;
4848

4949
export type UnboxedMsg<C = Content> = Msg<C> & {
50-
value: Msg<C>['value'] & {
50+
value: Msg<C>["value"] & {
5151
cyphertext: string;
5252
private: true;
5353
unbox: string;
5454
};
5555
meta?: {
5656
private: true;
5757
originalContent: string;
58-
}
58+
};
5959
};
6060

61-
export type Privatable<T> = T & {recps?: Array<FeedId>};
61+
export type Privatable<T> = T & { recps?: Array<FeedId> };
6262

6363
export type Content =
6464
| Privatable<PostContent>
@@ -68,7 +68,7 @@ export type Content =
6868
| null;
6969

7070
export type PostContent = {
71-
type: 'post';
71+
type: "post";
7272
text: string;
7373
channel?: string;
7474

@@ -84,22 +84,22 @@ export type PostContent = {
8484
};
8585

8686
export type AboutContent = {
87-
type: 'about';
87+
type: "about";
8888
about: FeedId;
8989
name?: string;
9090
description?: string;
9191
image?: string;
9292
};
9393

9494
export type ContactContent = {
95-
type: 'contact';
95+
type: "contact";
9696
contact?: FeedId;
9797
following?: boolean;
9898
blocking?: boolean;
9999
};
100100

101101
export type VoteContent = {
102-
type: 'vote';
102+
type: "vote";
103103
vote: {
104104
link: MsgId;
105105
value: number;
@@ -127,11 +127,11 @@ export type PeerMetadata = {
127127
port: number;
128128
key: string;
129129
name?: string;
130-
source: 'local' | 'pub' | 'manual';
130+
source: "local" | "pub" | "manual";
131131
announcers?: number;
132132
duration?: any;
133133
client: boolean;
134-
state: 'connecting' | 'connected' | 'disconnecting' | undefined;
134+
state: "connecting" | "connected" | "disconnecting" | undefined;
135135
stateChange: number;
136136
ping?: {
137137
rtt: {
@@ -150,3 +150,22 @@ export type PeerMetadata = {
150150
};
151151
};
152152
};
153+
154+
export type BlogContent = {
155+
type: "blog";
156+
title: string;
157+
summary: string;
158+
channel?: string;
159+
thumbnail?: string;
160+
blog: string;
161+
162+
/**
163+
* Links
164+
*/
165+
mentions?: Array<any>;
166+
root?: MsgId;
167+
branch?: MsgId | Array<MsgId>;
168+
fork?: MsgId;
169+
// recps: FeedLinks;
170+
// mentions: Links;
171+
};

utils.ts

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
import {
22
Msg,
33
PostContent,
4+
BlogContent,
45
AboutContent,
56
ContactContent,
67
VoteContent,
78
UnboxedMsg,
89
MsgId,
910
MsgInThread,
10-
} from './readme';
11+
} from "./readme";
1112

1213
export function isMsg(msg: any): msg is Msg<any> {
13-
return msg && msg.key && msg.value && typeof msg.value === 'object';
14+
return msg && msg.key && msg.value && typeof msg.value === "object";
1415
}
1516

1617
export function isRootMsg(msg: Msg<any>): boolean {
@@ -29,7 +30,7 @@ export function isIndirectReplyMsgToRoot(rootKey: MsgId) {
2930
}
3031

3132
export function isPostMsg(msg: Msg<any>): msg is Msg<PostContent> {
32-
return msg?.value?.content?.type === 'post';
33+
return msg?.value?.content?.type === "post";
3334
}
3435

3536
export function isRootPostMsg(msg: Msg<any>): msg is Msg<PostContent> {
@@ -41,27 +42,31 @@ export function isReplyPostMsg(msg: Msg<any>): msg is Msg<PostContent> {
4142
}
4243

4344
export function isAboutMsg(msg: Msg<any>): msg is Msg<AboutContent> {
44-
return msg?.value?.content?.type === 'about';
45+
return msg?.value?.content?.type === "about";
4546
}
4647

4748
export function isContactMsg(msg: Msg<any>): msg is Msg<ContactContent> {
48-
return msg?.value?.content?.type === 'contact';
49+
return msg?.value?.content?.type === "contact";
4950
}
5051

5152
export function isVoteMsg(msg: Msg<any>): msg is Msg<VoteContent> {
52-
return msg?.value?.content?.type === 'vote';
53+
return msg?.value?.content?.type === "vote";
5354
}
5455

5556
export function isPrivate(msg: Msg<any> | UnboxedMsg): boolean {
56-
if ((msg as UnboxedMsg).meta?.private) return true
57+
if ((msg as UnboxedMsg).meta?.private) return true;
5758
if ((msg as UnboxedMsg).value.private) return true;
5859
if (Array.isArray(msg.value.content?.recps)) return true;
59-
return typeof msg?.value?.content === 'string';
60+
return typeof msg?.value?.content === "string";
6061
}
6162

6263
export function isPublic(msg: Msg<any> | UnboxedMsg): boolean {
63-
if ((msg as UnboxedMsg).meta?.private) return false
64+
if ((msg as UnboxedMsg).meta?.private) return false;
6465
if ((msg as UnboxedMsg).value.private) return false;
6566
if (Array.isArray(msg.value.content?.recps)) return false;
66-
return typeof msg?.value?.content !== 'string';
67+
return typeof msg?.value?.content !== "string";
68+
}
69+
70+
export function isBlogMsg(msg: Msg<any>): msg is Msg<BlogContent> {
71+
return msg?.value?.content?.type === "blog";
6772
}

0 commit comments

Comments
 (0)