sessionState property

NetClientAzState sessionState

读取激活会话状态

Implementation

NetClientAzState get sessionState {
  if (_dirtySessionState) {
    //构建列表
    final okList = <Object>[];
    int unread = 0;
    _usershipMap.forEach((key, value) {
      if (value.dialog) {
        okList.add(value);
        unread += value.unread;
        //计算展示信息
        final target = getUser(value.rid);
        value.displayNick = ComTools.formatUserShipNick(value, target);
        value.displayIcon = target.icon;
        value.displayHead = target.head;
      }
    });
    _teamshipMap.forEach((key, value) {
      if (value.dialog) {
        okList.add(value);
        unread += value.unread;
        //计算展示信息
        final target = getTeam(value.rid);
        value.displayNick = ComTools.formatTeamNick(target);
        value.displayIcon = target.icon;
        value.displayHead = target.head;
      }
    });
    //按最近消息时间降序排列(注意使用的是动态类型)
    okList.sort((dynamic a, dynamic b) {
      if (a.top && !b.top) {
        return -1;
      } else if (!a.top && b.top) {
        return 1;
      } else {
        return a.update > b.update ? -1 : 1;
      }
    });
    //更新状态
    _sessionState.update(okList: okList, unread: unread);
    _dirtySessionState = false;
  }
  return _sessionState;
}