El siguiente enfoque debería ser capaz de resolverlo. Esta es una buena base tanto para el chat como para la mensajería, mientras que con el chat puede sondear mensajes recientes del lado del cliente y obtener una interfaz de usuario intuitiva.
Message {
MessageId,
SenderId, -- Foreign key User.UserId
DateSent,
Subject,
Content,
Attachment, -- can be null or default to a 0
...
}
UserMessage {
Id,
MessageId, -- Foreign key Message.MessagId
RecepientId, -- Foreign key User.UserId
DateRead -- can default to year 1900 if you do not want to deal with nulls
}
User {
UserId
UserName
...
}
Queries
Read = UserMessage where DateRead > year 1900 (or not equal to null)
Inbox = UserMessage where RecepientId = Me.UserId
Sent = Message where SenderId = Me.UserId
Conversation = Group by Subject
Attachment = (Simple = Path to attachment file. || Better = DocumentId ... see below)
Attachment
Document {
int DocumentId,
int DocTypeId,
virtual DocumentType DocumentType,
string FileName,
int UserId,
string mimeType,
float fileSize,
string storagePath,
int OrganizationId,
string fileHash,
string ipAddress,
DateTime DateCreated = DateTime.Now;
}
¿cómo podemos implementar esto en MySQL? –