public int GetNumOfComments(int threadId) { Message message = findMessage(threadId); FirstMessage fm; if (message.isFirst()) { fm = (FirstMessage)message; } else { throw new ArgumentException(error_responseNotThread); } return(fm.getNumofComments()); }
public bool deleteMessage(int messageID) { Message ms = findMessage(messageID); if (ms != null) { // if firstMessage, it should be deleted with all its comments if (ms.isFirst()) { HashSet <ResponseMessage> messagesForDeletion = ((FirstMessage)ms).getResponseMessages(); foreach (ResponseMessage rm in messagesForDeletion) { messages.Remove(rm); } } //remove the message anyway messages.Remove(ms); return(true); } throw new InvalidOperationException(error_messageIdNotFound); }
public bool deleteMessage(int userRequesterId, int messageID) { Message ms = findMessage(messageID); if (ms != null) { if ((!(ms.publisherID != userRequesterId)) && (!(userRequesterId != 1))) { throw new UnauthorizedAccessException("User " + userRequesterId + " has no permissions to delete the message " + messageID); } // if firstMessage, it should be deleted with all its comments if (ms.isFirst()) { FirstMessage fm = (FirstMessage)ms; HashSet <ResponseMessage> messagesForDeletion = fm.ResponseMessages; while (messagesForDeletion.Count > 0) { ResponseMessage rm = messagesForDeletion.ElementAt(0); fm.removeRespone(rm); messages.Remove(rm); } messages.Remove(fm); //removing firstMessage pointer from its thread Thread trd = GetFirstMessageThread(fm); DBthreadMan.remove(trd); } // if responseMessage, should delete itself and the pointer from its firstMessage else { ResponseMessage rm = (ResponseMessage)ms; FirstMessage fm = GetFirstMessage(rm); fm.removeRespone(rm); messages.Remove(rm); } saveMessageDB(); return(true); } throw new InvalidOperationException(error_messageIdNotFound); }