MCPcopy Create free account
hub / github.com/daodst/chat / findPushRuleInsertionIndex

Function findPushRuleInsertionIndex

clientapi/routing/pushrules.go:348–386  ·  view source on GitHub ↗
(rules []*pushrules.Rule, afterID, beforeID string)

Source from the content-addressed store, hash-verified

346}
347
348func findPushRuleInsertionIndex(rules []*pushrules.Rule, afterID, beforeID string) (int, error) {
349 var i int
350
351 if afterID != "" {
352 for ; i < len(rules); i++ {
353 if rules[i].RuleID == afterID {
354 break
355 }
356 }
357 if i == len(rules) {
358 return 0, jsonerror.NotFound("after: rule ID not found")
359 }
360 if rules[i].Default {
361 return 0, jsonerror.NotFound("after: rule ID must not be a default rule")
362 }
363 // We stopped on the "after" match to differentiate
364 // not-found from is-last-entry. Now we move to the earliest
365 // insertion point.
366 i++
367 }
368
369 if beforeID != "" {
370 for ; i < len(rules); i++ {
371 if rules[i].RuleID == beforeID {
372 break
373 }
374 }
375 if i == len(rules) {
376 return 0, jsonerror.NotFound("before: rule ID not found")
377 }
378 if rules[i].Default {
379 return 0, jsonerror.NotFound("before: rule ID must not be a default rule")
380 }
381 }
382
383 // UNSPEC: The spec does not say what to do if no after/before is
384 // given. Sytest fails if it doesn't go first.
385 return i, nil
386}

Callers 1

PutPushRuleByRuleIDFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected