🗃️ Add relations between quoted event and original event

This commit is contained in:
LittleSheep 2024-11-18 22:56:10 +08:00
parent a79995e7c0
commit 6c60e250e1
3 changed files with 29 additions and 25 deletions

View File

@ -62,6 +62,7 @@ func newMessageEvent(c *fiber.Ctx) error {
Type: data.Type,
Sender: member,
Channel: channel,
QuoteEventID: data.Body.QuoteEventID,
ChannelID: channel.ID,
SenderID: member.ID,
}

View File

@ -20,6 +20,8 @@ type Event struct {
Type string `json:"type"`
Channel Channel `json:"channel"`
Sender ChannelMember `json:"sender"`
QuoteEventID *uint `json:"quote_event_id,omitempty"`
QuoteEvent *Event `json:"quote_event,omitempty" gorm:"foreignKey:QuoteEventID"`
ChannelID uint `json:"channel_id"`
SenderID uint `json:"sender_id"`
}
@ -30,7 +32,7 @@ type EventMessageBody struct {
Text string `json:"text,omitempty"`
Algorithm string `json:"algorithm,omitempty"`
Attachments []string `json:"attachments,omitempty"`
QuoteEvent uint `json:"quote_event,omitempty"`
RelatedEvent uint `json:"related_event,omitempty"`
QuoteEventID *uint `json:"quote_event,omitempty"`
RelatedEvent *uint `json:"related_event,omitempty"`
RelatedUsers []uint `json:"related_users,omitempty"`
}

View File

@ -19,13 +19,14 @@ func EditMessage(event models.Event, body models.EventMessageBody) (models.Event
if err != nil {
return event, err
}
body.RelatedEvent = event.ID
body.RelatedEvent = &event.ID
_, err = NewEvent(models.Event{
Uuid: uuid.NewString(),
Body: EncodeMessageBody(body),
Type: models.EventMessageEdit,
Channel: event.Channel,
Sender: event.Sender,
QuoteEventID: body.QuoteEventID,
ChannelID: event.ChannelID,
SenderID: event.SenderID,
})
@ -44,7 +45,7 @@ func DeleteMessage(event models.Event) (models.Event, error) {
_, err = NewEvent(models.Event{
Uuid: uuid.NewString(),
Body: EncodeMessageBody(models.EventMessageBody{
RelatedEvent: event.ID,
RelatedEvent: &event.ID,
}),
Type: models.EventMessageDelete,
Channel: event.Channel,