Skip to content

Instantly share code, notes, and snippets.

@croaker
Created December 3, 2012 12:57
Show Gist options
  • Save croaker/4194890 to your computer and use it in GitHub Desktop.
Save croaker/4194890 to your computer and use it in GitHub Desktop.
Reporta Message System
+---------------+
| Conversation |0..* initiator 1+-------+1
|---------------|+---------------------+| User |+----+
|title | +-------+ |
|body | |
|started_at | |
| |0..* project 1+---------+ |
| |+---------------------+| Project | | participant
| | +---------+ |
| | |
+---------------+ |
+1 +1 |
| | conversation |
| +-------------------+ +----------+
|messages | |
| | |
+0..* +0..* +0..*
+---------------+ +---------------------------+
| Message | | ConversationParticipation |
|---------------| |---------------------------|
|body | |read? |
|sent_at | |notify? |
| | | |
| | | |
| | | |
+---------------+ +---------------------------+
class Conversation
has_many :messages
has_many :conversation_participations
has_many :participants, through: :conversation_participations
belongs_to :project
belongs_to :site_account
belongs_to :initiator, class_name: 'User'
# Attribute:
# topic, body, started_at
end
class Message
belongs_to :conversation, autosave: true, validate: true
belongs_to :sender, class_name: 'User'
# Attribute:
# body, sent_at
end
class ConversationParticipation
belongs_to :conversation
belongs_to :participant, class_name: 'User'
# Attribute:
# read, notify_participant als Booleans
end
class Users
has_many :conversations, through: :conversation_participations
has_many :conversation_participations, foreign_key: 'participant_id'
has_many :messages
end
class Project
has_many :conversations
end
@croaker
Copy link
Author

croaker commented Dec 3, 2012

Was habe ich mir dabei gedacht?

Im Prinzip reicht es bei jeder Conversation zu wissen, ob ein Participant die aktuellste Version gelesen hat. Es ist nicht so interessant sagen zu können, dass er z. B. die letzten 5 Messages einer Conversation verpasst hat. Auch dies ließe sich umsetzen, indem man ein last_read_at Attribut zu den ConversationParticipations hinzufügt.

Des Weiteren reicht es auch einmal zu wissen, ob der Participant Notifications erhalten will.

Was muss beachtet werden?

Wenn eine neue Conversation gestartet wir müssen alle Participants inklusive des Initiators in die ConversationParticipants. Denn jedes mal, wenn eine neue Message an die Conversation geht, müssen die ConversationParticipations auf unread gesetzt werden (außer für denjenigen, der die Nachricht verschickt hat, was nicht unbedingt der Initiator sein muss). Hinzugefügt zu dieser Conversation werden immer alle Benutzer, die der Initiator benachrichtigen möchte. Alle Anderen, die u. Ust. über das Projekt auf diese Conversation zugreifen können, nehmen erst teil, wenn sie auch eine Message geschickt haben.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment