added create date calculator for channel.

This commit is contained in:
5elenay
2021-08-22 17:45:45 +03:00
parent f80532ef53
commit b7cc1c0d5f
6 changed files with 35 additions and 7 deletions

View File

@@ -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 == "" {