Friday, May 18, 2018

Messaging

The last chunk that I wanted to get done before the end of the semester was Messaging. It took me a while to wrap my head around how I was going to do it, and the way that I picked was definitely inefficient but it worked so I was happy.

This would require two tables in the sql server. Messages, which held the username of the person sending the message, the username of the person receiving the message, a timestamp and the actual message. The second table is the Message_Box. This had the to_user and from_user field and an incoming field which held an integer that specified the amount of messages sent by from_user to to_user that to_user hadn't seen. Every time the message page was loaded the incoming field would be reset to 0 because all the messages from that user would be loaded. The real use of the incoming field is when two users are on their messaging pages and messaging each other. I have a method called StartMessageCheckingTask() that runs every second and checks if the incoming field for that user was higher than 0. If it was it would load the amount of incoming messages from from the bottom of the list of all messages sorted by their timestamp. Unfortunately this means that the sql server is being accessed every second while your on the messaging screen which isn't the greatest but it was good enough for what I needed at the time.

Now a user could tap on a pin and a box saying "Message" would popup. Clicking on the popup would bring you to a messaging screen where you would be able to message the user who's pin you had tapped.

No comments:

Post a Comment