增加私聊置顶和按设备统计未读

This commit is contained in:
xhgit committed 2026-11-15 22:35:45 +08:00
1 parent 7e165ba9b4
commit ec2679b991
19 files changed
+312 -52

No files matched your search

+2
View File
@@ -52,6 +52,8 @@ func New(accounts *account.Store, contactStore *contacts.Store, envelopeStore *d
mux.HandleFunc("POST /api/v1/contacts/{id}", a.authorized(a.changeContact))
mux.HandleFunc("GET /api/v1/inbox", a.authorized(a.inbox))
mux.HandleFunc("POST /api/v1/inbox", a.authorized(a.sendEnvelope))
mux.HandleFunc("GET /api/v1/inbox/unread", a.authorized(a.privateUnread))
mux.HandleFunc("POST /api/v1/inbox/seen", a.authorized(a.markPrivateSeen))
mux.HandleFunc("GET /api/v1/contacts/{id}/devices", a.authorized(a.contactDevices))
mux.HandleFunc("POST /api/v1/contacts/{id}/devices/{device}/claim", a.authorized(a.claimPackage))
mux.HandleFunc("POST /api/v1/key-packages", a.authorized(a.publishPackage))
+3 -1
View File
@@ -78,7 +78,9 @@ func (a *API) changeContact(w http.ResponseWriter, r *http.Request, _ string, id
}
pipe := a.redis.Pipeline()
pipe.Publish(r.Context(), "xhchat:contacts:"+identity.User.ID, "changed")
if input.Action != "preferences" && input.Action != "mute" && input.Action != "unmute" {
switch input.Action {
case "preferences", "mute", "unmute", "pin", "unpin":
default:
pipe.Publish(r.Context(), "xhchat:contacts:"+strings.ToLower(target), "changed")
}
_, _ = pipe.Exec(r.Context())
+40
View File
@@ -74,3 +74,43 @@ func (a *API) inbox(w http.ResponseWriter, r *http.Request, _ string, identity a
}
respond(w, 200, items)
}
func (a *API) privateUnread(w http.ResponseWriter, r *http.Request, _ string, identity account.Identity) {
if !a.limit(w, r, "private-unread:"+identity.Device.ID, 180) {
return
}
counts, err := a.delivery.Unread(r.Context(), identity.Device.ID)
if err != nil {
unavailable(w, err)
return
}
respond(w, 200, counts)
}
func (a *API) markPrivateSeen(w http.ResponseWriter, r *http.Request, _ string, identity account.Identity) {
var input struct {
SenderDevice string `json:"senderDevice"`
Sequence string `json:"sequence"`
}
if !parse(w, r, &input) {
return
}
sequence, err := strconv.ParseInt(input.Sequence, 10, 64)
if !uuidPattern.MatchString(input.SenderDevice) || err != nil || sequence <= 0 || strconv.FormatInt(sequence, 10) != input.Sequence {
problem(w, 400, "invalid_cursor", "无效的设备或已查看游标")
return
}
if !a.limit(w, r, "private-seen:"+identity.Device.ID, 180) {
return
}
err = a.delivery.MarkSeen(r.Context(), identity.Device.ID, strings.ToLower(input.SenderDevice), sequence)
if errors.Is(err, delivery.ErrUnavailable) {
problem(w, 404, "delivery_unavailable", "找不到当前设备可见的投递记录")
return
}
if err != nil {
unavailable(w, err)
return
}
w.WriteHeader(204)
}