in chat application ,, Two friends x, y (used the same device) x Send to y message then stored in database x make log-out of the application and y log-in application and open chat and received the message here the message stored twice on the local storage and this is problem how to prevent duplicate storage on local storage ?

Recommended Answers

All 4 Replies

Each user has a specific, unique, identifier, yes?

Pre-pend your root object with that decorator.



Can instead be:


Then your code can look for said data by something like:

localStorage[userID + "UserData"];

Mind you this is all pseudo code so you'll still have to do some work.

Happy coding!!

Thank you for your reply, it's really helpful.
But could you please explain it more?
It's not clear for me how i can implement it,on insertion of data or retrieval from storage?, (in android)

thank you.‏

i think it is a database problem..i hope the following table will handle the problem you're facing


when X sends msg to Y

msg_id    msg    sender   receiver    seen    msg_sent_time    msg_recv_time
    1     hi Y     X          Y        N         3.00 PM           null

when X logs out and Y logs in, display all new messages whose receiver is Y using the following query

SELECT * FROM `msg_table` WHERE receiver = 'Y' AND seen = 'N'

then for each new message seen by Y, update the seen status to Y

UPDATE `msg_table` SET seen='Y' WHERE msg_id = msg_id_from_previous_select

then, the table will look like this

msg_id    msg    sender   receiver    seen    msg_sent_time    msg_recv_time
    1     hi Y     X          Y        Y         3.00PM           3.05 PM

Thank you so much for your help, all I have to do now is tackle the coding. . Thank you

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.