接入私聊消息通知和联系人免打扰
This commit is contained in:
1 parent
5c882ac855
commit
7e165ba9b4
23 files changed
+286
-97
No files matched your search
@@ -15,6 +15,7 @@ func (a *API) sendEnvelope(w http.ResponseWriter, r *http.Request, _ string, ide
|
||||
MessageID string `json:"messageId"`
|
||||
RecipientDevice string `json:"recipientDevice"`
|
||||
Ciphertext []byte `json:"ciphertext"`
|
||||
Silent bool `json:"silent"`
|
||||
}
|
||||
if !parseLimit(w, r, &input, 96<<10) {
|
||||
return
|
||||
@@ -27,7 +28,8 @@ func (a *API) sendEnvelope(w http.ResponseWriter, r *http.Request, _ string, ide
|
||||
return
|
||||
}
|
||||
recipient := strings.ToLower(input.RecipientDevice)
|
||||
seq, err := a.delivery.Send(r.Context(), identity.Device.ID, recipient, input.MessageID, input.Ciphertext)
|
||||
seq, notify, err := a.delivery.Send(r.Context(), identity.Device.ID, recipient, input.MessageID, input.Ciphertext,
|
||||
input.Ciphertext[3] == 2 && !input.Silent)
|
||||
switch {
|
||||
case errors.Is(err, delivery.ErrUnavailable):
|
||||
problem(w, 404, "delivery_unavailable", "无法向指定设备投递")
|
||||
@@ -36,7 +38,11 @@ func (a *API) sendEnvelope(w http.ResponseWriter, r *http.Request, _ string, ide
|
||||
case err != nil:
|
||||
unavailable(w, err)
|
||||
default:
|
||||
_ = a.redis.Publish(r.Context(), "xhchat:inbox:"+recipient, "changed").Err()
|
||||
hint := "changed"
|
||||
if notify {
|
||||
hint = "private-notify:" + identity.User.ID
|
||||
}
|
||||
_ = a.redis.Publish(r.Context(), "xhchat:inbox:"+recipient, hint).Err()
|
||||
respond(w, 200, map[string]string{"sequence": seq})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user