chore: checkpoint current work

This commit is contained in:
Lorenzune
2026-04-03 05:22:26 +02:00
parent 83540ff329
commit 36c0221a54
477 changed files with 3799 additions and 1071 deletions
+23
View File
@@ -8,6 +8,7 @@ export class MessengerThread
{
public static MESSAGE_RECEIVED: string = 'MT_MESSAGE_RECEIVED';
public static THREAD_ID: number = 0;
private static MAX_CHATS: number = 250;
private _threadId: number;
private _participant: MessengerFriend;
@@ -38,6 +39,7 @@ export class MessengerThread
const chat = new MessengerThreadChat(senderId, message, secondsSinceSent, extraData, type);
group.addChat(chat);
this.pruneChats();
this._lastUpdated = new Date();
@@ -46,6 +48,27 @@ export class MessengerThread
return chat;
}
private pruneChats(): void
{
let totalChats = this._groups.reduce((total, current) => (total + current.chats.length), 0);
while(totalChats > MessengerThread.MAX_CHATS)
{
const firstGroup = this._groups[0];
if(!firstGroup) break;
if(firstGroup.chats.length) firstGroup.chats.shift();
if(!firstGroup.chats.length)
{
this._groups.shift();
}
totalChats--;
}
}
private getLastGroup(userId: number): MessengerThreadChatGroup
{
let group = this._groups[(this._groups.length - 1)];