5 Commits

Author SHA1 Message Date
Chuyaoyuan cda8a3e0ee Update UI 2026-05-13 15:22:39 +08:00
Chuyaoyuan 28eb17f60b front ui fix 2026-05-13 14:39:57 +08:00
Chuyaoyuan 9e42918d5e Inbox Message & bugs 2026-05-13 13:58:08 +08:00
Chuyaoyuan 4dfd27c785 update theme and user top 2026-05-12 18:49:34 +08:00
Chuyaoyuan ba8c1e3be3 update fix 2026-05-09 11:35:30 +08:00
62 changed files with 2234 additions and 303 deletions
View File
@@ -3,9 +3,11 @@ package com.yaoyuan.jiscuss;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.annotation.EnableCaching; import org.springframework.cache.annotation.EnableCaching;
import org.springframework.scheduling.annotation.EnableAsync;
@SpringBootApplication @SpringBootApplication
@EnableCaching @EnableCaching
@EnableAsync
public class JiccussApplication { public class JiccussApplication {
public static void main(String[] args) { public static void main(String[] args) {
@@ -50,6 +50,14 @@ public class Node {
private String ipAddress; private String ipAddress;
private String ipRegion;
private String browser;
private Integer likeCount;
private Integer dislikeCount;
private String copyright; private String copyright;
private Integer isApproved; private Integer isApproved;
@@ -52,6 +52,33 @@ public class PostCommonUtil {
postCustom.setAvatar(avatar); postCustom.setAvatar(avatar);
postCustom.setUsername(mapObj.get("create_username") != null ? String.valueOf(mapObj.get("create_username")) : null); postCustom.setUsername(mapObj.get("create_username") != null ? String.valueOf(mapObj.get("create_username")) : null);
postCustom.setRealname(mapObj.get("create_realname") != null ? String.valueOf(mapObj.get("create_realname")) : null); postCustom.setRealname(mapObj.get("create_realname") != null ? String.valueOf(mapObj.get("create_realname")) : null);
// floor number
if (mapObj.get("number") != null) {
postCustom.setNumber(Integer.parseInt(String.valueOf(mapObj.get("number"))));
}
// create user id
if (mapObj.get("create_id") != null) {
postCustom.setCreateId(Integer.parseInt(String.valueOf(mapObj.get("create_id"))));
}
// ip address
if (mapObj.get("ip_address") != null) {
postCustom.setIpAddress(String.valueOf(mapObj.get("ip_address")));
}
// ip region (may be null if column not yet populated)
if (mapObj.get("ip_region") != null) {
postCustom.setIpRegion(String.valueOf(mapObj.get("ip_region")));
}
// browser info (user_agent stored but only display-parsed browser is used)
if (mapObj.get("browser") != null) {
postCustom.setBrowser(String.valueOf(mapObj.get("browser")));
}
// vote counters
if (mapObj.get("like_count") != null) {
postCustom.setLikeCount(Integer.parseInt(String.valueOf(mapObj.get("like_count"))));
}
if (mapObj.get("dislike_count") != null) {
postCustom.setDislikeCount(Integer.parseInt(String.valueOf(mapObj.get("dislike_count"))));
}
String avatarReply = ""; String avatarReply = "";
if (mapObj.get("user_avatar") != null) { if (mapObj.get("user_avatar") != null) {
if (mapObj.get("user_avatar") instanceof Clob) { if (mapObj.get("user_avatar") instanceof Clob) {
@@ -1,15 +1,115 @@
package com.yaoyuan.jiscuss.controller; package com.yaoyuan.jiscuss.controller;
import com.yaoyuan.jiscuss.dto.InboxItem;
import com.yaoyuan.jiscuss.entity.Message;
import com.yaoyuan.jiscuss.entity.Notification;
import com.yaoyuan.jiscuss.entity.User;
import com.yaoyuan.jiscuss.entity.UserInfo;
import com.yaoyuan.jiscuss.service.IMessageService;
import com.yaoyuan.jiscuss.service.INotificationService;
import com.yaoyuan.jiscuss.service.IUsersService;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.ArrayList;
import java.util.List;
/** /**
* @author Chuyaoyuan * @author Chuyaoyuan
* 用户消息控制器 * 站内私信与通知控制器
*/ */
@Controller @Controller
public class UserMsgController extends BaseController { public class UserMsgController extends BaseController {
/** @Autowired
* 首页最新消息 private IMessageService messageService;
*/
@Autowired
private INotificationService notificationService;
@Autowired
private IUsersService usersService;
/** 收件箱:对话列表 */
@GetMapping("/messages")
public String inbox(HttpServletRequest request, ModelMap map) {
UserInfo user = getUserInfo(request);
if (user == null) return "redirect:/login";
List<Message> inboxList = messageService.getInbox(user.getId());
List<InboxItem> items = new ArrayList<>();
for (Message msg : inboxList) {
Integer otherId = msg.getSenderId().equals(user.getId()) ? msg.getReceiverId() : msg.getSenderId();
User other = usersService.findOne(otherId);
String rawName = (other != null) ? other.getUsername() : null;
String otherName = (rawName != null && !rawName.isBlank()) ? rawName : "用户" + otherId;
boolean hasUnread = !Boolean.TRUE.equals(msg.getIsRead()) && msg.getReceiverId().equals(user.getId());
items.add(new InboxItem(otherId, otherName, msg.getContent(), msg.getCreateTime(), hasUnread));
}
map.put("username", user.getUsername());
map.put("currentUserId", user.getId());
map.put("inboxItems", items);
map.put("unreadMsgCount", messageService.countUnread(user.getId()));
map.put("unreadNotifCount", notificationService.countUnread(user.getId()));
return "messages";
}
/** 对话详情页 */
@GetMapping("/messages/{otherId}")
public String conversation(@PathVariable Integer otherId, HttpServletRequest request, ModelMap map) {
UserInfo user = getUserInfo(request);
if (user == null) return "redirect:/login";
messageService.markConversationRead(user.getId(), otherId);
List<Message> messages = messageService.getConversation(user.getId(), otherId);
User other = usersService.findOne(otherId);
map.put("username", user.getUsername());
map.put("currentUserId", user.getId());
map.put("otherId", otherId);
map.put("otherUsername", other != null ? other.getUsername() : "用户" + otherId);
map.put("messages", messages);
map.put("unreadMsgCount", messageService.countUnread(user.getId()));
map.put("unreadNotifCount", notificationService.countUnread(user.getId()));
return "conversation";
}
/** 通知列表页 */
@GetMapping("/notifications")
public String notifications(@RequestParam(defaultValue = "0") int page,
HttpServletRequest request, ModelMap map) {
UserInfo user = getUserInfo(request);
if (user == null) return "redirect:/login";
notificationService.markAllRead(user.getId());
Page<Notification> notifs = notificationService.listByUser(user.getId(), page, 20);
List<String> fromUsernames = new ArrayList<>();
for (Notification n : notifs.getContent()) {
if (n.getFromUserId() != null) {
User from = usersService.findOne(n.getFromUserId());
fromUsernames.add(from != null ? from.getUsername() : "用户" + n.getFromUserId());
} else {
fromUsernames.add("系统");
}
}
map.put("username", user.getUsername());
map.put("notifications", notifs.getContent());
map.put("fromUsernames", fromUsernames);
map.put("totalPages", notifs.getTotalPages());
map.put("currentPage", page);
map.put("unreadMsgCount", messageService.countUnread(user.getId()));
map.put("unreadNotifCount", 0L);
return "notifications";
}
} }
@@ -1,68 +1,105 @@
package com.yaoyuan.jiscuss.controller; package com.yaoyuan.jiscuss.controller;
import com.yaoyuan.jiscuss.entity.Discussion;
import com.yaoyuan.jiscuss.entity.Post;
import com.yaoyuan.jiscuss.entity.User;
import com.yaoyuan.jiscuss.entity.UserInfo; import com.yaoyuan.jiscuss.entity.UserInfo;
import com.yaoyuan.jiscuss.service.IDiscussionsService; import com.yaoyuan.jiscuss.repository.DiscussionsRepository;
import com.yaoyuan.jiscuss.service.ITagsService; import com.yaoyuan.jiscuss.repository.LikeCollectRepository;
import com.yaoyuan.jiscuss.repository.PostsRepository;
import com.yaoyuan.jiscuss.service.IMessageService;
import com.yaoyuan.jiscuss.service.INotificationService;
import com.yaoyuan.jiscuss.service.IUsersService; import com.yaoyuan.jiscuss.service.IUsersService;
import jakarta.servlet.http.HttpServletRequest;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap; import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import jakarta.servlet.http.HttpServletRequest; import java.util.ArrayList;
import java.util.List;
/** /**
* @author Chuyaoyuan * @author Chuyaoyuan
* @Title:
* @Package com.yaoyuan.jiscuss.controller
* @Description:
* @date
*/ */
@Controller @Controller
public class UserPageController extends BaseController { public class UserPageController extends BaseController {
private static Logger logger = LoggerFactory.getLogger(UserPageController.class); private static final Logger logger = LoggerFactory.getLogger(UserPageController.class);
@Autowired @Autowired
private IUsersService usersService; private IUsersService usersService;
@Autowired @Autowired
private IDiscussionsService discussionsService; private DiscussionsRepository discussionsRepository;
@Autowired @Autowired
private ITagsService tagsService; private PostsRepository postsRepository;
@Autowired
private LikeCollectRepository likeCollectRepository;
@Autowired
private IMessageService messageService;
@Autowired
private INotificationService notificationService;
/** /**
* 用户页 * 用户个人主
*
* @return
*/ */
@RequestMapping("/user") @RequestMapping("/user")
public String user(@RequestParam(defaultValue = "discussion") String type, HttpServletRequest request, ModelMap map) { public String user(@RequestParam(defaultValue = "discussion") String type,
HttpServletRequest request, ModelMap map) {
// type 判断 UserInfo currentUser = getUserInfo(request);
if (type.equals("discussion")) { if (currentUser == null) return "redirect:/login";
map.put("discussion", "active");
User userEntity = usersService.findOne(currentUser.getId());
long liveDiscCount = discussionsRepository.countByStartUserId(currentUser.getId());
long liveReplyCount = postsRepository.countByCreateId(currentUser.getId());
map.put("username", currentUser.getUsername());
map.put("userEntity", userEntity);
map.put("liveDiscCount", liveDiscCount);
map.put("liveReplyCount", liveReplyCount);
map.put("type", type);
map.put("unreadMsgCount", messageService.countUnread(currentUser.getId()));
map.put("unreadNotifCount", notificationService.countUnread(currentUser.getId()));
if ("discussion".equals(type)) {
Page<Discussion> discussions = discussionsRepository.findByStartUserIdOrderByStartTimeDesc(
currentUser.getId(), PageRequest.of(0, 20));
map.put("discussions", discussions.getContent());
} else if ("reply".equals(type)) {
Page<Post> posts = postsRepository.findByCreateIdOrderByCreateTimeDesc(
currentUser.getId(), PageRequest.of(0, 20));
map.put("posts", posts.getContent());
// Attach discussion titles
List<String> discTitles = new ArrayList<>();
for (Post p : posts.getContent()) {
if (p.getDiscussionId() != null) {
Discussion d = discussionsRepository.findById(p.getDiscussionId()).orElse(null);
discTitles.add(d != null ? d.getTitle() : "");
} else {
discTitles.add("");
}
}
map.put("discTitles", discTitles);
} else if ("like".equals(type)) {
List<Integer> likedIds = likeCollectRepository.findLikedDiscussionIdsByUser(currentUser.getId());
List<Discussion> liked = new ArrayList<>();
for (Integer id : likedIds) {
Discussion d = discussionsRepository.findById(id).orElse(null);
if (d != null) liked.add(d);
}
map.put("likedDiscussions", liked);
} }
if (type.equals("change")) {
map.put("change", "active");
}
if (type.equals("like")) {
map.put("like", "active");
}
UserInfo user = getUserInfo(request);
if (user != null) {
map.put("username", user.getUsername());
map.put("data", "Jiscuss 用户:" + user.getUsername());
}
return "user"; return "user";
} }
} }
@@ -12,6 +12,9 @@ import com.yaoyuan.jiscuss.service.IDiscussionsTagsService;
import com.yaoyuan.jiscuss.service.IPostsService; import com.yaoyuan.jiscuss.service.IPostsService;
import com.yaoyuan.jiscuss.service.ITagsService; import com.yaoyuan.jiscuss.service.ITagsService;
import com.yaoyuan.jiscuss.service.IUsersService; import com.yaoyuan.jiscuss.service.IUsersService;
import com.yaoyuan.jiscuss.service.IpRegionService;
import com.yaoyuan.jiscuss.util.IpUtils;
import com.yaoyuan.jiscuss.util.UserAgentUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
@@ -56,6 +59,12 @@ public class UserPostController extends BaseController {
@Autowired @Autowired
private IUsersService usersService; private IUsersService usersService;
@Autowired
private IpRegionService ipRegionService;
@Autowired
private com.yaoyuan.jiscuss.service.INotificationService notificationService;
/** /**
* 首页查看主题列表(各种条件筛选,最热最新标签等) * 首页查看主题列表(各种条件筛选,最热最新标签等)
@@ -70,8 +79,13 @@ public class UserPostController extends BaseController {
* @return * @return
*/ */
@RequestMapping("/getdiscussionsbyid") @RequestMapping("/getdiscussionsbyid")
public String getDiscussionsById(HttpServletRequest request, ModelMap map, @RequestParam("id") Integer id) { public String getDiscussionsById(HttpServletRequest request, ModelMap map,
logger.info(">>> getDiscussionsById{}", id); @RequestParam("id") Integer id,
@RequestParam(defaultValue = "newest") String sort) {
logger.info(">>> getDiscussionsById{} sort={}", id, sort);
// Atomically increment view count before loading the discussion
discussionsService.incrementViewCount(id);
Discussion discussion = discussionsService.findOne(id); Discussion discussion = discussionsService.findOne(id);
// 获取此主题下的评论 // 获取此主题下的评论
@@ -93,10 +107,11 @@ public class UserPostController extends BaseController {
} }
List<Tag> tags = tagsService.findByDId(id); List<Tag> tags = tagsService.findByDId(id);
List postsObj = postsService.findPostCustomById(id); List postsObj = postsService.findPostCustomById(id, sort);
map.put("tags", tags); map.put("tags", tags);
map.put("discussions", newdd); map.put("discussions", newdd);
map.put("posts", postsObj); map.put("posts", postsObj);
map.put("sort", sort);
UserInfo user = getUserInfo(request); UserInfo user = getUserInfo(request);
if (user != null) { if (user != null) {
map.put("username", user.getUsername()); map.put("username", user.getUsername());
@@ -180,12 +195,27 @@ public class UserPostController extends BaseController {
post.setCreateId(user.getId()); post.setCreateId(user.getId());
} }
post.setCreateTime(new Date()); post.setCreateTime(new Date());
// Capture client IP, region, and browser
String clientIp = IpUtils.getClientIp(request);
post.setIpAddress(clientIp);
post.setIpRegion(ipRegionService.getRegion(clientIp));
post.setBrowser(UserAgentUtils.parseBrowser(request.getHeader("User-Agent")));
if (null != post.getParentId()) { if (null != post.getParentId()) {
Post temp = postsService.findOneByid(post.getParentId()); Post temp = postsService.findOneByid(post.getParentId());
post.setUserId(temp.getCreateId()); post.setUserId(temp.getCreateId());
} }
Post savePost = postsService.insert(post); Post savePost = postsService.insert(post);
// Notify the discussion starter about a reply (async, ignores self-reply)
if (post.getDiscussionId() != null && user != null) {
Discussion disc = discussionsService.findOne(post.getDiscussionId());
if (disc != null && disc.getStartUserId() != null) {
notificationService.notifyReply(disc.getStartUserId(), user.getId(),
disc.getId(), disc.getTitle());
}
}
Map<String, Object> resultobj = new HashMap<>(); Map<String, Object> resultobj = new HashMap<>();
logger.info(">>>{}", savePost); logger.info(">>>{}", savePost);
resultobj.put("msg", "添加评论成功"); resultobj.put("msg", "添加评论成功");
@@ -15,6 +15,7 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap; import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
@@ -50,6 +51,9 @@ public class UserSystemController extends BaseController {
@Autowired @Autowired
private ITagsService tagsService; private ITagsService tagsService;
@Autowired
private BCryptPasswordEncoder passwordEncoder;
/** /**
* 首页index * 首页index
* @param tag * @param tag
@@ -112,6 +116,8 @@ public class UserSystemController extends BaseController {
map.put("pageTotal", total); map.put("pageTotal", total);
map.put("pageNum", pageNum); map.put("pageNum", pageNum);
map.put("pageTotalPages", allDiscussionsPage.getTotalPages()); map.put("pageTotalPages", allDiscussionsPage.getTotalPages());
map.put("pageNumAll", allDiscussionsPage.getTotalPages());
map.put("topUsers", usersService.getTopActiveUsers(10));
UserInfo user = getUserInfo(request); UserInfo user = getUserInfo(request);
if (user != null) { if (user != null) {
map.put("username", user.getUsername()); map.put("username", user.getUsername());
@@ -250,7 +256,7 @@ public class UserSystemController extends BaseController {
} else { } else {
User user = new User(); User user = new User();
user.setEmail(email); user.setEmail(email);
user.setPassword(password); user.setPassword(passwordEncoder.encode(password));
user.setUsername(username); user.setUsername(username);
user.setRealname(username); user.setRealname(username);
user.setJoinTime(new Date()); user.setJoinTime(new Date());
@@ -0,0 +1,111 @@
package com.yaoyuan.jiscuss.controller.api;
import com.yaoyuan.jiscuss.controller.BaseController;
import com.yaoyuan.jiscuss.entity.Message;
import com.yaoyuan.jiscuss.entity.Notification;
import com.yaoyuan.jiscuss.entity.User;
import com.yaoyuan.jiscuss.entity.UserInfo;
import com.yaoyuan.jiscuss.response.ApiResponse;
import com.yaoyuan.jiscuss.service.IMessageService;
import com.yaoyuan.jiscuss.service.INotificationService;
import com.yaoyuan.jiscuss.service.IUsersService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Map;
/**
* REST API for private messages and notifications.
*/
@Tag(name = "Message API", description = "Private messages and notifications")
@RestController
@RequestMapping("/msg_api")
public class RestMsgController extends BaseController {
@Autowired
private IMessageService messageService;
@Autowired
private INotificationService notificationService;
@Autowired
private IUsersService usersService;
// ─── User card (public — accessible to any authenticated user) ────────
/** Returns basic user info for the hover card (discussionsCount, commentsCount). */
@Operation(summary = "Get user card info")
@GetMapping("/user-card/{id}")
public ApiResponse<Map<String, Object>> getUserCard(@PathVariable Integer id, HttpServletRequest request) {
UserInfo currentUser = getUserInfo(request);
if (currentUser == null) return ApiResponse.fail(401, "请先登录");
User user = usersService.findOne(id);
if (user == null) return ApiResponse.fail(404, "用户不存在");
return ApiResponse.ok(Map.of(
"id", user.getId(),
"username", user.getUsername() != null ? user.getUsername() : "",
"discussionsCount", user.getDiscussionsCount() != null ? user.getDiscussionsCount() : 0,
"commentsCount", user.getCommentsCount() != null ? user.getCommentsCount() : 0
));
}
// ─── Notifications ────────────────────────────────────────────────────
@Operation(summary = "Get unread notification + message counts")
@GetMapping("/unread-counts")
public ApiResponse<Map<String, Long>> unreadCounts(HttpServletRequest request) {
UserInfo user = getUserInfo(request);
if (user == null) return ApiResponse.ok(Map.of("notifications", 0L, "messages", 0L));
return ApiResponse.ok(Map.of(
"notifications", notificationService.countUnread(user.getId()),
"messages", messageService.countUnread(user.getId())
));
}
@Operation(summary = "Mark a notification as read")
@PostMapping("/notifications/{id}/read")
public ApiResponse<Void> markNotifRead(@PathVariable Integer id, HttpServletRequest request) {
UserInfo user = getUserInfo(request);
if (user == null) return ApiResponse.fail(401, "请先登录");
notificationService.markOneRead(id, user.getId());
return ApiResponse.ok(null);
}
@Operation(summary = "Mark all notifications as read")
@PostMapping("/notifications/read-all")
public ApiResponse<Void> markAllNotifRead(HttpServletRequest request) {
UserInfo user = getUserInfo(request);
if (user == null) return ApiResponse.fail(401, "请先登录");
notificationService.markAllRead(user.getId());
return ApiResponse.ok(null);
}
// ─── Messages ─────────────────────────────────────────────────────────
@Operation(summary = "Send a private message")
@PostMapping("/messages/send")
public ApiResponse<Message> sendMessage(
@RequestParam Integer receiverId,
@RequestParam String content,
HttpServletRequest request) {
UserInfo user = getUserInfo(request);
if (user == null) return ApiResponse.fail(401, "请先登录");
if (user.getId().equals(receiverId)) return ApiResponse.fail(400, "不能给自己发消息");
if (content == null || content.isBlank()) return ApiResponse.fail(400, "消息内容不能为空");
Message msg = messageService.send(user.getId(), receiverId, content.trim());
return ApiResponse.ok(msg);
}
@Operation(summary = "Get conversation with another user")
@GetMapping("/messages/conversation/{otherId}")
public ApiResponse<List<Message>> getConversation(@PathVariable Integer otherId, HttpServletRequest request) {
UserInfo user = getUserInfo(request);
if (user == null) return ApiResponse.fail(401, "请先登录");
messageService.markConversationRead(user.getId(), otherId);
return ApiResponse.ok(messageService.getConversation(user.getId(), otherId));
}
}
@@ -1,11 +1,16 @@
package com.yaoyuan.jiscuss.controller.api; package com.yaoyuan.jiscuss.controller.api;
import com.yaoyuan.jiscuss.dto.UserCreateRequest;
import com.yaoyuan.jiscuss.dto.UserMapper;
import com.yaoyuan.jiscuss.dto.UserResponse;
import com.yaoyuan.jiscuss.entity.User; import com.yaoyuan.jiscuss.entity.User;
import com.yaoyuan.jiscuss.exception.BaseException; import com.yaoyuan.jiscuss.exception.BaseException;
import com.yaoyuan.jiscuss.response.ApiResponse;
import com.yaoyuan.jiscuss.response.ResponseCode; import com.yaoyuan.jiscuss.response.ResponseCode;
import com.yaoyuan.jiscuss.service.IUsersService; import com.yaoyuan.jiscuss.service.IUsersService;
import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@@ -30,46 +35,51 @@ public class RestUserController {
@Autowired @Autowired
private IUsersService usersService; private IUsersService usersService;
@Autowired
private UserMapper userMapper;
@PostMapping("/user") @PostMapping("/user")
@Operation(summary = "新增用户") @Operation(summary = "新增用户")
public User save(@RequestBody User user) { public ApiResponse<UserResponse> save(@Valid @RequestBody UserCreateRequest request) {
User saveUser = usersService.insert(user); User user = userMapper.fromCreateRequest(request);
if (saveUser != null) { User saved = usersService.insert(user);
return saveUser; if (saved != null) {
} else { return ApiResponse.ok(userMapper.toResponse(saved));
throw new BaseException(ResponseCode.RESOURCES_NOT_EXIST);
} }
throw new BaseException(ResponseCode.RESOURCES_NOT_EXIST);
} }
@DeleteMapping("/user/{id}") @DeleteMapping("/user/{id}")
@Operation(summary = "删除用户") @Operation(summary = "删除用户")
public Boolean delete(@PathVariable Integer id) { public ApiResponse<Boolean> delete(@PathVariable Integer id) {
usersService.remove(id); usersService.remove(id);
return true; return ApiResponse.ok(true);
} }
@PutMapping("/user/{id}") @PutMapping("/user/{id}")
@Operation(summary = "修改用户") @Operation(summary = "修改用户")
public User update(@RequestBody User user, @PathVariable Integer id) { public ApiResponse<UserResponse> update(@RequestBody User user, @PathVariable Integer id) {
User updateuser = usersService.update(user, id); User updated = usersService.update(user, id);
if (updateuser != null) { if (updated != null) {
return updateuser; return ApiResponse.ok(userMapper.toResponse(updated));
} else {
throw new BaseException(ResponseCode.RESOURCES_NOT_EXIST);
} }
throw new BaseException(ResponseCode.RESOURCES_NOT_EXIST);
} }
@GetMapping("/user/{id}") @GetMapping("/user/{id}")
@Operation(summary = "获取用户") @Operation(summary = "获取用户")
public User getUser(@PathVariable Integer id) { public ApiResponse<UserResponse> getUser(@PathVariable Integer id) {
User user = usersService.findOne(id); User user = usersService.findOne(id);
logger.info("获取用户==>{}", user); logger.info("获取用户==>{}", user);
return user; return ApiResponse.ok(userMapper.toResponse(user));
} }
@GetMapping("/user") @GetMapping("/user")
@Operation(summary = "获取全部用户") @Operation(summary = "获取全部用户")
public List<User> getAllUsers() { public ApiResponse<List<UserResponse>> getAllUsers() {
return usersService.getAllList(); List<UserResponse> list = usersService.getAllList().stream()
.map(userMapper::toResponse)
.toList();
return ApiResponse.ok(list);
} }
} }
@@ -0,0 +1,63 @@
package com.yaoyuan.jiscuss.controller.api;
import com.yaoyuan.jiscuss.controller.BaseController;
import com.yaoyuan.jiscuss.entity.UserInfo;
import com.yaoyuan.jiscuss.response.ApiResponse;
import com.yaoyuan.jiscuss.service.ILikeCollectService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import jakarta.servlet.http.HttpServletRequest;
import java.util.Map;
/**
* REST API for voting (like / dislike) on discussions and posts.
*/
@Tag(name = "Vote API", description = "Like and dislike discussions and posts")
@RestController
@RequestMapping("/api")
public class VoteController extends BaseController {
@Autowired
private ILikeCollectService likeCollectService;
@Operation(summary = "Vote on a discussion")
@PostMapping("/discussions/{id}/vote")
public ApiResponse<Map<String, String>> voteDiscussion(
@PathVariable Integer id,
@RequestParam String action,
HttpServletRequest request) {
UserInfo user = getUserInfo(request);
if (user == null) {
return ApiResponse.fail(401, "请先登录");
}
if (!"like".equals(action) && !"dislike".equals(action)) {
return ApiResponse.fail(400, "action 参数必须是 like 或 dislike");
}
String result = likeCollectService.voteDiscussion(user.getId(), id, action);
return ApiResponse.ok(Map.of("action", result));
}
@Operation(summary = "Vote on a post (reply)")
@PostMapping("/posts/{id}/vote")
public ApiResponse<Map<String, String>> votePost(
@PathVariable Integer id,
@RequestParam String action,
HttpServletRequest request) {
UserInfo user = getUserInfo(request);
if (user == null) {
return ApiResponse.fail(401, "请先登录");
}
if (!"like".equals(action) && !"dislike".equals(action)) {
return ApiResponse.fail(400, "action 参数必须是 like 或 dislike");
}
String result = likeCollectService.votePost(user.getId(), id, action);
return ApiResponse.ok(Map.of("action", result));
}
}
@@ -0,0 +1,23 @@
package com.yaoyuan.jiscuss.dto;
import lombok.Data;
import java.util.Date;
/** View model for one inbox entry (latest message in a conversation). */
@Data
public class InboxItem {
private final Integer otherId;
private final String otherUsername;
private final String lastContent;
private final Date lastTime;
private final boolean hasUnread;
public InboxItem(Integer otherId, String otherUsername, String lastContent, Date lastTime, boolean hasUnread) {
this.otherId = otherId;
this.otherUsername = otherUsername;
this.lastContent = lastContent;
this.lastTime = lastTime;
this.hasUnread = hasUnread;
}
}
@@ -68,6 +68,9 @@ public class Discussion implements Serializable {
@Column(name = "like_count") @Column(name = "like_count")
private Integer likeCount; private Integer likeCount;
@Column(name = "dislike_count")
private Integer dislikeCount;
/** IP is resolved server-side via IpUtils.getClientIp() — never trusted from X-Forwarded-For alone. */ /** IP is resolved server-side via IpUtils.getClientIp() — never trusted from X-Forwarded-For alone. */
@Column(name = "ip_address") @Column(name = "ip_address")
private String ipAddress; private String ipAddress;
@@ -77,5 +80,8 @@ public class Discussion implements Serializable {
@Column(name = "create_time") @Column(name = "create_time")
private Date createTime; private Date createTime;
@Column(name = "view_count")
private Integer viewCount;
} }
@@ -48,6 +48,10 @@ public class LikeCollect implements Serializable {
@Column(name = "type") @Column(name = "type")
private String type; private String type;
/** Vote action: 'like' or 'dislike'. */
@Column(name = "action")
private String action;
@Column(name = "like_type") @Column(name = "like_type")
private String likeType; private String likeType;
@@ -0,0 +1,40 @@
package com.yaoyuan.jiscuss.entity;
import jakarta.persistence.*;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
@Data
@Entity
@Table(name = "message")
public class Message implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
@Column(name = "sender_id", nullable = false)
private Integer senderId;
@Column(name = "receiver_id", nullable = false)
private Integer receiverId;
@Column(name = "content", columnDefinition = "TEXT", nullable = false)
private String content;
@Column(name = "is_read")
private Boolean isRead = false;
@Column(name = "create_time")
private Date createTime;
/**
* Conversation identifier = "min(a,b)_max(a,b)", groups all messages
* between two users into a single conversation thread.
*/
@Column(name = "conversation_id", nullable = false)
private String conversationId;
}
@@ -0,0 +1,50 @@
package com.yaoyuan.jiscuss.entity;
import jakarta.persistence.*;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
@Data
@Entity
@Table(name = "notification")
public class Notification implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
/** Receiver user ID. */
@Column(name = "user_id", nullable = false)
private Integer userId;
/** Sender user ID (null for system notifications). */
@Column(name = "from_user_id")
private Integer fromUserId;
/** Notification type: reply / like / system. */
@Column(name = "type", nullable = false)
private String type;
@Column(name = "title")
private String title;
@Column(name = "content", columnDefinition = "TEXT")
private String content;
/** Related entity ID (e.g., discussion or post id). */
@Column(name = "related_id")
private Integer relatedId;
/** Type of related entity: discussion / post. */
@Column(name = "related_type")
private String relatedType;
@Column(name = "is_read")
private Boolean isRead = false;
@Column(name = "create_time")
private Date createTime;
}
@@ -54,12 +54,26 @@ public class Post implements Serializable {
@Column(name = "ip_address") @Column(name = "ip_address")
private String ipAddress; private String ipAddress;
/** Province/region derived from IP (e.g. "北京", "广东"). Stored on post creation. */
@Column(name = "ip_region")
private String ipRegion;
/** Parsed browser name+version (e.g. "Chrome 120"). Derived from User-Agent on post creation. */
@Column(name = "browser")
private String browser;
@Column(name = "copyright") @Column(name = "copyright")
private String copyright; private String copyright;
@Column(name = "is_approved") @Column(name = "is_approved")
private Integer isApproved; private Integer isApproved;
@Column(name = "like_count")
private Integer likeCount;
@Column(name = "dislike_count")
private Integer dislikeCount;
@Column(name = "create_id") @Column(name = "create_id")
private Integer createId; private Integer createId;
@@ -1,5 +1,6 @@
package com.yaoyuan.jiscuss.entity; package com.yaoyuan.jiscuss.entity;
import com.fasterxml.jackson.annotation.JsonIgnore;
import jakarta.persistence.Column; import jakarta.persistence.Column;
import jakarta.persistence.Entity; import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue; import jakarta.persistence.GeneratedValue;
@@ -39,7 +40,8 @@ public class User implements Serializable {
@Column(name = "email") @Column(name = "email")
private String email; private String email;
/** BCrypt-hashed password. Column length must be >= 68 (see V2 migration). */ /** BCrypt-hashed password. Column length must be >= 68 (see V2 migration). Never serialized to JSON. */
@JsonIgnore
@Column(name = "password") @Column(name = "password")
private String password; private String password;
@@ -77,10 +77,9 @@ public class UserInfo implements UserDetails {
@Override @Override
public String toString() { public String toString() {
return "UserInfo{" + return "UserInfo{" +
"authorities=" + authorities + "username='" + username + '\'' +
", password='" + password + '\'' +
", username='" + username + '\'' +
", id='" + id + '\'' + ", id='" + id + '\'' +
", authorities=" + authorities +
'}'; '}';
} }
} }
@@ -4,8 +4,12 @@ import com.yaoyuan.jiscuss.entity.Discussion;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query; import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
import java.util.Date;
@Repository @Repository
public interface DiscussionsRepository extends JpaRepository<Discussion, Integer> { public interface DiscussionsRepository extends JpaRepository<Discussion, Integer> {
@@ -14,5 +18,35 @@ public interface DiscussionsRepository extends JpaRepository<Discussion, Integer
"SELECT discussion_id from discussiontag where tag_id = ?1 ) ", nativeQuery = true) "SELECT discussion_id from discussiontag where tag_id = ?1 ) ", nativeQuery = true)
Page<Discussion> findByQuery(String tagId, Pageable pageable); Page<Discussion> findByQuery(String tagId, Pageable pageable);
@Modifying
@Transactional
@Query("UPDATE Discussion d SET d.viewCount = d.viewCount + 1 WHERE d.id = :id")
void incrementViewCount(@org.springframework.data.repository.query.Param("id") Integer id);
@Modifying
@Transactional
@Query("UPDATE Discussion d SET d.commentsCount = COALESCE(d.commentsCount, 0) + 1, d.lastTime = :lastTime, d.lastUserId = :userId WHERE d.id = :id")
void incrementCommentCount(
@org.springframework.data.repository.query.Param("id") Integer id,
@org.springframework.data.repository.query.Param("userId") Integer userId,
@org.springframework.data.repository.query.Param("lastTime") Date lastTime);
@Modifying
@Transactional
@Query("UPDATE Discussion d SET d.likeCount = COALESCE(d.likeCount, 0) + :delta WHERE d.id = :id")
void adjustLikeCount(@org.springframework.data.repository.query.Param("id") Integer id,
@org.springframework.data.repository.query.Param("delta") int delta);
@Modifying
@Transactional
@Query("UPDATE Discussion d SET d.dislikeCount = COALESCE(d.dislikeCount, 0) + :delta WHERE d.id = :id")
void adjustDislikeCount(@org.springframework.data.repository.query.Param("id") Integer id,
@org.springframework.data.repository.query.Param("delta") int delta);
/** Discussions started by a given user, most recent first. */
@Query("SELECT d FROM Discussion d WHERE d.startUserId = :userId ORDER BY d.startTime DESC")
org.springframework.data.domain.Page<Discussion> findByStartUserIdOrderByStartTimeDesc(
@org.springframework.data.repository.query.Param("userId") Integer userId,
org.springframework.data.domain.Pageable pageable);
long countByStartUserId(Integer startUserId);
} }
@@ -0,0 +1,25 @@
package com.yaoyuan.jiscuss.repository;
import com.yaoyuan.jiscuss.entity.LikeCollect;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import java.util.Optional;
@Repository
public interface LikeCollectRepository extends JpaRepository<LikeCollect, Integer> {
/** Find an existing vote record for a user on a discussion. */
@Query("FROM LikeCollect lc WHERE lc.userId = :userId AND lc.discussionId = :discussionId AND lc.type = 'discussion'")
Optional<LikeCollect> findDiscussionVote(@Param("userId") Integer userId, @Param("discussionId") Integer discussionId);
/** Find an existing vote record for a user on a post. */
@Query("FROM LikeCollect lc WHERE lc.userId = :userId AND lc.postId = :postId AND lc.type = 'post'")
Optional<LikeCollect> findPostVote(@Param("userId") Integer userId, @Param("postId") Integer postId);
/** Discussions liked by a user (action = 'like'). */
@Query("SELECT lc.discussionId FROM LikeCollect lc WHERE lc.userId = :userId AND lc.type = 'discussion' AND lc.action = 'like'")
java.util.List<Integer> findLikedDiscussionIdsByUser(@Param("userId") Integer userId);
}
@@ -0,0 +1,31 @@
package com.yaoyuan.jiscuss.repository;
import com.yaoyuan.jiscuss.entity.Message;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
@Repository
public interface MessageRepository extends JpaRepository<Message, Integer> {
/** Latest messages in a conversation, most recent first. */
List<Message> findByConversationIdOrderByCreateTimeDesc(String conversationId);
/** All messages sent by user. */
List<Message> findBySenderIdOrderByCreateTimeDesc(Integer senderId);
/** All messages received by user. */
List<Message> findByReceiverIdOrderByCreateTimeDesc(Integer receiverId);
long countByReceiverIdAndIsReadFalse(Integer receiverId);
@Modifying
@Transactional
@Query("UPDATE Message m SET m.isRead = true WHERE m.conversationId = :convId AND m.receiverId = :userId")
void markConversationReadForUser(@Param("convId") String convId, @Param("userId") Integer userId);
}
@@ -0,0 +1,29 @@
package com.yaoyuan.jiscuss.repository;
import com.yaoyuan.jiscuss.entity.Notification;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
@Repository
public interface NotificationRepository extends JpaRepository<Notification, Integer> {
Page<Notification> findByUserIdOrderByCreateTimeDesc(Integer userId, Pageable pageable);
long countByUserIdAndIsReadFalse(Integer userId);
@Modifying
@Transactional
@Query("UPDATE Notification n SET n.isRead = true WHERE n.userId = :userId")
void markAllReadByUserId(@Param("userId") Integer userId);
@Modifying
@Transactional
@Query("UPDATE Notification n SET n.isRead = true WHERE n.id = :id AND n.userId = :userId")
void markReadById(@Param("id") Integer id, @Param("userId") Integer userId);
}
@@ -2,9 +2,11 @@ package com.yaoyuan.jiscuss.repository;
import com.yaoyuan.jiscuss.entity.Post; import com.yaoyuan.jiscuss.entity.Post;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query; import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param; import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@@ -21,6 +23,20 @@ public interface PostsRepository extends JpaRepository<Post, Integer> {
@Query("from Post where discussionId = :dId") @Query("from Post where discussionId = :dId")
List<Post> findOneBy(@Param("dId") Integer dId); List<Post> findOneBy(@Param("dId") Integer dId);
/** Returns the current max floor number for a discussion (0 if no posts yet). */
@Query("SELECT COALESCE(MAX(p.number), 0) FROM Post p WHERE p.discussionId = :dId")
int findMaxNumberByDiscussionId(@Param("dId") Integer dId);
@Modifying
@Transactional
@Query("UPDATE Post p SET p.likeCount = COALESCE(p.likeCount, 0) + :delta WHERE p.id = :id")
void adjustLikeCount(@Param("id") Integer id, @Param("delta") int delta);
@Modifying
@Transactional
@Query("UPDATE Post p SET p.dislikeCount = COALESCE(p.dislikeCount, 0) + :delta WHERE p.id = :id")
void adjustDislikeCount(@Param("id") Integer id, @Param("delta") int delta);
@Query(value = "select p.*,u.avatar as user_avatar ,u.username as user_username ,u.realname as user_realname ," + @Query(value = "select p.*,u.avatar as user_avatar ,u.username as user_username ,u.realname as user_realname ," +
"u2.avatar as create_avatar ,u2.username as create_username ,u2.realname as create_realname \n" + "u2.avatar as create_avatar ,u2.username as create_username ,u2.realname as create_realname \n" +
"from post p \n" + "from post p \n" +
@@ -31,6 +47,15 @@ public interface PostsRepository extends JpaRepository<Post, Integer> {
List<Map<String, Object>> findPostCustomById(@Param("dId") Integer dId); List<Map<String, Object>> findPostCustomById(@Param("dId") Integer dId);
@Query(value = "select p.*,u.avatar as user_avatar ,u.username as user_username ,u.realname as user_realname ," +
"u2.avatar as create_avatar ,u2.username as create_username ,u2.realname as create_realname \n" +
"from post p \n" +
"left join user u on p.user_id = u.id \n" +
"left join user u2 on p.create_id = u2.id \n" +
"where p.discussion_id = :dId and p.parent_id is null order by p.create_time asc"
, nativeQuery = true)
List<Map<String, Object>> findAllByDIdAndparentIdNullOldest(@Param("dId") Integer dId);
@Query(value = "select p.*,u.avatar as user_avatar ,u.username as user_username ,u.realname as user_realname ," + @Query(value = "select p.*,u.avatar as user_avatar ,u.username as user_username ,u.realname as user_realname ," +
"u2.avatar as create_avatar ,u2.username as create_username ,u2.realname as create_realname \n" + "u2.avatar as create_avatar ,u2.username as create_username ,u2.realname as create_realname \n" +
"from post p \n" + "from post p \n" +
@@ -38,7 +63,16 @@ public interface PostsRepository extends JpaRepository<Post, Integer> {
"left join user u2 on p.create_id = u2.id \n" + "left join user u2 on p.create_id = u2.id \n" +
"where p.discussion_id = :dId and p.parent_id is null order by p.create_time desc" "where p.discussion_id = :dId and p.parent_id is null order by p.create_time desc"
, nativeQuery = true) , nativeQuery = true)
List<Map<String, Object>> findAllByDIdAndparentIdNull(@Param("dId") Integer dId); List<Map<String, Object>> findAllByDIdAndparentIdNullNewest(@Param("dId") Integer dId);
@Query(value = "select p.*,u.avatar as user_avatar ,u.username as user_username ,u.realname as user_realname ," +
"u2.avatar as create_avatar ,u2.username as create_username ,u2.realname as create_realname \n" +
"from post p \n" +
"left join user u on p.user_id = u.id \n" +
"left join user u2 on p.create_id = u2.id \n" +
"where p.discussion_id = :dId and p.parent_id is null order by p.like_count desc, p.create_time desc"
, nativeQuery = true)
List<Map<String, Object>> findAllByDIdAndparentIdNullHot(@Param("dId") Integer dId);
@Query(value = "select p.*,u.avatar as user_avatar ,u.username as user_username ,u.realname as user_realname ," + @Query(value = "select p.*,u.avatar as user_avatar ,u.username as user_username ,u.realname as user_realname ," +
"u2.avatar as create_avatar ,u2.username as create_username ,u2.realname as create_realname \n" + "u2.avatar as create_avatar ,u2.username as create_username ,u2.realname as create_realname \n" +
@@ -55,4 +89,11 @@ public interface PostsRepository extends JpaRepository<Post, Integer> {
// //
// @Query("from Post where parentId is not null and discussionId = :dId") // @Query("from Post where parentId is not null and discussionId = :dId")
// List<Post> findAllByDIdAndparentIdNotNull(@Param("dId")Integer dId); // List<Post> findAllByDIdAndparentIdNotNull(@Param("dId")Integer dId);
/** Posts (replies) created by a given user, most recent first. */
@Query("SELECT p FROM Post p WHERE p.createId = :userId ORDER BY p.createTime DESC")
org.springframework.data.domain.Page<Post> findByCreateIdOrderByCreateTimeDesc(
@Param("userId") Integer userId, org.springframework.data.domain.Pageable pageable);
long countByCreateId(Integer createId);
} }
@@ -2,9 +2,11 @@ package com.yaoyuan.jiscuss.repository;
import com.yaoyuan.jiscuss.entity.User; import com.yaoyuan.jiscuss.entity.User;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query; import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param; import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
import java.util.List; import java.util.List;
@@ -32,4 +34,18 @@ public interface UsersRepository extends JpaRepository<User, Integer> {
// REMOVED: checkByUsernameAndPassword — never compare passwords at the SQL layer. // REMOVED: checkByUsernameAndPassword — never compare passwords at the SQL layer.
// Password validation must go through BCryptPasswordEncoder.matches() in the service/security layer. // Password validation must go through BCryptPasswordEncoder.matches() in the service/security layer.
@Modifying
@Transactional
@Query("UPDATE User u SET u.commentsCount = COALESCE(u.commentsCount, 0) + 1 WHERE u.id = :id")
void incrementCommentCount(@Param("id") Integer id);
@Modifying
@Transactional
@Query("UPDATE User u SET u.discussionsCount = COALESCE(u.discussionsCount, 0) + 1 WHERE u.id = :id")
void incrementDiscussionCount(@Param("id") Integer id);
/** Top active users by comment count (for the ranking sidebar). Shows all users if counts are 0. */
@Query("FROM User u ORDER BY COALESCE(u.commentsCount, 0) DESC")
List<User> findTop10ActiveUsers(org.springframework.data.domain.Pageable pageable);
} }
@@ -15,6 +15,10 @@ public record ApiResponse<T>(int code, String msg, T data) {
return new ApiResponse<>(responseCode.getCode(), responseCode.getMsg(), null); return new ApiResponse<>(responseCode.getCode(), responseCode.getMsg(), null);
} }
public static <T> ApiResponse<T> fail(int code, String msg) {
return new ApiResponse<>(code, msg, null);
}
public static <T> ApiResponse<T> error(String message) { public static <T> ApiResponse<T> error(String message) {
return new ApiResponse<>(ResponseCode.SERVICE_ERROR.getCode(), message, null); return new ApiResponse<>(ResponseCode.SERVICE_ERROR.getCode(), message, null);
} }
@@ -14,4 +14,6 @@ public interface IDiscussionsService {
Discussion findOne(Integer id); Discussion findOne(Integer id);
Page<Discussion> queryAllDiscussionsList(Discussion discussion, int pageNumNew, int pageSiz, String tag, String type); Page<Discussion> queryAllDiscussionsList(Discussion discussion, int pageNumNew, int pageSiz, String tag, String type);
void incrementViewCount(Integer id);
} }
@@ -0,0 +1,22 @@
package com.yaoyuan.jiscuss.service;
/**
* Vote (like / dislike) service for discussions and posts.
*
* <p>Toggle semantics:
* <ul>
* <li>If the user has not voted → create a new vote with the requested action.</li>
* <li>If the user voted with the same action → cancel the vote (toggle off).</li>
* <li>If the user voted with a different action → switch the vote.</li>
* </ul>
*
* @return the user's current action after the operation: "like", "dislike", or "none" (cancelled)
*/
public interface ILikeCollectService {
/** Vote on a discussion. {@code action} must be "like" or "dislike". */
String voteDiscussion(Integer userId, Integer discussionId, String action);
/** Vote on a post (reply). {@code action} must be "like" or "dislike". */
String votePost(Integer userId, Integer postId, String action);
}
@@ -0,0 +1,23 @@
package com.yaoyuan.jiscuss.service;
import com.yaoyuan.jiscuss.entity.Message;
import java.util.List;
public interface IMessageService {
/** Send a message from sender to receiver. */
Message send(Integer senderId, Integer receiverId, String content);
/** All messages in a conversation (ordered oldest→newest). */
List<Message> getConversation(Integer userId, Integer otherId);
/** Inbox: latest message per conversation, sorted by latest activity (max 50). */
List<Message> getInbox(Integer userId);
/** Unread message count for a user. */
long countUnread(Integer userId);
/** Mark an entire conversation as read for the current user. */
void markConversationRead(Integer userId, Integer otherId);
}
@@ -0,0 +1,27 @@
package com.yaoyuan.jiscuss.service;
import com.yaoyuan.jiscuss.entity.Notification;
import org.springframework.data.domain.Page;
public interface INotificationService {
/** Create a notification for a user. */
Notification create(Integer toUserId, Integer fromUserId, String type, String title, String content,
Integer relatedId, String relatedType);
/** Convenience: create a "reply" notification. */
void notifyReply(Integer toUserId, Integer fromUserId, Integer discussionId, String discussionTitle);
/** Convenience: create a "like" notification for a post. */
void notifyLike(Integer toUserId, Integer fromUserId, Integer postId, Integer discussionId);
/** Unread notification count for a user. */
long countUnread(Integer userId);
/** Paged notification list for a user. */
Page<Notification> listByUser(Integer userId, int page, int size);
void markAllRead(Integer userId);
void markOneRead(Integer notificationId, Integer userId);
}
@@ -12,7 +12,7 @@ public interface IPostsService {
List<Post> findOneBy(Integer id); List<Post> findOneBy(Integer id);
List<PostCustom> findPostCustomById(Integer id); List findPostCustomById(Integer id, String sort);
Post findOneByid(Integer parentId); Post findOneByid(Integer parentId);
} }
@@ -27,4 +27,6 @@ public interface IUsersService {
List<User> findAllById(Iterable<Integer> ids); List<User> findAllById(Iterable<Integer> ids);
User update(User user, Integer id); User update(User user, Integer id);
List<User> getTopActiveUsers(int limit);
} }
@@ -0,0 +1,71 @@
package com.yaoyuan.jiscuss.service;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import java.util.Set;
/**
* Lightweight IP region service.
*
* <p>Current implementation distinguishes local/private addresses from external ones.
* To display accurate province-level location (e.g. "北京", "广东"), replace the
* {@code lookupExternal} method with an ip2region XDB lookup or similar offline database.
*
* <p>Upgrade path:
* <ol>
* <li>Add {@code org.lionsoul:ip2region:2.7.0} to pom.xml</li>
* <li>Place {@code ip2region.xdb} (from the ip2region GitHub release) under
* {@code src/main/resources/}</li>
* <li>Replace {@code lookupExternal()} with:
* {@code Searcher.newWithFileOnly(xdbPath).searchByStr(ip)}</li>
* </ol>
*/
@Service
public class IpRegionService {
private static final Logger log = LoggerFactory.getLogger(IpRegionService.class);
private static final Set<String> LOCAL_PREFIXES = Set.of(
"127.", "0.", "::1", "0:0:0:0:0:0:0:1"
);
private static final Set<String> PRIVATE_PREFIXES = Set.of(
"10.", "192.168.", "172.16.", "172.17.", "172.18.", "172.19.",
"172.20.", "172.21.", "172.22.", "172.23.", "172.24.", "172.25.",
"172.26.", "172.27.", "172.28.", "172.29.", "172.30.", "172.31."
);
/**
* Returns a display-friendly region label for the given IP address.
*
* @param ip client IP string (IPv4 or IPv6)
* @return region label, e.g. "本地", "局域网", or "未知地区"
*/
public String getRegion(String ip) {
if (ip == null || ip.isBlank()) {
return "";
}
for (String prefix : LOCAL_PREFIXES) {
if (ip.startsWith(prefix)) {
return "本地";
}
}
for (String prefix : PRIVATE_PREFIXES) {
if (ip.startsWith(prefix)) {
return "局域网";
}
}
return lookupExternal(ip);
}
/**
* Override this method to integrate an offline IP database (e.g. ip2region).
* Default implementation returns "未知地区" as a placeholder.
*/
protected String lookupExternal(String ip) {
// TODO: integrate ip2region XDB for accurate province-level lookup
return "未知地区";
}
}
@@ -2,6 +2,7 @@ package com.yaoyuan.jiscuss.service.impl;
import com.yaoyuan.jiscuss.entity.Discussion; import com.yaoyuan.jiscuss.entity.Discussion;
import com.yaoyuan.jiscuss.repository.DiscussionsRepository; import com.yaoyuan.jiscuss.repository.DiscussionsRepository;
import com.yaoyuan.jiscuss.repository.UsersRepository;
import com.yaoyuan.jiscuss.service.IDiscussionsService; import com.yaoyuan.jiscuss.service.IDiscussionsService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example; import org.springframework.data.domain.Example;
@@ -20,6 +21,9 @@ public class DiscussionsServiceImpl implements IDiscussionsService {
@Autowired @Autowired
private DiscussionsRepository discussionsRepository; private DiscussionsRepository discussionsRepository;
@Autowired
private UsersRepository usersRepository;
@Transactional(readOnly = true) @Transactional(readOnly = true)
@Override @Override
public List<Discussion> getAllList() { public List<Discussion> getAllList() {
@@ -29,14 +33,18 @@ public class DiscussionsServiceImpl implements IDiscussionsService {
@Transactional @Transactional
@Override @Override
public Discussion insert(Discussion discussion) { public Discussion insert(Discussion discussion) {
return discussionsRepository.save(discussion); Discussion saved = discussionsRepository.save(discussion);
// Maintain user discussions count
if (discussion.getCreateId() != null) {
usersRepository.incrementDiscussionCount(discussion.getCreateId());
}
return saved;
} }
@Transactional(readOnly = true) @Transactional(readOnly = true)
@Override @Override
public Discussion findOne(Integer id) { public Discussion findOne(Integer id) {
// getReferenceById replaces removed JpaRepository.getOne() return discussionsRepository.findById(id).orElse(null);
return discussionsRepository.getReferenceById(id);
} }
@Transactional(readOnly = true) @Transactional(readOnly = true)
@@ -55,4 +63,10 @@ public class DiscussionsServiceImpl implements IDiscussionsService {
return discussionsRepository.findAll(example, pageable); return discussionsRepository.findAll(example, pageable);
} }
} }
@Transactional
@Override
public void incrementViewCount(Integer id) {
discussionsRepository.incrementViewCount(id);
}
} }
@@ -0,0 +1,119 @@
package com.yaoyuan.jiscuss.service.impl;
import com.yaoyuan.jiscuss.entity.LikeCollect;
import com.yaoyuan.jiscuss.entity.Post;
import com.yaoyuan.jiscuss.repository.DiscussionsRepository;
import com.yaoyuan.jiscuss.repository.LikeCollectRepository;
import com.yaoyuan.jiscuss.repository.PostsRepository;
import com.yaoyuan.jiscuss.service.ILikeCollectService;
import com.yaoyuan.jiscuss.service.INotificationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Date;
import java.util.Optional;
@Service
public class LikeCollectServiceImpl implements ILikeCollectService {
@Autowired
private LikeCollectRepository likeCollectRepository;
@Autowired
private DiscussionsRepository discussionsRepository;
@Autowired
private PostsRepository postsRepository;
@Autowired
private INotificationService notificationService;
@Transactional
@Override
public String voteDiscussion(Integer userId, Integer discussionId, String action) {
Optional<LikeCollect> existing = likeCollectRepository.findDiscussionVote(userId, discussionId);
if (existing.isPresent()) {
LikeCollect vote = existing.get();
if (vote.getAction().equals(action)) {
// Toggle off: cancel the same action
likeCollectRepository.delete(vote);
adjustDiscussion(discussionId, action, -1);
return "none";
} else {
// Switch action: undo old, apply new
adjustDiscussion(discussionId, vote.getAction(), -1);
vote.setAction(action);
likeCollectRepository.save(vote);
adjustDiscussion(discussionId, action, +1);
return action;
}
} else {
// New vote
LikeCollect vote = new LikeCollect();
vote.setUserId(userId);
vote.setDiscussionId(discussionId);
vote.setType("discussion");
vote.setAction(action);
vote.setCreateId(userId);
vote.setCreateTime(new Date());
likeCollectRepository.save(vote);
adjustDiscussion(discussionId, action, +1);
return action;
}
}
@Transactional
@Override
public String votePost(Integer userId, Integer postId, String action) {
Optional<LikeCollect> existing = likeCollectRepository.findPostVote(userId, postId);
if (existing.isPresent()) {
LikeCollect vote = existing.get();
if (vote.getAction().equals(action)) {
likeCollectRepository.delete(vote);
adjustPost(postId, action, -1);
return "none";
} else {
adjustPost(postId, vote.getAction(), -1);
vote.setAction(action);
likeCollectRepository.save(vote);
adjustPost(postId, action, +1);
return action;
}
} else {
LikeCollect vote = new LikeCollect();
vote.setUserId(userId);
vote.setPostId(postId);
vote.setType("post");
vote.setAction(action);
vote.setCreateId(userId);
vote.setCreateTime(new Date());
likeCollectRepository.save(vote);
adjustPost(postId, action, +1);
// Notify post author when liked (not disliked)
if ("like".equals(action)) {
Post post = postsRepository.findById(postId).orElse(null);
if (post != null && post.getCreateId() != null) {
notificationService.notifyLike(post.getCreateId(), userId, postId, post.getDiscussionId());
}
}
return action;
}
}
private void adjustDiscussion(Integer id, String action, int delta) {
if ("like".equals(action)) {
discussionsRepository.adjustLikeCount(id, delta);
} else {
discussionsRepository.adjustDislikeCount(id, delta);
}
}
private void adjustPost(Integer id, String action, int delta) {
if ("like".equals(action)) {
postsRepository.adjustLikeCount(id, delta);
} else {
postsRepository.adjustDislikeCount(id, delta);
}
}
}
@@ -0,0 +1,85 @@
package com.yaoyuan.jiscuss.service.impl;
import com.yaoyuan.jiscuss.entity.Message;
import com.yaoyuan.jiscuss.repository.MessageRepository;
import com.yaoyuan.jiscuss.service.IMessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Date;
import java.util.List;
@Service
public class MessageServiceImpl implements IMessageService {
@Autowired
private MessageRepository messageRepository;
private String buildConversationId(Integer a, Integer b) {
return Math.min(a, b) + "_" + Math.max(a, b);
}
@Transactional
@Override
public Message send(Integer senderId, Integer receiverId, String content) {
Message msg = new Message();
msg.setSenderId(senderId);
msg.setReceiverId(receiverId);
msg.setContent(content);
msg.setIsRead(false);
msg.setCreateTime(new Date());
msg.setConversationId(buildConversationId(senderId, receiverId));
return messageRepository.save(msg);
}
@Transactional(readOnly = true)
@Override
public List<Message> getConversation(Integer userId, Integer otherId) {
String convId = buildConversationId(userId, otherId);
List<Message> msgs = messageRepository.findByConversationIdOrderByCreateTimeDesc(convId);
// reverse to get oldest-first order
java.util.Collections.reverse(msgs);
return msgs;
}
@Transactional(readOnly = true)
@Override
public List<Message> getInbox(Integer userId) {
// Fetch sent and received separately, merge, then deduplicate by conversationId
List<Message> sent = messageRepository.findBySenderIdOrderByCreateTimeDesc(userId);
List<Message> received = messageRepository.findByReceiverIdOrderByCreateTimeDesc(userId);
// Merge both lists, sort by createTime descending
java.util.List<Message> all = new java.util.ArrayList<>();
all.addAll(sent);
all.addAll(received);
all.sort((a, b) -> {
if (a.getCreateTime() == null) return 1;
if (b.getCreateTime() == null) return -1;
return b.getCreateTime().compareTo(a.getCreateTime());
});
// Keep only the latest message per conversation
java.util.LinkedHashMap<String, Message> seen = new java.util.LinkedHashMap<>();
for (Message m : all) {
String cid = (m.getConversationId() != null && !m.getConversationId().isEmpty())
? m.getConversationId()
: Math.min(m.getSenderId(), m.getReceiverId()) + "_" + Math.max(m.getSenderId(), m.getReceiverId());
seen.putIfAbsent(cid, m);
}
return new java.util.ArrayList<>(seen.values());
}
@Transactional(readOnly = true)
@Override
public long countUnread(Integer userId) {
return messageRepository.countByReceiverIdAndIsReadFalse(userId);
}
@Transactional
@Override
public void markConversationRead(Integer userId, Integer otherId) {
messageRepository.markConversationReadForUser(buildConversationId(userId, otherId), userId);
}
}
@@ -0,0 +1,83 @@
package com.yaoyuan.jiscuss.service.impl;
import com.yaoyuan.jiscuss.entity.Notification;
import com.yaoyuan.jiscuss.repository.NotificationRepository;
import com.yaoyuan.jiscuss.service.INotificationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Date;
@Service
public class NotificationServiceImpl implements INotificationService {
@Autowired
private NotificationRepository notificationRepository;
@Transactional
@Override
public Notification create(Integer toUserId, Integer fromUserId, String type, String title,
String content, Integer relatedId, String relatedType) {
// Do not notify yourself
if (toUserId != null && toUserId.equals(fromUserId)) {
return null;
}
Notification n = new Notification();
n.setUserId(toUserId);
n.setFromUserId(fromUserId);
n.setType(type);
n.setTitle(title);
n.setContent(content);
n.setRelatedId(relatedId);
n.setRelatedType(relatedType);
n.setIsRead(false);
n.setCreateTime(new Date());
return notificationRepository.save(n);
}
@Async
@Override
public void notifyReply(Integer toUserId, Integer fromUserId, Integer discussionId, String discussionTitle) {
create(toUserId, fromUserId, "reply",
"有人回复了你的帖子",
"在话题《" + discussionTitle + "》中回复了你",
discussionId, "discussion");
}
@Async
@Override
public void notifyLike(Integer toUserId, Integer fromUserId, Integer postId, Integer discussionId) {
create(toUserId, fromUserId, "like",
"有人赞了你的回复",
null, postId, "post");
}
@Transactional(readOnly = true)
@Override
public long countUnread(Integer userId) {
return notificationRepository.countByUserIdAndIsReadFalse(userId);
}
@Transactional(readOnly = true)
@Override
public Page<Notification> listByUser(Integer userId, int page, int size) {
return notificationRepository.findByUserIdOrderByCreateTimeDesc(
userId, PageRequest.of(page, size));
}
@Transactional
@Override
public void markAllRead(Integer userId) {
notificationRepository.markAllReadByUserId(userId);
}
@Transactional
@Override
public void markOneRead(Integer notificationId, Integer userId) {
notificationRepository.markReadById(notificationId, userId);
}
}
@@ -4,7 +4,9 @@ import com.yaoyuan.jiscuss.common.Node;
import com.yaoyuan.jiscuss.common.PostCommonUtil; import com.yaoyuan.jiscuss.common.PostCommonUtil;
import com.yaoyuan.jiscuss.entity.Post; import com.yaoyuan.jiscuss.entity.Post;
import com.yaoyuan.jiscuss.entity.custom.PostCustom; import com.yaoyuan.jiscuss.entity.custom.PostCustom;
import com.yaoyuan.jiscuss.repository.DiscussionsRepository;
import com.yaoyuan.jiscuss.repository.PostsRepository; import com.yaoyuan.jiscuss.repository.PostsRepository;
import com.yaoyuan.jiscuss.repository.UsersRepository;
import com.yaoyuan.jiscuss.service.IPostsService; import com.yaoyuan.jiscuss.service.IPostsService;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@@ -13,6 +15,7 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Optional; import java.util.Optional;
@@ -23,6 +26,12 @@ public class PostsServiceImpl implements IPostsService {
@Autowired @Autowired
private PostsRepository postsRepository; private PostsRepository postsRepository;
@Autowired
private DiscussionsRepository discussionsRepository;
@Autowired
private UsersRepository usersRepository;
@Transactional(readOnly = true) @Transactional(readOnly = true)
@Override @Override
public List<Post> getAllList() { public List<Post> getAllList() {
@@ -48,17 +57,19 @@ public class PostsServiceImpl implements IPostsService {
@Transactional(readOnly = true) @Transactional(readOnly = true)
@Override @Override
public List findPostCustomById(Integer id) { public List findPostCustomById(Integer id, String sort) {
//查询id为1且parentId为null的评论 // Choose sort order for top-level posts
List<Map<String, Object>> firstposts = postsRepository.findAllByDIdAndparentIdNull(id); List<Map<String, Object>> firstposts = switch (sort == null ? "newest" : sort) {
case "oldest" -> postsRepository.findAllByDIdAndparentIdNullOldest(id);
case "hot" -> postsRepository.findAllByDIdAndparentIdNullHot(id);
default -> postsRepository.findAllByDIdAndparentIdNullNewest(id); // newest (root only, create_time desc)
};
List<PostCustom> firstpostCustomList = PostCommonUtil.getNewPostsObjMap(firstposts); List<PostCustom> firstpostCustomList = PostCommonUtil.getNewPostsObjMap(firstposts);
// List<PostCustom> firstpostCustomListNew = PostCommonUtil.getNewPostsObjCustom(firstpostCustomList);
//查询id为1且parentId不为null的评论 //查询id为1且parentId不为null的评论
List<Map<String, Object>> thenposts = postsRepository.findAllByDIdAndparentIdNotNull(id); List<Map<String, Object>> thenposts = postsRepository.findAllByDIdAndparentIdNotNull(id);
List<PostCustom> thenpostCustomList = PostCommonUtil.getNewPostsObjMap(thenposts); List<PostCustom> thenpostCustomList = PostCommonUtil.getNewPostsObjMap(thenposts);
// List<PostCustom> thenpostCustomListNew = PostCommonUtil.getNewPostsObjCustom(thenpostCustomList);
//新建一个Node集合。 //新建一个Node集合。
ArrayList<Node> nodes = new ArrayList<>(); ArrayList<Node> nodes = new ArrayList<>();
//将第一层评论都添加都Node集合中 //将第一层评论都添加都Node集合中
@@ -72,15 +83,27 @@ public class PostsServiceImpl implements IPostsService {
//打印回复链表 //打印回复链表
Node.show(list); Node.show(list);
// List<Map<String, Object>> posts = postsRepository.findPostCustomById(id);
// List<PostCustom> postCustomList = PostCommonUtil.getNewPostsObjMap(posts);
// List<PostCustom> postCustomListNew = PostCommonUtil.getNewPostsObjCustom(postCustomList);
return list; return list;
} }
@Transactional @Transactional
@Override @Override
public Post insert(Post post) { public Post insert(Post post) {
return postsRepository.save(post); // Auto-assign floor number within the same transaction to ensure consistency
if (post.getDiscussionId() != null) {
int nextNumber = postsRepository.findMaxNumberByDiscussionId(post.getDiscussionId()) + 1;
post.setNumber(nextNumber);
}
Post saved = postsRepository.save(post);
// Maintain discussion comment count and last activity
if (post.getDiscussionId() != null) {
discussionsRepository.incrementCommentCount(post.getDiscussionId(), post.getCreateId(), new Date());
}
// Maintain user comment count
if (post.getCreateId() != null) {
usersRepository.incrementCommentCount(post.getCreateId());
}
return saved;
} }
} }
@@ -146,6 +146,13 @@ public class UsersServiceImpl implements IUsersService {
return usersRepository.findAllById(ids); return usersRepository.findAllById(ids);
} }
@Transactional(readOnly = true)
@Override
public List<User> getTopActiveUsers(int limit) {
return usersRepository.findTop10ActiveUsers(
org.springframework.data.domain.PageRequest.of(0, limit));
}
} }
@@ -0,0 +1,58 @@
package com.yaoyuan.jiscuss.util;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* Lightweight User-Agent parser.
* Extracts a human-readable browser name and major version without
* importing a heavy third-party library.
*
* <p>Detection order matters: Edge must be checked before Chrome, and
* Chrome before Safari, because UA strings commonly contain multiple tokens.
*/
public final class UserAgentUtils {
private UserAgentUtils() {}
private static final Pattern EDGE = Pattern.compile("Edg(?:e|A|iOS)?/([\\d.]+)", Pattern.CASE_INSENSITIVE);
private static final Pattern FIREFOX = Pattern.compile("Firefox/([\\d.]+)", Pattern.CASE_INSENSITIVE);
private static final Pattern CHROME = Pattern.compile("Chrome/([\\d.]+)", Pattern.CASE_INSENSITIVE);
private static final Pattern SAFARI = Pattern.compile("Version/([\\d.]+).*Safari", Pattern.CASE_INSENSITIVE);
private static final Pattern OPERA = Pattern.compile("OPR/([\\d.]+)", Pattern.CASE_INSENSITIVE);
private static final Pattern IE = Pattern.compile("(?:MSIE |Trident/.*rv:)([\\d.]+)", Pattern.CASE_INSENSITIVE);
/**
* Returns a short browser description, e.g. "Chrome 120", "Firefox 121", "Safari 17".
* Returns "未知浏览器" when detection fails.
*
* @param userAgent the raw User-Agent header value
* @return display string, never null
*/
public static String parseBrowser(String userAgent) {
if (userAgent == null || userAgent.isBlank()) {
return "未知浏览器";
}
// Order matters: Edge contains 'Chrome', Chrome contains 'Safari'
String r;
if ((r = match(EDGE, userAgent, "Edge")) != null) return r;
if ((r = match(OPERA, userAgent, "Opera")) != null) return r;
if ((r = match(FIREFOX, userAgent, "Firefox")) != null) return r;
if ((r = match(CHROME, userAgent, "Chrome")) != null) return r;
if ((r = match(SAFARI, userAgent, "Safari")) != null) return r;
if ((r = match(IE, userAgent, "IE")) != null) return r;
return "未知浏览器";
}
private static String match(Pattern pattern, String ua, String name) {
Matcher m = pattern.matcher(ua);
if (m.find()) {
String version = m.group(1);
// Only keep major version number
int dotIdx = version.indexOf('.');
String major = dotIdx > 0 ? version.substring(0, dotIdx) : version;
return name + " " + major;
}
return null;
}
}
@@ -0,0 +1,26 @@
-- V6: Add indexes for high-frequency query columns.
-- All indexes use IF NOT EXISTS for idempotent migrations.
-- post table: most reads filter/sort by discussion_id, parent_id, create_time
CREATE INDEX IF NOT EXISTS idx_post_discussion_id ON post(discussion_id);
CREATE INDEX IF NOT EXISTS idx_post_parent_id ON post(parent_id);
CREATE INDEX IF NOT EXISTS idx_post_create_time ON post(create_time);
CREATE INDEX IF NOT EXISTS idx_post_create_id ON post(create_id);
-- discussion table: sorted by id/create_time/start_time/like_count; joined on start_user_id/last_user_id
CREATE INDEX IF NOT EXISTS idx_discussion_create_time ON discussion(create_time);
CREATE INDEX IF NOT EXISTS idx_discussion_start_time ON discussion(start_time);
CREATE INDEX IF NOT EXISTS idx_discussion_like_count ON discussion(like_count);
CREATE INDEX IF NOT EXISTS idx_discussion_start_user_id ON discussion(start_user_id);
CREATE INDEX IF NOT EXISTS idx_discussion_last_user_id ON discussion(last_user_id);
-- discussiontag table: used in tag-filter queries and cascade deletes
CREATE INDEX IF NOT EXISTS idx_discussiontag_discussion_id ON discussiontag(discussion_id);
CREATE INDEX IF NOT EXISTS idx_discussiontag_tag_id ON discussiontag(tag_id);
-- user table: login and username-lookup path
CREATE INDEX IF NOT EXISTS idx_user_username ON user(username);
-- likecollect table: user activity queries
CREATE INDEX IF NOT EXISTS idx_likecollect_user_id ON likecollect(user_id);
CREATE INDEX IF NOT EXISTS idx_likecollect_discussion_id ON likecollect(discussion_id);
@@ -0,0 +1,5 @@
-- V7: Add view_count to discussion table.
-- Tracks how many times a discussion has been viewed.
ALTER TABLE discussion ADD COLUMN IF NOT EXISTS view_count INTEGER NOT NULL DEFAULT 0;
CREATE INDEX IF NOT EXISTS idx_discussion_view_count ON discussion(view_count);
@@ -0,0 +1,19 @@
-- V8: Add vote (like/dislike) support and IP/browser meta to posts
-- likecollect: add explicit action column ('like' or 'dislike')
ALTER TABLE likecollect ADD COLUMN action VARCHAR(20);
-- discussion: add dislike counter
ALTER TABLE discussion ADD COLUMN dislike_count INTEGER DEFAULT 0;
-- post: add per-post vote counters
ALTER TABLE post ADD COLUMN like_count INTEGER DEFAULT 0;
ALTER TABLE post ADD COLUMN dislike_count INTEGER DEFAULT 0;
-- indexes for vote lookup
CREATE INDEX IF NOT EXISTS idx_likecollect_user_discussion ON likecollect(user_id, discussion_id);
CREATE INDEX IF NOT EXISTS idx_likecollect_user_post ON likecollect(user_id, post_id);
-- post: add IP region and parsed browser name
ALTER TABLE post ADD COLUMN ip_region VARCHAR(100);
ALTER TABLE post ADD COLUMN browser VARCHAR(200);
@@ -0,0 +1,33 @@
-- V9: Add notification and private message support
-- Notification table: system/reply/like alerts to a user
CREATE TABLE IF NOT EXISTS notification (
id INT PRIMARY KEY AUTO_INCREMENT,
user_id INT NOT NULL, -- receiver
from_user_id INT, -- sender (NULL for system notifications)
type VARCHAR(50) NOT NULL, -- 'reply', 'like', 'system'
title VARCHAR(200),
content TEXT,
related_id INT, -- e.g. discussion_id or post_id
related_type VARCHAR(50), -- 'discussion', 'post'
is_read BOOLEAN DEFAULT FALSE,
create_time DATETIME DEFAULT CURRENT_TIMESTAMP
);
CREATE INDEX IF NOT EXISTS idx_notification_user ON notification(user_id);
CREATE INDEX IF NOT EXISTS idx_notification_user_unread ON notification(user_id, is_read);
-- Message table: private messages between users
CREATE TABLE IF NOT EXISTS message (
id INT PRIMARY KEY AUTO_INCREMENT,
sender_id INT NOT NULL,
receiver_id INT NOT NULL,
content TEXT NOT NULL,
is_read BOOLEAN DEFAULT FALSE,
create_time DATETIME DEFAULT CURRENT_TIMESTAMP,
conversation_id VARCHAR(50) NOT NULL -- format: min_max of user IDs
);
CREATE INDEX IF NOT EXISTS idx_message_receiver ON message(receiver_id);
CREATE INDEX IF NOT EXISTS idx_message_conversation ON message(conversation_id, create_time);
CREATE INDEX IF NOT EXISTS idx_message_receiver_unread ON message(receiver_id, is_read);
File diff suppressed because one or more lines are too long
+1
View File
@@ -0,0 +1 @@
#nprogress{pointer-events:none}#nprogress .bar{background:#29d;position:fixed;z-index:1031;top:0;left:0;width:100%;height:2px}#nprogress .peg{display:block;position:absolute;right:0;width:100px;height:100%;box-shadow:0 0 10px #29d,0 0 5px #29d;opacity:1;-webkit-transform:rotate(3deg) translate(0,-4px);-ms-transform:rotate(3deg) translate(0,-4px);transform:rotate(3deg) translate(0,-4px)}#nprogress .spinner{display:block;position:fixed;z-index:1031;top:15px;right:15px}#nprogress .spinner-icon{width:18px;height:18px;box-sizing:border-box;border:2px solid transparent;border-top-color:#29d;border-left-color:#29d;border-radius:50%;-webkit-animation:nprogress-spinner 400ms linear infinite;animation:nprogress-spinner 400ms linear infinite}.nprogress-custom-parent{overflow:hidden;position:relative}.nprogress-custom-parent #nprogress .bar,.nprogress-custom-parent #nprogress .spinner{position:absolute}@-webkit-keyframes nprogress-spinner{0%{-webkit-transform:rotate(0deg)}100%{-webkit-transform:rotate(360deg)}}@keyframes nprogress-spinner{0%{transform:rotate(0deg)}100%{transform:rotate(360deg)}}
+1
View File
@@ -0,0 +1 @@
!function(n,e){"function"==typeof define&&define.amd?define(e):"object"==typeof exports?module.exports=e():n.NProgress=e()}(this,function(){function n(n,e,t){return e>n?e:n>t?t:n}function e(n){return 100*(-1+n)}function t(n,t,r){var i;return i="translate3d"===c.positionUsing?{transform:"translate3d("+e(n)+"%,0,0)"}:"translate"===c.positionUsing?{transform:"translate("+e(n)+"%,0)"}:{"margin-left":e(n)+"%"},i.transition="all "+t+"ms "+r,i}function r(n,e){var t="string"==typeof n?n:o(n);return t.indexOf(" "+e+" ")>=0}function i(n,e){var t=o(n),i=t+e;r(t,e)||(n.className=i.substring(1))}function s(n,e){var t,i=o(n);r(n,e)&&(t=i.replace(" "+e+" "," "),n.className=t.substring(1,t.length-1))}function o(n){return(" "+(n.className||"")+" ").replace(/\s+/gi," ")}function a(n){n&&n.parentNode&&n.parentNode.removeChild(n)}var u={};u.version="0.2.0";var c=u.settings={minimum:.08,easing:"ease",positionUsing:"",speed:200,trickle:!0,trickleRate:.02,trickleSpeed:800,showSpinner:!0,barSelector:'[role="bar"]',spinnerSelector:'[role="spinner"]',parent:"body",template:'<div class="bar" role="bar"><div class="peg"></div></div><div class="spinner" role="spinner"><div class="spinner-icon"></div></div>'};u.configure=function(n){var e,t;for(e in n)t=n[e],void 0!==t&&n.hasOwnProperty(e)&&(c[e]=t);return this},u.status=null,u.set=function(e){var r=u.isStarted();e=n(e,c.minimum,1),u.status=1===e?null:e;var i=u.render(!r),s=i.querySelector(c.barSelector),o=c.speed,a=c.easing;return i.offsetWidth,l(function(n){""===c.positionUsing&&(c.positionUsing=u.getPositioningCSS()),f(s,t(e,o,a)),1===e?(f(i,{transition:"none",opacity:1}),i.offsetWidth,setTimeout(function(){f(i,{transition:"all "+o+"ms linear",opacity:0}),setTimeout(function(){u.remove(),n()},o)},o)):setTimeout(n,o)}),this},u.isStarted=function(){return"number"==typeof u.status},u.start=function(){u.status||u.set(0);var n=function(){setTimeout(function(){u.status&&(u.trickle(),n())},c.trickleSpeed)};return c.trickle&&n(),this},u.done=function(n){return n||u.status?u.inc(.3+.5*Math.random()).set(1):this},u.inc=function(e){var t=u.status;return t?("number"!=typeof e&&(e=(1-t)*n(Math.random()*t,.1,.95)),t=n(t+e,0,.994),u.set(t)):u.start()},u.trickle=function(){return u.inc(Math.random()*c.trickleRate)},function(){var n=0,e=0;u.promise=function(t){return t&&"resolved"!==t.state()?(0===e&&u.start(),n++,e++,t.always(function(){e--,0===e?(n=0,u.done()):u.set((n-e)/n)}),this):this}}(),u.render=function(n){if(u.isRendered())return document.getElementById("nprogress");i(document.documentElement,"nprogress-busy");var t=document.createElement("div");t.id="nprogress",t.innerHTML=c.template;var r,s=t.querySelector(c.barSelector),o=n?"-100":e(u.status||0),l=document.querySelector(c.parent);return f(s,{transition:"all 0 linear",transform:"translate3d("+o+"%,0,0)"}),c.showSpinner||(r=t.querySelector(c.spinnerSelector),r&&a(r)),l!=document.body&&i(l,"nprogress-custom-parent"),l.appendChild(t),t},u.remove=function(){s(document.documentElement,"nprogress-busy"),s(document.querySelector(c.parent),"nprogress-custom-parent");var n=document.getElementById("nprogress");n&&a(n)},u.isRendered=function(){return!!document.getElementById("nprogress")},u.getPositioningCSS=function(){var n=document.body.style,e="WebkitTransform"in n?"Webkit":"MozTransform"in n?"Moz":"msTransform"in n?"ms":"OTransform"in n?"O":"";return e+"Perspective"in n?"translate3d":e+"Transform"in n?"translate":"margin"};var l=function(){function n(){var t=e.shift();t&&t(n)}var e=[];return function(t){e.push(t),1==e.length&&n()}}(),f=function(){function n(n){return n.replace(/^-ms-/,"ms-").replace(/-([\da-z])/gi,function(n,e){return e.toUpperCase()})}function e(n){var e=document.body.style;if(n in e)return n;for(var t,r=i.length,s=n.charAt(0).toUpperCase()+n.slice(1);r--;)if(t=i[r]+s,t in e)return t;return n}function t(t){return t=n(t),s[t]||(s[t]=e(t))}function r(n,e,r){e=t(e),n.style[e]=r}var i=["Webkit","O","Moz","ms"],s={};return function(n,e){var t,i,s=arguments;if(2==s.length)for(t in e)i=e[t],void 0!==i&&e.hasOwnProperty(t)&&r(n,t,i);else r(n,s[1],s[2])}}();return u});
@@ -1,3 +1,73 @@
/* ── CSS custom properties for theme switching ────────────────────────────── */
:root {
--bg-page: #f7f8fa;
--bg-card: #ffffff;
--text-primary: #333333;
--text-secondary: #888888;
--accent: #2185d0;
--border: rgba(34, 36, 38, 0.15);
}
[data-theme="dark"] {
--bg-page: #1b1c1d;
--bg-card: #2d2d2d;
--text-primary: #e0e0e0;
--text-secondary: #999999;
--accent: #6435c9;
--border: rgba(255, 255, 255, 0.1);
}
/* ── Global reset ─────────────────────────────────────────────────────────── */
html, body { margin: 0; padding: 0; }
body { background-color: var(--bg-page) !important; color: var(--text-primary); }
/* ── Sticky header (CSS sticky — works on all pages) ─────────────────────── */
#menu.ui.menu {
position: sticky;
top: 0;
z-index: 999;
margin-top: 0 !important;
margin-bottom: 0 !important;
box-shadow: 0 2px 6px rgba(0,0,0,.08);
}
/* ── Page content spacing ─────────────────────────────────────────────────── */
#container { margin-top: 1.5rem !important; }
/* ── Back-to-top button ───────────────────────────────────────────────────── */
#backToTop {
position: fixed;
bottom: 32px;
right: 32px;
width: 42px;
height: 42px;
border-radius: 50%;
background: var(--accent);
color: #fff;
border: none;
cursor: pointer;
display: none;
align-items: center;
justify-content: center;
font-size: 1.2em;
box-shadow: 0 2px 8px rgba(0,0,0,.2);
z-index: 1000;
transition: opacity .2s;
}
#backToTop:hover { opacity: .85; }
/* Apply card background where Semantic UI uses white */
[data-theme="dark"] .ui.card,
[data-theme="dark"] .ui.segment,
[data-theme="dark"] #context2,
[data-theme="dark"] .ui.menu { background-color: var(--bg-card) !important; color: var(--text-primary) !important; }
[data-theme="dark"] .ui.header,
[data-theme="dark"] .ui.dividing.header { color: var(--text-primary) !important; border-bottom-color: var(--border) !important; }
[data-theme="dark"] a { color: var(--accent) !important; }
/* ── Layout helpers ───────────────────────────────────────────────────────── */
.nullright { .nullright {
float: right; float: right;
} }
+10 -15
View File
@@ -1,30 +1,25 @@
<#--jquery--> <#--NProgress - page load progress bar (local first)-->
<link rel="stylesheet" type="text/css" href="/static/lib/nprogress.min.css"/>
<script src="/static/lib/nprogress.min.js"></script>
<script>if(typeof NProgress !== 'undefined') NProgress.start();</script>
<#--jquery (local first, CDN fallback)-->
<link rel="icon" type="image/png" href="/static/assets/images/logo.png"> <link rel="icon" type="image/png" href="/static/assets/images/logo.png">
<script crossorigin="anonymous" integrity="sha384-vk5WoKIaW/vJyUAd9n/wmopsmNhiy+L2Z+SBxGYnUkunIxVxAv/UtMOhba/xskxh" <script src="/static/lib/jquery.min.js"></script>
src="https://lib.baomitu.com/jquery/3.4.1/jquery.min.js"></script> <script>window.jQuery || document.write('<script src="https://lib.baomitu.com/jquery/3.4.1/jquery.min.js"><\/script>')</script>
<#--semantic-ui--> <#--semantic-ui-->
<link rel="stylesheet" type="text/css" href="/static/semanticui/semantic.css"> <link rel="stylesheet" type="text/css" href="/static/semanticui/semantic.css">
<#-- <script type="text/javascript" src="static/jquery/jquery-3.4.1.min.js"></script>-->
<script type="text/javascript" src="/static/semanticui/semantic.js"></script> <script type="text/javascript" src="/static/semanticui/semantic.js"></script>
<#--<link crossorigin="anonymous" integrity="sha384-ATvSpJEmy1egycrmomcFxVn4Z0A6rfjwlzDQrts/1QRerQhR9EEpEYtdysLpQPuQ"-->
<#-- href="https://lib.baomitu.com/semantic-ui/2.4.1/semantic.min.css" rel="stylesheet">-->
<link rel="stylesheet" type="text/css" href="/static/semanticui/my.css"> <link rel="stylesheet" type="text/css" href="/static/semanticui/my.css">
<#--<script crossorigin="anonymous" integrity="sha384-6urqf2sgCGDfIXcoxTUOVIoQV+jFr/Zuc4O2wCRS6Rnd8w0OJ17C4Oo3PuXu8ZtF"-->
<#-- src="https://lib.baomitu.com/semantic-ui/2.4.1/semantic.min.js"></script>-->
<#--tinymce-->
<script crossorigin="anonymous" integrity="sha384-CpsBIlOAWHuSRRN235sCBzEeKN6hLT6SpOGRkGadKpYj0gDP7+s3Q8pC38z8uGHH"
src="https://lib.baomitu.com/tinymce/5.1.1/tinymce.min.js"></script>
<#--tinymce (CDN)-->
<script src="https://lib.baomitu.com/tinymce/5.1.1/tinymce.min.js"></script>
<#--layx--> <#--layx-->
<link href="/static/layx/layx.min.css?b14794a8a3baf3e8b58e" rel="stylesheet"> <link href="/static/layx/layx.min.css?b14794a8a3baf3e8b58e" rel="stylesheet">
<script type="text/javascript" src="/static/layx/layx.min.js?b14794a8a3baf3e8b58e"></script> <script type="text/javascript" src="/static/layx/layx.min.js?b14794a8a3baf3e8b58e"></script>
<script type="text/javascript" charset="UTF-8" src="/static/js/comm/util.js"></script> <script type="text/javascript" charset="UTF-8" src="/static/js/comm/util.js"></script>
+2 -1
View File
@@ -7,8 +7,8 @@
<div class="three wide column"> <div class="three wide column">
<h4 class="ui header">关于遥远</h4> <h4 class="ui header">关于遥远</h4>
<div class="ui link list"> <div class="ui link list">
<a href="http://yaoyuan.io" class="item">Yaoyuan.io</a>
<a href="http://cyy.im" class="item">CYY.IM</a> <a href="http://cyy.im" class="item">CYY.IM</a>
<a href="http://chuyaoyuan.com" class="item">Chuyaoyuan</a>
</div> </div>
</div> </div>
@@ -45,4 +45,5 @@
</div> </div>
</div> </div>
</div> </div>
<script>if(typeof NProgress !== 'undefined') NProgress.done();</script>
+88 -1
View File
@@ -1,7 +1,7 @@
<div class="ui main menu" id="menu"> <div class="ui main menu" id="menu">
<div class="ui container"> <div class="ui container">
<div href="/" class="header borderless item"> <div href="/" class="header borderless item">
<img class="logo" src="static/assets/images/logo.png"> <img class="logo" src="/static/assets/images/logo.png">
&nbsp;Jiscuss &nbsp;Jiscuss
</div> </div>
<a class=" item borderless" href="/">首页</a> <a class=" item borderless" href="/">首页</a>
@@ -24,6 +24,27 @@
<input type="text" placeholder="搜索"> <input type="text" placeholder="搜索">
</div> </div>
</div> </div>
<div class="item">
<a id="themeToggle" title="切换主题" style="cursor:pointer; font-size:1.2em; color:inherit;">
<i class="moon icon" id="themeIcon"></i>
</a>
</div>
<#if username??>
<div class="item">
<a href="/notifications" title="通知" style="position:relative; cursor:pointer; color:inherit;">
<i class="bell icon"></i>
<span id="headerNotifBadge" class="ui circular mini red label"
style="display:none; position:absolute; top:-4px; right:-8px; font-size:10px; padding:2px 4px;"></span>
</a>
</div>
<div class="item">
<a href="/messages" title="私信" style="position:relative; cursor:pointer; color:inherit;">
<i class="envelope icon"></i>
<span id="headerMsgBadge" class="ui circular mini red label"
style="display:none; position:absolute; top:-4px; right:-8px; font-size:10px; padding:2px 4px;"></span>
</a>
</div>
</#if>
<div class="item" id="userlogin"> <div class="item" id="userlogin">
<#if username??> <#if username??>
<form class="ui large form" action="/logout" id="logoutForm" method="post" style="display: none;"> <form class="ui large form" action="/logout" id="logoutForm" method="post" style="display: none;">
@@ -40,3 +61,69 @@
<script type="text/javascript" charset="UTF-8" src="/static/js/user/header.js"></script> <script type="text/javascript" charset="UTF-8" src="/static/js/user/header.js"></script>
<script>
(function() {
var saved = localStorage.getItem('jiscuss-theme') || 'light';
if (saved === 'dark') { document.documentElement.setAttribute('data-theme', 'dark'); }
document.addEventListener('DOMContentLoaded', function() {
var btn = document.getElementById('themeToggle');
var icon = document.getElementById('themeIcon');
function applyTheme(t) {
if (t === 'dark') {
document.documentElement.setAttribute('data-theme', 'dark');
icon.className = 'sun icon';
} else {
document.documentElement.removeAttribute('data-theme');
icon.className = 'moon icon';
}
}
applyTheme(saved);
if (btn) {
btn.onclick = function() {
var current = localStorage.getItem('jiscuss-theme') || 'light';
var next = current === 'dark' ? 'light' : 'dark';
localStorage.setItem('jiscuss-theme', next);
applyTheme(next);
};
}
// Fetch unread counts and update header badges
function updateBadges() {
$.get('/msg_api/unread-counts', function(resp) {
if (!resp || resp.code !== 10000) return;
var d = resp.data || {};
var notifBadge = document.getElementById('headerNotifBadge');
var msgBadge = document.getElementById('headerMsgBadge');
if (notifBadge) {
if (d.notifications > 0) { notifBadge.textContent = d.notifications > 99 ? '99+' : d.notifications; notifBadge.style.display = ''; }
else { notifBadge.style.display = 'none'; }
}
if (msgBadge) {
if (d.messages > 0) { msgBadge.textContent = d.messages > 99 ? '99+' : d.messages; msgBadge.style.display = ''; }
else { msgBadge.style.display = 'none'; }
}
});
}
if (document.getElementById('headerNotifBadge')) {
updateBadges();
setInterval(updateBadges, 60000); // refresh every 60s
}
// NProgress — stop loading bar when page is ready
if (typeof NProgress !== 'undefined') NProgress.done();
// Back-to-top button
var $top = document.getElementById('backToTop');
if ($top) {
window.addEventListener('scroll', function() {
$top.style.display = window.scrollY > 300 ? 'flex' : 'none';
});
$top.addEventListener('click', function() {
window.scrollTo({ top: 0, behavior: 'smooth' });
});
}
});
})();
</script>
<#-- 全局返回顶部按钮 -->
<button id="backToTop" title="返回顶部"><i class="angle up icon" style="margin:0;"></i></button>
@@ -0,0 +1,114 @@
<!DOCTYPE html>
<html>
<head>
<title>与 ${otherUsername} 的对话 - Jiscuss</title>
<meta name="_csrf" content="${_csrf.token}"/>
<meta name="_csrf_header" content="${_csrf.headerName}"/>
<#include "comm/commjs.ftl"/>
<style>
.msg-bubble { max-width: 65%; padding: 10px 14px; border-radius: 12px; margin: 6px 0; display: inline-block; word-break: break-word; }
.msg-mine { background: #2185d0; color: #fff; border-bottom-right-radius: 2px; }
.msg-other { background: #fff; color: #333; border: 1px solid #e0e0e0; border-bottom-left-radius: 2px; }
.msg-row { display: flex; margin: 4px 0; }
.msg-row.mine { justify-content: flex-end; }
.msg-row.other { justify-content: flex-start; }
.msg-time { font-size: 0.75em; color: #aaa; margin: 2px 8px; align-self: flex-end; }
#chatBox { height: 450px; overflow-y: auto; padding: 16px; background: #f7f8fa; border: 1px solid #e0e0e0; border-radius: 8px; }
#msgInput { resize: none; border-radius: 6px; }
</style>
</head>
<body style="background:#f7f8fa;">
<#include "comm/header.ftl"/>
<div class="ui container" style="margin-top:2em; margin-bottom:4em;">
<div class="ui breadcrumb" style="margin-bottom:1em;">
<a class="section" href="/messages"><i class="envelope icon"></i> 收件箱</a>
<div class="divider"> / </div>
<div class="active section">${otherUsername}</div>
</div>
<h3 class="ui header">${otherUsername}</h3>
<div id="chatBox">
<#if messages?has_content>
<#list messages as msg>
<div class="msg-row <#if msg.senderId == currentUserId>mine<#else>other</#if>">
<#if msg.senderId != currentUserId>
<div class="msg-bubble msg-other">${msg.content}</div>
<span class="msg-time">${msg.createTime?string("HH:mm")}</span>
<#else>
<span class="msg-time">${msg.createTime?string("HH:mm")}</span>
<div class="msg-bubble msg-mine">${msg.content}</div>
</#if>
</div>
</#list>
<#else>
<div style="text-align:center; color:#aaa; padding:60px 0;">暂无消息,发送第一条吧!</div>
</#if>
</div>
<div class="ui form" style="margin-top:1em;">
<div class="field">
<textarea id="msgInput" rows="3" placeholder="输入消息..." style="width:100%;"></textarea>
</div>
<button class="ui primary button" id="sendBtn">
<i class="send icon"></i> 发送
</button>
</div>
</div>
<#include "comm/footer.ftl"/>
<script>
var otherId = ${otherId};
var csrfToken = $('meta[name="_csrf"]').attr('content');
var csrfHeader = $('meta[name="_csrf_header"]').attr('content');
$('#sendBtn').on('click', function() {
var content = $('#msgInput').val().trim();
if (!content) return;
$(this).addClass('loading');
var headers = {};
headers[csrfHeader] = csrfToken;
$.ajax({
url: '/msg_api/messages/send',
type: 'POST',
headers: headers,
data: { receiverId: otherId, content: content },
success: function(resp) {
$('#sendBtn').removeClass('loading');
if (resp && resp.code === 10000) {
$('#msgInput').val('');
// Append new bubble
var now = new Date();
var timeStr = (now.getHours()<10?'0':'')+now.getHours()+':'+(now.getMinutes()<10?'0':'')+now.getMinutes();
var html = '<div class="msg-row mine">' +
'<span class="msg-time">'+timeStr+'</span>' +
'<div class="msg-bubble msg-mine">'+$('<div>').text(content).html()+'</div>' +
'</div>';
$('#chatBox').append(html);
$('#chatBox').scrollTop($('#chatBox')[0].scrollHeight);
} else {
alert(resp.message || '发送失败');
}
},
error: function() {
$('#sendBtn').removeClass('loading');
alert('发送失败,请重试');
}
});
});
// Allow Ctrl+Enter to send
$('#msgInput').on('keydown', function(e) {
if (e.ctrlKey && e.keyCode === 13) { $('#sendBtn').click(); }
});
// Scroll to bottom on load
$(document).ready(function() {
var box = document.getElementById('chatBox');
box.scrollTop = box.scrollHeight;
});
</script>
</body>
</html>
+184 -28
View File
@@ -1,7 +1,7 @@
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<title>主题详情页</title>
<head> <head>
<title>主题详情页</title>
<!-- <link rel="stylesheet" type="text/css" href="static/semanticui/semantic.css"> --> <!-- <link rel="stylesheet" type="text/css" href="static/semanticui/semantic.css"> -->
<!-- <script src="static/jquery/jquery-3.4.1.min.js"></script> --> <!-- <script src="static/jquery/jquery-3.4.1.min.js"></script> -->
<!-- <script src="static/semanticui/semantic.min.js"></script> --> <!-- <script src="static/semanticui/semantic.min.js"></script> -->
@@ -45,13 +45,25 @@
</div> </div>
<div class="ui labeled button" tabindex="0" style=" margin-top: 30px;"> <div class="ui labeled button" tabindex="0" style=" margin-top: 30px;">
<div class="ui red button"> <div class="ui red button" id="likeBtn" onclick="voteDiscussion('like')">
<i class="heart icon"></i> 赞这个主题 <i class="heart icon"></i> 赞这个主题
</div> </div>
<a class="ui basic red left pointing label"> <a class="ui basic red left pointing label" id="likeCount">
1,048 ${discussions.likeCount!0}
</a> </a>
</div> </div>
<div class="ui labeled button" tabindex="0" style="margin-left:8px; margin-top: 30px;">
<div class="ui grey button" id="dislikeBtn" onclick="voteDiscussion('dislike')">
<i class="thumbs down icon"></i> 踩
</div>
<a class="ui basic grey left pointing label" id="dislikeCount">
${discussions.dislikeCount!0}
</a>
</div>
<span style="margin-left:12px; color:#888; font-size:0.9em;">
<i class="eye icon"></i> ${discussions.viewCount!0} 浏览
&nbsp;&nbsp;<i class="comment icon"></i> ${discussions.commentsCount!0} 回复
</span>
<div class="ui feed"> <div class="ui feed">
@@ -86,7 +98,14 @@
</div> </div>
<div class="ui threaded comments"> <div class="ui threaded comments">
<h3 class="ui dividing header">评论区</h3> <h3 class="ui dividing header">
评论区
<div class="ui mini buttons" style="float:right; font-size:0.75em;">
<a class="ui button <#if sort == 'oldest'>active</#if>" href="?id=${discussions.id}&sort=oldest">最早</a>
<a class="ui button <#if sort == 'newest'>active</#if>" href="?id=${discussions.id}&sort=newest">最新</a>
<a class="ui button <#if sort == 'hot'>active</#if>" href="?id=${discussions.id}&sort=hot">最热</a>
</div>
</h3>
<input type="hidden" name="postId" id="postId" value=""/> <input type="hidden" name="postId" id="postId" value=""/>
<!-- 定义遍历方法 --> <!-- 定义遍历方法 -->
@@ -101,15 +120,20 @@
<img src="/static/assets/images/logo.png"> <img src="/static/assets/images/logo.png">
</a> </a>
<div class="content"> <div class="content">
<a class="author">${post.username}</a> <a class="author user-card-trigger" data-user-id="${post.createId!''}">${post.username}</a>
<span style="color:#aaa; font-size:0.8em; margin-left:6px;">#${post.number!''}</span>
<div class="metadata"> <div class="metadata">
<span class="date">${post.createTime}</span> <span class="date">${post.createTime}</span>
<#if post.ipRegion?? && post.ipRegion != ""><span style="margin-left:6px;"><i class="map marker alternate icon"></i>${post.ipRegion}</span></#if>
<#if post.browser?? && post.browser != ""><span style="margin-left:6px;"><i class="chrome icon"></i>${post.browser}</span></#if>
</div> </div>
<div class="text"> <div class="text">
${post.content} ${post.content}
</div> </div>
<div class="actions"> <div class="actions">
<a class="reply" onclick="replyThis('${post.username}', '${post.id}')">回复</a> <a class="reply" onclick="replyThis('${post.username}', '${post.id}')">回复</a>
<a onclick="votePost(${post.id}, 'like')" style="cursor:pointer;"><i class="thumbs up outline icon"></i>${(post.likeCount!0)?c}</a>
<a onclick="votePost(${post.id}, 'dislike')" style="cursor:pointer;"><i class="thumbs down outline icon"></i>${(post.dislikeCount!0)?c}</a>
</div> </div>
</div> </div>
<div class="comments"> <div class="comments">
@@ -123,15 +147,20 @@
<img src="/static/assets/images/logo.png"> <img src="/static/assets/images/logo.png">
</a> </a>
<div class="content"> <div class="content">
<a class="author">${post.username}</a> <a class="author user-card-trigger" data-user-id="${post.createId!''}">${post.username}</a>
<span style="color:#aaa; font-size:0.8em; margin-left:6px;">#${post.number!''}</span>
<div class="metadata"> <div class="metadata">
<span class="date">${post.createTime}</span> <span class="date">${post.createTime}</span>
<#if post.ipRegion?? && post.ipRegion != ""><span style="margin-left:6px;"><i class="map marker alternate icon"></i>${post.ipRegion}</span></#if>
<#if post.browser?? && post.browser != ""><span style="margin-left:6px;"><i class="chrome icon"></i>${post.browser}</span></#if>
</div> </div>
<div class="text"> <div class="text">
${post.content} ${post.content}
</div> </div>
<div class="actions"> <div class="actions">
<a class="reply" onclick="replyThis('${post.username}', '${post.id}')">回复</a> <a class="reply" onclick="replyThis('${post.username}', '${post.id}')">回复</a>
<a onclick="votePost(${post.id}, 'like')" style="cursor:pointer;"><i class="thumbs up outline icon"></i>${(post.likeCount!0)?c}</a>
<a onclick="votePost(${post.id}, 'dislike')" style="cursor:pointer;"><i class="thumbs down outline icon"></i>${(post.dislikeCount!0)?c}</a>
</div> </div>
</div> </div>
</div> </div>
@@ -259,28 +288,23 @@
<div class="mobile only sixteen wide column"> <div class="mobile only sixteen wide column">
<div class="ui segment">Jiscuss手机可见,内容正在编写中,pc端可正常访问</div> <div id="context2" style="padding: 1em; background: #fff; border-radius: 0.28571429rem; border: 1px solid rgba(34, 36, 38, 0.15);">
<div class="ui pagination menu"> <h3 class="ui header"><i class="edit outline icon"></i>${discussions.title}</h3>
<a class="icon item"> <div class="ui main text container">${discussions.content}</div>
<i class="left chevron icon"></i> <div style="margin-top:1em; color:#888; font-size:0.85em;">
</a> <i class="eye icon"></i> ${discussions.viewCount!0} 浏览 &nbsp;
<a class="item"> <i class="comment icon"></i> ${discussions.commentsCount!0} 回复
1 </div>
</a> <div class="ui threaded comments" style="margin-top:1em;">
<a class="item"> <h4 class="ui dividing header">评论区</h4>
2 <@bpTree posts=posts />
</a> <form class="ui reply form" style="margin-top:1em;">
<div class="disabled item"> <div class="field"><textarea id="postContentMobile"></textarea></div>
... <div class="ui blue labeled submit icon button" onclick="addPostMobile()">
<i class="icon edit"></i> 添加评论
</div>
</form>
</div> </div>
<a class="item">
10
</a>
<a class="item">
11
</a>
<a class="icon item"> <i class="right chevron icon"></i>
</a>
</div> </div>
</div> </div>
@@ -299,10 +323,142 @@
console.log('已经登陆:' + username); console.log('已经登陆:' + username);
</#if> </#if>
setDiscussionsId('${discussions.id}'); setDiscussionsId('${discussions.id}');
// User card — custom fixed-position tooltip (more reliable than Semantic UI popup)
var cardCache = {};
var $card = $('<div id="jUserCard" style="position:fixed;background:#fff;border:1px solid #ddd;border-radius:6px;padding:12px 16px;box-shadow:0 4px 16px rgba(0,0,0,.15);z-index:9999;min-width:180px;display:none;"></div>').appendTo('body');
function showCard(u, x, y) {
$card.html(
'<div style="font-weight:700;font-size:1em;margin-bottom:4px;">' + (u.username || '') + '</div>' +
'<div style="color:#888;font-size:.88em;">发帖: ' + (u.discussionsCount || 0) +
'&nbsp;&nbsp;回复: ' + (u.commentsCount || 0) + '</div>' +
'<div style="margin-top:8px;"><a class="open-msg-modal" data-uid="' + u.id + '" data-uname="' + (u.username||'') + '" style="font-size:.85em;color:#2185d0;cursor:pointer;"><i class="envelope icon"></i>发私信</a></div>'
).css({ left: x + 14, top: y + 14 }).show();
}
$(document).on('mouseenter', '.user-card-trigger', function(e) {
var userId = $(this).data('user-id');
if (!userId) return;
if (cardCache[userId]) { showCard(cardCache[userId], e.clientX, e.clientY); return; }
$.getJSON('/msg_api/user-card/' + userId, function(res) {
if (res && res.code === 10000 && res.data) {
cardCache[userId] = res.data;
showCard(res.data, e.clientX, e.clientY);
}
});
}).on('mousemove', '.user-card-trigger', function(e) {
if ($card.is(':visible')) $card.css({ left: e.clientX + 14, top: e.clientY + 14 });
}).on('mouseleave', '.user-card-trigger', function() {
// Delay hide so user can click links inside card
setTimeout(function() {
if (!$card.is(':hover')) $card.hide();
}, 300);
});
$card.on('mouseleave', function() { $card.hide(); });
}); });
function voteDiscussion(action) {
var token = $("meta[name='_csrf']").attr("content");
var header = $("meta[name='_csrf_header']").attr("content");
$.ajax({
url: '/api/discussions/${discussions.id}/vote?action=' + action,
type: 'POST',
beforeSend: function(xhr) { xhr.setRequestHeader(header, token); },
success: function(res) {
if (res.code === 10000) {
location.reload();
} else {
alert(res.msg || '操作失败,请先登录');
}
},
error: function() { alert('请先登录'); }
});
}
function votePost(postId, action) {
var token = $("meta[name='_csrf']").attr("content");
var header = $("meta[name='_csrf_header']").attr("content");
$.ajax({
url: '/api/posts/' + postId + '/vote?action=' + action,
type: 'POST',
beforeSend: function(xhr) { xhr.setRequestHeader(header, token); },
success: function(res) {
if (res.code === 10000) {
location.reload();
} else {
alert(res.msg || '操作失败,请先登录');
}
},
error: function() { alert('请先登录'); }
});
}
</script> </script>
<script type="text/javascript" charset="UTF-8" src="/static/js/user/discussions.js"></script> <script type="text/javascript" charset="UTF-8" src="/static/js/user/discussions.js"></script>
<#-- 私信弹窗 Modal -->
<div class="ui small modal" id="sendMsgModal">
<div class="header"><i class="envelope icon"></i> 发送私信给 <span id="msgModalUsername"></span></div>
<div class="content">
<div class="ui form">
<div class="field">
<textarea id="msgModalContent" rows="4" placeholder="输入消息内容..." style="resize:none;"></textarea>
</div>
<div id="msgModalError" class="ui red message" style="display:none;"></div>
</div>
</div>
<div class="actions">
<div class="ui cancel button">取消</div>
<div class="ui primary button" id="msgModalSendBtn">
<i class="send icon"></i>发送
</div>
</div>
</div>
<script>
var _msgReceiverId = null;
var _msgCsrfToken = $('meta[name="_csrf"]').attr('content');
var _msgCsrfHeader = $('meta[name="_csrf_header"]').attr('content');
// Open modal when user clicks 发私信 in user card
$(document).on('click', '.open-msg-modal', function() {
_msgReceiverId = $(this).data('uid');
var uname = $(this).data('uname');
$('#msgModalUsername').text(uname);
$('#msgModalContent').val('');
$('#msgModalError').hide();
$('#jUserCard').hide();
$('#sendMsgModal').modal('show');
});
$('#msgModalSendBtn').on('click', function() {
var content = $('#msgModalContent').val().trim();
if (!content) { $('#msgModalError').text('消息内容不能为空').show(); return; }
var $btn = $(this).addClass('loading disabled');
var headers = {};
headers[_msgCsrfHeader] = _msgCsrfToken;
$.ajax({
url: '/msg_api/messages/send',
type: 'POST',
headers: headers,
data: { receiverId: _msgReceiverId, content: content },
success: function(resp) {
$btn.removeClass('loading disabled');
if (resp && resp.code === 10000) {
$('#sendMsgModal').modal('hide');
massage('私信发送成功!', 'success', '');
} else {
$('#msgModalError').text((resp && resp.msg) || '发送失败,请重试').show();
}
},
error: function() {
$btn.removeClass('loading disabled');
$('#msgModalError').text('请求失败,请确认已登录').show();
}
});
});
</script>
</body> </body>
</html> </html>
+82 -79
View File
@@ -1,7 +1,7 @@
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<title>Jiscuss Demo</title>
<head> <head>
<title>Jiscuss Demo</title>
<!-- default header name is X-CSRF-TOKEN --> <!-- default header name is X-CSRF-TOKEN -->
<meta name="_csrf" content="${_csrf.token}"/> <meta name="_csrf" content="${_csrf.token}"/>
<meta name="_csrf_header" content="${_csrf.headerName}"/> <meta name="_csrf_header" content="${_csrf.headerName}"/>
@@ -226,33 +226,27 @@
</div> </div>
</div> </div>
<div class="ui card black "> <div class="ui card">
<div class="content"> <div class="content">
<div class="header">预留功能</div> <div class="header">🏆 活跃用户排行</div>
</div> </div>
<div class="content"> <div class="content">
<h4 class="ui sub header">Jiscuss</h4> <div class="ui middle aligned divided list">
<div class="ui small feed"> <#if topUsers?? && topUsers?size gt 0>
<div class="event"> <#list topUsers as u>
<div class="content"> <div class="item">
<div class="summary"> <img class="ui avatar image" src="/static/assets/images/logo.png">
<a>Jiscuss</a> 会持续更新, <a>Jiscuss</a> 将一直更新完善,感谢支持! <div class="content">
<a class="header">${u.username}</a>
<div class="description">${u.commentsCount!0} 回复</div>
</div> </div>
</div> </div>
</div> </#list>
<#else>
<div class="event"> <div class="item" style="color:#aaa;">暂无数据</div>
<div class="content"> </#if>
<div class="summary">
<a>2019</a> 测试内容
</div>
</div>
</div>
</div> </div>
</div> </div>
<div class="extra content">
<button class="ui button">预留按钮</button>
</div>
</div> </div>
@@ -347,10 +341,13 @@
</div> </div>
<div class="nullright meta"> <div class="nullright meta">
<a class="like "> <a class="like ">
<i class="like icon"></i> ${discussions.likeCount} 喜欢 <i class="like icon"></i> ${discussions.likeCount!0} 喜欢
</a> </a>
<a class="comment "> <a class="comment ">
<i class="comment icon"></i> ${discussions.commentsCount} 回复 <i class="comment icon"></i> ${discussions.commentsCount!0} 回复
</a>
<a class="comment ">
<i class="eye icon"></i> ${discussions.viewCount!0} 浏览
</a> </a>
</div> </div>
</div> </div>
@@ -397,10 +394,13 @@
</div> </div>
<div class="nullright meta"> <div class="nullright meta">
<a class="like "> <a class="like ">
<i class="like icon"></i> ${discussions.likeCount} 喜欢 <i class="like icon"></i> ${discussions.likeCount!0} 喜欢
</a> </a>
<a class="comment "> <a class="comment ">
<i class="comment icon"></i> ${discussions.commentsCount} 回复 <i class="comment icon"></i> ${discussions.commentsCount!0} 回复
</a>
<a class="comment ">
<i class="eye icon"></i> ${discussions.viewCount!0} 浏览
</a> </a>
</div> </div>
</div> </div>
@@ -446,10 +446,13 @@
</div> </div>
<div class="nullright meta"> <div class="nullright meta">
<a class="like "> <a class="like ">
<i class="like icon"></i> ${discussions.likeCount} 喜欢 <i class="like icon"></i> ${discussions.likeCount!0} 喜欢
</a> </a>
<a class="comment "> <a class="comment ">
<i class="comment icon"></i> ${discussions.commentsCount} 回复 <i class="comment icon"></i> ${discussions.commentsCount!0} 回复
</a>
<a class="comment ">
<i class="eye icon"></i> ${discussions.viewCount!0} 浏览
</a> </a>
</div> </div>
</div> </div>
@@ -461,68 +464,68 @@
</div> </div>
<#-- Pagination: preserves tag and type query parameters -->
<div class="ui borderless menu"> <div class="ui borderless menu">
<a class="icon item" id="upPage"> <#assign baseUrl = "/?tag=" + tag + "&type=" + type>
<i class="left chevron icon"></i> <#if pageNum gt 1>
</a> <a class="icon item" href="${baseUrl}&pageNum=${pageNum - 1}">
<i class="left chevron icon"></i>
</a>
<#else>
<div class="disabled icon item"><i class="left chevron icon"></i></div>
</#if>
<#list pageDiscussions as page> <#list pageDiscussions as page>
<#if page == pageNum && !(username)??> <#assign pageInt = page?number>
<a class="item" style=" background-color: #7d827d;" href="/?pageNum=${page}"> <#if pageInt == pageNum>
${page} <a class="active item" href="${baseUrl}&pageNum=${page}">${page}</a>
</a> <#else>
</#if> <a class="item" href="${baseUrl}&pageNum=${page}">${page}</a>
<#if page != pageNum && !(username)??>
<a class="item" href="/?pageNum=${page}">
${page}
</a>
</#if>
<#if page == pageNum && username??>
<a class="item" style=" background-color: #7d827d;" href="/main?pageNum=${page}">
${page}
</a>
</#if>
<#if page != pageNum && username??>
<a class="item" href="/main?pageNum=${page}">
${page}
</a>
</#if> </#if>
</#list> </#list>
<a class="icon item" id="nextPage"> <i class="right chevron icon"></i> <#if pageNum lt pageTotalPages>
</a> <a class="icon item" href="${baseUrl}&pageNum=${pageNum + 1}">
<i class="right chevron icon"></i>
</a>
<#else>
<div class="disabled icon item"><i class="right chevron icon"></i></div>
</#if>
</div> </div>
<!--pager-->
<#--<div class="ui borderless menu">
<ul class="pagination">
<#import "./comm/page.ftl" as page />
<@page.fpage page=pageNum pagesize=pageSize totalpages=pageTotalPages totalrecords=pageTotal url="/" />
</ul>
</div>-->
</div> </div>
<div class="mobile only sixteen wide column"> <div class="mobile only sixteen wide column">
<div class="ui segment">Jiscuss手机可见,内容正在编写中,pc端可正常访问</div> <div class="ui large feed">
<#list allDiscussions as discussions>
<div class="event">
<div class="content">
<div class="summary">
<a href="/getdiscussionsbyid?id=${discussions.id}">
${discussions.title}
</a>
<div class="date">${discussions.startTime}</div>
</div>
<div class="meta">
<a><b>${discussions.username}</b></a>&nbsp;•&nbsp;
<i class="comment icon"></i>${discussions.commentsCount!0} 回复&nbsp;
<i class="eye icon"></i>${discussions.viewCount!0} 浏览
</div>
</div>
</div>
<div class="ui fitted divider"></div>
</#list>
</div>
<div class="ui borderless menu"> <div class="ui borderless menu">
<a class="icon item"> <#if pageNum gt 1>
<i class="left chevron icon"></i> <a class="icon item" href="${baseUrl}&pageNum=${pageNum - 1}"><i class="left chevron icon"></i></a>
</a> <#else>
<a class="item"> <div class="disabled icon item"><i class="left chevron icon"></i></div>
1 </#if>
</a> <span class="item">${pageNum} / ${pageTotalPages}</span>
<a class="item"> <#if pageNum lt pageTotalPages>
2 <a class="icon item" href="${baseUrl}&pageNum=${pageNum + 1}"><i class="right chevron icon"></i></a>
</a> <#else>
<div class="disabled item"> <div class="disabled icon item"><i class="right chevron icon"></i></div>
... </#if>
</div>
<a class="item">
10
</a>
<a class="item">
11
</a>
<a class="icon item"> <i class="right chevron icon"></i>
</a>
</div> </div>
</div> </div>
+1 -1
View File
@@ -1,7 +1,7 @@
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<title>Jiscuss Demo</title>
<head> <head>
<title>Jiscuss Demo</title>
<#include "comm/commjs.ftl"/> <#include "comm/commjs.ftl"/>
<style type="text/css"> <style type="text/css">
body { body {
+59
View File
@@ -0,0 +1,59 @@
<!DOCTYPE html>
<html>
<head>
<title>私信收件箱 - Jiscuss</title>
<meta name="_csrf" content="${_csrf.token}"/>
<meta name="_csrf_header" content="${_csrf.headerName}"/>
<#include "comm/commjs.ftl"/>
</head>
<body style="background:#f7f8fa;">
<#include "comm/header.ftl"/>
<div class="ui container" style="margin-top:2em; margin-bottom:4em;">
<h2 class="ui header">
<i class="envelope icon"></i>
<div class="content">私信收件箱
<#if unreadMsgCount?? && (unreadMsgCount > 0)>
<span class="ui mini red label">${unreadMsgCount} 未读</span>
</#if>
</div>
</h2>
<div class="ui divider"></div>
<#if inboxItems?has_content>
<div class="ui relaxed divided list">
<#list inboxItems as item>
<a class="item" href="/messages/${item.otherId}"
style="padding:1em 0; display:flex; align-items:center; gap:1em; color:inherit; text-decoration:none; cursor:pointer;">
<div class="ui circular label"
style="min-width:40px;height:40px;line-height:40px;text-align:center;font-size:1.1em;background:#2185d0;color:#fff;">
${(item.otherUsername?has_content)?then(item.otherUsername?substring(0,1)?upper_case, "?")}
</div>
<div style="flex:1; overflow:hidden;">
<div style="font-weight:bold;">${item.otherUsername}</div>
<div style="color:#888; font-size:0.9em; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; max-width:450px;">
${item.lastContent}
</div>
</div>
<div style="color:#aaa; font-size:0.85em; white-space:nowrap;">
<#if item.lastTime??>${item.lastTime?string("MM-dd HH:mm")}</#if>
</div>
<#if item.hasUnread>
<span class="ui mini red label">未读</span>
</#if>
</a>
</#list>
</div>
<#else>
<div class="ui placeholder segment">
<div class="ui icon header">
<i class="envelope open outline icon"></i>
暂无私信
</div>
</div>
</#if>
</div>
<#include "comm/footer.ftl"/>
</body>
</html>
+1 -1
View File
@@ -1,7 +1,7 @@
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<title>新建主题页</title>
<head> <head>
<title>新建主题页</title>
<!-- <link rel="stylesheet" type="text/css" href="static/semanticui/semantic.css"> --> <!-- <link rel="stylesheet" type="text/css" href="static/semanticui/semantic.css"> -->
<!-- <script src="static/jquery/jquery-3.4.1.min.js"></script> --> <!-- <script src="static/jquery/jquery-3.4.1.min.js"></script> -->
<!-- <script src="static/semanticui/semantic.min.js"></script> --> <!-- <script src="static/semanticui/semantic.min.js"></script> -->
+1 -1
View File
@@ -1,7 +1,7 @@
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<title>新建标签页</title>
<head> <head>
<title>新建标签页</title>
<!-- <link rel="stylesheet" type="text/css" href="static/semanticui/semantic.css"> --> <!-- <link rel="stylesheet" type="text/css" href="static/semanticui/semantic.css"> -->
<!-- <script src="static/jquery/jquery-3.4.1.min.js"></script> --> <!-- <script src="static/jquery/jquery-3.4.1.min.js"></script> -->
<!-- <script src="static/semanticui/semantic.min.js"></script> --> <!-- <script src="static/semanticui/semantic.min.js"></script> -->
@@ -0,0 +1,77 @@
<!DOCTYPE html>
<html>
<head>
<title>通知 - Jiscuss</title>
<meta name="_csrf" content="${_csrf.token}"/>
<meta name="_csrf_header" content="${_csrf.headerName}"/>
<#include "comm/commjs.ftl"/>
</head>
<body style="background:#f7f8fa;">
<#include "comm/header.ftl"/>
<div class="ui container" style="margin-top:2em; margin-bottom:4em;">
<h2 class="ui header">
<i class="bell icon"></i>
<div class="content">通知</div>
</h2>
<div class="ui divider"></div>
<#if notifications?has_content>
<div class="ui feed" style="background:#fff; border-radius:8px; padding:1em;">
<#list notifications as notif>
<div class="event" style="padding:1em 0; border-bottom:1px solid #f0f0f0;">
<div class="label" style="float:left; margin-right:1em;">
<#if notif.type == "reply">
<i class="reply blue icon" style="font-size:1.5em;"></i>
<#elseif notif.type == "like">
<i class="heart red icon" style="font-size:1.5em;"></i>
<#else>
<i class="info circle grey icon" style="font-size:1.5em;"></i>
</#if>
</div>
<div class="content" style="margin-left:3em;">
<div class="summary">
<#if fromUsernames?has_content && notif?index < fromUsernames?size>
<strong>${fromUsernames[notif?index]}</strong>
</#if>
${notif.title!"通知"}
<#if notif.relatedId?? && notif.relatedType?? && notif.relatedType == "discussion">
&nbsp;<a href="/getdiscussionsbyid?id=${notif.relatedId}">查看帖子</a>
<#elseif notif.relatedId?? && notif.relatedType?? && notif.relatedType == "post">
&nbsp;<a href="#">查看回复</a>
</#if>
</div>
<#if notif.content??>
<div class="extra text" style="color:#666; margin-top:4px;">${notif.content}</div>
</#if>
<div class="date" style="color:#aaa; font-size:0.85em; margin-top:4px;">
<#if notif.createTime??>${notif.createTime?string("yyyy-MM-dd HH:mm")}</#if>
</div>
</div>
</div>
</#list>
</div>
<#if (totalPages > 1)>
<div class="ui center aligned basic segment">
<div class="ui pagination menu">
<#list 0..(totalPages-1) as p>
<a class="item <#if p == currentPage>active</#if>" href="/notifications?page=${p}">${p+1}</a>
</#list>
</div>
</div>
</#if>
<#else>
<div class="ui placeholder segment">
<div class="ui icon header">
<i class="bell slash outline icon"></i>
暂无通知
</div>
</div>
</#if>
</div>
<#include "comm/footer.ftl"/>
</body>
</html>
+1 -1
View File
@@ -1,7 +1,7 @@
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<title>Jiscuss Demo</title>
<head> <head>
<title>Jiscuss Demo</title>
<#include "comm/commjs.ftl"/> <#include "comm/commjs.ftl"/>
<style type="text/css"> <style type="text/css">
+131 -97
View File
@@ -1,118 +1,152 @@
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<title>用户详情页</title>
<head> <head>
<!-- <link rel="stylesheet" type="text/css" href="static/semanticui/semantic.css"> --> <title>${username!}的个人主页 - Jiscuss</title>
<!-- <script src="static/jquery/jquery-3.4.1.min.js"></script> -->
<!-- <script src="static/semanticui/semantic.min.js"></script> -->
<meta name="_csrf" content="${_csrf.token}"/> <meta name="_csrf" content="${_csrf.token}"/>
<meta name="_csrf_header" content="${_csrf.headerName}"/> <meta name="_csrf_header" content="${_csrf.headerName}"/>
<#include "comm/commjs.ftl"/> <#include "comm/commjs.ftl"/>
<style>
.profile-card { background:#fff; border-radius:10px; padding:24px; box-shadow:0 1px 4px rgba(0,0,0,.08); margin-bottom:1.5em; }
.profile-stat { text-align:center; }
.profile-stat .number { font-size:1.6em; font-weight:bold; color:var(--color-primary,#2185d0); }
.profile-stat .label2 { color:#888; font-size:0.85em; }
.tab-content { background:#fff; border-radius:8px; padding:1.2em; min-height:200px; }
</style>
</head> </head>
<body style=" background: #f7f8fa;"> <body style="background:#f7f8fa;">
<#include "comm/header.ftl"/> <#include "comm/header.ftl"/>
<div class="ui container" id="container"> <div class="ui container" style="margin-top:2em; margin-bottom:4em;">
<h1>${username}的个人主页</h1> <div class="ui grid stackable">
<#-- Left: profile info -->
<h2 class="ui dividing header">详情</h2> <div class="four wide column">
<div class="profile-card" style="text-align:center;">
<div class="ui vertical stripe segment"> <div class="ui circular image" style="width:80px;height:80px;margin:0 auto 1em;">
<#-- <div class="ui middle aligned stackable grid container">--> <#if userEntity?? && userEntity.avatar??>
<div class="ui internally celled grid"> <img src="${userEntity.avatar}" style="width:80px;height:80px;object-fit:cover;border-radius:50%;">
<div class="row"> <#else>
<div class="eight wide column"> <div style="width:80px;height:80px;border-radius:50%;background:#2185d0;color:#fff;font-size:2em;line-height:80px;text-align:center;">
<div class="ui secondary menu"> ${(username!"")?substring(0,1)?upper_case}
<a class="item ${discussion}" href="/user?type=discussion">主题</a>
<a class="item ${change}" href="/user?type=change">动态</a>
<a class="item ${like}" href="/user?type=like">喜欢收藏</a>
</div>
<div class="ui bottom attached tab segment ${discussion}">
主题...
</div>
<div class="ui bottom attached tab segment ${change}">
动态...
</div>
<div class="ui bottom attached tab segment ${like}">
喜欢收藏...
</div>
</div>
<div class="six wide right floated column">
<div class="ui link cards">
<div class="card">
<div class="image">
<img src="static/assets/images/logo.png">
</div>
<div class="content">
<div class="header">Matt Giampietro</div>
<div class="meta">
<a>Friends</a>
</div>
<div class="description">
Matthew is an interior designer living in New York.
</div>
</div>
<div class="extra content">
<span class="right floated">
Joined in 2013
</span>
<span>
<i class="user icon"></i>
75 Friends
</span>
</div>
</div> </div>
</#if>
</div>
<div style="font-size:1.2em; font-weight:bold;">${username!}</div>
<#if userEntity?? && userEntity.realname??>
<div style="color:#888; font-size:0.9em;">${userEntity.realname}</div>
</#if>
<#if userEntity?? && userEntity.joinTime??>
<div style="color:#aaa; font-size:0.8em; margin-top:4px;">
加入于 ${userEntity.joinTime?string("yyyy-MM-dd")}
</div>
</#if>
</div>
<div class="profile-card">
<div class="ui three column grid" style="text-align:center;">
<div class="column profile-stat">
<div class="number">${liveDiscCount!0}</div>
<div class="label2">发帖</div>
</div>
<div class="column profile-stat">
<div class="number">${liveReplyCount!0}</div>
<div class="label2">回复</div>
</div>
<div class="column profile-stat">
<div class="number">${(userEntity.level)!1}</div>
<div class="label2">等级</div>
</div> </div>
</div> </div>
</div> </div>
<div class="row"> </div>
<div class="center aligned column">
<button class="ui basic button" id="userButton"> <#-- Right: tabs -->
<i class="icon hand peace outline"></i> <div class="twelve wide column">
小按钮·点下试试 <div class="ui pointing secondary menu">
</button> <a class="item <#if type == 'discussion'>active</#if>" href="/user?type=discussion">
</div> <i class="list icon"></i>主题
</a>
<a class="item <#if type == 'reply'>active</#if>" href="/user?type=reply">
<i class="comment icon"></i>回复
</a>
<a class="item <#if type == 'like'>active</#if>" href="/user?type=like">
<i class="heart icon"></i>点赞
</a>
</div>
<div class="tab-content">
<#if type == 'discussion'>
<#if discussions?has_content>
<div class="ui divided list">
<#list discussions as d>
<div class="item" style="padding:10px 0; display:flex; justify-content:space-between; align-items:center;">
<div>
<a href="/getdiscussionsbyid?id=${d.id}" style="font-weight:500;">${d.title}</a>
<div style="color:#aaa; font-size:0.8em; margin-top:2px;">
<#if d.startTime??>${d.startTime?string("yyyy-MM-dd")}</#if>
</div>
</div>
<div style="color:#aaa; font-size:0.85em; white-space:nowrap; margin-left:1em;">
<i class="comment outline icon"></i>${(d.commentsCount)!0}
&nbsp;<i class="eye icon"></i>${(d.viewCount)!0}
</div>
</div>
</#list>
</div>
<#else>
<div class="ui placeholder segment" style="border:none; box-shadow:none;">
<div class="ui icon header"><i class="file outline icon"></i>暂无发帖记录</div>
</div>
</#if>
<#elseif type == 'reply'>
<#if posts?has_content>
<div class="ui divided list">
<#list posts as p>
<div class="item" style="padding:10px 0;">
<div style="color:#888; font-size:0.85em; margin-bottom:4px;">
<#if discTitles?has_content && p?index < discTitles?size>
回复了 <a href="/getdiscussionsbyid?id=${p.discussionId!0}">${discTitles[p?index]}</a>
</#if>
&nbsp;·&nbsp;
<#if p.createTime??>${p.createTime?string("MM-dd HH:mm")}</#if>
</div>
<div style="color:#333;"><#if (p.content?length > 150)>${p.content?html?substring(0, 150)}…<#else>${p.content?html}</#if></div>
</div>
</#list>
</div>
<#else>
<div class="ui placeholder segment" style="border:none; box-shadow:none;">
<div class="ui icon header"><i class="comment outline icon"></i>暂无回复记录</div>
</div>
</#if>
<#elseif type == 'like'>
<#if likedDiscussions?has_content>
<div class="ui divided list">
<#list likedDiscussions as d>
<div class="item" style="padding:10px 0; display:flex; justify-content:space-between; align-items:center;">
<div>
<a href="/getdiscussionsbyid?id=${d.id}" style="font-weight:500;">${d.title}</a>
<div style="color:#aaa; font-size:0.8em;">
<#if d.startTime??>${d.startTime?string("yyyy-MM-dd")}</#if>
</div>
</div>
<div style="color:#aaa; font-size:0.85em; white-space:nowrap; margin-left:1em;">
<i class="heart red icon"></i>${(d.likeCount)!0}
</div>
</div>
</#list>
</div>
<#else>
<div class="ui placeholder segment" style="border:none; box-shadow:none;">
<div class="ui icon header"><i class="heart outline icon"></i>暂无点赞记录</div>
</div>
</#if>
</#if>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
<#include "comm/footer.ftl"/> <#include "comm/footer.ftl"/>
<#-- <div class="ui bottom vertical inverted sidebar labeled icon menu" id="userButtonsidebar">-->
<div class="ui bottom item three labeled icon sidebar menu scale down" id="userButtonsidebar">
<#-- <div class="ui bottom demo inverted nine item labeled icon sidebar menu scale down visible" style="">-->
<a class="item">
<i class="home icon"></i>
主题
</a>
<a class="item">
<i class="block layout icon"></i>
动态
</a>
<a class="item">
<i class="smile icon"></i>
喜欢收藏
</a>
</div>
<script type="text/javascript">
$(document).ready(function () {
<#if username??>
setusername('${username}');
console.log('已经登陆:' + username);
</#if>
<#--setDiscussionsId('${discussions.id}');-->
$('#userTab')
.tab()
;
});
</script>
<script type="text/javascript" charset="UTF-8" src="/static/js/user/user.js"></script>
</body> </body>
</html> </html>