Class ChatNotificationService

java.lang.Object
io.meeds.chat.service.ChatNotificationService

@Service public class ChatNotificationService extends Object
This service creates and manages all different notifications related to the chat application
  • Field Details

    • IN_KEY

      public static String IN_KEY
    • USER_CHAT_NOTIFICATION_SCOPE

      public static final org.exoplatform.commons.api.settings.data.Scope USER_CHAT_NOTIFICATION_SCOPE
    • MUTED_ROOMS

      public static final String MUTED_ROOMS
      See Also:
    • DEFAULT_UNREAD_DELAY_SECONDS

      public static final long DEFAULT_UNREAD_DELAY_SECONDS
      Default delay a message must stay unread before a device pops it, applied when the device defines no delay of its own.
      See Also:
    • CHAT_NOTIFICATION_KIND

      public static final String CHAT_NOTIFICATION_KIND
      See Also:
    • SENDS_YOU_A_CHAT_KEY

      public static final String SENDS_YOU_A_CHAT_KEY
      See Also:
    • MORE_MESSAGES_KEY

      public static final String MORE_MESSAGES_KEY
      See Also:
    • MARK_READ_ACTION

      public static final String MARK_READ_ACTION
      See Also:
    • MARK_READ_LABEL_KEY

      public static final String MARK_READ_LABEL_KEY
      See Also:
    • OPEN_ROOM_CLIENT_ACTION

      public static final String OPEN_ROOM_CLIENT_ACTION
      In-page action of a room popup click (DOM event name the chat quick-actions bundle listens to, see Constants.js ACTION_OPEN_CHAT_ROOM_FROM_PUSH)
      See Also:
    • READ_WATERMARK_KEY_PREFIX

      public static final String READ_WATERMARK_KEY_PREFIX
      See Also:
  • Constructor Details

    • ChatNotificationService

      public ChatNotificationService()
  • Method Details

    • onMatrixPushReceived

      public void onMatrixPushReceived(String eventId, String roomId, String userName, String pushKey)
      Single entry point of the Synapse push-gateway callback for one recipient: resolves the event once server-side, then dispatches — a mention additionally produces the standard on-site/mail notification (its push is opted out), and every message schedules a deferred self-contained popup per subscribed device, cancelled at fire time if read meanwhile. One popup per chatroom: it shows the latest unread message and how many more are unread, replacing the room's previous popup on the device. A space room's event is read with the administrator account, so the recipient must be a member of the space: the pusher key names the recipient, and nothing else in the push proves it may read that room.
      Parameters:
      eventId - the Matrix event ID
      roomId - the Matrix room ID
      userName - the recipient platform username
      pushKey - the recipient device pushkey (JWT), used to resolve private room events
    • markRoomAsRead

      public void markRoomAsRead(String userName, String roomId, String eventId, Long readTimestamp) throws org.exoplatform.commons.exception.ObjectNotFoundException, IllegalAccessException
      Marks a room as read for a user up to an event — the server-side read anchor: (1) the m.read receipt is posted with the user's own Matrix identity so every client converges through sync, (2) the read watermark is recorded durably, (3) the pending popups covered by it are discarded. Idempotent; the watermark only moves forward.
      Parameters:
      userName - the platform user
      roomId - the Matrix room id
      eventId - the event read up to (high-water mark)
      readTimestamp - the timestamp of that event when known, else now
      Throws:
      org.exoplatform.commons.exception.ObjectNotFoundException - when the room is unknown
      IllegalAccessException - when the user is not a member of the room
    • clearPendingMessages

      public void clearPendingMessages(String userName, String roomId, long upToTimestamp)
      Discards the pending popups of a room up to a timestamp: their deferred sends are cancelled at fire time. Called when the room is read up to that point (read-anchor story).
      Parameters:
      userName - the recipient platform username
      roomId - the Matrix room ID
      upToTimestamp - read watermark (inclusive)
    • onAgentPushReceived

      public void onAgentPushReceived(String eventId, String roomId, String login)
      Entry point of a digital worker's push, called by the push gateway once it verified the worker's pusher key. Hands over to the platform, as the matrix.agent.mentioned event, a message of a space room that mentions the worker through m.mentions, is not the worker's own and is not an edit; anything else is ignored.

      The room kind is decided first, before anything is read from Synapse, and this is the only place the chat add-on decides it for a worker: an unknown room, a disabled one or a direct message returns at once, so a direct message, which has no space and would need the worker's own token, never holds the worker's pusher. A direct-message hand-off would start here. The worker must then be a member of the room's space: the pusher key is the only credential of the push, so the membership is checked here rather than inferred from Synapse pushing only the rooms the account joined. Every Synapse call is bounded, and every failure is logged and swallowed: the push gateway answers a worker's push with a success whatever happens, since Synapse would otherwise retry that event before any later one.

      Parameters:
      eventId - the Matrix event id
      roomId - the Matrix room id
      login - the mentioned worker's login
    • isPrivateRoomMutedForUser

      public boolean isPrivateRoomMutedForUser(String userName, String roomId)
    • toggleMutePrivateRoom

      public void toggleMutePrivateRoom(String userName, String roomId)