added create date calculator for channel.
This commit is contained in:
18
channel.go
18
channel.go
@@ -4,11 +4,15 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"time"
|
||||
|
||||
"github.com/oklog/ulid/v2"
|
||||
)
|
||||
|
||||
// Channel struct.
|
||||
type Channel struct {
|
||||
Client *Client
|
||||
Client *Client
|
||||
CreatedAt time.Time
|
||||
|
||||
Id string `json:"_id"`
|
||||
ChannelType string `json:"channel_type"`
|
||||
@@ -32,6 +36,18 @@ type FetchedMessages struct {
|
||||
Users []*User `json:"users"`
|
||||
}
|
||||
|
||||
// Calculate creation date and edit the struct.
|
||||
func (c *Channel) CalculateCreationDate() error {
|
||||
ulid, err := ulid.Parse(c.Id)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
c.CreatedAt = time.UnixMilli(int64(ulid.Time()))
|
||||
return nil
|
||||
}
|
||||
|
||||
// Send a message to the channel.
|
||||
func (c Channel) SendMessage(message *SendMessage) (*Message, error) {
|
||||
if message.Nonce == "" {
|
||||
|
||||
Reference in New Issue
Block a user