Remove messages from one caller without affecting the other

Asked

Viewed 56 times

3

I am implementing a messaging system and need to make a way to remove messages from one caller without affecting the other.

So-and-so and Sicrano exchange messages:

  1. At a certain point, Fulano removes the conversation, but Sicrano continues with the full conversation history.
  2. When Fulano and Sicrano resume the dialogue, Fulano will only see the new messages and Sicrano continues with the messages from the beginning.
  3. Naturally, messages can only be removed when both remove the conversation, and when a new message is exchanged there will be no old messages.

Perhaps by setting an individual flag with the timestamp of the last removal of the conversation, so only those messages that were earlier than the date were deleted by both Fulano and Sicrano would be listed. That way it would be easier to 'hide' in the message box those that were removed by an interlocutor, but it would be more complicated to combine the point where both parties deleted the messages to actually give a DELETE.

2 answers

2

I prefer to leave for the idea of timestamp also, about your doubt of the DELETE I would do something like that:

  1. A timestamp for each user of that conversation that will be overwritten every time they click remove.

  2. So-and-so removed the messages, when Sicrano remove would DELETE in the Messages table passing the MENOR timestamp among the 2.

  3. Why the MENOR? Simple, based on the smallest you know that both erased up there, if you catch the MAIOR it will happen that the other user has not deleted it yet.

  4. From the time you have already removed once, every time the next user (different from the last one who did the deed) do the removal then run the DELETE.

  • I followed the same reasoning, I would make a select limiting the messages by timestamp, and the delete would be via cron.

  • 1

    In the case of select you will execute according to the timestamp at the time of the delete is always the smallest.

1

From the way you describe the problem, it seems clear to me that a "message" and a "message in history" are independent entities. You have to make a model like

CREATE TABLE Message (
    MessageId INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
    Content TEXT NOT NULL);

CREATE TABLE UserMessage (
    UserId INT NOT NULL,
    MessageId INT NOT NULL,
    SentBy INT NOT NULL,
    DateTime DATETIME NOT NULL,
    PRIMARY KEY (UserId, MessageId),
    FOREIGN KEY (UserId) REFERENCES User ON DELETE CASCADE,
    FOREIGN KEY (MessageId) REFERENCES Message ON DELETE CASCADE,
    FOREIGN KEY (SentBy) REFERENCES User (UserId) ON DELETE CASCADE);

You’d run a Garbage Collector regularly to erase the Message older than a certain time.

  • By court order, you have to tap into Ana’s communication: you create a user for the police and add a UserMessage whenever there is a UserMessage associated with Ana (you can have a table of stapled users and do this via a Trigger, for example).

  • In the case of forwarded messages or distribution groups, you only need to store a copy of the message to everyone who received the message - this is especially convenient if people can send videos, images, ...

  • If only one particular message is private - for example, I accidentally sent an intimate message meant for my girlfriend to the football group - I can delete that message without destroying the rest of the conversation.

  • Jeez, I had not understood his problem as a "wiretap". For me it was a normal chat hahahaha

  • It is not in the scope that @Papacharlie defined, but it can happen (therefore, by Murphy’s Law, going happen).

  • @Maiconcarraro, is a common messaging system, but did not want to enter this explanation to ask the simplest question - my fault. The cron would clean the marked content for removal after X months as the law says.

  • I did not quite understand point 1. In a way court order is certain, but it would only be necessary to keep the communication log between users. The delete is executed after the legal term and the flag message display is what changes.

  • The point is that message maintenance and police access use the normal system mechanism without you needing to implement an additional mechanism.

  • The police do not use the system to track messages, nor anyone with access to the system. Messages are confidential and delivered in order. I still don’t understand what it would be police access.

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.