backend for xcvr appview
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

add addchannel, make posting channel redirect

rachel-mp4 affd2350 56b603ef

+49 -14
+4 -2
server/internal/db/db.go
··· 194 194 type URIHost struct { 195 195 URI string 196 196 Host string 197 + Topic string 197 198 LastID uint32 198 199 } 199 200 ··· 201 202 rows, err := s.pool.Query(ctx, ` 202 203 SELECT 203 204 channels.uri, 204 - channels.host 205 + channels.host, 206 + channels.topic, 205 207 FROM channels 206 208 `) 207 209 if err != nil { ··· 211 213 var urihosts = make([]URIHost, 0, 100) 212 214 for rows.Next() { 213 215 var urihost URIHost 214 - err := rows.Scan(&urihost.URI, &urihost.Host) 216 + err := rows.Scan(&urihost.URI, &urihost.Host, &urihost.Topic) 215 217 if err != nil { 216 218 return nil, err 217 219 }
+18 -11
server/internal/handler/lrcHandlers.go
··· 41 41 h.serverError(w, errors.New("couldn't find client: "+err.Error())) 42 42 return 43 43 } 44 - 45 44 lcr, now, err := h.parseChannelRequest(r) 46 45 if err != nil { 47 46 h.badRequest(w, err) ··· 62 61 CreatedAt: *now, 63 62 IndexedAt: time.Now(), 64 63 } 65 - err = h.db.StoreChannel(&channel, r.Context()) 66 - if err != nil { 67 - h.serverError(w, errors.New("well... the record posted but i couldn't store it: "+err.Error())) 68 - return 69 - } 70 - h.getChannels(w, r) 64 + h.postPostChannelPostHandler(&channel, w, r) 71 65 } 72 66 73 67 func (h *Handler) parseChannelRequest(r *http.Request) (*lex.ChannelRecord, *time.Time, error) { ··· 121 115 CreatedAt: *now, 122 116 IndexedAt: time.Now(), 123 117 } 124 - err = h.db.StoreChannel(&channel, r.Context()) 118 + h.postPostChannelPostHandler(&channel, w, r) 119 + } 120 + 121 + func (h *Handler) postPostChannelPostHandler(channel *types.Channel, w http.ResponseWriter, r *http.Request) { 122 + err := h.db.StoreChannel(channel, r.Context()) 123 + if err != nil { 124 + h.serverError(w, errors.New("well... the record posted but i couldn't store it: "+err.Error())) 125 + return 126 + } 127 + err = h.model.AddChannel(channel) 125 128 if err != nil { 126 - h.serverError(w, errors.New("sooo... the record posted but i couldn't store it: "+err.Error())) 129 + h.serverError(w, errors.New("very strange situation: "+err.Error())) 127 130 return 128 131 } 129 - h.getChannels(w, r) 130 - 132 + handle, err := h.db.ResolveDid(channel.DID, r.Context()) 133 + if err != nil { 134 + h.serverError(w, errors.New("couldn't find handle")) 135 + } 136 + rkey, _ := atputils.RkeyFromUri(channel.URI) 137 + http.Redirect(w, r, fmt.Sprintf("/c/%s/%s", handle, rkey), http.StatusCreated) 131 138 } 132 139 133 140 func (h *Handler) parseMessageRequest(r *http.Request) (lmr *lex.MessageRecord, now *time.Time, handle *string, nonce []byte, err error) {
+27 -1
server/internal/model/channel.go
··· 29 29 30 30 type channelModel struct { 31 31 uri string 32 + welcome string 32 33 serverModel *serverModel 33 34 streamModel *lexStreamModel 34 35 } ··· 99 100 for _, uri := range uris { 100 101 valid := (uri.Host == myid) 101 102 beep := channelModel{ 102 - uri: uri.URI, 103 + welcome: uri.Topic, 104 + uri: uri.URI, 103 105 } 104 106 if valid { 105 107 beep.serverModel = &serverModel{lastID: uri.LastID} ··· 115 117 } 116 118 } 117 119 120 + func (m *Model) AddChannel(c *types.Channel) error { 121 + _, ok := m.uriMap[c.URI] 122 + if ok { 123 + return errors.New("tried to add existing server!") 124 + } 125 + valid := (c.Host == os.Getenv("MY_IDENTITY")) 126 + var welcome string 127 + if c.Topic == nil { 128 + welcome = "and now you're connected" 129 + } else { 130 + welcome = *c.Topic 131 + } 132 + beep := channelModel{ 133 + welcome: welcome, 134 + uri: c.URI, 135 + } 136 + if valid { 137 + beep.serverModel = &serverModel{lastID: 1} 138 + } 139 + m.uriMap[c.URI] = &beep 140 + return nil 141 + } 142 + 118 143 func (m *Model) getServer(uri string) (*lrcd.Server, error) { 119 144 m.mu.Lock() 120 145 defer m.mu.Unlock() ··· 134 159 initChan := make(chan lrcpb.Event_Init, 100) 135 160 136 161 server, err := lrcd.NewServer( 162 + lrcd.WithWelcome(cm.welcome), 137 163 lrcd.WithLogging(os.Stdout, true), 138 164 lrcd.WithInitialID(lastID), 139 165 lrcd.WithInitChannel(initChan),