calebmer / connect

10 stars 2 forks source link

Mentions #29

Open calebmer opened 5 years ago

calebmer commented 5 years ago

In posts and comments users should be able to mention other users with @. For example: @calebmer how ya doin?. That should send a notification to calebmer’s account and render as a link to calebmer’s profile when the post or comment renders.

baruchadi commented 5 years ago

So I can see a couple of ways to resolve this:

  1. store tokens in each post of the mentions
  2. parse raw strings on client and figure out if a mention is valid

let's say I have the following post: hey @calebmer can you help me w/ typescript?

for both methods, we will need a search function. to find all possible user mentions and validate if it is a mention to a user or just unrelated text. let's assume the function does just that, call it findMentions for now.

  1. We would format a post a bit differently, and break the post string or replace the @name with some kind of to represent the user. This will happen on the server upon receiving the string and prior to inserting to the db using the findMentions function.
    • this can be w/ text breaks. we at this point turn the post to an array rather than just a string. the result would be:
      • ["hey ", {user_id:00001, text:"@calebmer"}, "can you help me w/ typescript"]
    • client will then look for those objects and replace them w/ the text value and link to the user_id
    • prior to posting, we could also use the findMentions to have autocomplete on client side (sort of like what slack is doing)
  2. other option is to parse on the client side at all times, this would be less efficient in my opinion. You will run findMentions on every post the user sees. if valid, replace w/ a link. this will cause a lot of db interaction or caching of all users on client side to make it more efficient.

personally, I would go for the first option, but if you guys have a different way that you can think of or want me to elaborate on the second option, let me know.

Cheers!

calebmer commented 5 years ago

Part of what I’m looking for in this feature and #30 is some specification of how Connect content should be encoded. For instance, how should we encode mentions?

Hello @user#123!
Hello @#123!
Hello <@user#123>!

If we pick any of these then what is our escape character?

I at least want us to decide on an escape character for extra information that is not visible in the text. Since we don’t expect humans to write this, we can get creative with Unicode. We could use the ❰❱ brackets to signify enhanced text content. Like HTML uses <>.

Hello ❰@user#123❱!

For bold content:

Hello ❰b: this is bold❱!

…or we could just use Markdown. But then Markdown has a bunch of features we don’t want. Also, we need features that Markdown doesn’t include like mentions.

calebmer commented 5 years ago

Yep! I like your first option. My comment was more pointing out that it doesn’t have to be JSON. We can create our own format if we don‘t like JSON.

calebmer commented 5 years ago

Actually, you know what, I like JSON. We can have TypeScript types for it. We’d also end up parsing a custom string into JSON anyway. I retract my idea.

baruchadi commented 5 years ago

we could definitely use our own encoding, I was thinking array b/c that would be amazingly easy to parse and turn to a component. each post is an array, say use variable named post

return <TextElement>
post.map(token=>{
    if( typeof token === string ) {
        return token
    }
else{
switch(token.type){
    case mention:
         return <Mention token={token} />
    break; // more stuff here.
}
}
})
</TextElement>
calebmer commented 5 years ago

I totally agree. I’m convinced. JSON is better because it is:

brenthaertlein commented 5 years ago

I'm very interested to see how this plays out. Mentions are something that I find very interesting and if I can contribute in any way I will.

calebmer commented 5 years ago

Please work on this @brenthaertlein 😀

It’s probably a good idea to start with #30 to get the basic framework in place and then move on to mentions.