A Simple Messaging System with Comments

This article expands on the simple messaging system with comments subsystem. If you have not read it yet, please visit Simple Messaging System by clicking here. Now, onto the expansion…

First, we review our table structure again here :

  • message_id <- auto-increment by system
  • message_origin <- usually refers to the id in a users table
  • message_destination <- usually refers to the id in a users table
  • message_content <- the information
  • message_timestamp <- the date and time the message was sent
  • is_reply_to <- we put the previous message_id here
  • original_message_id <- we put the first message_id here

I decided to go with method 2.

Comments

Now, if the message is public, a third party can enter the conversation at any time. How do we handle this ?

Our message system does not have any privacy indicator. A privacy indicator is used to set the message to public or private. We are going to assume that all messages are basically public. So, we create a new field called is_private.

Naturally the system will check if it is private or public and display it accordingly, which is outside the scope of this article. It is up to your implementation.

Let us continue.

A comment can be made anywhere inside the conversation.

For example, while Alex and Britney are having exchanging messages, Charlie join the conversation. Since he is a friend of Alex, he send a message ‘Hi Alex, Hi Britney’. So we insert a record with the following information:

  • 3
  • Charlie
  • Alex
  • Hi Alex, Hi Britney
  • 11 December 2013 17.40
  • 1
  • 1
  • FALSE

Following our previous examples, we have two records sharing the same is_reply_to and original_message_id. In this case, we use the timestamp to display which one is displayed first.

As an alternative, we can simply allow comment only on the last reply message. We will not have the problem above.

The difference between Reply and Comment is that Reply is private between two people while Comment can be done with two or more people in public

Our table structure with Comment expansion becomes :

  • message_id <- auto-increment by system
  • message_origin <- usually refers to the id in a users table
  • message_destination <- usually refers to the id in a users table
  • message_content <- the information
  • message_timestamp <- the date and time the message was sent
  • is_reply_to <- we put the previous message_id here
  • original_message_id <- we put the first message_id
  • is_private <- we put a boolean value indicating if this message can be viewed outside the original parties.

What can happens next ? Well, stay tuned for the next expansion to our simple messaging system…