holic / chirp-city

a lil birb told me
https://chirp.city
3 stars 0 forks source link

Reactions #10

Open holic opened 2 years ago

holic commented 2 years ago

Trying to think through some ideas for reactions. Since most platforms are going the way of "react with any emoji", it makes sense to me to start with more than just likes/favorites, at least at the protocol level. The indexer/frontend can decide which ones are allowed.

Possible approaches

1. Text-based and human-readable, like iMessage → SMS

For replies/"subtweets", I'll probably be using a regular PublicMessage with the chirp ID inside the message text. The subgraph will parse these out and associate the message objects together and the frontend will do whatever replace-with-embed necessary.

We could do something similar for reactions like iMessage does when reacting to an SMS, where it might look like

> chirp:137:23896424:107
Reacted with "👍"

I am liking the "degrades to human readable text" approach. But the downside is that the Chirp City subgraph and any future indexers/clients would need to know about and parse these messages and associate objects, etc. together. Seems like lots of room for error without structured data?

2. Reaction event

We could create a separate event for reactions specifically. This leans more into the "structured data" approach without being too heavy, and keeps the PublicMessage channels clear in case there are several clients listening/indexing these but haven't caught up with new syntaxes/features like the above.

There's a few approaches here I can think of. The obvious one uses the message ID like above as the reference point. We won't be able to add indexed to the messageId because it's a dynamic length string, though. Maybe a hash stored in a uint, just for the purposes of filtering? Is an indexed, fixed-length string possible?

event MessageReaction(address from, string messageId, string reaction);

The message ID is just a pointer to a log item, so we could break it out into its component parts. The downside here is that we can use indexed on a maximum of three fields, but we have ~four that I could see being useful to have indexed. Which do we leave out?

event LogReaction(address from, uint chainId, uint blockNumber, uint logIndex, string reaction);

(using "log" here instead of "chirp" in case it becomes broadly useful to have a general purpose reaction event for log items.

Another possibility is using a generic object ID, rather than just a message, which lets you react to ~anything on the blockchain (see below for schema/spec proposal):

event Reaction(address from, string objectId, string reaction);

To get this indexed, we could do:

event Reaction(address indexed from, uint indexed objectIdHash, string objectId, string reaction);

Related: object ID schema

It might be useful to come up with a standard set of IDs that correspond to blockchain entities for referencing later, then a Reaction event could refer to any kind of object, not just a message/log/event. Same with the reply/embed syntax.