Exemple #1
0
 private int handleGlobalMessage(User user) {
   List<MessageSend> messages = null;
   List<MessageSend> all = (List<MessageSend>) globalMessageCache.get(GLOBAL_MESSAGE);
   Map<String, Object> map = (Map<String, Object>) messageCache.get(user.getId());
   if (map == null) {
     map = new HashMap<String, Object>();
   }
   if (!map.containsKey(GLOBAL_MESSAGE)) {
     messages =
         messageSendDao.selectUnSendMessageByTypeAndUser(MessageType.GLOBAL, user, maxCount);
   } else {
     List<MessageSend> received = (List<MessageSend>) map.get(GLOBAL_MESSAGE);
     if (!Validators.isEmptyOrNull(received)) {
       messages = getUnrecieve(received, all);
     } else {
       messages = all;
     }
   }
   if (!messages.isEmpty()) {
     List<MessageReceive> receives = new ArrayList<MessageReceive>(messages.size());
     for (MessageSend send : messages) {
       MessageReceive receive = new MessageReceive();
       receive.setMessage(send);
       receive.setIsRead(false);
       receive.setReceiver(user);
       receive.setStatus(MessageStatus.COMMON);
       receives.add(receive);
     }
     messageReceiveDao.inserts(receives);
   }
   map.put(GLOBAL_MESSAGE, new ArrayList<MessageSend>(all));
   messageCache.put(user.getId(), map);
   return messages.size();
 }
Exemple #2
0
 private void addCount(User user, int count) {
   int _count = 0;
   Map<String, Object> map = (Map<String, Object>) messageCache.get(user.getId());
   if (map != null) {
     if (map.containsKey(UNREAD_COUNT)) {
       _count = (Integer) map.get(UNREAD_COUNT);
     }
   } else {
     map = new HashMap<String, Object>();
   }
   _count += count;
   map.put(UNREAD_COUNT, _count);
   messageCache.put(user.getId(), map);
 }
Exemple #3
0
 public String getUrlByUser(User user, boolean myMenu, String protocol) {
   Space space = user.getSpace();
   if (myMenu) {
     if (space != null && enableSpaceDomain) {
       return getUrlBySpace(space, protocol) + "/my";
     } else {
       return protocol + "://" + domainAndPort + contextPath + "/my";
     }
   } else {
     if (space != null) {
       return getUrlBySpace(space, protocol);
     } else {
       return protocol + "://" + domainAndPort + contextPath + "/user/" + user.getId();
     }
   }
 }
Exemple #4
0
  @Override
  @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
  public int getToReadMessageCount(User user) {
    int unreadFromSources = handleGlobalMessage(user);
    Map<String, Object> map = (Map<String, Object>) messageCache.get(user.getId());
    if (map != null && map.containsKey(UNREAD_COUNT)) {
      int totalCount = (Integer) map.get(UNREAD_COUNT) + unreadFromSources;
      addCount(user, unreadFromSources);
      return totalCount;
    }

    MessageReceivePageParam param = new MessageReceivePageParam();
    param.setIsRead(false);
    param.setReceiver(user);
    int count = messageReceiveDao.selectCount(param);
    addCount(user, count);
    return count;
  }