From 2c35e9c30457247628b13057dd8d8be6e9b6d9a1 Mon Sep 17 00:00:00 2001 From: Iris Lightshard Date: Wed, 26 Jun 2024 21:13:44 -0600 Subject: [PATCH] change some models, make get ready to build some UI, etc --- adapter/mastodon.go | 18 ++++++------------ adapter/misskey.go | 33 ++++++++++++++++++++++----------- adapter/nostr.go | 4 +--- models/msg.go | 17 ++++++++++------- 4 files changed, 39 insertions(+), 33 deletions(-) diff --git a/adapter/mastodon.go b/adapter/mastodon.go index 12ff0cc..18106fe 100644 --- a/adapter/mastodon.go +++ b/adapter/mastodon.go @@ -105,18 +105,12 @@ func (self *MastoAdapter) mastoUpdateToMessage(status madon.Status) *Message { parent, _ = self.masto.GetStatus(*status.InReplyToID) } msg := Message{ - Protocol: "mastodon", - Content: status.Content, - Uri: status.URI, - Author: Author{ - Id: fmt.Sprintf("%d", status.Account.ID), - Name: status.Account.Username, - // TODO: we can add the fields to the profiledata as well - ProfileData: status.Account.Note, - ProfileUri: status.Account.URL, - ProfilePic: status.Account.Avatar, - }, - Created: status.CreatedAt, + Protocol: "mastodon", + Content: status.Content, + Uri: status.URI, + Author: status.Account.Acct, + Created: status.CreatedAt, + Visibility: status.Visibility, } if parent != nil { msg.ReplyTo = &parent.URI diff --git a/adapter/misskey.go b/adapter/misskey.go index efe9d41..e6f5bad 100644 --- a/adapter/misskey.go +++ b/adapter/misskey.go @@ -4,6 +4,7 @@ import ( "fmt" . "forge.lightcrystal.systems/lightcrystal/underbbs/models" "github.com/yitsushi/go-misskey" + mkcore "github.com/yitsushi/go-misskey/core" mkm "github.com/yitsushi/go-misskey/models" n "github.com/yitsushi/go-misskey/services/notes" tl "github.com/yitsushi/go-misskey/services/notes/timeline" @@ -175,17 +176,27 @@ func (self *MisskeyAdapter) cacheAndConvert(n mkm.Note) *Message { if !exists || timestamp.Before(n.CreatedAt) { self.cache[n.ID] = n.CreatedAt msg := Message{ - Uri: n.URI, - Author: Author{ - Id: n.User.ID, - Name: n.User.Name, - // ProfileUri: *n.User.URL, - ProfilePic: n.User.AvatarURL, - }, - Protocol: "misskey", - Adapter: self.nickname, - Created: n.CreatedAt, - Content: n.Text, + Uri: n.URI, + Author: fmt.Sprintf("%s@%s", n.User.Username, mkcore.StringValue(n.User.Host)), + Protocol: "misskey", + Adapter: self.nickname, + Created: n.CreatedAt, + Content: n.Text, + Attachments: []Attachment{}, + Visibility: n.Visibility, + ReplyTo: n.ReplyID, + ReplyCount: int(n.RepliesCount), + Replies: []string{}, + } + + for _, f := range n.Files { + msg.Attachments = append(msg.Attachments, Attachment{ + Src: f.URL, + ThumbSrc: f.ThumbnailURL, + Size: f.Size, + Desc: f.Comment, + CreatedAt: f.CreatedAt, + }) } return &msg } diff --git a/adapter/nostr.go b/adapter/nostr.go index 991a7f4..2185f22 100644 --- a/adapter/nostr.go +++ b/adapter/nostr.go @@ -98,9 +98,7 @@ func (self *NostrAdapter) nostrEventToMsg(evt *nostr.Event) (Message, error) { switch evt.Kind { case nostr.KindTextNote: m.Uri = evt.ID - m.Author = Author{ - Id: evt.PubKey, - } + m.Author = evt.PubKey m.Created = evt.CreatedAt.Time() m.Content = evt.Content return m, nil diff --git a/models/msg.go b/models/msg.go index 7169908..2c9cef2 100644 --- a/models/msg.go +++ b/models/msg.go @@ -7,15 +7,17 @@ import ( type Message struct { Uri string - Author Author + Author string Protocol string Adapter string Content string Attachments []Attachment ReplyTo *string - Replies []*string - Mentions []Author + Replies []string + ReplyCount int + Mentions []string Created time.Time + Visibility string Aux map[string]string } @@ -23,15 +25,16 @@ type Author struct { Id string Name string ProfileData interface{} - Messages []Message ProfileUri string ProfilePic string } type Attachment struct { - Src string - Data []uint8 - Desc string + Src string + ThumbSrc string + Desc string + CreatedAt time.Time + Size uint64 } type SocketData interface {