fix im p0 backend issues
This commit is contained in:
+13
-4
@@ -3570,6 +3570,7 @@ func serveIMFavoriteBatchCreate(wrt http.ResponseWriter, req *http.Request) {
|
||||
failed = append(failed, map[string]any{"topic": sourceTopic, "seq": src.Seq, "reason": relationErrorReason(err)})
|
||||
continue
|
||||
}
|
||||
idempotencyKey := favoriteItemIdempotencyKey(req.Header.Get("Idempotency-Key"), sourceTopic, src.Seq)
|
||||
fav := &types.FavoriteItem{
|
||||
TenantID: principal.TenantID,
|
||||
FavoriteID: "fav_" + store.Store.GetUidString(),
|
||||
@@ -3580,7 +3581,7 @@ func serveIMFavoriteBatchCreate(wrt http.ResponseWriter, req *http.Request) {
|
||||
Snapshot: favoriteSnapshot(msg),
|
||||
AttachmentRefs: favoriteAttachmentRefs(msg),
|
||||
Availability: messageAvailability(*msg),
|
||||
IdempotencyKey: strings.TrimSpace(req.Header.Get("Idempotency-Key")),
|
||||
IdempotencyKey: idempotencyKey,
|
||||
CollectedAt: now,
|
||||
CreatedAt: now,
|
||||
UpdatedAt: now,
|
||||
@@ -4021,13 +4022,13 @@ func serveIMMessageContext(wrt http.ResponseWriter, req *http.Request) {
|
||||
writeIMError(wrt, req, http.StatusNotFound, 30004, imReasonMalformedRequest, "message context route not found", nil)
|
||||
return
|
||||
}
|
||||
principal, _, ok := authenticateTopicReader(wrt, req, topic)
|
||||
principal, normalizedTopic, ok := authenticateTopicReader(wrt, req, topic)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
before := parseIMLimit(req.URL.Query().Get("before"), 20, 100)
|
||||
after := parseIMLimit(req.URL.Query().Get("after"), 20, 100)
|
||||
msgs, err := store.Messages.GetAll(principal.TenantID, topic, principal.Uid, &types.QueryOpt{Since: seq - int64(before), Before: seq + int64(after) + 1, Limit: before + after + 1})
|
||||
msgs, err := store.Messages.GetAll(principal.TenantID, normalizedTopic, principal.Uid, &types.QueryOpt{Since: seq - int64(before), Before: seq + int64(after) + 1, Limit: before + after + 1})
|
||||
if err != nil {
|
||||
writeIMRelationError(wrt, req, err)
|
||||
return
|
||||
@@ -4036,7 +4037,7 @@ func serveIMMessageContext(wrt http.ResponseWriter, req *http.Request) {
|
||||
for _, msg := range msgs {
|
||||
items = append(items, messageContextPayload(msg))
|
||||
}
|
||||
writeIMSuccess(wrt, req, map[string]any{"topic": topic, "anchor_seq": seq, "items": items})
|
||||
writeIMSuccess(wrt, req, map[string]any{"topic": normalizedTopic, "anchor_seq": seq, "items": items})
|
||||
}
|
||||
|
||||
func serveIMTopicMedia(wrt http.ResponseWriter, req *http.Request) {
|
||||
@@ -9353,6 +9354,14 @@ func normalizeIMFavoriteSourceTopic(viewer types.Uid, topic string) (string, boo
|
||||
return normalizeIMUserVisibleTopic(viewer, topic)
|
||||
}
|
||||
|
||||
func favoriteItemIdempotencyKey(requestKey, topic string, seq int64) string {
|
||||
requestKey = strings.TrimSpace(requestKey)
|
||||
if requestKey == "" {
|
||||
return ""
|
||||
}
|
||||
return stableIMEventID("favorite", requestKey, strings.TrimSpace(topic), seq)
|
||||
}
|
||||
|
||||
func normalizeIMUserVisibleTopic(viewer types.Uid, topic string) (string, bool) {
|
||||
topic = strings.TrimSpace(topic)
|
||||
if topic == "" {
|
||||
|
||||
Reference in New Issue
Block a user