Search code examples
iosparse-platformmessaging

How to mark conversation or message to be unread in a messaging app using ios7 and parse.com?


I am building a messaging application for iPhone using Parse as my backend. How can I mark the conversation in the inbox view (not the message view) as there are unread messages here? But I want this the receiver to see it and not the sender... Since push notifications aren't always reliable, I want to find a way to let the user know there is an unread message in some conversation thread.

Any input is greatly appreciated.

EDIT:

I have two classes, one is conversation class which holds an array that points to the messages which reside in messages class. This set up was thankfully suggested by a StackOverflow member a while back.

I have not tried any code to post here... I don't even know how this will work... I am trying to implement a way with my current setup to flag a conversation if it has new messages. I thought about adding a column which indicates new messages inside this thread and based on it I can probably change the cell color in the inbox which has this flag set but then again this will show for both sender and receiver... I want it to show for receiver only and since receiver could be multiple in this case, this is where I am having an issue... It seems like there has to be another class that keeps track of this unless something can be done with the current setup...


Solution

  • So your current schema looks something like this?

    Conversation : class
    - messages : Array<Message>
    - participants : Array<_User>
    Message : class
    - body : String
    

    In regards to tracking read count vs message count, you could do that with a counter, e.g.

    Conversation : class
    - messages : Array<Message>
    - participants : Array<ConversationParticipant>
    - messageCount : Number
    ConversationParticipant : class
    - readMessageCount : Number
    - user : Pointer<_User>
    Message : class
    - body : String
    - readBy : Array<_User>
    

    The idea would be:

    • user adding a message to a conversation:
      • add author to readBy array on message
      • increase messageCount on Conversation
      • increase readMessageCount on ConversationParticipant for author
      • add message to messages on Conversation
    • user (recipient) reading a message:
      • increase readMessageCount on ConversationParticipant
      • add user to readBy array on message
    • showing new message count on conversation:
      • compare messageCount on Conversation to readMessageCount on ConversationParticipant that matches the current user
    • showing read/unread status per message
      • check if readBy contains pointer to the current user (don't need to include() them, just compare the ID on the pointer)

    Much of this could be done in Cloud Code in beforeSave or afterSave.