-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added user comment count support (#17)
- Loading branch information
Showing
10 changed files
with
333 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,7 @@ jobs: | |
- uses: actions/[email protected] | ||
- uses: actions/setup-go@v2 | ||
with: | ||
go-version: "^1.15.6" | ||
go-version: "^1.16.6" | ||
- uses: golangci/golangci-lint-action@v2 | ||
with: | ||
version: v1.35 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package counts | ||
|
||
// Comment is a Comment in Coral. | ||
type Comment struct { | ||
AuthorID string `bson:"authorID"` | ||
StoryID string `bson:"storyID"` | ||
Status string `bson:"status"` | ||
ActionCounts map[string]int `bson:"actionCounts"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,63 @@ | ||
package counts | ||
|
||
type CommentCounts struct { | ||
Action map[string]int `bson:"action"` | ||
Status struct { | ||
Approved int `bson:"APPROVED"` | ||
None int `bson:"NONE"` | ||
Premod int `bson:"PREMOD"` | ||
Rejected int `bson:"REJECTED"` | ||
SystemWithheld int `bson:"SYSTEM_WITHHELD"` | ||
} `bson:"status"` | ||
ModerationQueue struct { | ||
Total int `bson:"total"` | ||
Queues struct { | ||
Unmoderated int `bson:"unmoderated"` | ||
Reported int `bson:"reported"` | ||
Pending int `bson:"pending"` | ||
} `bson:"queues"` | ||
} `bson:"moderationQueue"` | ||
type CommentStatusCounts struct { | ||
Approved int `bson:"APPROVED"` | ||
None int `bson:"NONE"` | ||
Premod int `bson:"PREMOD"` | ||
Rejected int `bson:"REJECTED"` | ||
SystemWithheld int `bson:"SYSTEM_WITHHELD"` | ||
} | ||
|
||
func (csc *CommentStatusCounts) Increment(comment *Comment) { | ||
switch comment.Status { | ||
case "APPROVED": | ||
csc.Approved++ | ||
case "NONE": | ||
csc.None++ | ||
case "PREMOD": | ||
csc.Premod++ | ||
case "REJECTED": | ||
csc.Rejected++ | ||
case "SYSTEM_WITHHELD": | ||
csc.SystemWithheld++ | ||
} | ||
} | ||
|
||
type CommentModerationQueue struct { | ||
Total int `bson:"total"` | ||
Queues struct { | ||
Unmoderated int `bson:"unmoderated"` | ||
Reported int `bson:"reported"` | ||
Pending int `bson:"pending"` | ||
} `bson:"queues"` | ||
} | ||
|
||
func (cmq *CommentModerationQueue) Increment(comment *Comment) { | ||
switch comment.Status { | ||
case "NONE": | ||
cmq.Total++ | ||
cmq.Queues.Unmoderated++ | ||
|
||
// If this comment has a flag on it, then it should also be in the reported | ||
// queue. | ||
if count, ok := comment.ActionCounts["FLAG"]; ok && count > 0 { | ||
cmq.Queues.Reported++ | ||
} | ||
case "PREMOD": | ||
cmq.Total++ | ||
cmq.Queues.Unmoderated++ | ||
cmq.Queues.Pending++ | ||
case "SYSTEM_WITHHELD": | ||
cmq.Total++ | ||
cmq.Queues.Unmoderated++ | ||
cmq.Queues.Pending++ | ||
} | ||
} | ||
|
||
type CommentActionCounts map[string]int | ||
|
||
func (cac CommentActionCounts) Increment(comment *Comment) { | ||
for key, count := range comment.ActionCounts { | ||
cac[key] += count | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.