diff --git a/pkg/internal/http/api/events_message_api.go b/pkg/internal/http/api/events_message_api.go index c2002e1..84e7142 100644 --- a/pkg/internal/http/api/events_message_api.go +++ b/pkg/internal/http/api/events_message_api.go @@ -57,14 +57,15 @@ func newMessageEvent(c *fiber.Ctx) error { _ = jsoniter.Unmarshal(raw, &parsed) event := models.Event{ - Uuid: data.Uuid, - Body: parsed, - Type: data.Type, - Sender: member, - Channel: channel, - QuoteEventID: data.Body.QuoteEventID, - ChannelID: channel.ID, - SenderID: member.ID, + Uuid: data.Uuid, + Body: parsed, + Type: data.Type, + Sender: member, + Channel: channel, + QuoteEventID: data.Body.QuoteEventID, + RelatedEventID: data.Body.RelatedEventID, + ChannelID: channel.ID, + SenderID: member.ID, } if event, err = services.NewEvent(event); err != nil { diff --git a/pkg/internal/models/events.go b/pkg/internal/models/events.go index 3f6d303..d4d6bc0 100644 --- a/pkg/internal/models/events.go +++ b/pkg/internal/models/events.go @@ -15,24 +15,26 @@ const ( type Event struct { cruda.BaseModel - Uuid string `json:"uuid"` - Body datatypes.JSONMap `json:"body"` - 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"` + Uuid string `json:"uuid"` + Body datatypes.JSONMap `json:"body"` + 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"` + RelatedEventID *uint `json:"related_event_id,omitempty"` + RelatedEvent *Event `json:"related_event,omitempty" gorm:"foreignKey:RelatedEventID"` + 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 []string `json:"attachments,omitempty"` - QuoteEventID *uint `json:"quote_event,omitempty"` - RelatedEvent *uint `json:"related_event,omitempty"` - RelatedUsers []uint `json:"related_users,omitempty"` + Text string `json:"text,omitempty"` + Algorithm string `json:"algorithm,omitempty"` + Attachments []string `json:"attachments,omitempty"` + QuoteEventID *uint `json:"quote_event,omitempty"` + RelatedEventID *uint `json:"related_event,omitempty"` + RelatedUsers []uint `json:"related_users,omitempty"` } diff --git a/pkg/internal/services/messages.go b/pkg/internal/services/messages.go index 2a1d651..cd49a1d 100644 --- a/pkg/internal/services/messages.go +++ b/pkg/internal/services/messages.go @@ -19,16 +19,17 @@ func EditMessage(event models.Event, body models.EventMessageBody) (models.Event if err != nil { return event, err } - body.RelatedEvent = &event.ID + body.RelatedEventID = &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, + Uuid: uuid.NewString(), + Body: EncodeMessageBody(body), + Type: models.EventMessageEdit, + Channel: event.Channel, + Sender: event.Sender, + QuoteEventID: body.QuoteEventID, + RelatedEventID: body.RelatedEventID, + ChannelID: event.ChannelID, + SenderID: event.SenderID, }) if err != nil { return event, err @@ -45,13 +46,14 @@ func DeleteMessage(event models.Event) (models.Event, error) { _, err = NewEvent(models.Event{ Uuid: uuid.NewString(), Body: EncodeMessageBody(models.EventMessageBody{ - RelatedEvent: &event.ID, + RelatedEventID: &event.ID, }), - Type: models.EventMessageDelete, - Channel: event.Channel, - Sender: event.Sender, - ChannelID: event.ChannelID, - SenderID: event.SenderID, + Type: models.EventMessageDelete, + Channel: event.Channel, + Sender: event.Sender, + RelatedEventID: &event.ID, + ChannelID: event.ChannelID, + SenderID: event.SenderID, }) if err != nil { return event, err