Initial move

This commit is contained in:
2024-09-03 14:50:33 +02:00
parent adb6be0006
commit 9fa656ed5e
138 changed files with 13117 additions and 0 deletions

View File

@@ -0,0 +1,46 @@
import { Channel, IChannel } from "./channel";
export interface IChannelList {
channels: IChannel[]
}
export class ChannelList implements IChannelList {
channels: Channel[] = [];
constructor(channels?: IChannelList) {
this.channels = channels?.channels?.map((chan) => new Channel(chan)) || [];
}
public addChannel(channel: Channel): void {
this.channels.push(channel);
}
public removeChannel(channelId: number): void {
this.channels = this.channels.filter(channel => channel.id !== channelId);
}
public getChannel(channelId: number): Channel|undefined {
return this.channels.find(channel => channel.id === channelId);
}
public getChannelByName(channelName: string): IChannel|undefined {
return this.channels.find(channel => channel.name === channelName);
}
public getChannels(): Channel[] {
return this.channels;
}
public getChannelIds(): number[] {
return this.channels.map(channel => channel.id);
}
public getChannelNames(): string[] {
return this.channels.map(channel => channel.name);
}
public getChannelId(channelName: string): number|undefined {
const channel = this.getChannelByName(channelName);
return channel ? channel.id : undefined;
}
}

View File

@@ -0,0 +1,60 @@
import { IMessage, Message } from "./message";
export interface IChannel {
id: number;
name: string;
messages: IMessage[];
createdAt: number;
}
export class Channel implements IChannel {
id: number;
name: string;
messages: Message[];
createdAt: number;
private messageToIdMap: Map<number, Message>;
constructor(channel: IChannel) {
this.id = channel.id;
this.name = channel.name;
this.messages = [];
this.messageToIdMap = new Map();
channel.messages?.forEach((msg) => this.addMessage(new Message(msg)));
this.createdAt = channel.createdAt;
}
public addMessage(message: Message): void {
this.messages.push(message);
this.messageToIdMap.set(message.id, message);
}
public removeMessage(messageId: number): void {
this.messages = this.messages.filter(message => message.id !== messageId);
this.messageToIdMap.delete(messageId);
}
public getMessage(messageId: number): Message|undefined {
return this.messageToIdMap.get(messageId);
}
public getMessageByContent(content: string): Message|undefined {
return this.messages.find(message => message.content === content);
}
public getMessages(): Message[] {
return this.messages;
}
public getMessageIds(): number[] {
return this.messages.map(message => message.id);
}
public getMessageContents(): string[] {
return this.messages.map(message => message.content);
}
public getMessageId(content: string): number|undefined {
const message = this.getMessageByContent(content);
return message ? message.id : undefined;
}
}

View File

@@ -0,0 +1,33 @@
export interface IMessage {
id: number;
channelId?: number;
content: string;
fileId?: number;
fileType?: string;
filePath?: string;
fileSize?: number;
originalName?: string;
createdAt: string;
}
export class Message implements IMessage {
id: number;
content: string;
fileId?: number;
fileType?: string;
filePath?: string;
fileSize?: number;
originalName?: string;
createdAt: string;
constructor(message: IMessage) {
this.id = message.id;
this.content = message.content;
this.fileId = message.fileId;
this.fileType = message.fileType;
this.filePath = message.filePath;
this.fileSize = message.fileSize;
this.originalName = message.originalName;
this.createdAt = message.createdAt;
}
}

View File

@@ -0,0 +1,10 @@
import { IChannelList } from "./channel-list";
import { IUnsentMessage } from "./unsent-message";
export interface IState {
token: string;
apiUrl: string;
defaultChannelId: number;
channelList: IChannelList;
unsentMessages: IUnsentMessage[];
}

View File

@@ -0,0 +1,23 @@
export interface IUnsentMessage {
id: number;
content: string;
blob?: Blob;
createdAt: string;
channelId: number;
}
export class UnsentMessage implements IUnsentMessage {
id: number;
content: string;
blob?: Blob;
createdAt: string;
channelId: number;
constructor(message: IUnsentMessage) {
this.id = message.id;
this.content = message.content;
this.blob = message.blob;
this.createdAt = message.createdAt;
this.channelId = message.channelId;
}
}