use of net.jforum.entities.UserSession in project jforum2 by rafaelsteil.
the class PrivateMessageAction method sendSave.
public void sendSave() {
if (!SessionFacade.isLogged()) {
this.setTemplateName(ViewCommon.contextToLogin());
return;
}
UserDAO userDao = DataAccessDriver.getInstance().newUserDAO();
String toUserIdStr = this.request.getParameter("toUserId");
String toUsername = this.request.getParameter("toUsername");
int toUserId = -1;
// inserted the username by hand in the form's field
if (toUserIdStr == null || "".equals(toUserIdStr.trim())) {
List l = userDao.findByName(toUsername, true);
if (l.size() > 0) {
User u = (User) l.get(0);
toUserId = u.getId();
}
} else {
toUserId = Integer.parseInt(toUserIdStr);
}
// We failed to get the user id?
if (toUserId == -1) {
this.setTemplateName(TemplateKeys.PM_SENDSAVE_USER_NOTFOUND);
this.context.put("message", I18n.getMessage("PrivateMessage.userIdNotFound"));
return;
}
PrivateMessage pm = new PrivateMessage();
pm.setPost(PostCommon.fillPostFromRequest());
// Sender
User fromUser = new User();
fromUser.setId(SessionFacade.getUserSession().getUserId());
pm.setFromUser(fromUser);
// Recipient
User toUser = userDao.selectById(toUserId);
pm.setToUser(toUser);
boolean preview = ("1".equals(this.request.getParameter("preview")));
if (!preview) {
DataAccessDriver.getInstance().newPrivateMessageDAO().send(pm);
this.setTemplateName(TemplateKeys.PM_SENDSAVE);
this.context.put("message", I18n.getMessage("PrivateMessage.messageSent", new String[] { this.request.getContextPath() + "/pm/inbox" + SystemGlobals.getValue(ConfigKeys.SERVLET_EXTENSION) }));
// If the target user if in the forum, then increments its
// private messate count
String sid = SessionFacade.isUserInSession(toUserId);
if (sid != null) {
UserSession us = SessionFacade.getUserSession(sid);
us.setPrivateMessages(us.getPrivateMessages() + 1);
}
if (toUser.getEmail() != null && toUser.getEmail().trim().length() > 0 && SystemGlobals.getBoolValue(ConfigKeys.MAIL_NOTIFY_ANSWERS)) {
Executor.execute(new EmailSenderTask(new PrivateMessageSpammer(toUser)));
}
} else {
this.context.put("preview", true);
this.context.put("post", pm.getPost());
Post postPreview = new Post(pm.getPost());
this.context.put("postPreview", PostCommon.preparePostForDisplay(postPreview));
this.context.put("pm", pm);
this.send();
}
}
use of net.jforum.entities.UserSession in project jforum2 by rafaelsteil.
the class I18n method getMessage.
/**
* @see #getMessage(String, String, Object[])
* @param messageName String
* @param params Object
* @return String
*/
public static String getMessage(String messageName, Object[] params) {
String lang = "";
UserSession us = SessionFacade.getUserSession();
if (us != null && us.getLang() != null) {
lang = us.getLang();
}
if ("".equals(lang)) {
return getMessage(defaultName, messageName, params);
}
return getMessage(lang, messageName, params);
}
Aggregations