This commit is contained in:
Bill 2021-12-08 06:47:06 -05:00
commit 9a2b740ce7
4 changed files with 32 additions and 97 deletions

View File

@ -1,91 +0,0 @@
import { IMessageDataWrapper } from '../../../../../../core';
export class GroupDataParser
{
private _id: number;
private _title: string;
private _badge: string;
private _colorA: string;
private _colorB: string;
private _ownerOrFavorite: boolean;
private _ownerId: number;
private _hasForum: boolean;
constructor(wrapper: IMessageDataWrapper)
{
if(!wrapper) throw new Error('invalid_wrapper');
this.flush();
this.parse(wrapper);
}
public flush(): boolean
{
this._id = 0;
this._title = null;
this._badge = null;
this._colorA = null;
this._colorB = null;
this._ownerOrFavorite = null;
this._ownerId = 0;
this._hasForum = false;
return true;
}
public parse(wrapper: IMessageDataWrapper): boolean
{
if(!wrapper) return false;
this._id = wrapper.readInt();
this._title = wrapper.readString();
this._badge = wrapper.readString();
this._colorA = wrapper.readString();
this._colorB = wrapper.readString();
this._ownerOrFavorite = wrapper.readBoolean();
this._ownerId = wrapper.readInt();
this._hasForum = wrapper.readBoolean();
return true;
}
public get id(): number
{
return this._id;
}
public get title(): string
{
return this._title;
}
public get badge(): string
{
return this._badge;
}
public get colorA(): string
{
return this._colorA;
}
public get colorB(): string
{
return this._colorB;
}
public get ownerOrFavorite(): boolean
{
return this._ownerOrFavorite;
}
public get ownerId(): number
{
return this._ownerId;
}
public get hasForum(): boolean
{
return this._hasForum;
}
}

View File

@ -1,3 +1,2 @@
export * from './GroupDataBadgePart';
export * from './GroupDataParser';
export * from './GroupMemberParser';

View File

@ -1,5 +1,5 @@
import { IMessageDataWrapper, IMessageParser } from '../../../../../../core';
import { GroupDataParser } from '../../group/utils/GroupDataParser';
import { HabboGroupEntryData } from '../HabboGroupEntryData';
export class UserProfileParser implements IMessageParser
{
@ -13,7 +13,7 @@ export class UserProfileParser implements IMessageParser
private _isMyFriend: boolean;
private _requestSent: boolean;
private _isOnline: boolean;
private _groups: GroupDataParser[];
private _groups: HabboGroupEntryData[];
private _secondsSinceLastVisit: number;
private _openProfileWindow: boolean;
@ -54,7 +54,7 @@ export class UserProfileParser implements IMessageParser
for(let i = 0; i < groupsCount; i++)
{
this._groups.push(new GroupDataParser(wrapper));
this._groups.push(new HabboGroupEntryData(wrapper));
}
this._secondsSinceLastVisit = wrapper.readInt();
@ -113,7 +113,7 @@ export class UserProfileParser implements IMessageParser
return this._isOnline;
}
public get groups(): GroupDataParser[]
public get groups(): HabboGroupEntryData[]
{
return this._groups;
}

View File

@ -39,8 +39,35 @@ declare global
export class LegacyExternalInterface
{
private static readonly MESSAGE_KEY = 'Nitro_LegacyExternalInterface';
private static _isListeningForPostMessages = false;
public static get available(): boolean
{
if(!this._isListeningForPostMessages)
{
this._isListeningForPostMessages = true;
window.addEventListener('message', (ev) =>
{
if(typeof ev.data !== 'string') return;
if(ev.data.startsWith(LegacyExternalInterface.MESSAGE_KEY))
{
const { method, params } = JSON.parse(
ev.data.substr(LegacyExternalInterface.MESSAGE_KEY.length)
);
const fn = (window as any)[method];
if(!fn) return;
fn(...params);
return;
}
});
}
return true;
}
@ -51,7 +78,7 @@ export class LegacyExternalInterface
{
if(window.top !== window)
{
window.top.postMessage('Nitro_LegacyExternalInterface' + JSON.stringify({
window.top.postMessage(LegacyExternalInterface.MESSAGE_KEY + JSON.stringify({
method,
params
}), '*');