diff --git a/doc/api.oa3 b/doc/api.oa3 index 56aa451b..1f35bd8f 100644 --- a/doc/api.oa3 +++ b/doc/api.oa3 @@ -3510,6 +3510,9 @@ components: status: type: string enum: [ pending, confirmed, requested, connecting, connected ] + statusUpdated: + type: integer + format: int64 token: type: string notes: diff --git a/net/server/internal/api_addCard.go b/net/server/internal/api_addCard.go index 79ea0fbf..ebf441fe 100644 --- a/net/server/internal/api_addCard.go +++ b/net/server/internal/api_addCard.go @@ -1,6 +1,7 @@ package databag import ( + "time" "databag/internal/store" "encoding/hex" "errors" @@ -57,6 +58,7 @@ func AddCard(w http.ResponseWriter, r *http.Request) { Node: identity.Node, ProfileRevision: identity.Revision, Status: APPCardConfirmed, + StatusUpdated: time.Now().Unix(), ViewRevision: 0, InToken: hex.EncodeToString(data), AccountID: account.GUID, diff --git a/net/server/internal/api_setCardStatus.go b/net/server/internal/api_setCardStatus.go index f43cd9f4..a92539c8 100644 --- a/net/server/internal/api_setCardStatus.go +++ b/net/server/internal/api_setCardStatus.go @@ -4,6 +4,7 @@ import ( "databag/internal/store" "encoding/hex" "errors" + "time" "github.com/gorilla/mux" "github.com/theckman/go-securerandom" "gorm.io/gorm" @@ -105,6 +106,7 @@ func SetCardStatus(w http.ResponseWriter, r *http.Request) { } } slot.Card.Status = status + slot.Card.StatusUpdated = time.Now().Unix() slot.Card.NotifiedView = viewRevision slot.Card.NotifiedArticle = articleRevision slot.Card.NotifiedChannel = channelRevision diff --git a/net/server/internal/api_setCloseMessage.go b/net/server/internal/api_setCloseMessage.go index ff6b327d..55889b48 100644 --- a/net/server/internal/api_setCloseMessage.go +++ b/net/server/internal/api_setCloseMessage.go @@ -56,6 +56,9 @@ func SetCloseMessage(w http.ResponseWriter, r *http.Request) { if res := tx.Model(&card).Update("status", APPCardConfirmed).Error; res != nil { return res } + if res := tx.Model(&card).Update("status_updated", time.Now().Unix()).Error; res != nil { + return res + } } if res := tx.Model(&card).Update("detail_revision", account.CardRevision+1).Error; res != nil { return res diff --git a/net/server/internal/api_setOpenMessage.go b/net/server/internal/api_setOpenMessage.go index 985a1eac..8d3675f2 100644 --- a/net/server/internal/api_setOpenMessage.go +++ b/net/server/internal/api_setOpenMessage.go @@ -67,6 +67,7 @@ func SetOpenMessage(w http.ResponseWriter, r *http.Request) { card.Node = connect.Node card.ProfileRevision = connect.ProfileRevision card.Status = APPCardPending + card.StatusUpdated = time.Now().Unix() card.NotifiedProfile = connect.ProfileRevision card.NotifiedArticle = connect.ArticleRevision card.NotifiedView = connect.ViewRevision @@ -124,9 +125,11 @@ func SetOpenMessage(w http.ResponseWriter, r *http.Request) { } if card.Status == APPCardConfirmed { card.Status = APPCardRequested + card.StatusUpdated = time.Now().Unix() } if card.Status == APPCardConnecting { card.Status = APPCardConnected + card.StatusUpdated = time.Now().Unix() } card.OutToken = connect.Token card.DetailRevision = account.CardRevision + 1 diff --git a/net/server/internal/modelUtil.go b/net/server/internal/modelUtil.go index 51bd0b09..0f949cc8 100644 --- a/net/server/internal/modelUtil.go +++ b/net/server/internal/modelUtil.go @@ -69,13 +69,14 @@ func getCardRevisionModel(slot *store.CardSlot) *Card { func getCardDetailModel(slot *store.CardSlot) *CardDetail { - var groups []string + var groups []string = []string{} for _, group := range slot.Card.Groups { groups = append(groups, group.GroupSlot.GroupSlotID) } return &CardDetail{ Status: slot.Card.Status, + StatusUpdated: slot.Card.StatusUpdated, Token: slot.Card.OutToken, Notes: slot.Card.Notes, Groups: groups, diff --git a/net/server/internal/models.go b/net/server/internal/models.go index 0ea0fb98..898ab842 100644 --- a/net/server/internal/models.go +++ b/net/server/internal/models.go @@ -113,7 +113,9 @@ type CardData struct { type CardDetail struct { Status string `json:"status"` - Token string `json:"token,omitempty"` + StatusUpdated int64 `json:"statusUpdated"` + + Token string `json:"token,omitempty"` Notes string `json:"notes,omitempty"` diff --git a/net/server/internal/store/schema.go b/net/server/internal/store/schema.go index a8d2ab71..a3ae9dab 100644 --- a/net/server/internal/store/schema.go +++ b/net/server/internal/store/schema.go @@ -151,6 +151,7 @@ type Card struct { ProfileRevision int64 `gorm:"not null"` DetailRevision int64 `gorm:"not null;default:1"` Status string `gorm:"not null"` + StatusUpdated int64 InToken string `gorm:"not null;index:cardguid,unique"` OutToken string Notes string