fix notes v2

This commit is contained in:
Asim Aslam
2021-11-01 15:43:05 +00:00
parent 7eb9bdca87
commit 30a4639ceb

View File

@@ -2,6 +2,7 @@ package handler
import ( import (
"context" "context"
"encoding/json"
"fmt" "fmt"
"time" "time"
@@ -28,8 +29,10 @@ type Notes struct {
} }
func newMessage(ev map[string]interface{}) *structpb.Struct { func newMessage(ev map[string]interface{}) *structpb.Struct {
v, _ := structpb.NewStruct(ev) st := new(structpb.Struct)
return v b, _ := json.Marshal(ev)
json.Unmarshal(b, st)
return st
} }
// Create inserts a new note in the store // Create inserts a new note in the store
@@ -190,7 +193,14 @@ func (h *Notes) Subscribe(ctx context.Context, req *pb.SubscribeRequest, stream
} }
ev := msg.Message.AsMap() ev := msg.Message.AsMap()
note := ev["note"].(*pb.Note) if ev == nil {
continue
}
note, ok := ev["note"].(*pb.Note)
if !ok {
continue
}
// filter if necessary by id // filter if necessary by id
if len(req.Id) > 0 && note.Id != req.Id { if len(req.Id) > 0 && note.Id != req.Id {