Add created/updated fields for new & updated messages

This commit is contained in:
Denis Arh
2018-07-29 01:19:42 +02:00
parent 66d7cd7193
commit 99eac17751
3 changed files with 19 additions and 4 deletions
+7 -1
View File
@@ -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 {
+9 -3
View File
@@ -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 {
+3
View File
@@ -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,
}
}