Skip to content

Commit 6814fe8

Browse files
committed
add util isIndirectReplyMsgToRoot()
1 parent 57d09cb commit 6814fe8

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

readme.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ export type Msg<C = Content> = {
4040
timestamp: number;
4141
};
4242

43+
export type MsgInThread = Msg<{
44+
root?: MsgId;
45+
fork?: MsgId;
46+
branch?: MsgId;
47+
}>
48+
4349
export type UnboxedMsg<C = Content> = Msg<C> & {
4450
value: Msg<C>['value'] & {
4551
cyphertext: string;

utils.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
VoteContent,
77
UnboxedMsg,
88
MsgId,
9+
MsgInThread,
910
} from './readme';
1011

1112
export function isMsg(msg: any): msg is Msg<any> {
@@ -17,7 +18,14 @@ export function isRootMsg(msg: Msg<any>): boolean {
1718
}
1819

1920
export function isReplyMsgToRoot(rootKey: MsgId) {
20-
return (msg: Msg<{root?: MsgId}>) => msg?.value?.content?.root === rootKey;
21+
return (msg: MsgInThread) => msg?.value?.content?.root === rootKey;
22+
}
23+
24+
export function isIndirectReplyMsgToRoot(rootKey: MsgId) {
25+
return (msg: MsgInThread) =>
26+
msg?.value?.content?.root === rootKey ||
27+
msg?.value?.content?.branch === rootKey ||
28+
msg?.value?.content?.fork === rootKey;
2129
}
2230

2331
export function isPostMsg(msg: Msg<any>): msg is Msg<PostContent> {

0 commit comments

Comments
 (0)