components/chatroom.js
function preProcessObject(obj) {
	for (let key in obj) {
		if (!obj.hasOwnProperty(key)) {
			continue;
		}

		let val = obj[key];
		if (key.match(/^steamid_/) && typeof val === 'string' && val != '0') {
			obj[key] = new SteamID(val.toString());
		} else if (key == 'timestamp' || key.match(/^time_/) || key.match(/_timestamp$/)) {
			if (val === 0) {
				obj[key] = null;
			} else if (val !== null) {
				obj[key] = new Date(val * 1000);
			}
		} else if (key == 'clanid' && typeof val === 'number') {
			let id = new SteamID();
			id.universe = SteamID.Universe.PUBLIC;
			id.type = SteamID.Type.CLAN;
			id.instance = SteamID.Instance.ALL;
			id.accountid = val;
			obj[key] = id;
		} else if ((key == 'accountid' || key.match(/^accountid_/) || key.match(/_accountid$/)) && (typeof val === 'number' || val === null)) {
			let newKey = key == 'accountid' ? 'steamid' : key.replace('accountid_', 'steamid_').replace('_accountid', '_steamid');
			obj[newKey] = val === 0 || val === null ? null : SteamID.fromIndividualAccountID(val);
			delete obj[key];
		} else if (key.includes('avatar_sha')) {
			let url = null;
			if (obj[key] && obj[key].length) {
				url = "https://steamcdn-a.akamaihd.net/steamcommunity/public/images/chaticons/";
				url += obj[key][0].toString(16) + '/';
				url += obj[key][1].toString(16) + '/';
				url += obj[key][2].toString(16) + '/';
				url += obj[key].toString('hex') + '_256.jpg';
			}

			obj[key.replace('avatar_sha', 'avatar_url')] = url;
		} else if (key.match(/^can_/) && obj[key] === null) {
			obj[key] = false;
		} else if (isDataObject(val)) {
			obj[key] = preProcessObject(val);
		} else if (Array.isArray(val) && val.every(isDataObject)) {
			obj[key] = val.map(v => preProcessObject(v));
		}
	}

	return obj;
}
function preProcessObject(obj) {
	for (let key in obj) {
		if (!obj.hasOwnProperty(key)) {
			continue;
		}

		let val = obj[key];
		if (key.match(/^steamid_/) && typeof val === 'string' && val != '0') {
			obj[key] = new SteamID(val.toString());
		} else if (key == 'timestamp' || key.match(/^time_/) || key.match(/_timestamp$/)) {
			if (val === 0) {
				obj[key] = null;
			} else if (val !== null) {
				obj[key] = new Date(val * 1000);
			}
		} else if (key == 'clanid' && typeof val === 'number') {
			let id = new SteamID();
			id.universe = SteamID.Universe.PUBLIC;
			id.type = SteamID.Type.CLAN;
			id.instance = SteamID.Instance.ALL;
			id.accountid = val;
			obj[key] = id;
		} else if ((key == 'accountid' || key.match(/^accountid_/) || key.match(/_accountid$/)) && (typeof val === 'number' || val === null)) {
			let newKey = key == 'accountid' ? 'steamid' : key.replace('accountid_', 'steamid_').replace('_accountid', '_steamid');
			obj[newKey] = val === 0 || val === null ? null : SteamID.fromIndividualAccountID(val);
			delete obj[key];
		} else if (key.includes('avatar_sha')) {
			let url = null;
			if (obj[key] && obj[key].length) {
				url = "https://steamcdn-a.akamaihd.net/steamcommunity/public/images/chaticons/";
				url += obj[key][0].toString(16) + '/';
				url += obj[key][1].toString(16) + '/';
				url += obj[key][2].toString(16) + '/';
				url += obj[key].toString('hex') + '_256.jpg';
			}

			obj[key.replace('avatar_sha', 'avatar_url')] = url;
		} else if (key.match(/^can_/) && obj[key] === null) {
			obj[key] = false;
		} else if (isDataObject(val)) {
			obj[key] = preProcessObject(val);
		} else if (Array.isArray(val) && val.every(isDataObject)) {
			obj[key] = val.map(v => preProcessObject(v));
		}
	}

	return obj;
}
function preProcessObject ( obj ) { for ( let key in obj ) { if ( ! obj . hasOwnProperty ( key ) ) { continue ; } let val = obj [ key ] ; if ( key . match ( / ^steamid_ / ) && typeof val === 'string' && val != '0' ) { obj [ key ] = new SteamID ( val . toString ( ) ) ; } else if ( key == 'timestamp' || key . match ( / ^time_ / ) || key . match ( / _timestamp$ / ) ) { if ( val === 0 ) { obj [ key ] = null ; } else if ( val !== null ) { obj [ key ] = new Date ( val * 1000 ) ; } } else if ( key == 'clanid' && typeof val === 'number' ) { let id = new SteamID ( ) ; id . universe = SteamID . Universe . PUBLIC ; id . type = SteamID . Type . CLAN ; id . instance = SteamID . Instance . ALL ; id . accountid = val ; obj [ key ] = id ; } else if ( ( key == 'accountid' || key . match ( / ^accountid_ / ) || key . match ( / _accountid$ / ) ) && ( typeof val === 'number' || val === null ) ) { let newKey = key == 'accountid' ? 'steamid' : key . replace ( 'accountid_' , 'steamid_' ) . replace ( '_accountid' , '_steamid' ) ; obj [ newKey ] = val === 0 || val === null ? null : SteamID . fromIndividualAccountID ( val ) ; delete obj [ key ] ; } else if ( key . includes ( 'avatar_sha' ) ) { let url = null ; if ( obj [ key ] && obj [ key ] . length ) { url = "https://steamcdn-a.akamaihd.net/steamcommunity/public/images/chaticons/" ; url += obj [ key ] [ 0 ] . toString ( 16 ) + '/' ; url += obj [ key ] [ 1 ] . toString ( 16 ) + '/' ; url += obj [ key ] [ 2 ] . toString ( 16 ) + '/' ; url += obj [ key ] . toString ( 'hex' ) + '_256.jpg' ; } obj [ key . replace ( 'avatar_sha' , 'avatar_url' ) ] = url ; } else if ( key . match ( / ^can_ / ) && obj [ key ] === null ) { obj [ key ] = false ; } else if ( isDataObject ( val ) ) { obj [ key ] = preProcessObject ( val ) ; } else if ( Array . isArray ( val ) && val . every ( isDataObject ) ) { obj [ key ] = val . map ( v => preProcessObject ( v ) ) ; } } return obj ; }
Pre-process a generic chat object.
@param {object} obj
@returns {object}
Pre - process a generic chat object .