Simple Messaging System with Announcement

In the previous article we discuss broadcast, now we are going to cover announcement for our simple messaging system. What is the difference ?

Well, broadcast and announcement both is a one way conversation. The difference is what happens after the broadcast/announcement is made.

With broadcast, the conversation continues individually between two users.

While an announcement remains as a single message. The best illustration is a bulletin board. The message is put up on the bulletin board for everyone to read.

In our case, it is send to all users. Of course we have to be able to control it so it reaches a specific group of users instead of everybody. Especially in multi group environment.

We are essentially going to use the same method as broadcast, with the exception that instead of working like a batch insert of messages. There is only one message for one announcement.

Also because we now have multiple message types, it is time we update the table with message_type to indicate what kind of message is stored. So, it is going to contain the value of 0 for normal, 1 for reply, 2 for broadcast and 3 for announcement.

Because we live in a digital world, naturally the announcement can be commented. It works just like a reply because it is an ordinary message. Care must be taken however to ensure that only the group members can reply.

So, our database structure 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.
  • message_type <- 0=normal, 1=reply, 2=broadcast, 3=announcement

Now, I believe I have cover just about everything that can happen in messages. Hope you find the article series useful.

As usual, put your thoughts in the comment section below.