增加群聊置顶、免打扰和应用内提醒

This commit is contained in:
xhgit committed 2026-11-14 16:00:46 +08:00
1 parent ced6e9030d
commit f54077ce46
17 files changed
+228 -42

No files matched your search

+12 -7
View File
@@ -97,11 +97,11 @@ func (a *API) publishGroupEpoch(w http.ResponseWriter, r *http.Request, _ string
groupError(w, err)
return
}
devices := make([]string, 0, len(input.Devices))
devices := make([]groups.EpochDevice, 0, len(input.Devices))
for _, device := range input.Devices {
devices = append(devices, device.Device)
devices = append(devices, groups.EpochDevice{ID: device.Device})
}
a.hintGroup(r.Context(), id, devices)
a.hintGroup(r.Context(), id, devices, "", false)
w.WriteHeader(204)
}
@@ -129,21 +129,26 @@ func (a *API) sendGroupMessage(w http.ResponseWriter, r *http.Request, _ string,
return
}
message := groups.Message{ID: input.ID, Epoch: input.Epoch, Wire: input.Wire, AttachmentID: input.AttachmentID}
sequence, devices, err := a.groups.Send(r.Context(), id, actor.User.ID, actor.Device.ID, message)
sequence, devices, created, err := a.groups.Send(r.Context(), id, actor.User.ID, actor.Device.ID, message)
if err != nil {
groupError(w, err)
return
}
a.hintGroup(r.Context(), id, devices)
a.hintGroup(r.Context(), id, devices, actor.Device.ID, created)
respond(w, 200, map[string]string{"sequence": sequence})
}
func (a *API) hintGroup(ctx context.Context, group string, devices []string) {
func (a *API) hintGroup(ctx context.Context, group string, devices []groups.EpochDevice, sender string, newMessage bool) {
ctx, cancel := context.WithTimeout(context.WithoutCancel(ctx), 250*time.Millisecond)
defer cancel()
pipe := a.redis.Pipeline()
group = strings.ToLower(group)
for _, device := range devices {
pipe.Publish(ctx, "xhchat:inbox:"+device, "group:"+strings.ToLower(group))
prefix := "group:"
if newMessage && !device.Muted && sender != device.ID {
prefix = "group-notify:"
}
pipe.Publish(ctx, "xhchat:inbox:"+device.ID, prefix+group)
}
// Hints are best effort. The durable cursor is also polled by clients.
_, _ = pipe.Exec(ctx)