コード例 #1
0
 public int getTotalUnreadCount() {
   int count = 0;
   for (UnreadEntity entity : unreadMsgMap.values()) {
     if (!entity.isForbidden()) {
       count = count + entity.getUnReadCnt();
     }
   }
   return count;
 }
コード例 #2
0
  public void add(MessageEntity msg) {
    // 更新session list中的msg信息
    // 更新未读消息计数
    if (msg == null) {
      logger.d("unread#unreadMgr#add msg is null!");
      return;
    }
    // isFirst场景:出现一条未读消息,出现小红点,需要触发 [免打扰的情况下]
    boolean isFirst = false;
    logger.d("unread#unreadMgr#add unread msg:%s", msg);
    UnreadEntity unreadEntity;
    int loginId = IMLoginManager.instance().getLoginId();
    String sessionKey = msg.getSessionKey();
    boolean isSend = msg.isSend(loginId);
    if (isSend) {
      IMNotificationManager.instance().cancelSessionNotifications(sessionKey);
      return;
    }

    if (unreadMsgMap.containsKey(sessionKey)) {
      unreadEntity = unreadMsgMap.get(sessionKey);
      // 判断最后一条msgId是否相同
      if (unreadEntity.getLaststMsgId() == msg.getMsgId()) {
        return;
      }
      unreadEntity.setUnReadCnt(unreadEntity.getUnReadCnt() + 1);
    } else {
      isFirst = true;
      unreadEntity = new UnreadEntity();
      unreadEntity.setUnReadCnt(1);
      unreadEntity.setPeerId(msg.getPeerId(isSend));
      unreadEntity.setSessionType(msg.getSessionType());
      unreadEntity.buildSessionKey();
    }

    unreadEntity.setLatestMsgData(msg.getMessageDisplay());
    unreadEntity.setLaststMsgId(msg.getMsgId());
    addIsForbidden(unreadEntity);

    /** 放入manager 状态中 */
    unreadMsgMap.put(unreadEntity.getSessionKey(), unreadEntity);

    /** 没有被屏蔽才会发送广播 */
    if (!unreadEntity.isForbidden() || isFirst) {
      UnreadEvent unreadEvent = new UnreadEvent();
      unreadEvent.event = UnreadEvent.Event.UNREAD_MSG_RECEIVED;
      unreadEvent.entity = unreadEntity;
      triggerEvent(unreadEvent);
    }
  }
コード例 #3
0
  private void handleMsgRecv(UnreadEntity entity) {
    logger.d("notification#recv unhandled message");
    int peerId = entity.getPeerId();
    int sessionType = entity.getSessionType();
    logger.d("notification#msg no one handled, peerId:%d, sessionType:%d", peerId, sessionType);

    // 判断是否设定了免打扰
    if (entity.isForbidden()) {
      logger.d("notification#GROUP_STATUS_SHIELD");
      return;
    }

    // PC端是否登陆 取消 【暂时先关闭】
    //        if(IMLoginManager.instance().isPcOnline()){
    //            logger.d("notification#isPcOnline");
    //            return;
    //        }

    // 全局开关
    boolean globallyOnOff =
        configurationSp.getCfg(
            SysConstant.SETTING_GLOBAL, ConfigurationSp.CfgDimension.NOTIFICATION);
    if (globallyOnOff) {
      logger.d("notification#shouldGloballyShowNotification is false, return");
      return;
    }

    // 单独的设置
    boolean singleOnOff =
        configurationSp.getCfg(entity.getSessionKey(), ConfigurationSp.CfgDimension.NOTIFICATION);
    if (singleOnOff) {
      logger.d("notification#shouldShowNotificationBySession is false, return");
      return;
    }

    // if the message is a multi login message which send from another terminal,not need notificate
    // to status bar
    // 判断是否是自己的消息
    if (IMLoginManager.instance().getLoginId() != peerId) {
      showNotification(entity);
    }
  }