models/communities/User.js

import SDK from "../../sdk";

/**
 * @class User
 * @property {string} userId - GetSocial User id.
 * @property {string} displayName - Display name.
 * @property {string} avatarUrl - User avatar.
 * @property {Object[]} identities - All identities added to the user.
 * @property {Object<string, string>} publicProperties - All public properties of user.
 * @property {boolean} [verified=false] - User is verified.
 */

export default class User {
  constructor(args) {
    this.id = args.id || null;
    this.displayName = args.displayName || null;
    this.avatarUrl = args.avatarUrl || null;
    this.identities = args.identities || null;
    this.publicProperties = args.publicProperties || null;
    this.verified = args.verified || false;
  }

  /**
   * Create fake User data with app info
   *
   * @memberof User
   * @returns {Object} User instance
   * @ignore
   */
  static appUserData() {
    return {
      id: 'app',
      verified: true,
      displayName: SDK._appInfo.name,
      avatarUrl: SDK._appInfo.iconUrl
    };
  }

  /**
   * Create User from THPublicUser
   *
   * @memberof User
   * @param {Object} user - THPublicUser instance
   * @returns {User} User instance
   * @ignore
   */
   static create(user) {
    return new User({
      ...user,
      verified: user.isVerified ||
        user.verified ||
        (user.internalPublicProperties &&
          !!user.internalPublicProperties.verified)
    });
  }
}