Index: chat-tool/tool/src/java/org/sakaiproject/chat2/tool/ChatTool.java =================================================================== --- chat-tool/tool/src/java/org/sakaiproject/chat2/tool/ChatTool.java (revision 64895) +++ chat-tool/tool/src/java/org/sakaiproject/chat2/tool/ChatTool.java (working copy) @@ -532,16 +532,24 @@ public String processActionSubmitMessage() { + DecoratedChannel dChannel = getCurrentChannel(); try { - ChatMessage message = getChatManager().createNewMessage( - getCurrentChannel().getChatChannel(), SessionManager.getCurrentSessionUserId()); - message.setBody( FormattedText.convertPlaintextToFormattedText(newMessageText)); - if (!newMessageText.equals("")) { - newMessageText = ""; - getChatManager().updateMessage(message); - getChatManager().sendMessage(message); - } - return PAGE_ROOM_CONTROL; + if (dChannel != null) + { + ChatMessage message = getChatManager().createNewMessage( + dChannel.getChatChannel(), SessionManager.getCurrentSessionUserId()); + message.setBody( FormattedText.convertPlaintextToFormattedText(newMessageText)); + if (!newMessageText.equals("")) { + newMessageText = ""; + getChatManager().updateMessage(message); + getChatManager().sendMessage(message); + } + return PAGE_ROOM_CONTROL; + } + else + { + return ""; + } } catch (PermissionException e) { setErrorMessage(PERMISSION_ERROR, new String[] {ChatFunctions.CHAT_FUNCTION_NEW}); @@ -605,7 +613,8 @@ public String processActionBackToRoom() { - String filter = getCurrentChannel().getChatChannel().getFilterType(); + DecoratedChannel dChannel = getCurrentChannel(); + String filter = dChannel != null ? dChannel.getChatChannel().getFilterType() : ""; if(filter.equals(ChatChannel.FILTER_ALL)){ setMessageOptions(Integer.toString(MESSAGEOPTIONS_ALL_MESSAGES)); }else if(filter.equals(ChatChannel.FILTER_BY_NUMBER)){ @@ -684,49 +693,57 @@ public String processActionEditRoomSave() { //Set the filter param here - ChatChannel channel = getCurrentChannelEdit().getChatChannel(); - boolean directEdit = getCurrentChannelEdit().isDirectEdit(); - - //set default number and time values based on the decordatedChannel class - channel.setNumberParam(getCurrentChannelEdit().getFilterParamLast()); - channel.setTimeParam(getCurrentChannelEdit().getFilterParamPast()); - - if (channel.getFilterType().equals(ChatChannel.FILTER_BY_NUMBER)) { - channel.setFilterParam(getCurrentChannelEdit().getFilterParamLast()); - } - else if (channel.getFilterType().equals(ChatChannel.FILTER_BY_TIME)) { - channel.setFilterParam(getCurrentChannelEdit().getFilterParamPast()); - } - else if (channel.getFilterType().equals(ChatChannel.FILTER_NONE)) { - channel.setFilterParam(0); - } - String retView = PAGE_LIST_ROOMS; - - if (directEdit) - retView = PAGE_ENTER_ROOM; - else - retView = PAGE_LIST_ROOMS; - - if (validateChannel(channel)) - try { - getChatManager().updateChannel(channel, true); - - if (getCurrentChannel() != null && getCurrentChannel().getChatChannel().getId().equals(channel.getId())) { - setCurrentChannel(new DecoratedChatChannel(this, channel)); - } - setCurrentChannelEdit(null); - - } - catch (PermissionException e) { - setErrorMessage(PERMISSION_ERROR, new String[] {ChatFunctions.CHAT_FUNCTION_EDIT_CHANNEL}); - return ""; - } - else { - //Message should get set in the validateChannel method - //setErrorMessage(VALIDATION_ERROR, new String[] {ChatFunctions.CHAT_FUNCTION_DELETE_PREFIX}); - retView = ""; - } - return retView; + DecoratedChatChannel dChannel = getCurrentChannelEdit(); + if (dChannel != null) + { + ChatChannel channel = dChannel.getChatChannel(); + boolean directEdit = dChannel.isDirectEdit(); + + //set default number and time values based on the decordatedChannel class + channel.setNumberParam(dChannel.getFilterParamLast()); + channel.setTimeParam(dChannel.getFilterParamPast()); + + if (channel.getFilterType().equals(ChatChannel.FILTER_BY_NUMBER)) { + channel.setFilterParam(dChannel.getFilterParamLast()); + } + else if (channel.getFilterType().equals(ChatChannel.FILTER_BY_TIME)) { + channel.setFilterParam(dChannel.getFilterParamPast()); + } + else if (channel.getFilterType().equals(ChatChannel.FILTER_NONE)) { + channel.setFilterParam(0); + } + String retView = PAGE_LIST_ROOMS; + + if (directEdit) + retView = PAGE_ENTER_ROOM; + else + retView = PAGE_LIST_ROOMS; + + if (validateChannel(channel)) + try { + getChatManager().updateChannel(channel, true); + + if (dChannel != null && dChannel.getChatChannel().getId().equals(channel.getId())) { + setCurrentChannel(new DecoratedChatChannel(this, channel)); + } + setCurrentChannelEdit(null); + + } + catch (PermissionException e) { + setErrorMessage(PERMISSION_ERROR, new String[] {ChatFunctions.CHAT_FUNCTION_EDIT_CHANNEL}); + return ""; + } + else { + //Message should get set in the validateChannel method + //setErrorMessage(VALIDATION_ERROR, new String[] {ChatFunctions.CHAT_FUNCTION_DELETE_PREFIX}); + retView = ""; + } + return retView; + } + else + { + return ""; + } } /** @@ -735,7 +752,8 @@ */ public String processActionEditRoomCancel() { - boolean directEdit = getCurrentChannelEdit().isDirectEdit(); + DecoratedChannel dChannel = getCurrentChannelEdit(); + boolean directEdit = dChannel != null ? dChannel.isDirectEdit() : false; setCurrentChannelEdit(null); if (directEdit) @@ -1118,16 +1136,17 @@ protected int initMessageOptions() { int result = MESSAGEOPTIONS_ALL_MESSAGES; - if (getCurrentChannel().getChatChannel().getFilterType().equals(ChatChannel.FILTER_ALL)) { + DecoratedChatChannel dChannel = getCurrentChannel(); + if (dChannel != null && dChannel.getChatChannel().getFilterType().equals(ChatChannel.FILTER_ALL)) { result = MESSAGEOPTIONS_ALL_MESSAGES; } - else if (getCurrentChannel().getChatChannel().getFilterType().equals(ChatChannel.FILTER_BY_NUMBER)) { + else if (dChannel != null && dChannel.getChatChannel().getFilterType().equals(ChatChannel.FILTER_BY_NUMBER)) { result = MESSAGEOPTIONS_MESSAGES_BY_NUMBER; } - else if (getCurrentChannel().getChatChannel().getFilterType().equals(ChatChannel.FILTER_BY_TIME)) { + else if (dChannel != null && dChannel.getChatChannel().getFilterType().equals(ChatChannel.FILTER_BY_TIME)) { result = MESSAGEOPTIONS_MESSAGES_BY_DATE; } - else if (getCurrentChannel().getChatChannel().getFilterType().equals(ChatChannel.FILTER_NONE)) { + else if (dChannel != null && dChannel.getChatChannel().getFilterType().equals(ChatChannel.FILTER_NONE)) { result = MESSAGEOPTIONS_NO_MESSAGES; } return result; @@ -1201,60 +1220,68 @@ } public boolean getCanRenderAllMessages() { + DecoratedChannel dChannel = getCurrentChannel(); return (!getCanRenderMessageOptions() && - getCurrentChannel().getChatChannel().getFilterType().equals(ChatChannel.FILTER_ALL)) || + dChannel != null && dChannel.getChatChannel().getFilterType().equals(ChatChannel.FILTER_ALL)) || (getCanRenderMessageOptions() && messageOptions == MESSAGEOPTIONS_ALL_MESSAGES); } public boolean getCanRenderDateMessages() { + DecoratedChannel dChannel = getCurrentChannel(); return (!getCanRenderMessageOptions() && - getCurrentChannel().getChatChannel().getFilterType().equals(ChatChannel.FILTER_BY_TIME)) || + dChannel != null && dChannel.getChatChannel().getFilterType().equals(ChatChannel.FILTER_BY_TIME)) || (getCanRenderMessageOptions() && messageOptions == MESSAGEOPTIONS_MESSAGES_BY_DATE); } public boolean getCanRenderNumberMessages() { - return (!getCanRenderMessageOptions() && - getCurrentChannel().getChatChannel().getFilterType().equals(ChatChannel.FILTER_BY_NUMBER)) || + DecoratedChannel dChannel = getCurrentChannel(); + return (!getCanRenderMessageOptions() && + dChannel != null && dChannel.getChatChannel().getFilterType().equals(ChatChannel.FILTER_BY_NUMBER)) || (getCanRenderMessageOptions() && messageOptions == MESSAGEOPTIONS_MESSAGES_BY_NUMBER); } public boolean getCanRenderNoMessages() { + DecoratedChannel dChannel = getCurrentChannel(); return (!getCanRenderMessageOptions() && - getCurrentChannel().getChatChannel().getFilterType().equals(ChatChannel.FILTER_NONE)) || + dChannel != null && dChannel.getChatChannel().getFilterType().equals(ChatChannel.FILTER_NONE)) || (getCanRenderMessageOptions() && messageOptions == MESSAGEOPTIONS_NO_MESSAGES); } public List getMessageOptionsList() { List messageOptions = new ArrayList(); - int numberParam = getCurrentChannel().getChatChannel().getNumberParam(); - int timeParam = getCurrentChannel().getChatChannel().getTimeParam(); - - if(getCanRenderMessageOptions()){ - - SelectItem item1 = new SelectItem(Integer.toString(MESSAGEOPTIONS_ALL_MESSAGES), getMessageFromBundle("allMessages")); - SelectItem item2 = new SelectItem(Integer.toString(MESSAGEOPTIONS_MESSAGES_BY_NUMBER), getCustomOptionText(ChatChannel.FILTER_BY_NUMBER, numberParam)); - SelectItem item3 = new SelectItem(Integer.toString(MESSAGEOPTIONS_MESSAGES_BY_DATE), getCustomOptionText(ChatChannel.FILTER_BY_TIME, timeParam)); - SelectItem item4 = new SelectItem(Integer.toString(MESSAGEOPTIONS_NO_MESSAGES), getCustomOptionText(ChatChannel.FILTER_NONE, 0)); - - messageOptions.add(item1); - messageOptions.add(item2); - messageOptions.add(item3); - messageOptions.add(item4); - }else{ - String filter = getCurrentChannel().getChatChannel().getFilterType(); - SelectItem item = null; - if(filter.equals(ChatChannel.FILTER_ALL)){ - item = new SelectItem(Integer.toString(MESSAGEOPTIONS_ALL_MESSAGES), getMessageFromBundle("allMessages")); - }else if(filter.equals(ChatChannel.FILTER_BY_NUMBER)){ - item = new SelectItem(Integer.toString(MESSAGEOPTIONS_MESSAGES_BY_NUMBER), getCustomOptionText(ChatChannel.FILTER_BY_NUMBER, numberParam)); - }else if(filter.equals(ChatChannel.FILTER_BY_TIME)){ - item = new SelectItem(Integer.toString(MESSAGEOPTIONS_MESSAGES_BY_DATE), getCustomOptionText(ChatChannel.FILTER_BY_TIME, timeParam)); - }else if(filter.equals(ChatChannel.FILTER_NONE)){ - item = new SelectItem(Integer.toString(MESSAGEOPTIONS_NO_MESSAGES), getCustomOptionText(ChatChannel.FILTER_NONE, 0)); + DecreatedChannel dChannel = getCurrentChannel(); + if (dChannel != null) + { + int numberParam = dChannel.getChatChannel().getNumberParam(); + int timeParam = dChannel.getChatChannel().getTimeParam(); + + if(getCanRenderMessageOptions()){ + + SelectItem item1 = new SelectItem(Integer.toString(MESSAGEOPTIONS_ALL_MESSAGES), getMessageFromBundle("allMessages")); + SelectItem item2 = new SelectItem(Integer.toString(MESSAGEOPTIONS_MESSAGES_BY_NUMBER), getCustomOptionText(ChatChannel.FILTER_BY_NUMBER, numberParam)); + SelectItem item3 = new SelectItem(Integer.toString(MESSAGEOPTIONS_MESSAGES_BY_DATE), getCustomOptionText(ChatChannel.FILTER_BY_TIME, timeParam)); + SelectItem item4 = new SelectItem(Integer.toString(MESSAGEOPTIONS_NO_MESSAGES), getCustomOptionText(ChatChannel.FILTER_NONE, 0)); + + messageOptions.add(item1); + messageOptions.add(item2); + messageOptions.add(item3); + messageOptions.add(item4); + }else{ + String filter = dChannel.getChatChannel().getFilterType(); + SelectItem item = null; + if(filter.equals(ChatChannel.FILTER_ALL)){ + item = new SelectItem(Integer.toString(MESSAGEOPTIONS_ALL_MESSAGES), getMessageFromBundle("allMessages")); + }else if(filter.equals(ChatChannel.FILTER_BY_NUMBER)){ + item = new SelectItem(Integer.toString(MESSAGEOPTIONS_MESSAGES_BY_NUMBER), getCustomOptionText(ChatChannel.FILTER_BY_NUMBER, numberParam)); + }else if(filter.equals(ChatChannel.FILTER_BY_TIME)){ + item = new SelectItem(Integer.toString(MESSAGEOPTIONS_MESSAGES_BY_DATE), getCustomOptionText(ChatChannel.FILTER_BY_TIME, timeParam)); + }else if(filter.equals(ChatChannel.FILTER_NONE)){ + item = new SelectItem(Integer.toString(MESSAGEOPTIONS_NO_MESSAGES), getCustomOptionText(ChatChannel.FILTER_NONE, 0)); + } + messageOptions.add(item); } - messageOptions.add(item); } - return messageOptions; + return messageOptions; } /** @@ -1262,7 +1289,8 @@ * @return */ public boolean getCanRenderMessageOptions() { - return getCurrentChannel().getChatChannel().isEnableUserOverride(); + DecoratedChannel dChannel = getCurrentChannel(); + return dChannel != null? dChannel.getChatChannel().isEnableUserOverride() : false; } protected String getCustomOptionValue(String filterType) { @@ -1312,14 +1340,15 @@ { Date xDaysOld = null; int maxMessages = 0; - + DecoratedChannel dChannel = getCurrentChannel(); + if (Integer.parseInt(getMessageOptions()) == MESSAGEOPTIONS_MESSAGES_BY_DATE) { - int x = getCurrentChannel().getChatChannel().getTimeParam(); + int x = dChannel != null? dChannel.getChatChannel().getTimeParam():0; xDaysOld = getChatManager().calculateDateByOffset(x); maxMessages = ChatChannel.MAX_MESSAGES; } else if (Integer.parseInt(getMessageOptions()) == MESSAGEOPTIONS_MESSAGES_BY_NUMBER) { - int x = getCurrentChannel().getChatChannel().getNumberParam(); + int x = dChannel != null?dChannel.getChatChannel().getNumberParam():0; maxMessages = x; } else if (Integer.parseInt(getMessageOptions()) == MESSAGEOPTIONS_ALL_MESSAGES) { @@ -1438,9 +1467,10 @@ public String getViewingChatRoomText() { String title = null; - if (getCurrentChannel() != null && getCurrentChannel().getChatChannel() != null) + DecoratedChannel dChannel = getCurrentChannel(); + if (dChannel != null && dChannel.getChatChannel() != null) { - title = getCurrentChannel().getChatChannel().getTitle(); + title = dChannel.getChatChannel().getTitle(); } return getMessageFromBundle("viewingChatRoomText", new Object[]{title}); }