接入私聊消息通知和联系人免打扰
This commit is contained in:
1 parent
5c882ac855
commit
7e165ba9b4
23 files changed
+286
-97
No files matched your search
@@ -78,7 +78,7 @@ 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" {
|
||||
if input.Action != "preferences" && input.Action != "mute" && input.Action != "unmute" {
|
||||
pipe.Publish(r.Context(), "xhchat:contacts:"+strings.ToLower(target), "changed")
|
||||
}
|
||||
_, _ = pipe.Exec(r.Context())
|
||||
|
||||
@@ -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})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -109,12 +109,18 @@ func (a *API) realtime(w http.ResponseWriter, r *http.Request) {
|
||||
event["type"] = "group_list_changed"
|
||||
case inboxChannel:
|
||||
event["type"] = "inbox_changed"
|
||||
kind, group, _ := strings.Cut(change.Payload, ":")
|
||||
if (kind == "group" || kind == "group-notify") && uuidPattern.MatchString(group) {
|
||||
event["type"] = "group_changed"
|
||||
event["groupId"] = group
|
||||
if kind == "group-notify" {
|
||||
kind, id, _ := strings.Cut(change.Payload, ":")
|
||||
if uuidPattern.MatchString(id) {
|
||||
switch kind {
|
||||
case "private-notify":
|
||||
event["contactId"] = id
|
||||
event["notify"] = true
|
||||
case "group", "group-notify":
|
||||
event["type"] = "group_changed"
|
||||
event["groupId"] = id
|
||||
if kind == "group-notify" {
|
||||
event["notify"] = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user