diff --git a/lexicons/org/xcvr/notes.lex b/lexicons/org/xcvr/notes.lex index 581eed9..b033f46 100644 --- a/lexicons/org/xcvr/notes.lex +++ b/lexicons/org/xcvr/notes.lex @@ -103,7 +103,7 @@ org.xcvr image: def alt: string - blob: blob + blob?: blob aspectRatio?: aspectRatio aspectRatio: def @@ -112,7 +112,7 @@ org.xcvr video: def alt: string - blob: blob + blob?: blob # captions? messageView: def @@ -146,14 +146,13 @@ org.xcvr imageView: def alt: string - src: string + src?: string aspectRatio?: aspectRatio videoView: def alt: string - src: string + src?: string # captions? - signedMessageView: def uri: uri diff --git a/server/internal/model/channelLexiconStream.go b/server/internal/model/channelLexiconStream.go index d66ad94..4d7e22c 100644 --- a/server/internal/model/channelLexiconStream.go +++ b/server/internal/model/channelLexiconStream.go @@ -3,8 +3,11 @@ package model import ( "context" "errors" + "fmt" "net/http" + "os" "rvcx/internal/atputils" + "rvcx/internal/lex" "rvcx/internal/types" "time" @@ -132,3 +135,36 @@ func (m *Model) BroadcastMessage(uri string, msg *types.Message) error { cm.broadcast(mv) return nil } + +func (m *Model) BroadcastImage(uri string, media *types.Image) error { + cm := m.uriMap[uri] + if cm == nil { + return errors.New("failed to map uri to lsm!") + } + pv, err := m.store.GetProfileView(media.DID, context.Background()) + if err != nil { + return errors.New("failed to get profile view: " + err.Error()) + } + ar := lex.AspectRatio{ + Width: *media.Width, + Height: *media.Height, + } + src := fmt.Sprintf("%s/xrpc/org.xcvr.lrc.getImage?uri=%s", os.Getenv("MY_IDENTITY"), media.URI) + + img := types.ImageView{ + Alt: media.Alt, + Src: &src, + AspectRatio: &ar, + } + mv := types.MediaView{ + URI: media.URI, + Author: *pv, + Image: &img, + Nick: media.Nick, + Color: media.Color, + SignetURI: media.SignetURI, + PostedAt: media.PostedAt, + } + cm.broadcast(mv) + return nil +} diff --git a/server/internal/types/lexicons.go b/server/internal/types/lexicons.go index c3b7fac..e250139 100644 --- a/server/internal/types/lexicons.go +++ b/server/internal/types/lexicons.go @@ -227,6 +227,23 @@ type Image struct { IndexedAt time.Time } +type MediaView struct { + Type string `json:"$type,const=org.xcvr.lrc.defs#messageView"` + URI string `json:"uri"` + Author ProfileView `json:"author"` + Image *ImageView `json:"imageView,omitempty"` + Nick *string `json:"nick,omitempty"` + Color *uint32 `json:"color,omitempty"` + SignetURI string `json:"signetURI"` + PostedAt time.Time `json:"postedAt"` +} + +type ImageView struct { + Alt string `json:"alt"` + Src *string `json:"src,omitempty"` + AspectRatio *lex.AspectRatio `json:"AspectRatio,omitempty"` +} + type ParseMediaRequest struct { Nick *string `json:"nick,omitempty"` Color *uint32 `json:"color,omitempty"` @@ -234,3 +251,14 @@ type ParseMediaRequest struct { Image *lex.Image `json:"image,omitempty"` Type string `json:"type"` } + +func (m MediaView) MarshalJSON() ([]byte, error) { + type Alias MediaView + return json.Marshal(&struct { + Type string `json:"$type"` + *Alias + }{ + Type: "org.xcvr.lrc.defs#mediaView", + Alias: (*Alias)(&m), + }) +}