use of net.jforum.entities.PrivateMessage in project jforum2 by rafaelsteil.
the class GenericPrivateMessageDAO method selectFromSent.
/**
* @see net.jforum.dao.PrivateMessageDAO#selectFromSent(net.jforum.entities.User)
*/
public List selectFromSent(User user) {
String query = SystemGlobals.getSql("PrivateMessageModel.baseListing");
query = query.replaceAll("#FILTER#", SystemGlobals.getSql("PrivateMessageModel.sent"));
PreparedStatement p = null;
ResultSet rs = null;
try {
p = JForumExecutionContext.getConnection().prepareStatement(query);
p.setInt(1, user.getId());
List pmList = new ArrayList();
rs = p.executeQuery();
while (rs.next()) {
PrivateMessage pm = this.getPm(rs, false);
User toUser = new User();
toUser.setId(rs.getInt("user_id"));
toUser.setUsername(rs.getString("username"));
pm.setToUser(toUser);
pmList.add(pm);
}
return pmList;
} catch (SQLException e) {
throw new DatabaseException(e);
} finally {
DbUtils.close(rs, p);
}
}
use of net.jforum.entities.PrivateMessage in project jforum2 by rafaelsteil.
the class GenericPrivateMessageDAO method getPm.
protected PrivateMessage getPm(ResultSet rs, boolean full) throws SQLException {
PrivateMessage pm = new PrivateMessage();
Post p = new Post();
pm.setId(rs.getInt("privmsgs_id"));
pm.setType(rs.getInt("privmsgs_type"));
p.setTime(new Date(rs.getTimestamp("privmsgs_date").getTime()));
p.setSubject(rs.getString("privmsgs_subject"));
SimpleDateFormat df = new SimpleDateFormat(SystemGlobals.getValue(ConfigKeys.DATE_TIME_FORMAT));
pm.setFormatedDate(df.format(p.getTime()));
if (full) {
UserDAO um = DataAccessDriver.getInstance().newUserDAO();
pm.setFromUser(um.selectById(rs.getInt("privmsgs_from_userid")));
pm.setToUser(um.selectById(rs.getInt("privmsgs_to_userid")));
p.setBbCodeEnabled(rs.getInt("privmsgs_enable_bbcode") == 1);
p.setSignatureEnabled(rs.getInt("privmsgs_attach_sig") == 1);
p.setHtmlEnabled(rs.getInt("privmsgs_enable_html") == 1);
p.setSmiliesEnabled(rs.getInt("privmsgs_enable_smilies") == 1);
p.setText(this.getPmText(rs));
}
pm.setPost(p);
return pm;
}
use of net.jforum.entities.PrivateMessage in project jforum2 by rafaelsteil.
the class PrivateMessageAction method reply.
public void reply() {
if (!SessionFacade.isLogged()) {
this.setTemplateName(ViewCommon.contextToLogin());
return;
}
int id = this.request.getIntParameter("id");
PrivateMessage pm = new PrivateMessage();
pm.setId(id);
pm = DataAccessDriver.getInstance().newPrivateMessageDAO().selectById(pm);
int userId = SessionFacade.getUserSession().getUserId();
if (pm.getToUser().getId() != userId && pm.getFromUser().getId() != userId) {
this.setTemplateName(TemplateKeys.PM_READ_DENIED);
this.context.put("message", I18n.getMessage("PrivateMessage.readDenied"));
return;
}
pm.getPost().setSubject(I18n.getMessage("PrivateMessage.replyPrefix") + pm.getPost().getSubject());
this.context.put("pm", pm);
this.context.put("pmReply", true);
this.sendFormCommon(DataAccessDriver.getInstance().newUserDAO().selectById(SessionFacade.getUserSession().getUserId()));
}
use of net.jforum.entities.PrivateMessage in project jforum2 by rafaelsteil.
the class PrivateMessageAction method read.
public void read() {
if (!SessionFacade.isLogged()) {
this.setTemplateName(ViewCommon.contextToLogin());
return;
}
int id = this.request.getIntParameter("id");
PrivateMessage pm = new PrivateMessage();
pm.setId(id);
pm = DataAccessDriver.getInstance().newPrivateMessageDAO().selectById(pm);
// Don't allow the read of messages that don't belongs
// to the current user
UserSession us = SessionFacade.getUserSession();
int userId = us.getUserId();
if (pm.getToUser().getId() == userId || pm.getFromUser().getId() == userId) {
pm.getPost().setText(PostCommon.preparePostForDisplay(pm.getPost()).getText());
// Update the message status, if needed
if (pm.getType() == PrivateMessageType.NEW) {
pm.setType(PrivateMessageType.READ);
DataAccessDriver.getInstance().newPrivateMessageDAO().updateType(pm);
int totalMessages = us.getPrivateMessages();
if (totalMessages > 0) {
us.setPrivateMessages(totalMessages - 1);
}
}
User u = pm.getFromUser();
ViewCommon.prepareUserSignature(u);
this.context.put("pm", pm);
this.setTemplateName(TemplateKeys.PM_READ);
} else {
this.setTemplateName(TemplateKeys.PM_READ_DENIED);
this.context.put("message", I18n.getMessage("PrivateMessage.readDenied"));
}
}
use of net.jforum.entities.PrivateMessage in project jforum2 by rafaelsteil.
the class PrivateMessageAction method delete.
public void delete() {
if (!SessionFacade.isLogged()) {
this.setTemplateName(ViewCommon.contextToLogin());
return;
}
String[] ids = this.request.getParameterValues("id");
if (ids != null && ids.length > 0) {
PrivateMessage[] deleteList = new PrivateMessage[ids.length];
int unreadCount = 0;
PrivateMessageDAO dao = DataAccessDriver.getInstance().newPrivateMessageDAO();
for (int i = 0; i < ids.length; i++) {
PrivateMessage pm = dao.selectById(new PrivateMessage(Integer.parseInt(ids[i])));
if (pm.getType() == PrivateMessageType.NEW) {
unreadCount++;
}
deleteList[i] = pm;
}
UserSession userSession = SessionFacade.getUserSession();
dao.delete(deleteList, userSession.getUserId());
// Subtracts the number of delete messages
int total = userSession.getPrivateMessages() - unreadCount;
if (total < 0) {
total = 0;
}
userSession.setPrivateMessages(total);
}
this.setTemplateName(TemplateKeys.PM_DELETE);
this.context.put("message", I18n.getMessage("PrivateMessage.deleteDone", new String[] { this.request.getContextPath() + "/pm/inbox" + SystemGlobals.getValue(ConfigKeys.SERVLET_EXTENSION) }));
}
Aggregations