aboutsummaryrefslogtreecommitdiff
path: root/backend/notes
diff options
context:
space:
mode:
Diffstat (limited to 'backend/notes')
-rw-r--r--backend/notes/app.bsky.feed.post.go74
-rw-r--r--backend/notes/note.go13
2 files changed, 87 insertions, 0 deletions
diff --git a/backend/notes/app.bsky.feed.post.go b/backend/notes/app.bsky.feed.post.go
new file mode 100644
index 0000000..21256be
--- /dev/null
+++ b/backend/notes/app.bsky.feed.post.go
@@ -0,0 +1,74 @@
+package notes
+
+import (
+ "fmt"
+ "strings"
+ "time"
+)
+
+type AppBskyFeedPostNote struct {
+ URI string
+ AuthorDID string
+ AuthorHandle string
+ Text string
+ CreatedAt time.Time
+ ReplyTo *string
+}
+
+type AppBskyFeedPostRecord struct {
+ URI string `json:"uri"`
+ Value struct {
+ Text string `json:"text"`
+ CreatedAt string `json:"createdAt"`
+ Reply *struct {
+ Parent struct {
+ URI string `json:"uri"`
+ } `json:"parent"`
+ } `json:"reply,omitempty"`
+ } `json:"value"`
+}
+
+func (bp *AppBskyFeedPostNote) GetID() string {
+ return bp.URI
+}
+
+func (bp *AppBskyFeedPostNote) GetAuthorDID() string {
+ return bp.AuthorDID
+}
+
+func (bp *AppBskyFeedPostNote) GetAuthorHandle() string {
+ return bp.AuthorHandle
+}
+
+func (bp *AppBskyFeedPostNote) GetTimestamp() time.Time {
+ return bp.CreatedAt
+}
+
+func (bp *AppBskyFeedPostNote) GetReplyTo() *string {
+ return bp.ReplyTo
+}
+
+func AppBskyFeedPostFromRecord(record AppBskyFeedPostRecord) (*AppBskyFeedPostNote, error) {
+ createdAt, err := time.Parse(time.RFC3339, record.Value.CreatedAt)
+ if err != nil {
+ return nil, fmt.Errorf("failed to parse timestamp: %w", err)
+ }
+ if record.Value.Text == "" {
+ return nil, fmt.Errorf("missing required field: text")
+ }
+ if record.URI == "" {
+ return nil, fmt.Errorf("missing required field: uri")
+ }
+
+ parts := strings.Split(record.URI, "/") // at://DID/collection/rkey
+ did := parts[2]
+
+ return &AppBskyFeedPostNote{
+ URI: record.URI,
+ AuthorDID: did,
+ AuthorHandle: "author_handle", // wip
+ CreatedAt: createdAt,
+ Text: record.Value.Text,
+ ReplyTo: &record.Value.Reply.Parent.URI,
+ }, nil
+}
diff --git a/backend/notes/note.go b/backend/notes/note.go
new file mode 100644
index 0000000..1d92948
--- /dev/null
+++ b/backend/notes/note.go
@@ -0,0 +1,13 @@
+package notes
+
+import (
+ "time"
+)
+
+type Note interface {
+ GetID() string
+ GetAuthorDID() string
+ GetAuthorHandle() string
+ GetTimestamp() time.Time
+ GetReplyTo() *string
+}