Skip to content

Commit 7019ad2

Browse files
committed
Fix: 修复回复某一个评论时链接错误Bug
1 parent ece21b6 commit 7019ad2

File tree

4 files changed

+142
-122
lines changed

4 files changed

+142
-122
lines changed

upupor-service/src/main/java/com/upupor/service/business/replay/ContentReply.java

Lines changed: 40 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,30 @@
11
/*
2-
* MIT License
3-
*
4-
* Copyright (c) 2021-2022 yangrunkang
5-
*
6-
* Author: yangrunkang
7-
* Email: yangrunkang53@gmail.com
8-
*
9-
* Permission is hereby granted, free of charge, to any person obtaining a copy
10-
* of this software and associated documentation files (the "Software"), to deal
11-
* in the Software without restriction, including without limitation the rights
12-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13-
* copies of the Software, and to permit persons to whom the Software is
14-
* furnished to do so, subject to the following conditions:
15-
*
16-
* The above copyright notice and this permission notice shall be included in all
17-
* copies or substantial portions of the Software.
18-
*
19-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25-
* SOFTWARE.
2+
* <!--
3+
* ~ MIT License
4+
* ~
5+
* ~ Copyright (c) 2021-2022 yangrunkang
6+
* ~
7+
* ~ Author: yangrunkang
8+
* ~ Email: yangrunkang53@gmail.com
9+
* ~
10+
* ~ Permission is hereby granted, free of charge, to any person obtaining a copy
11+
* ~ of this software and associated documentation files (the "Software"), to deal
12+
* ~ in the Software without restriction, including without limitation the rights
13+
* ~ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14+
* ~ copies of the Software, and to permit persons to whom the Software is
15+
* ~ furnished to do so, subject to the following conditions:
16+
* ~
17+
* ~ The above copyright notice and this permission notice shall be included in all
18+
* ~ copies or substantial portions of the Software.
19+
* ~
20+
* ~ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21+
* ~ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22+
* ~ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23+
* ~ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24+
* ~ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25+
* ~ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26+
* ~ SOFTWARE.
27+
* -->
2628
*/
2729

2830
package com.upupor.service.business.replay;
@@ -36,13 +38,13 @@
3638
import com.upupor.service.listener.event.ReplayCommentEvent;
3739
import com.upupor.service.types.ContentType;
3840
import com.upupor.service.types.MessageType;
41+
import org.jetbrains.annotations.NotNull;
3942
import org.springframework.stereotype.Component;
4043

4144
import javax.annotation.Resource;
4245
import java.util.Objects;
4346

44-
import static com.upupor.framework.CcConstant.MsgTemplate.CONTENT_INNER_MSG;
45-
import static com.upupor.framework.CcConstant.MsgTemplate.PROFILE_INNER_MSG;
47+
import static com.upupor.framework.CcConstant.MsgTemplate.*;
4648

4749
/**
4850
* @author Yang Runkang (cruise)
@@ -75,15 +77,21 @@ public void reply(ReplayCommentEvent replayCommentEvent) {
7577
Content content = getTarget(replayCommentEvent.getTargetId());
7678

7779
// 评论回复站内信
78-
String msg = "您关于《" + String.format(CONTENT_INNER_MSG, content.getContentId(), msgId, content.getTitle())
79-
+ "》的文章评论,收到了来自"
80-
+ String.format(PROFILE_INNER_MSG, createReplayUserId, msgId, createReplayUserName)
81-
+ "的回复,请" + String.format(CONTENT_INNER_MSG, content.getContentId(), msgId, "点击查看");
80+
String innerMsg = buildByTemplate(msgId, createReplayUserId, createReplayUserName, content, CONTENT_INNER_MSG);
81+
String emailMsg = buildByTemplate(msgId, createReplayUserId, createReplayUserName, content, CONTENT_EMAIL);
8282

8383
// 站内信通知
84-
getMessageService().addMessage(beRepliedUserId, msg, MessageType.USER_REPLAY, msgId);
84+
getMessageService().addMessage(beRepliedUserId, innerMsg, MessageType.USER_REPLAY, msgId);
8585
// 邮件通知
86-
getMessageService().sendEmail(beRepliedMember.getEmail(), title(), msg, beRepliedUserId);
86+
getMessageService().sendEmail(beRepliedMember.getEmail(), title(), emailMsg, beRepliedUserId);
87+
}
88+
89+
@NotNull
90+
private String buildByTemplate(String msgId, String createReplayUserId, String createReplayUserName, Content content, String template) {
91+
return "您关于《" + String.format(template, content.getContentId(), msgId, content.getTitle())
92+
+ "》的文章评论,收到了来自"
93+
+ String.format(PROFILE_INNER_MSG, createReplayUserId, msgId, createReplayUserName)
94+
+ "的回复,请" + String.format(template, content.getContentId(), msgId, "点击查看");
8795
}
8896

8997
@Override

upupor-service/src/main/java/com/upupor/service/business/replay/MessageBoardReply.java

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,30 @@
11
/*
2-
* MIT License
3-
*
4-
* Copyright (c) 2021-2022 yangrunkang
5-
*
6-
* Author: yangrunkang
7-
* Email: yangrunkang53@gmail.com
8-
*
9-
* Permission is hereby granted, free of charge, to any person obtaining a copy
10-
* of this software and associated documentation files (the "Software"), to deal
11-
* in the Software without restriction, including without limitation the rights
12-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13-
* copies of the Software, and to permit persons to whom the Software is
14-
* furnished to do so, subject to the following conditions:
15-
*
16-
* The above copyright notice and this permission notice shall be included in all
17-
* copies or substantial portions of the Software.
18-
*
19-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25-
* SOFTWARE.
2+
* <!--
3+
* ~ MIT License
4+
* ~
5+
* ~ Copyright (c) 2021-2022 yangrunkang
6+
* ~
7+
* ~ Author: yangrunkang
8+
* ~ Email: yangrunkang53@gmail.com
9+
* ~
10+
* ~ Permission is hereby granted, free of charge, to any person obtaining a copy
11+
* ~ of this software and associated documentation files (the "Software"), to deal
12+
* ~ in the Software without restriction, including without limitation the rights
13+
* ~ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14+
* ~ copies of the Software, and to permit persons to whom the Software is
15+
* ~ furnished to do so, subject to the following conditions:
16+
* ~
17+
* ~ The above copyright notice and this permission notice shall be included in all
18+
* ~ copies or substantial portions of the Software.
19+
* ~
20+
* ~ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21+
* ~ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22+
* ~ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23+
* ~ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24+
* ~ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25+
* ~ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26+
* ~ SOFTWARE.
27+
* -->
2628
*/
2729

2830
package com.upupor.service.business.replay;
@@ -62,13 +64,13 @@ public void reply(ReplayCommentEvent replayCommentEvent) {
6264
Member beReplayedUser = getMember(replayCommentEvent.getBeRepliedUserId());
6365
String msgId = msgId();
6466

65-
String msg = buildMsgByTemplate(replayCommentEvent, msgId, MESSAGE_INTEGRAL);
66-
String email = buildMsgByTemplate(replayCommentEvent, msgId, MESSAGE_EMAIL);
67+
String innerMsg = buildMsgByTemplate(replayCommentEvent, msgId, MESSAGE_INTEGRAL);
68+
String emailMsg = buildMsgByTemplate(replayCommentEvent, msgId, MESSAGE_EMAIL);
6769
// 站内信通知
68-
getMessageService().addMessage(beReplayedUser.getUserId(), msg, MessageType.USER_REPLAY, msgId);
70+
getMessageService().addMessage(beReplayedUser.getUserId(), innerMsg, MessageType.USER_REPLAY, msgId);
6971
// 邮件通知
7072
String title = "留言板有新的回复消息";
71-
getMessageService().sendEmail(beReplayedUser.getEmail(), title, email, beReplayedUser.getUserId());
73+
getMessageService().sendEmail(beReplayedUser.getEmail(), title, emailMsg, beReplayedUser.getUserId());
7274
}
7375

7476
@NotNull

upupor-service/src/main/java/com/upupor/service/business/replay/RadioReply.java

Lines changed: 40 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,30 @@
11
/*
2-
* MIT License
3-
*
4-
* Copyright (c) 2021-2022 yangrunkang
5-
*
6-
* Author: yangrunkang
7-
* Email: yangrunkang53@gmail.com
8-
*
9-
* Permission is hereby granted, free of charge, to any person obtaining a copy
10-
* of this software and associated documentation files (the "Software"), to deal
11-
* in the Software without restriction, including without limitation the rights
12-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13-
* copies of the Software, and to permit persons to whom the Software is
14-
* furnished to do so, subject to the following conditions:
15-
*
16-
* The above copyright notice and this permission notice shall be included in all
17-
* copies or substantial portions of the Software.
18-
*
19-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25-
* SOFTWARE.
2+
* <!--
3+
* ~ MIT License
4+
* ~
5+
* ~ Copyright (c) 2021-2022 yangrunkang
6+
* ~
7+
* ~ Author: yangrunkang
8+
* ~ Email: yangrunkang53@gmail.com
9+
* ~
10+
* ~ Permission is hereby granted, free of charge, to any person obtaining a copy
11+
* ~ of this software and associated documentation files (the "Software"), to deal
12+
* ~ in the Software without restriction, including without limitation the rights
13+
* ~ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14+
* ~ copies of the Software, and to permit persons to whom the Software is
15+
* ~ furnished to do so, subject to the following conditions:
16+
* ~
17+
* ~ The above copyright notice and this permission notice shall be included in all
18+
* ~ copies or substantial portions of the Software.
19+
* ~
20+
* ~ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21+
* ~ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22+
* ~ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23+
* ~ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24+
* ~ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25+
* ~ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26+
* ~ SOFTWARE.
27+
* -->
2628
*/
2729

2830
package com.upupor.service.business.replay;
@@ -36,13 +38,13 @@
3638
import com.upupor.service.listener.event.ReplayCommentEvent;
3739
import com.upupor.service.types.ContentType;
3840
import com.upupor.service.types.MessageType;
41+
import org.jetbrains.annotations.NotNull;
3942
import org.springframework.stereotype.Component;
4043

4144
import javax.annotation.Resource;
4245
import java.util.Objects;
4346

44-
import static com.upupor.framework.CcConstant.MsgTemplate.PROFILE_INNER_MSG;
45-
import static com.upupor.framework.CcConstant.MsgTemplate.RADIO_INNER_MSG;
47+
import static com.upupor.framework.CcConstant.MsgTemplate.*;
4648

4749
/**
4850
* @author Yang Runkang (cruise)
@@ -72,16 +74,22 @@ public void reply(ReplayCommentEvent replayCommentEvent) {
7274
Member beReplayedUser = getMember(beRepliedUserId);
7375

7476
Radio radio = getTarget(replayCommentEvent.getTargetId());
75-
String msg = "电台《" + String.format(RADIO_INNER_MSG, radio.getRadioId(), msgId, radio.getRadioIntro())
76-
+ "》,收到了来自"
77-
+ String.format(PROFILE_INNER_MSG, creatorReplayUserId, msgId, creatorReplayUserName)
78-
+ "的回复,请" + String.format(RADIO_INNER_MSG, radio.getRadioId(), msgId, "点击查看");
77+
String innerMsg = buildByTemplate(creatorReplayUserId, creatorReplayUserName, msgId, radio, RADIO_INNER_MSG);
78+
String emailMsg = buildByTemplate(creatorReplayUserId, creatorReplayUserName, msgId, radio, RADIO_EMAIL);
7979

8080

8181
// 站内信通知
82-
getMessageService().addMessage(beRepliedUserId, msg, MessageType.USER_REPLAY, msgId);
82+
getMessageService().addMessage(beRepliedUserId, innerMsg, MessageType.USER_REPLAY, msgId);
8383
// 邮件通知
84-
getMessageService().sendEmail(beReplayedUser.getEmail(), title(), msg, beRepliedUserId);
84+
getMessageService().sendEmail(beReplayedUser.getEmail(), title(), emailMsg, beRepliedUserId);
85+
}
86+
87+
@NotNull
88+
private String buildByTemplate(String creatorReplayUserId, String creatorReplayUserName, String msgId, Radio radio, String template) {
89+
return "电台《" + String.format(template, radio.getRadioId(), msgId, radio.getRadioIntro())
90+
+ "》,收到了来自"
91+
+ String.format(PROFILE_INNER_MSG, creatorReplayUserId, msgId, creatorReplayUserName)
92+
+ "的回复,请" + String.format(template, radio.getRadioId(), msgId, "点击查看");
8593
}
8694

8795
@Override

upupor-web/src/main/java/com/upupor/web/controller/CommentsController.java renamed to upupor-web/src/main/java/com/upupor/web/controller/CommentController.java

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,44 @@
11
/*
2-
* MIT License
3-
*
4-
* Copyright (c) 2021-2022 yangrunkang
5-
*
6-
* Author: yangrunkang
7-
* Email: yangrunkang53@gmail.com
8-
*
9-
* Permission is hereby granted, free of charge, to any person obtaining a copy
10-
* of this software and associated documentation files (the "Software"), to deal
11-
* in the Software without restriction, including without limitation the rights
12-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13-
* copies of the Software, and to permit persons to whom the Software is
14-
* furnished to do so, subject to the following conditions:
15-
*
16-
* The above copyright notice and this permission notice shall be included in all
17-
* copies or substantial portions of the Software.
18-
*
19-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25-
* SOFTWARE.
2+
* <!--
3+
* ~ MIT License
4+
* ~
5+
* ~ Copyright (c) 2021-2022 yangrunkang
6+
* ~
7+
* ~ Author: yangrunkang
8+
* ~ Email: yangrunkang53@gmail.com
9+
* ~
10+
* ~ Permission is hereby granted, free of charge, to any person obtaining a copy
11+
* ~ of this software and associated documentation files (the "Software"), to deal
12+
* ~ in the Software without restriction, including without limitation the rights
13+
* ~ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14+
* ~ copies of the Software, and to permit persons to whom the Software is
15+
* ~ furnished to do so, subject to the following conditions:
16+
* ~
17+
* ~ The above copyright notice and this permission notice shall be included in all
18+
* ~ copies or substantial portions of the Software.
19+
* ~
20+
* ~ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21+
* ~ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22+
* ~ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23+
* ~ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24+
* ~ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25+
* ~ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26+
* ~ SOFTWARE.
27+
* -->
2628
*/
2729

2830
package com.upupor.web.controller;
2931

32+
import com.upupor.framework.BusinessException;
33+
import com.upupor.framework.CcConstant;
34+
import com.upupor.framework.CcResponse;
35+
import com.upupor.framework.ErrorCode;
3036
import com.upupor.security.limiter.LimitType;
3137
import com.upupor.security.limiter.UpuporLimit;
32-
import com.upupor.framework.CcConstant;
3338
import com.upupor.service.data.dao.entity.Comment;
3439
import com.upupor.service.data.dao.entity.Member;
3540
import com.upupor.service.data.service.CommentService;
3641
import com.upupor.service.data.service.MemberService;
37-
import com.upupor.framework.BusinessException;
38-
import com.upupor.framework.CcResponse;
39-
import com.upupor.framework.ErrorCode;
4042
import com.upupor.service.listener.event.ReplayCommentEvent;
4143
import com.upupor.service.listener.event.ToCommentSuccessEvent;
4244
import com.upupor.service.outer.req.AddCommentReq;
@@ -67,15 +69,15 @@
6769
@RestController
6870
@RequiredArgsConstructor
6971
@RequestMapping("/comment")
70-
public class CommentsController {
72+
public class CommentController {
7173
private final CommentService commentService;
7274
private final MemberService memberService;
7375
private final ApplicationEventPublisher eventPublisher;
7476

7577
@ApiOperation("添加评论")
7678
@PostMapping("/add")
7779
@ResponseBody
78-
@UpuporLimit(limitType = LimitType.CREATE_COMMENT,needSpendMoney = true)
80+
@UpuporLimit(limitType = LimitType.CREATE_COMMENT, needSpendMoney = true)
7981
public CcResponse add(AddCommentReq addCommentReq) {
8082
CcResponse cc = new CcResponse();
8183
if (Objects.isNull(addCommentReq.getCommentSource())) {

0 commit comments

Comments
 (0)