View Javadoc
1   /**
2    * This file Copyright (c) 2012-2015 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  
41  /**
42   * Manages users messages.
43   */
44  public interface MessagesManager {
45  
46      /**
47       * MessageListener.
48       */
49      public interface MessageListener {
50  
51          void messageSent(Message message);
52  
53          void messageCleared(Message message);
54      }
55  
56      /**
57       * 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.
58       *         If you'll use it to register your own MessageListeners this likely to introduce a memory leak. You should listen to the MessageEvent instead.
59       */
60      void registerMessagesListener(String userName, MessageListener listener);
61  
62      void unregisterMessagesListener(String userName, MessageListener listener);
63  
64      /**
65       * Returns the number of uncleared (unread) messages for this user.
66       * 
67       * @param userName name of the user
68       * @return number of uncleared messages
69       */
70      int getNumberOfUnclearedMessagesForUser(String userName);
71  
72      /**
73       * Returns the number of uncleared (unread) messages for this user and for the specific message type.
74       */
75      int getNumberOfUnclearedMessagesForUserAndByType(String userName, MessageType type);
76  
77      /**
78       * Returns all messages kept for a specific user.
79       * 
80       * @param userName name of the user
81       * @return list of messages kept for the user
82       */
83      List<Message> getMessagesForUser(String userName);
84  
85      /**
86       * Returns a message.
87       *
88       * @param userName name of the user
89       * @return list of messages kept for the user
90       */
91      Message getMessageById(String userName, String messageId);
92  
93      /**
94       * Send message to a specific user.
95       *
96       * @param userName name of the user to receive the message
97       * @param message message to send
98       */
99      void sendMessage(String userName, Message message);
100 
101     /**
102      * Send message to a specific group.
103      *
104      * @param groupName name of the group to receive the message
105      * @param message message to send
106      */
107     void sendGroupMessage(String groupName, Message message);
108 
109     /**
110      * Send message to the current user.
111      *
112      * @param message message to send
113      */
114     void sendLocalMessage(Message message);
115 
116     /**
117      * Sends a message to all users.
118      *
119      * @param message message to send
120      */
121     void broadcastMessage(Message message);
122 
123     /**
124      * Marks a message as cleared.
125      *
126      * @param userName name of the user the message belongs to
127      * @param messageId id of message
128      */
129     void clearMessage(String userName, String messageId);
130 
131     void removeMessage(String userName, String messageId);
132 }