1 /** 2 * This file Copyright (c) 2012-2018 Magnolia International 3 * Ltd. (http://www.magnolia-cms.com). All rights reserved. 4 * 5 * 6 * This file is dual-licensed under both the Magnolia 7 * Network Agreement and the GNU General Public License. 8 * You may elect to use one or the other of these licenses. 9 * 10 * This file is distributed in the hope that it will be 11 * useful, but AS-IS and WITHOUT ANY WARRANTY; without even the 12 * implied warranty of MERCHANTABILITY or FITNESS FOR A 13 * PARTICULAR PURPOSE, TITLE, or NONINFRINGEMENT. 14 * Redistribution, except as permitted by whichever of the GPL 15 * or MNA you select, is prohibited. 16 * 17 * 1. For the GPL license (GPL), you can redistribute and/or 18 * modify this file under the terms of the GNU General 19 * Public License, Version 3, as published by the Free Software 20 * Foundation. You should have received a copy of the GNU 21 * General Public License, Version 3 along with this program; 22 * if not, write to the Free Software Foundation, Inc., 51 23 * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 24 * 25 * 2. For the Magnolia Network Agreement (MNA), this file 26 * and the accompanying materials are made available under the 27 * terms of the MNA which accompanies this distribution, and 28 * is available at http://www.magnolia-cms.com/mna.html 29 * 30 * Any modifications to this file must keep this entire header 31 * intact. 32 * 33 */ 34 package info.magnolia.ui.framework.message; 35 36 import info.magnolia.ui.api.message.Message; 37 import info.magnolia.ui.api.message.MessageType; 38 39 import java.util.List; 40 import java.util.Map; 41 42 /** 43 * Manages users messages. 44 */ 45 public interface MessagesManager { 46 47 /** 48 * MessageListener. 49 */ 50 public interface MessageListener { 51 52 void messageSent(Message message); 53 54 void messageCleared(Message message); 55 56 void messageRemoved(String id); 57 } 58 59 /** 60 * Beware: this method is for registering message listeners and should only be used by the entry point of our application AdmincentralUI where we register a dispatcher. 61 * If you'll use it to register your own MessageListeners this likely to introduce a memory leak. You should listen to the MessageEvent instead. 62 */ 63 void registerMessagesListener(String userName, MessageListener listener); 64 65 void unregisterMessagesListener(String userName, MessageListener listener); 66 67 /** 68 * Returns the number of uncleared (unread) messages for this user. 69 * 70 * @param userName name of the user 71 * @return number of uncleared messages 72 */ 73 int getNumberOfUnclearedMessagesForUser(String userName); 74 75 /** 76 * Returns the number of uncleared (unread) messages for this user and for the specific message type. 77 */ 78 int getNumberOfUnclearedMessagesForUserAndByType(String userName, MessageType type); 79 80 /** 81 * Returns all messages kept for a specific user. 82 * 83 * @param userName name of the user 84 * @return list of messages kept for the user 85 * @deprecated since 5.3.9 - potentially dangerous since it returns the whole set of messages for the user which could be large. 86 * The {@link #getMessageBatch(String, java.util.List, java.util.Map, int, int)} should be used instead because it allows to set the limit and offset parameters. 87 */ 88 @Deprecated 89 List<Message> getMessagesForUser(String userName); 90 91 /** 92 * More efficient way to query message objects - the amount of return payload is limited, pre-sorted and filtered by type. 93 * 94 * @param types message types to include in the batch 95 * @param sortCriteria properties to order by (true if ascending) 96 * @param limit max amount of entries to inclde in the batch 97 * @param offset first entry index to query 98 * @return list of <code>N = limit</code> {@link Message}'s starting from <code>index = offset</code> 99 */ 100 List<Message> getMessageBatch(String userName, List<MessageType> types, Map<String, Boolean> sortCriteria, int limit, int offset); 101 102 /** 103 * Get amount of messages of certain types. 104 * 105 * @param types types of messages to take in account 106 * @return amount of messages of certain types 107 */ 108 long getMessagesAmount(String userName, List<MessageType> types); 109 110 /** 111 * Returns a message. 112 * 113 * @param userName name of the user 114 * @return list of messages kept for the user 115 */ 116 Message getMessageById(String userName, String messageId); 117 118 /** 119 * Send message to a specific user. 120 * 121 * @param userName name of the user to receive the message 122 * @param message message to send 123 */ 124 void sendMessage(String userName, Message message); 125 126 /** 127 * Send message to a specific group. 128 * 129 * @param groupName name of the group to receive the message 130 * @param message message to send 131 */ 132 void sendGroupMessage(String groupName, Message message); 133 134 /** 135 * Send message to the current user. 136 * 137 * @param message message to send 138 */ 139 void sendLocalMessage(Message message); 140 141 /** 142 * Sends a message to all users. 143 * 144 * @param message message to send 145 */ 146 void broadcastMessage(Message message); 147 148 /** 149 * Marks a message as cleared. 150 * 151 * @param userName name of the user the message belongs to 152 * @param messageId id of message 153 */ 154 void clearMessage(String userName, String messageId); 155 156 void removeMessage(String userName, String messageId); 157 158 void saveMessage(String userName, Message message); 159 }