Accept numeric favorite sequence
This commit is contained in:
+11
-10
@@ -407,8 +407,8 @@ type imMessageRevisionRequest struct {
|
||||
|
||||
type imFavoritesBatchCreateRequest struct {
|
||||
Messages []struct {
|
||||
Topic string `json:"topic"`
|
||||
Seq int64 `json:"seq,string"`
|
||||
Topic string `json:"topic"`
|
||||
Seq imForwardSeq `json:"seq"`
|
||||
} `json:"messages"`
|
||||
}
|
||||
|
||||
@@ -3557,27 +3557,28 @@ func serveIMFavoriteBatchCreate(wrt http.ResponseWriter, req *http.Request) {
|
||||
failed := make([]map[string]any, 0)
|
||||
for _, src := range body.Messages {
|
||||
sourceTopic, sourceOK := normalizeIMFavoriteSourceTopic(principal.Uid, src.Topic)
|
||||
if !sourceOK || src.Seq <= 0 {
|
||||
failed = append(failed, map[string]any{"topic": src.Topic, "seq": src.Seq, "reason": imReasonMalformedRequest})
|
||||
seq := int64(src.Seq)
|
||||
if !sourceOK || seq <= 0 {
|
||||
failed = append(failed, map[string]any{"topic": src.Topic, "seq": seq, "reason": imReasonMalformedRequest})
|
||||
continue
|
||||
}
|
||||
if err := requireTopicReader(principal, sourceTopic); err != nil {
|
||||
failed = append(failed, map[string]any{"topic": sourceTopic, "seq": src.Seq, "reason": relationErrorReason(err)})
|
||||
failed = append(failed, map[string]any{"topic": sourceTopic, "seq": seq, "reason": relationErrorReason(err)})
|
||||
continue
|
||||
}
|
||||
msg, err := store.Messages.GetOne(principal.TenantID, sourceTopic, src.Seq)
|
||||
msg, err := store.Messages.GetOne(principal.TenantID, sourceTopic, seq)
|
||||
if err != nil {
|
||||
failed = append(failed, map[string]any{"topic": sourceTopic, "seq": src.Seq, "reason": relationErrorReason(err)})
|
||||
failed = append(failed, map[string]any{"topic": sourceTopic, "seq": seq, "reason": relationErrorReason(err)})
|
||||
continue
|
||||
}
|
||||
idempotencyKey := favoriteItemIdempotencyKey(req.Header.Get("Idempotency-Key"), sourceTopic, src.Seq)
|
||||
idempotencyKey := favoriteItemIdempotencyKey(req.Header.Get("Idempotency-Key"), sourceTopic, seq)
|
||||
fav := &types.FavoriteItem{
|
||||
TenantID: principal.TenantID,
|
||||
FavoriteID: "fav_" + store.Store.GetUidString(),
|
||||
UserID: principal.Uid,
|
||||
ItemType: imMessageType(msg),
|
||||
SourceTopic: sourceTopic,
|
||||
SourceSeq: src.Seq,
|
||||
SourceSeq: seq,
|
||||
Snapshot: favoriteSnapshot(msg),
|
||||
AttachmentRefs: favoriteAttachmentRefs(msg),
|
||||
Availability: messageAvailability(*msg),
|
||||
@@ -3588,7 +3589,7 @@ func serveIMFavoriteBatchCreate(wrt http.ResponseWriter, req *http.Request) {
|
||||
}
|
||||
item, err := store.Favorites.Create(principal.TenantID, fav)
|
||||
if err != nil {
|
||||
failed = append(failed, map[string]any{"topic": src.Topic, "seq": src.Seq, "reason": relationErrorReason(err)})
|
||||
failed = append(failed, map[string]any{"topic": src.Topic, "seq": seq, "reason": relationErrorReason(err)})
|
||||
continue
|
||||
}
|
||||
if item.FavoriteID == fav.FavoriteID {
|
||||
|
||||
Reference in New Issue
Block a user