plebbit / plebbit-js

A Javascript API to build applications using plebbit
GNU General Public License v2.0
41 stars 7 forks source link

implement instant replies #24

Open estebanabaroa opened 10 months ago

estebanabaroa commented 10 months ago

steps to get instant replies:

assuming the user calls plebbit.createComment({pubsub: true, cid: 'Qm...'}) and comment.update()

join pubsub /last-reply/Qm...

the value received is (all peers must store the last answer they have and answer the fetch protocol with it)

CommentUpdate {
  cid: string
  signature: Signature
  sequenceNumber: number (first reply is 0, last reply is the previous children count)
}

validate the sub comment update signature

the last reply has the highest reply.sequenceNumber (property added by sub owner)

whenever the last reply changes, download all the replies you don't yet have by scrolling reply.previousCid

emit comment 'update' event by adding the new replies to the comment.replies

for as long as the user is joined to the pubsub, keep listening for new replies and emitting updates. possibly implement comment.pubsubStop() or just use comment.stop() which already exists to leave the pubsub.

TODO: eventually think of how we would consolidate page cids with the comment.replies, maybe we have an array comment.newReplies or something for new replies

steps to publish instant replies:

assuming the user calls plebbit.createComment({pubsub: true, parentCid: 'Qm...'}) and comment.publish()

publish comment normally, and wait for challenge verification. challenge verifications must contain challengeVerificationMessage.publication.update:

CommentUpdate {
  cid: string
  signature: Signature
  sequenceNumber: number
}

join pubsub /last-reply/Qm...

spam mitigation

random people can't spam because all the comment updates are signed by the sub owner and have a sequence number, so not signed or duplicate comments can be ignored/blocked from the pubsub

Rinse12 commented 10 months ago

Are we able to implement this at the moment or do we need to modify Kubo?

estebanabaroa commented 10 months ago

Are we able to implement this at the moment or do we need to modify Kubo?

I believe we would implement this in javascript only for now, because writing it in go would be pretty complicated, and most people use the browser/mobile version anyway.

I wrote an example of how to use the fetch protocol here to add persistence to ipns over pubsub (@helia/ipns doesnt have it yet) https://github.com/estebanabaroa/custom-pubsub/blob/master/demo3.js

It works but I wasn't able to make it interoperate with kubo, so I might be doing something wrong. I will write a more direct example of how we would use pubsub and the fetch protocol when I have time, so you could wait for that to start working on it.

I think instant replies is fairly high priority to get a prototype working though, so that plebchan can work more like 4chan. We should work on it soon imo.

estebanabaroa commented 2 months ago

the value received is (all peers must store the last answer they have and answer the fetch protocol with it)

CommentUpdate {
  cid: string
  signature: Signature
  sequenceNumber: number (first reply is 0, last reply is the previous children count)
}

we probably actually want to send the full {comment, update} similar to PageComment type of the protocol, this way peers dont have to fetch the comment from IPFS, though peers probably want to add the comment to IPFS when they receive it, so they can seed it, for people who join the pubsub late and haven't received all the comments.

which means

challenge verifications must contain challengeVerificationMessage.publication.update:

challengeVerificationMessage should probably be something like challengeVerificationMessage.comment and challengeVerificationMessage.commentUpdate