接入群成员与邀请实时同步
This commit is contained in:
1 parent
b2e04e8174
commit
5cae19a256
9 files changed
+175
-38
No files matched your search
@@ -64,11 +64,14 @@ func (a *API) realtime(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
inboxChannel := "xhchat:inbox:" + identity.Device.ID
|
||||
subscription := a.redis.Subscribe(r.Context(), "xhchat:contacts:"+identity.User.ID, inboxChannel)
|
||||
groupsChannel := "xhchat:groups:" + identity.User.ID
|
||||
subscription := a.redis.Subscribe(r.Context(), "xhchat:contacts:"+identity.User.ID, inboxChannel, groupsChannel)
|
||||
defer subscription.Close()
|
||||
if _, err = subscription.Receive(r.Context()); err != nil {
|
||||
unavailable(w, err)
|
||||
return
|
||||
for range 3 {
|
||||
if _, err = subscription.Receive(r.Context()); err != nil {
|
||||
unavailable(w, err)
|
||||
return
|
||||
}
|
||||
}
|
||||
changes := subscription.Channel()
|
||||
// The exact Origin was checked before consuming the ticket.
|
||||
@@ -101,7 +104,10 @@ func (a *API) realtime(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
writeCtx, cancel := context.WithTimeout(ctx, 5*time.Second)
|
||||
event := map[string]string{"type": "contacts_changed"}
|
||||
if change.Channel == inboxChannel {
|
||||
switch change.Channel {
|
||||
case groupsChannel:
|
||||
event["type"] = "group_list_changed"
|
||||
case inboxChannel:
|
||||
event["type"] = "inbox_changed"
|
||||
if group, found := strings.CutPrefix(change.Payload, "group:"); found && uuidPattern.MatchString(group) {
|
||||
event["type"] = "group_changed"
|
||||
|
||||
Reference in new issue
Block a user