Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

新增天气卡片 #151

Merged
merged 2 commits into from
Oct 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -905,7 +905,52 @@ public void addChatRoomMsg(final RequestContext context) {
} catch (Exception e) {
LOGGER.log(Level.INFO, "User " + userName + " failed to send a red packet.");
}
} else if (content.startsWith("[setdiscuss]") && content.endsWith("[/setdiscuss]")) {
} else if (content.startsWith("[weather]") && content.endsWith("[/weather]")){
String weatherString = content.replaceAll("^\\[weather\\]", "").replaceAll("\\[/weather\\]$", "");

JSONObject weatherJSON = new JSONObject();
// 加活跃
incLiveness(userId);
// 聊天室内容保存到数据库
final Transaction transaction = chatRoomRepository.beginTransaction();
try {
msg.put(Common.CONTENT, weatherString);
String oId = chatRoomRepository.add(new JSONObject().put("content", msg.toString()));
msg.put("oId", oId);
} catch (RepositoryException e) {
LOGGER.log(Level.ERROR, "Cannot save ChatRoom message to the database.", e);
}
transaction.commit();
msg = msg.put("md", msg.optString(Common.CONTENT)).put(Common.CONTENT, processMarkdown(msg.optString(Common.CONTENT)));
final JSONObject pushMsg = JSONs.clone(msg);
pushMsg.put(Common.TIME, new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(msg.optLong(Common.TIME)));
ChatroomChannel.notifyChat(pushMsg);

context.renderJSON(StatusCodes.SUCC);

try {
final List<JSONObject> atUsers = atUsers(msg.optString(Common.CONTENT), userName);
if (Objects.nonNull(atUsers) && !atUsers.isEmpty()) {
for (JSONObject user : atUsers) {
final JSONObject notification = new JSONObject();
notification.put(Notification.NOTIFICATION_USER_ID, user.optString("oId"));
notification.put(Notification.NOTIFICATION_DATA_ID, msg.optString("oId"));
notificationMgmtService.addChatRoomAtNotification(notification);
}
}
} catch (Exception e) {
LOGGER.log(Level.ERROR, "notify user failed", e);
}

try {
final JSONObject user = userQueryService.getUser(userId);
user.put(UserExt.USER_LATEST_CMT_TIME, System.currentTimeMillis());
userMgmtService.updateUser(userId, user);
} catch (final Exception e) {
LOGGER.log(Level.ERROR, "Update user latest comment time failed", e);
}

} else if (content.startsWith("[setdiscuss]") && content.endsWith("[/setdiscuss]")) {
// 扣钱
final boolean succ = null != pointtransferMgmtService.transfer(userId, Pointtransfer.ID_C_SYS,
Pointtransfer.TRANSFER_TYPE_C_ACTIVITY_SET_DISCUSS,
Expand Down
Loading
Loading