public static List<User> getThreadUsers(long userId, long mbThreadId)
      throws PortalException, SystemException {

    List<User> users = new ArrayList<User>();

    // Users who have contributed to the thread

    List<MBMessage> mbMessages =
        UserThreadServiceUtil.getThreadMessages(
            mbThreadId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, false);

    for (MBMessage mbMessage : mbMessages) {
      if (userId == mbMessage.getUserId()) {
        continue;
      }

      User user = UserLocalServiceUtil.fetchUser(mbMessage.getUserId());

      if (user == null) {
        user = UserLocalServiceUtil.createUser(mbMessage.getUserId());

        user.setFirstName(mbMessage.getUserName());
        user.setStatus(WorkflowConstants.STATUS_INACTIVE);
      }

      if (!users.contains(user)) {
        users.add(user);
      }
    }

    // Users who can view the thread

    List<UserThread> userThreads = UserThreadLocalServiceUtil.getMBThreadUserThreads(mbThreadId);

    for (UserThread userThread : userThreads) {
      if (userId == userThread.getUserId()) {
        continue;
      }

      User user = UserLocalServiceUtil.fetchUser(userThread.getUserId());

      if (user == null) {
        user = UserLocalServiceUtil.createUser(userThread.getUserId());

        user.setFirstName(userThread.getUserName());
        user.setStatus(WorkflowConstants.STATUS_INACTIVE);
      }

      if (!users.contains(user)) {
        users.add(user);
      }
    }

    return users;
  }
  public void updateUserName(User user) {
    String userName = user.getFullName();

    List<UserThread> userThreads = userThreadPersistence.findByUserId(user.getUserId());

    for (UserThread userThread : userThreads) {
      if (!userName.equals(userThread.getUserName())) {
        userThread.setUserName(userName);

        userThreadPersistence.update(userThread);
      }
    }
  }