added more conditions
This commit is contained in:
parent
c5d6c8a29c
commit
b6715c2375
@ -69,7 +69,7 @@ func (h Handler) HandleError(e error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (h Handler) HandleTextMessage(msg groupme.Message) {
|
func (h Handler) HandleTextMessage(msg groupme.Message) {
|
||||||
fmt.Println(msg.Text, msg.Name)
|
fmt.Println(msg.Text, msg.Name, msg.Attachments)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h Handler) HandleJoin(group groupme.ID) {
|
func (h Handler) HandleJoin(group groupme.ID) {
|
||||||
@ -113,3 +113,12 @@ func (h Handler) HandleNewAvatarInGroup(group groupme.ID, user groupme.ID, avata
|
|||||||
}
|
}
|
||||||
fmt.Printf("In group %s, user %s has new avatar with url %s\n", group.String(), user.String(), avatarURL)
|
fmt.Printf("In group %s, user %s has new avatar with url %s\n", group.String(), user.String(), avatarURL)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (h Handler) HandleMembers(group groupme.ID, members []groupme.Member, added bool) {
|
||||||
|
action := "removed"
|
||||||
|
if added {
|
||||||
|
action = "added"
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Printf("In group %s, users %v %s\n", group.String(), members, action)
|
||||||
|
}
|
||||||
|
2
go.mod
2
go.mod
@ -7,6 +7,6 @@ go 1.15
|
|||||||
require (
|
require (
|
||||||
github.com/google/uuid v1.2.0
|
github.com/google/uuid v1.2.0
|
||||||
github.com/gorilla/mux v1.8.0
|
github.com/gorilla/mux v1.8.0
|
||||||
github.com/karmanyaahm/wray v0.0.0-20160519030252-f36984f6648c
|
github.com/karmanyaahm/wray v0.0.0-20210303233435-756d58657c14
|
||||||
github.com/stretchr/testify v1.7.0
|
github.com/stretchr/testify v1.7.0
|
||||||
)
|
)
|
||||||
|
4
go.sum
4
go.sum
@ -9,6 +9,10 @@ github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI=
|
|||||||
github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
|
github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
|
||||||
github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo=
|
github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo=
|
||||||
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
|
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
|
||||||
|
github.com/karmanyaahm/wray v0.0.0-20160519030252-f36984f6648c h1:K6LcMJIgTvSTgi77TUeD7qx7Vq5lEYRKTYSTp5WPMH4=
|
||||||
|
github.com/karmanyaahm/wray v0.0.0-20160519030252-f36984f6648c/go.mod h1:LqTl7/Bd5gKDCT0UI3kbfgjCcr1caZHsNk0PZ7bZid8=
|
||||||
|
github.com/karmanyaahm/wray v0.0.0-20210303233435-756d58657c14 h1:NrATjZKvkY+ojL8FXTWa3fQ+wihFrAxLNE6T+wOkIcY=
|
||||||
|
github.com/karmanyaahm/wray v0.0.0-20210303233435-756d58657c14/go.mod h1:ysD86MIEevmAkdfdg5s6Qt3I07RN6fvMAyna7jCGG2o=
|
||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM=
|
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM=
|
||||||
|
53
real_time.go
53
real_time.go
@ -77,6 +77,9 @@ type HandleGroupMetadata interface {
|
|||||||
type HandleGroupMembership interface {
|
type HandleGroupMembership interface {
|
||||||
HandleNewNickname(group ID, user ID, newName string)
|
HandleNewNickname(group ID, user ID, newName string)
|
||||||
HandleNewAvatarInGroup(group ID, user ID, avatarURL string)
|
HandleNewAvatarInGroup(group ID, user ID, avatarURL string)
|
||||||
|
|
||||||
|
//HandleNewMembers returns only partial member with id and nickname; added is false if removing
|
||||||
|
HandleMembers(group ID, members []Member, added bool)
|
||||||
}
|
}
|
||||||
|
|
||||||
//PushSubscription manages real time subscription
|
//PushSubscription manages real time subscription
|
||||||
@ -133,7 +136,10 @@ func (r *PushSubscription) StartListening(context context.Context) {
|
|||||||
channel := msg.Channel()
|
channel := msg.Channel()
|
||||||
|
|
||||||
if strings.HasPrefix(channel, groupChannel) || strings.HasPrefix(channel, dmChannel) {
|
if strings.HasPrefix(channel, groupChannel) || strings.HasPrefix(channel, dmChannel) {
|
||||||
r.chatEvent(contentType, content)
|
c := content.(map[string]interface{})["line"]
|
||||||
|
d, _ := json.Marshal(c)
|
||||||
|
r.chatEvent(contentType, d)
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
switch contentType {
|
switch contentType {
|
||||||
@ -190,25 +196,19 @@ func (r *PushSubscription) StartListening(context context.Context) {
|
|||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *PushSubscription) chatEvent(contentType string, content interface{}) {
|
func (r *PushSubscription) chatEvent(contentType string, b []byte) {
|
||||||
switch contentType {
|
switch contentType {
|
||||||
case "favorite":
|
case "favorite":
|
||||||
b, ok := content.(map[string]interface{})["line"].(Message)
|
data := Message{}
|
||||||
|
_ = json.Unmarshal(b, &data)
|
||||||
if !ok {
|
|
||||||
log.Println(content)
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, h := range r.handlers {
|
for _, h := range r.handlers {
|
||||||
if h, ok := h.(HandlerLike); ok {
|
if h, ok := h.(HandlerLike); ok {
|
||||||
h.HandleLike(b.UserID, b.FavoritedBy)
|
h.HandleLike(data.ID, data.FavoritedBy)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
default: //TODO: see if any other types are returned
|
default: //TODO: see if any other types are returned
|
||||||
println("HEHE")
|
|
||||||
log.Println(contentType)
|
log.Println(contentType)
|
||||||
b, _ := json.Marshal(content)
|
|
||||||
log.Fatalln(string(b))
|
log.Fatalln(string(b))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -248,6 +248,31 @@ func (r *PushSubscription) systemEvent(groupID ID, msg systemMessage) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
|
case "membership.announce.added":
|
||||||
|
data := struct {
|
||||||
|
Added []Member `json:"added_users"`
|
||||||
|
}{}
|
||||||
|
_ = json.Unmarshal(b, &data)
|
||||||
|
for _, h := range r.handlers {
|
||||||
|
if h, ok := h.(HandleGroupMembership); ok {
|
||||||
|
h.HandleMembers(groupID, data.Added, true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break
|
||||||
|
case "membership.notifications.removed":
|
||||||
|
data := struct {
|
||||||
|
Added Member `json:"removed_user"`
|
||||||
|
}{}
|
||||||
|
_ = json.Unmarshal(b, &data)
|
||||||
|
for _, h := range r.handlers {
|
||||||
|
if h, ok := h.(HandleGroupMembership); ok {
|
||||||
|
h.HandleMembers(groupID, []Member{data.Added}, false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break
|
||||||
|
case "group.role_change_admin":
|
||||||
|
//TODO
|
||||||
|
break
|
||||||
case "group.name_change":
|
case "group.name_change":
|
||||||
data := struct {
|
data := struct {
|
||||||
Name string
|
Name string
|
||||||
@ -307,6 +332,12 @@ func (r *PushSubscription) systemEvent(groupID ID, msg systemMessage) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
|
case "group.type_change", "group.required_approval_enabled", "group.required_approval_disabled":
|
||||||
|
//TODO: group joining
|
||||||
|
break
|
||||||
|
case "group.shared", "group.unshared":
|
||||||
|
//TODO
|
||||||
|
break
|
||||||
default:
|
default:
|
||||||
log.Println(kind)
|
log.Println(kind)
|
||||||
log.Fatalln(string(b))
|
log.Fatalln(string(b))
|
||||||
|
Loading…
Reference in New Issue
Block a user