Add membership

This commit is contained in:
Karmanyaah Malhotra 2021-03-01 10:06:01 -05:00
parent eeb2f88b97
commit da7bc977a3

View File

@ -63,6 +63,9 @@ type HandlerText interface {
type HandlerLike interface { type HandlerLike interface {
HandleLike(Message) HandleLike(Message)
} }
type HandlerMembership interface {
HandleJoin(ID)
}
//PushSubscription manages real time subscription //PushSubscription manages real time subscription
type PushSubscription struct { type PushSubscription struct {
@ -104,12 +107,12 @@ func (r *PushSubscription) StartListening(context context.Context) {
contentType := data["type"].(string) contentType := data["type"].(string)
switch contentType { switch contentType {
case "line.create": case "line.create", "direct_message.create":
b, _ := json.Marshal(content) b, _ := json.Marshal(content)
out := Message{} out := Message{}
json.Unmarshal(b, &out) json.Unmarshal(b, &out)
//fmt.Printf("%+v\n", out) //TODO //fmt.Printf("%+v\n", out) //TODO logging
for _, h := range r.handlers { for _, h := range r.handlers {
if h, ok := h.(HandlerText); ok { if h, ok := h.(HandlerText); ok {
h.HandleTextMessage(out) h.HandleTextMessage(out)
@ -131,6 +134,17 @@ func (r *PushSubscription) StartListening(context context.Context) {
h.HandleLike(out) h.HandleLike(out)
} }
} }
break
case "membership.create":
c, _ := content.(map[string]interface{})
id, _ := c["id"].(string)
for _, h := range r.handlers {
if h, ok := h.(HandlerMembership); ok {
h.HandleJoin(ID(id))
}
}
break break
case "ping": case "ping":
break break
@ -139,6 +153,8 @@ func (r *PushSubscription) StartListening(context context.Context) {
break break
} }
log.Println(contentType) log.Println(contentType)
b, _ := json.Marshal(content)
log.Println(string(b))
log.Fatalln(data) log.Fatalln(data)
} }