use of net.jforum.dao.PrivateMessageDAO 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