From 1015e1e1901fcff9d0f776a9ec86b7ed784667b1 Mon Sep 17 00:00:00 2001 From: Jake Taylor <jake@privategrity.com> Date: Tue, 7 Mar 2023 20:37:50 +0000 Subject: [PATCH] Renamed lease field in channels indexedDb to lease_v2, such that its type can... --- indexedDb/impl/channels/implementation.go | 14 ++++++++++-- indexedDb/impl/channels/model.go | 26 +++++++++++------------ 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/indexedDb/impl/channels/implementation.go b/indexedDb/impl/channels/implementation.go index 80333135..703e4bb0 100644 --- a/indexedDb/impl/channels/implementation.go +++ b/indexedDb/impl/channels/implementation.go @@ -12,6 +12,7 @@ package main import ( "crypto/ed25519" "encoding/json" + "strconv" "strings" "sync" "syscall/js" @@ -382,7 +383,7 @@ func buildMessage(channelID, messageID, parentID []byte, nickname string, ChannelID: channelID, ParentMessageID: parentID, Timestamp: timestamp, - Lease: lease, + Lease: strconv.FormatInt(int64(lease), 10), Status: uint8(status), Hidden: hidden, Pinned: pinned, @@ -466,6 +467,15 @@ func (w *wasmModel) GetMessage( } } + lease := time.Duration(0) + if len(lookupResult.Lease) > 0 { + leaseInt, err := strconv.ParseInt(lookupResult.Lease, 10, 64) + if err != nil { + return channels.ModelMessage{}, err + } + lease = time.Duration(leaseInt) + } + return channels.ModelMessage{ UUID: lookupResult.ID, Nickname: lookupResult.Nickname, @@ -473,7 +483,7 @@ func (w *wasmModel) GetMessage( ChannelID: channelId, ParentMessageID: parentMsgId, Timestamp: lookupResult.Timestamp, - Lease: lookupResult.Lease, + Lease: lease, Status: channels.SentStatus(lookupResult.Status), Hidden: lookupResult.Hidden, Pinned: lookupResult.Pinned, diff --git a/indexedDb/impl/channels/model.go b/indexedDb/impl/channels/model.go index d90d5d0f..5ea934d7 100644 --- a/indexedDb/impl/channels/model.go +++ b/indexedDb/impl/channels/model.go @@ -45,19 +45,19 @@ const ( // The user's nickname can change each message, but the rest does not. We // still duplicate all of it for each entry to simplify code for now. type Message struct { - ID uint64 `json:"id"` // Matches pkeyName - Nickname string `json:"nickname"` - MessageID []byte `json:"message_id"` // Index - ChannelID []byte `json:"channel_id"` // Index - ParentMessageID []byte `json:"parent_message_id"` // Index - Timestamp time.Time `json:"timestamp"` // Index - Lease time.Duration `json:"lease"` - Status uint8 `json:"status"` - Hidden bool `json:"hidden"` - Pinned bool `json:"pinned"` // Index - Text []byte `json:"text"` - Type uint16 `json:"type"` - Round uint64 `json:"round"` + ID uint64 `json:"id"` // Matches pkeyName + Nickname string `json:"nickname"` + MessageID []byte `json:"message_id"` // Index + ChannelID []byte `json:"channel_id"` // Index + ParentMessageID []byte `json:"parent_message_id"` // Index + Timestamp time.Time `json:"timestamp"` // Index + Lease string `json:"lease_v2"` + Status uint8 `json:"status"` + Hidden bool `json:"hidden"` + Pinned bool `json:"pinned"` // Index + Text []byte `json:"text"` + Type uint16 `json:"type"` + Round uint64 `json:"round"` // User cryptographic Identity struct -- could be pulled out Pubkey []byte `json:"pubkey"` -- GitLab