Add membership
This commit is contained in:
parent
eeb2f88b97
commit
da7bc977a3
20
real_time.go
20
real_time.go
@ -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)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user