Skip to content

Commit

Permalink
added new reward for answer authors, closes #449
Browse files Browse the repository at this point in the history
  • Loading branch information
albogdano committed Apr 27, 2024
1 parent 8c93ac8 commit 9fd740d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/main/java/com/erudika/scoold/ScooldConfig.java
Expand Up @@ -24,11 +24,11 @@
import static com.erudika.scoold.ScooldServer.SIGNINLINK;
import static com.erudika.scoold.ScooldServer.SIGNOUTLINK;
import com.typesafe.config.ConfigObject;
import jakarta.inject.Named;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import jakarta.inject.Named;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
import org.springframework.stereotype.Component;
Expand Down Expand Up @@ -1882,6 +1882,16 @@ public int answerApprovedRewardVoter() {
return getConfigInt("answer_approve_reward_voter", 3);
}

@Documented(position = 1741,
identifier = "answer_create_reward_author",
value = "5",
type = Integer.class,
category = "Reputation and Rewards",
description = "Reputation points given to author who added an answer to a question (awarded once per question).")
public int answerCreatedRewardAuthor() {
return getConfigInt("answer_create_reward_author", 5);
}

@Documented(position = 1750,
identifier = "post_votedown_penalty_author",
value = "3",
Expand Down
Expand Up @@ -21,6 +21,7 @@
import com.erudika.para.core.Address;
import com.erudika.para.core.ParaObject;
import com.erudika.para.core.User;
import com.erudika.para.core.utils.Config;
import com.erudika.para.core.utils.Pager;
import com.erudika.para.core.utils.Para;
import com.erudika.para.core.utils.ParaObjectUtils;
Expand Down Expand Up @@ -231,6 +232,7 @@ public String reply(@PathVariable String id, @PathVariable(required = false) Str
answer.setCreatorid(authUser.getId());
answer.setParentid(showPost.getId());
answer.setSpace(showPost.getSpace());
addRepOnReplyOnce(showPost, authUser, false);
answer.create();

showPost.setAnswercount(showPost.getAnswercount() + 1);
Expand Down Expand Up @@ -276,6 +278,7 @@ public String modApprove(@PathVariable String id, HttpServletRequest req) {
//utils.sendNewPostNotifications(showPost, req);
} else if (showPost instanceof UnapprovedReply) {
showPost.setType(Utils.type(Reply.class));
addRepOnReplyOnce(pc.read(showPost.getParentid()), (Profile) pc.read(showPost.getCreatorid()), true);
pc.create(showPost);
}
utils.deleteReportsAfterModAction(showPost);
Expand Down Expand Up @@ -515,6 +518,13 @@ public List<Reply> getAllAnswers(Profile authUser, Post showPost, Pager itemcoun
}
answers.addAll(showPost.getAnswers(itemcount));
itemcount.setCount(itemcount.getCount() + p.getCount());
if (utils.postsNeedApproval(req) && authUser != null && !utils.isMod(authUser)) {
List<UnapprovedReply> uanswerslist = pc.findQuery(Utils.type(UnapprovedReply.class),
Config._PARENTID + ":\"" + showPost.getId() + "\" AND " +
Config._CREATORID + ":\"" + authUser.getId() + "\"");
itemcount.setCount(itemcount.getCount() + uanswerslist.size());
answers.addAll(uanswerslist);
}
return answers;
}

Expand Down Expand Up @@ -631,4 +641,13 @@ private void triggerQuestionViewEvent(Post question, HttpServletRequest req) {
utils.triggerHookEvent("question.view", payload);
}
}

private void addRepOnReplyOnce(Post parentPost, Profile author, boolean isModAction) {
if ((!CONF.postsNeedApproval() || isModAction) && CONF.answerCreatedRewardAuthor() > 0 &&
!parentPost.getCreatorid().equals(author.getId()) && pc.getCount(Utils.type(Reply.class),
Map.of(Config._PARENTID, parentPost.getId(), Config._CREATORID, author.getId())) == 0) {
author.addRep(CONF.answerCreatedRewardAuthor());
pc.update(author);
}
}
}

0 comments on commit 9fd740d

Please sign in to comment.