Skip to content

Commit eceb3ef

Browse files
committed
Give default upvote to comments
1 parent 2046080 commit eceb3ef

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

jsonstore/jsonstore.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,8 @@ func (app *JSONStoreApplication) DeliverTx(tx []byte) types.ResponseDeliverTx {
265265
comment.Content = entity["content"].(string)
266266
comment.Date = FindTimeFromObjectID(comment.ID.Hex())
267267
comment.PostID = bson.ObjectIdHex(entity["postId"].(string))
268+
comment.Upvotes = 1
269+
comment.Score = hotScore(comment.Upvotes, comment.Date)
268270

269271
if entity["parentCommentId"] != nil {
270272
comment.ParentCommentID = bson.ObjectIdHex(entity["parentCommentId"].(string))
@@ -291,6 +293,13 @@ func (app *JSONStoreApplication) DeliverTx(tx []byte) types.ResponseDeliverTx {
291293
panic(dbErr)
292294
}
293295

296+
// For recording default upvote
297+
var document UserCommentVote
298+
document.ID = bson.NewObjectId()
299+
document.UserID = user.ID
300+
document.CommentID = comment.ID
301+
302+
db.C("usercommentvotes").Insert(document)
294303
db.C("posts").Update(bson.M{"_id": comment.PostID}, bson.M{"$inc": bson.M{"numComments": 1}})
295304

296305
break

0 commit comments

Comments
 (0)