Basically move messages to events

This commit is contained in:
2024-06-27 22:38:18 +08:00
parent 44b5da1630
commit 57f2aa518e
12 changed files with 516 additions and 418 deletions

View File

@ -1,8 +1,8 @@
package models
// Account profiles basically fetched from Hydrogen.Identity
// But cache at here for better usage
// At the same time this model can make relations between local models
// But cached at here for better usage
// At the same time, this model can make relations between local models
type Account struct {
BaseModel

View File

@ -14,7 +14,7 @@ type Channel struct {
Name string `json:"name"`
Description string `json:"description"`
Members []ChannelMember `json:"members"`
Messages []Message `json:"messages"`
Messages []Event `json:"messages"`
Calls []Call `json:"calls"`
Type ChannelType `json:"type"`
Account Account `json:"account"`
@ -44,6 +44,6 @@ type ChannelMember struct {
Notify NotifyLevel `json:"notify"`
PowerLevel int `json:"power_level"`
Calls []Call `json:"calls" gorm:"foreignKey:FounderID"`
Messages []Message `json:"messages" gorm:"foreignKey:SenderID"`
Calls []Call `json:"calls" gorm:"foreignKey:FounderID"`
Events []Event `json:"events" gorm:"foreignKey:SenderID"`
}

View File

@ -0,0 +1,33 @@
package models
import "gorm.io/datatypes"
const (
EventMessageNew = "messages.new"
EventMessageEdit = "messages.edit"
EventMessageDelete = "messages.delete"
EventSystemChanges = "system.changes"
)
type Event struct {
BaseModel
Uuid string `json:"uuid"`
Body datatypes.JSONMap `json:"body"`
Type string `json:"type"`
Channel Channel `json:"channel"`
Sender ChannelMember `json:"sender"`
ChannelID uint `json:"channel_id"`
SenderID uint `json:"sender_id"`
}
// Event Payloads
type EventMessageBody struct {
Text string `json:"text,omitempty"`
Algorithm string `json:"algorithm,omitempty"`
Attachments []uint `json:"attachments,omitempty"`
QuoteEvent uint `json:"quote_event,omitempty"`
RelatedEvent uint `json:"related_event,omitempty"`
RelatedUsers []uint `json:"related_users,omitempty"`
}

View File

@ -1,22 +0,0 @@
package models
import "gorm.io/datatypes"
const (
MessageTextType = "m.text"
)
type Message struct {
BaseModel
Uuid string `json:"uuid"`
Content datatypes.JSONMap `json:"content"`
Type string `json:"type"`
Attachments datatypes.JSONSlice[uint] `json:"attachments"`
Channel Channel `json:"channel"`
Sender ChannelMember `json:"sender"`
ReplyID *uint `json:"reply_id"`
ReplyTo *Message `json:"reply_to" gorm:"foreignKey:ReplyID"`
ChannelID uint `json:"channel_id"`
SenderID uint `json:"sender_id"`
}