backend for xcvr appview

add broadcast image to channel lexicon stream

+68 -5
+4 -5
lexicons/org/xcvr/notes.lex
··· 103 103 104 104 image: def 105 105 alt: string 106 - blob: blob 106 + blob?: blob 107 107 aspectRatio?: aspectRatio 108 108 109 109 aspectRatio: def ··· 112 112 113 113 video: def 114 114 alt: string 115 - blob: blob 115 + blob?: blob 116 116 # captions? 117 117 118 118 messageView: def ··· 146 146 147 147 imageView: def 148 148 alt: string 149 - src: string 149 + src?: string 150 150 aspectRatio?: aspectRatio 151 151 152 152 videoView: def 153 153 alt: string 154 - src: string 154 + src?: string 155 155 # captions? 156 - 157 156 158 157 signedMessageView: def 159 158 uri: uri
+36
server/internal/model/channelLexiconStream.go
··· 3 3 import ( 4 4 "context" 5 5 "errors" 6 + "fmt" 6 7 "net/http" 8 + "os" 7 9 "rvcx/internal/atputils" 10 + "rvcx/internal/lex" 8 11 "rvcx/internal/types" 9 12 "time" 10 13 ··· 132 135 cm.broadcast(mv) 133 136 return nil 134 137 } 138 + 139 + func (m *Model) BroadcastImage(uri string, media *types.Image) error { 140 + cm := m.uriMap[uri] 141 + if cm == nil { 142 + return errors.New("failed to map uri to lsm!") 143 + } 144 + pv, err := m.store.GetProfileView(media.DID, context.Background()) 145 + if err != nil { 146 + return errors.New("failed to get profile view: " + err.Error()) 147 + } 148 + ar := lex.AspectRatio{ 149 + Width: *media.Width, 150 + Height: *media.Height, 151 + } 152 + src := fmt.Sprintf("%s/xrpc/org.xcvr.lrc.getImage?uri=%s", os.Getenv("MY_IDENTITY"), media.URI) 153 + 154 + img := types.ImageView{ 155 + Alt: media.Alt, 156 + Src: &src, 157 + AspectRatio: &ar, 158 + } 159 + mv := types.MediaView{ 160 + URI: media.URI, 161 + Author: *pv, 162 + Image: &img, 163 + Nick: media.Nick, 164 + Color: media.Color, 165 + SignetURI: media.SignetURI, 166 + PostedAt: media.PostedAt, 167 + } 168 + cm.broadcast(mv) 169 + return nil 170 + }
+28
server/internal/types/lexicons.go
··· 227 227 IndexedAt time.Time 228 228 } 229 229 230 + type MediaView struct { 231 + Type string `json:"$type,const=org.xcvr.lrc.defs#messageView"` 232 + URI string `json:"uri"` 233 + Author ProfileView `json:"author"` 234 + Image *ImageView `json:"imageView,omitempty"` 235 + Nick *string `json:"nick,omitempty"` 236 + Color *uint32 `json:"color,omitempty"` 237 + SignetURI string `json:"signetURI"` 238 + PostedAt time.Time `json:"postedAt"` 239 + } 240 + 241 + type ImageView struct { 242 + Alt string `json:"alt"` 243 + Src *string `json:"src,omitempty"` 244 + AspectRatio *lex.AspectRatio `json:"AspectRatio,omitempty"` 245 + } 246 + 230 247 type ParseMediaRequest struct { 231 248 Nick *string `json:"nick,omitempty"` 232 249 Color *uint32 `json:"color,omitempty"` ··· 234 251 Image *lex.Image `json:"image,omitempty"` 235 252 Type string `json:"type"` 236 253 } 254 + 255 + func (m MediaView) MarshalJSON() ([]byte, error) { 256 + type Alias MediaView 257 + return json.Marshal(&struct { 258 + Type string `json:"$type"` 259 + *Alias 260 + }{ 261 + Type: "org.xcvr.lrc.defs#mediaView", 262 + Alias: (*Alias)(&m), 263 + }) 264 + }