From da7bc977a34609396bcd6d835c714d3499034fc1 Mon Sep 17 00:00:00 2001 From: Karmanyaah Malhotra Date: Mon, 1 Mar 2021 10:06:01 -0500 Subject: [PATCH] Add membership --- real_time.go | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/real_time.go b/real_time.go index f6d3ad6..f520c52 100644 --- a/real_time.go +++ b/real_time.go @@ -63,6 +63,9 @@ type HandlerText interface { type HandlerLike interface { HandleLike(Message) } +type HandlerMembership interface { + HandleJoin(ID) +} //PushSubscription manages real time subscription type PushSubscription struct { @@ -104,12 +107,12 @@ func (r *PushSubscription) StartListening(context context.Context) { contentType := data["type"].(string) switch contentType { - case "line.create": + case "line.create", "direct_message.create": b, _ := json.Marshal(content) out := Message{} json.Unmarshal(b, &out) - //fmt.Printf("%+v\n", out) //TODO + //fmt.Printf("%+v\n", out) //TODO logging for _, h := range r.handlers { if h, ok := h.(HandlerText); ok { h.HandleTextMessage(out) @@ -131,6 +134,17 @@ func (r *PushSubscription) StartListening(context context.Context) { 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 case "ping": break @@ -139,6 +153,8 @@ func (r *PushSubscription) StartListening(context context.Context) { break } log.Println(contentType) + b, _ := json.Marshal(content) + log.Println(string(b)) log.Fatalln(data) }