接入群成员与邀请实时同步
This commit is contained in:
1 parent
b2e04e8174
commit
5cae19a256
9 files changed
+175
-38
No files matched your search
@@ -1,9 +1,11 @@
|
||||
package httpapi
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
"unicode"
|
||||
"unicode/utf8"
|
||||
|
||||
@@ -52,6 +54,7 @@ func (a *API) createGroup(w http.ResponseWriter, r *http.Request, _ string, id a
|
||||
groupError(w, err)
|
||||
return
|
||||
}
|
||||
a.hintGroupList(r.Context(), []string{id.User.ID})
|
||||
respond(w, 201, group)
|
||||
}
|
||||
|
||||
@@ -109,9 +112,25 @@ func (a *API) changeGroup(w http.ResponseWriter, r *http.Request, _ string, id a
|
||||
if !a.limit(w, r, "group-change:"+id.User.ID, 60) {
|
||||
return
|
||||
}
|
||||
if err := a.groups.Change(r.Context(), id.User.ID, group, change); err != nil {
|
||||
users, err := a.groups.Change(r.Context(), id.User.ID, group, change)
|
||||
if err != nil {
|
||||
groupError(w, err)
|
||||
return
|
||||
}
|
||||
a.hintGroupList(r.Context(), users)
|
||||
w.WriteHeader(204)
|
||||
}
|
||||
|
||||
func (a *API) hintGroupList(ctx context.Context, users []string) {
|
||||
ctx, cancel := context.WithTimeout(context.WithoutCancel(ctx), 250*time.Millisecond)
|
||||
defer cancel()
|
||||
pipe := a.redis.Pipeline()
|
||||
seen := make(map[string]bool, len(users))
|
||||
for _, user := range users {
|
||||
if !seen[user] {
|
||||
pipe.Publish(ctx, "xhchat:groups:"+user, "changed")
|
||||
seen[user] = true
|
||||
}
|
||||
}
|
||||
_, _ = pipe.Exec(ctx)
|
||||
}
|
||||
Reference in new issue
Block a user