mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-16 19:33:09 -06:00
fixed high cyclomatic complexity
This commit is contained in:
parent
112f6f5820
commit
848d928238
|
|
@ -99,78 +99,47 @@ func GetPushRule(
|
||||||
util.GetLogger(req.Context()).WithError(err).Error("Could not unmarshal pushrules data")
|
util.GetLogger(req.Context()).WithError(err).Error("Could not unmarshal pushrules data")
|
||||||
return jsonerror.InternalServerError()
|
return jsonerror.InternalServerError()
|
||||||
}
|
}
|
||||||
|
pushRule := PushRule{}
|
||||||
switch kind {
|
switch kind {
|
||||||
case "override":
|
case "override":
|
||||||
for _, pushRule := range pushRuleSet.Global.Override {
|
pushRule = getPushRulebyId(pushRuleSet.Global.Override, ruleID)
|
||||||
if pushRule.RuleId == ruleID {
|
|
||||||
return util.JSONResponse{
|
|
||||||
Code: http.StatusOK,
|
|
||||||
JSON: pushRule,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return util.JSONResponse{
|
|
||||||
Code: http.StatusNotFound,
|
|
||||||
JSON: jsonerror.NotFound("Not found"),
|
|
||||||
}
|
|
||||||
case "underride":
|
case "underride":
|
||||||
for _, pushRule := range pushRuleSet.Global.Underride {
|
pushRule = getPushRulebyId(pushRuleSet.Global.Underride, ruleID)
|
||||||
if pushRule.RuleId == ruleID {
|
|
||||||
return util.JSONResponse{
|
|
||||||
Code: http.StatusOK,
|
|
||||||
JSON: pushRule,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return util.JSONResponse{
|
|
||||||
Code: http.StatusNotFound,
|
|
||||||
JSON: jsonerror.NotFound("Not found"),
|
|
||||||
}
|
|
||||||
case "sender":
|
case "sender":
|
||||||
for _, pushRule := range pushRuleSet.Global.Sender {
|
pushRule = getPushRulebyId(pushRuleSet.Global.Sender, ruleID)
|
||||||
if pushRule.RuleId == ruleID {
|
|
||||||
return util.JSONResponse{
|
|
||||||
Code: http.StatusOK,
|
|
||||||
JSON: pushRule,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return util.JSONResponse{
|
|
||||||
Code: http.StatusNotFound,
|
|
||||||
JSON: jsonerror.NotFound("Not found"),
|
|
||||||
}
|
|
||||||
case "room":
|
case "room":
|
||||||
for _, pushRule := range pushRuleSet.Global.Room {
|
pushRule = getPushRulebyId(pushRuleSet.Global.Room, ruleID)
|
||||||
if pushRule.RuleId == ruleID {
|
|
||||||
return util.JSONResponse{
|
|
||||||
Code: http.StatusOK,
|
|
||||||
JSON: pushRule,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return util.JSONResponse{
|
|
||||||
Code: http.StatusNotFound,
|
|
||||||
JSON: jsonerror.NotFound("Not found"),
|
|
||||||
}
|
|
||||||
case "content":
|
case "content":
|
||||||
for _, pushRule := range pushRuleSet.Global.Content {
|
pushRule = getPushRulebyId(pushRuleSet.Global.Content, ruleID)
|
||||||
if pushRule.RuleId == ruleID {
|
|
||||||
return util.JSONResponse{
|
|
||||||
Code: http.StatusOK,
|
|
||||||
JSON: pushRule,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return util.JSONResponse{
|
|
||||||
Code: http.StatusNotFound,
|
|
||||||
JSON: jsonerror.NotFound("Not found"),
|
|
||||||
}
|
|
||||||
default:
|
default:
|
||||||
return util.JSONResponse{
|
return util.JSONResponse{
|
||||||
Code: http.StatusBadRequest,
|
Code: http.StatusBadRequest,
|
||||||
JSON: jsonerror.NotFound("Unrecognised request"),
|
JSON: jsonerror.NotFound("Unrecognised request"),
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if pushRule.RuleId == ruleID {
|
||||||
|
return util.JSONResponse{
|
||||||
|
Code: http.StatusOK,
|
||||||
|
JSON: pushRule,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return util.JSONResponse{
|
||||||
|
Code: http.StatusNotFound,
|
||||||
|
JSON: jsonerror.NotFound("Not found"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Returns a single push rule which matches given ruleID
|
||||||
|
func getPushRulebyId(pushRules []PushRule, ruleID string) PushRule {
|
||||||
|
for _, pushRule := range pushRules {
|
||||||
|
if pushRule.RuleId == ruleID {
|
||||||
|
return pushRule
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return PushRule{}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue