Add created/updated fields for new & updated messages
This commit is contained in:
@@ -36,7 +36,13 @@ func (s *Session) messageUpdate(ctx context.Context, p *incoming.MessageUpdate)
|
||||
return err
|
||||
}
|
||||
|
||||
return s.sendToAllSubscribers(&outgoing.MessageUpdate{ID: p.ID, Message: msg.Message}, p.ID)
|
||||
omsg := &outgoing.MessageUpdate{
|
||||
ID: p.ID,
|
||||
Message: msg.Message,
|
||||
UpdatedAt: *msg.UpdatedAt,
|
||||
}
|
||||
|
||||
return s.sendToAllSubscribers(omsg, p.ID)
|
||||
}
|
||||
|
||||
func (s *Session) messageDelete(ctx context.Context, p *incoming.MessageDelete) error {
|
||||
|
||||
@@ -2,16 +2,20 @@ package outgoing
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"time"
|
||||
)
|
||||
|
||||
type (
|
||||
Message struct {
|
||||
ID string `json:"id"`
|
||||
ChannelID string `json:"cid"`
|
||||
Message string `json:"m"`
|
||||
Type string `json:"t"`
|
||||
ReplyTo string `json:"rid"`
|
||||
Message string `json:"m"`
|
||||
UserID string `json:"uid"`
|
||||
ChannelID string `json:"cid"`
|
||||
ReplyTo string `json:"rid"`
|
||||
|
||||
CreatedAt time.Time `json:"created_at,omitempty" db:"created_at"`
|
||||
UpdatedAt *time.Time `json:"updated_at,omitempty" db:"updated_at"`
|
||||
}
|
||||
|
||||
Messages []*Message
|
||||
@@ -19,6 +23,8 @@ type (
|
||||
MessageUpdate struct {
|
||||
ID string `json:"id"`
|
||||
Message string `json:"m"`
|
||||
|
||||
UpdatedAt time.Time `json:"updated_at,omitempty" db:"updated_at"`
|
||||
}
|
||||
|
||||
MessageDelete struct {
|
||||
|
||||
@@ -14,6 +14,9 @@ func payloadFromMessage(msg *types.Message) *outgoing.Message {
|
||||
Type: msg.Type,
|
||||
UserID: strconv.FormatUint(msg.UserID, 10),
|
||||
ReplyTo: strconv.FormatUint(msg.ReplyTo, 10),
|
||||
|
||||
CreatedAt: msg.CreatedAt,
|
||||
UpdatedAt: msg.UpdatedAt,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user