mirror of
https://github.com/duckietm/Nitro-V3.git
synced 2026-06-20 07:26:19 +00:00
🆙 Init V3
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
import { IGroupChatData } from './IGroupChatData';
|
||||
|
||||
export const GetGroupChatData = (extraData: string) =>
|
||||
{
|
||||
if(!extraData || !extraData.length) return null;
|
||||
|
||||
const splitData = extraData.split('/');
|
||||
const username = splitData[0];
|
||||
const figure = splitData[1];
|
||||
const userId = parseInt(splitData[2]);
|
||||
|
||||
return ({ username: username, figure: figure, userId: userId } as IGroupChatData);
|
||||
};
|
||||
@@ -0,0 +1,6 @@
|
||||
export interface IGroupChatData
|
||||
{
|
||||
username: string;
|
||||
figure: string;
|
||||
userId: number;
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
import { FriendParser } from '@nitrots/nitro-renderer';
|
||||
|
||||
export class MessengerFriend
|
||||
{
|
||||
public static RELATIONSHIP_NONE: number = 0;
|
||||
public static RELATIONSHIP_HEART: number = 1;
|
||||
public static RELATIONSHIP_SMILE: number = 2;
|
||||
public static RELATIONSHIP_BOBBA: number = 3;
|
||||
|
||||
public id: number = -1;
|
||||
public name: string = null;
|
||||
public gender: number = 0;
|
||||
public online: boolean = false;
|
||||
public followingAllowed: boolean = false;
|
||||
public figure: string = null;
|
||||
public categoryId: number = 0;
|
||||
public motto: string = null;
|
||||
public realName: string = null;
|
||||
public lastAccess: string = null;
|
||||
public persistedMessageUser: boolean = false;
|
||||
public vipMember: boolean = false;
|
||||
public pocketHabboUser: boolean = false;
|
||||
public relationshipStatus: number = -1;
|
||||
public unread: number = 0;
|
||||
|
||||
public populate(parser: FriendParser): void
|
||||
{
|
||||
this.id = parser.id;
|
||||
this.name = parser.name;
|
||||
this.gender = parser.gender;
|
||||
this.online = parser.online;
|
||||
this.followingAllowed = parser.followingAllowed;
|
||||
this.figure = parser.figure;
|
||||
this.categoryId = parser.categoryId;
|
||||
this.motto = parser.motto;
|
||||
this.realName = parser.realName;
|
||||
this.lastAccess = parser.lastAccess;
|
||||
this.persistedMessageUser = parser.persistedMessageUser;
|
||||
this.vipMember = parser.vipMember;
|
||||
this.pocketHabboUser = parser.pocketHabboUser;
|
||||
this.relationshipStatus = parser.relationshipStatus;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
export class MessengerGroupType
|
||||
{
|
||||
public static readonly GROUP_CHAT = 0;
|
||||
public static readonly PRIVATE_CHAT = 1;
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
export class MessengerIconState
|
||||
{
|
||||
public static HIDDEN: number = 0;
|
||||
public static SHOW: number = 1;
|
||||
public static UNREAD: number = 2;
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
import { FriendRequestData } from '@nitrots/nitro-renderer';
|
||||
|
||||
export class MessengerRequest
|
||||
{
|
||||
private _id: number;
|
||||
private _name: string;
|
||||
private _requesterUserId: number;
|
||||
private _figureString: string;
|
||||
|
||||
public populate(data: FriendRequestData): boolean
|
||||
{
|
||||
if(!data) return false;
|
||||
|
||||
this._id = data.requestId;
|
||||
this._name = data.requesterName;
|
||||
this._figureString = data.figureString;
|
||||
this._requesterUserId = data.requesterUserId;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public get id(): number
|
||||
{
|
||||
return this._id;
|
||||
}
|
||||
|
||||
public get name(): string
|
||||
{
|
||||
return this._name;
|
||||
}
|
||||
|
||||
public get requesterUserId(): number
|
||||
{
|
||||
return this._requesterUserId;
|
||||
}
|
||||
|
||||
public get figureString(): string
|
||||
{
|
||||
return this._figureString;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
import { FriendCategoryData } from '@nitrots/nitro-renderer';
|
||||
|
||||
export class MessengerSettings
|
||||
{
|
||||
constructor(
|
||||
public userFriendLimit: number = 0,
|
||||
public normalFriendLimit: number = 0,
|
||||
public extendedFriendLimit: number = 0,
|
||||
public categories: FriendCategoryData[] = [])
|
||||
{}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
import { GetGroupChatData } from './GetGroupChatData';
|
||||
import { MessengerFriend } from './MessengerFriend';
|
||||
import { MessengerGroupType } from './MessengerGroupType';
|
||||
import { MessengerThreadChat } from './MessengerThreadChat';
|
||||
import { MessengerThreadChatGroup } from './MessengerThreadChatGroup';
|
||||
|
||||
export class MessengerThread
|
||||
{
|
||||
public static MESSAGE_RECEIVED: string = 'MT_MESSAGE_RECEIVED';
|
||||
public static THREAD_ID: number = 0;
|
||||
|
||||
private _threadId: number;
|
||||
private _participant: MessengerFriend;
|
||||
private _groups: MessengerThreadChatGroup[];
|
||||
private _lastUpdated: Date;
|
||||
private _unreadCount: number;
|
||||
|
||||
constructor(participant: MessengerFriend)
|
||||
{
|
||||
this._threadId = ++MessengerThread.THREAD_ID;
|
||||
this._participant = participant;
|
||||
this._groups = [];
|
||||
this._lastUpdated = new Date();
|
||||
this._unreadCount = 0;
|
||||
}
|
||||
|
||||
public addMessage(senderId: number, message: string, secondsSinceSent: number = 0, extraData: string = null, type: number = 0): MessengerThreadChat
|
||||
{
|
||||
const isGroupChat = (senderId < 0 && extraData);
|
||||
const userId = isGroupChat ? GetGroupChatData(extraData).userId : senderId;
|
||||
|
||||
const group = this.getLastGroup(userId);
|
||||
|
||||
if(!group) return;
|
||||
|
||||
if(isGroupChat) group.type = MessengerGroupType.GROUP_CHAT;
|
||||
|
||||
const chat = new MessengerThreadChat(senderId, message, secondsSinceSent, extraData, type);
|
||||
|
||||
group.addChat(chat);
|
||||
|
||||
this._lastUpdated = new Date();
|
||||
|
||||
this._unreadCount++;
|
||||
|
||||
return chat;
|
||||
}
|
||||
|
||||
private getLastGroup(userId: number): MessengerThreadChatGroup
|
||||
{
|
||||
let group = this._groups[(this._groups.length - 1)];
|
||||
|
||||
if(group && (group.userId === userId)) return group;
|
||||
|
||||
group = new MessengerThreadChatGroup(userId);
|
||||
|
||||
this._groups.push(group);
|
||||
|
||||
return group;
|
||||
}
|
||||
|
||||
public setRead(): void
|
||||
{
|
||||
this._unreadCount = 0;
|
||||
}
|
||||
|
||||
public get threadId(): number
|
||||
{
|
||||
return this._threadId;
|
||||
}
|
||||
|
||||
public get participant(): MessengerFriend
|
||||
{
|
||||
return this._participant;
|
||||
}
|
||||
|
||||
public get groups(): MessengerThreadChatGroup[]
|
||||
{
|
||||
return this._groups;
|
||||
}
|
||||
|
||||
public get lastUpdated(): Date
|
||||
{
|
||||
return this._lastUpdated;
|
||||
}
|
||||
|
||||
public get unreadCount(): number
|
||||
{
|
||||
return this._unreadCount;
|
||||
}
|
||||
|
||||
public get unread(): boolean
|
||||
{
|
||||
return (this._unreadCount > 0);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
export class MessengerThreadChat
|
||||
{
|
||||
public static CHAT: number = 0;
|
||||
public static ROOM_INVITE: number = 1;
|
||||
public static STATUS_NOTIFICATION: number = 2;
|
||||
public static SECURITY_NOTIFICATION: number = 3;
|
||||
|
||||
private _type: number;
|
||||
private _senderId: number;
|
||||
private _message: string;
|
||||
private _secondsSinceSent: number;
|
||||
private _extraData: string;
|
||||
private _date: Date;
|
||||
|
||||
constructor(senderId: number, message: string, secondsSinceSent: number = 0, extraData: string = null, type: number = 0)
|
||||
{
|
||||
this._type = type;
|
||||
this._senderId = senderId;
|
||||
this._message = message;
|
||||
this._secondsSinceSent = secondsSinceSent;
|
||||
this._extraData = extraData;
|
||||
this._date = new Date();
|
||||
}
|
||||
|
||||
public get type(): number
|
||||
{
|
||||
return this._type;
|
||||
}
|
||||
|
||||
public get senderId(): number
|
||||
{
|
||||
return this._senderId;
|
||||
}
|
||||
|
||||
public get message(): string
|
||||
{
|
||||
return this._message;
|
||||
}
|
||||
|
||||
public get secondsSinceSent(): number
|
||||
{
|
||||
return this._secondsSinceSent;
|
||||
}
|
||||
|
||||
public get extraData(): string
|
||||
{
|
||||
return this._extraData;
|
||||
}
|
||||
|
||||
public get date(): Date
|
||||
{
|
||||
return this._date;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
import { MessengerGroupType } from './MessengerGroupType';
|
||||
import { MessengerThreadChat } from './MessengerThreadChat';
|
||||
|
||||
export class MessengerThreadChatGroup
|
||||
{
|
||||
private _userId: number;
|
||||
private _chats: MessengerThreadChat[];
|
||||
private _type: number;
|
||||
|
||||
constructor(userId: number, type = MessengerGroupType.PRIVATE_CHAT)
|
||||
{
|
||||
this._userId = userId;
|
||||
this._chats = [];
|
||||
this._type = type;
|
||||
}
|
||||
|
||||
public addChat(message: MessengerThreadChat): void
|
||||
{
|
||||
this._chats.push(message);
|
||||
}
|
||||
|
||||
public get userId(): number
|
||||
{
|
||||
return this._userId;
|
||||
}
|
||||
|
||||
public get chats(): MessengerThreadChat[]
|
||||
{
|
||||
return this._chats;
|
||||
}
|
||||
|
||||
public get type(): number
|
||||
{
|
||||
return this._type;
|
||||
}
|
||||
|
||||
public set type(type: number)
|
||||
{
|
||||
this._type = type;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
import { CreateLinkEvent } from '@nitrots/nitro-renderer';
|
||||
|
||||
export function OpenMessengerChat(friendId: number = 0): void
|
||||
{
|
||||
if(friendId === 0) CreateLinkEvent('friends-messenger/toggle');
|
||||
else CreateLinkEvent(`friends-messenger/${ friendId }`);
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
export * from './GetGroupChatData';
|
||||
export * from './IGroupChatData';
|
||||
export * from './MessengerFriend';
|
||||
export * from './MessengerGroupType';
|
||||
export * from './MessengerIconState';
|
||||
export * from './MessengerRequest';
|
||||
export * from './MessengerSettings';
|
||||
export * from './MessengerThread';
|
||||
export * from './MessengerThreadChat';
|
||||
export * from './MessengerThreadChatGroup';
|
||||
export * from './OpenMessengerChat';
|
||||
Reference in New Issue
Block a user