How to make comments in Activity Stream? (like Facebook)

I begin to develop a stream of activity. I read How to implement a social network activity stream and What is the best way to implement a social activity stream? ... What I didn't find is the best way to add comments to events. Like facebook, each comment can be commented by a different person.

If each activity comment is saved as a different activity, I would not be able to get that comment's activity without being asked. So the solution I am thinking about is to store the comments in the serialization data field of each activity. If a user wants to delete their comment, I will have to update this activity.

That's the right decision? Is there a better approach?

Thanks!

+2


a source to share


2 answers


I agree with Jakub - it depends on your backend, but what you need is an efficient tree storage method. If you are using SQL database I would keep both parent activity and tree root (main id?). This way you can quickly get a whole comment tree given any comment or activity id.

Then your search code will look something like this:

  • To replay the entire commentary activity stream, grab all posts with the same primary ID. You probably want to think of master records as having a null parent id.
  • When adding a comment, you need to update two fields - the main ID and the parent ID. You can get both of them directly from the parent activity without doing any lookups.
  • When you delete a comment, just delete it and it will disappear from the tree.
  • If you just want the "main" actions, select where parent = null and you're done.


An example if it helps:

  • Main activity (id = 123, p = null, m = 123)
    • Comment (id = 124, p = 123, m = 123)
    • One more comment (id = 125, p = 123, m = 123)
      • Subcomplex (id = 126, p = 125, m = 123)

I remember reading an example of this using document based storage with Couch-DB. I can't find it now, but from memory it used something like this (master ids for parent entries).

+1


a source


This kind depends on what type of backend you are using and what your constraints are.



Serializing comments seems like a sane approach, or I think you could just use a polymorphic comment table (if you are using a relational db).

0


a source







All Articles