0
votes

i am developing a simple chat app using firebase, in which till now user authentication, creating friend list, sending and receiving msg functionalities are done. now i have added a menu item in conversation activity called as "Delete conversation" , obviously which will clear the conversation msgs.

Now let me tell you the database structure for msg stored in firebase database.

> messages
>     <ConversationId>
>          <MsgId>
>                text:"hello"
>                timestamp:<timestamp>
>                sender:<sender's uid>
>                receiver:<receiver's uid>
>          <MsgId>
>                ....

So, my question is, The conversation includes minimum 2 users. right. so , suppose i implement a delete conversation to delete all the entries in a particular conversation id. it will delete all the data under that conversation id. but suppose delete conversation is clicked by only user1... user2 wants all that conversation. then how can i implement it? do i need to create a local database? to store and sync all the messages in users phone?

2

2 Answers

5
votes

Recently i have executed this functionality. So you can achieve this by adding some functionality. First you need to add one more node in your message like this

<ConversationId>
     <MsgId>
           text:"hello"
           timestamp:<timestamp>
           deleted:<user uid>  //id of first user who deleted the conversation 
           sender:<sender's uid>
           receiver:<receiver's uid>
     <MsgId>
           ....

So trick is when one of the any two user deleted the conversation, store his user id in deleted node and in code put the check when you receive all messages from firebase, if deleted node have same uid then do not add this message (means this message is deleted by user).

Through this now you are able to delete the single message or entire conversation and then if other user also deletes the conversation or single message then you have to check if deleted node have any uid as a value in it, if yes then delete the whole message.

I followed the technique. vote if this will help you

0
votes

I depends on what you want. For example: do you still want the conversations on the server? -> add a tag for user 1 (who deleted the conversation) so the conversation will not be displayed for user 1. You could even manage for who the message is viewable.

Saving, loading and deleting the data on the client side, as you suggested, also works fine.