feat: lots more improvements
Some checks failed
JS Unit Tests / test (pull_request) Failing after 29s
Build Test / test (pull_request) Successful in 31s
PHP Unit Tests / test (pull_request) Successful in 1m12s

Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
2026-04-25 15:41:16 -04:00
parent 86e4772d45
commit 99a68737d1
26 changed files with 902 additions and 596 deletions

View File

@@ -8,6 +8,7 @@ import type {
MessagePartInterface,
MessagePartModelInterface
} from "@/types/message";
import { clonePlain } from './clone-plain';
/**
* Message class for working with message objects
@@ -25,29 +26,24 @@ export class MessageObject implements MessageModelInterface {
}
fromJson(data: MessageInterface): MessageObject {
this._data = data;
this._data = clonePlain(data);
this._body = null;
return this;
}
toJson(): MessageInterface {
const json = {
...this._data
};
if (this._body) {
json.body = this._body.toJson();
}
return json;
const json = this._body
? {
...this._data,
body: this._body.toJson(),
}
: this._data;
return clonePlain(json);
}
clone(): MessageObject {
const cloned = new MessageObject();
cloned._data = {
...this._data,
};
if (this._body) {
cloned._body = this._body.clone();
}
return cloned;
return new MessageObject().fromJson(this.toJson());
}
/** Properties */
@@ -101,7 +97,7 @@ export class MessageObject implements MessageModelInterface {
}
get flags(): { read?: boolean; flagged?: boolean; answered?: boolean; draft?: boolean } | {} {
return this._data.flags ?? {};
return clonePlain(this._data.flags ?? {});
}
get body(): MessagePartObject | null {
@@ -195,20 +191,20 @@ export class MessageAddressObject implements MessageAddressInterface {
_data: MessageAddressInterface;
constructor(data: MessageAddressInterface) {
this._data = data;
this._data = clonePlain(data);
}
fromJson(data: MessageAddressInterface): MessageAddressObject {
this._data = data;
this._data = clonePlain(data);
return this;
}
toJson(): MessageAddressInterface {
return this._data;
return clonePlain(this._data);
}
clone(): MessageAddressObject {
return new MessageAddressObject({ ...this._data });
return new MessageAddressObject(this.toJson());
}
/** Properties */
@@ -233,38 +229,40 @@ export class MessagePartObject implements MessagePartModelInterface {
constructor(data?: Partial<MessagePartInterface>) {
this._data = {
partId: data?.partId ?? null,
blobId: data?.blobId ?? null,
size: data?.size ?? null,
name: data?.name ?? null,
type: data?.type ?? null,
charset: data?.charset ?? null,
disposition: data?.disposition ?? null,
cid: data?.cid ?? null,
language: data?.language ?? null,
location: data?.location ?? null,
content: data?.content ?? null,
subParts: data?.subParts ?? [],
partId: clonePlain(data?.partId ?? null),
blobId: clonePlain(data?.blobId ?? null),
size: clonePlain(data?.size ?? null),
name: clonePlain(data?.name ?? null),
type: clonePlain(data?.type ?? null),
charset: clonePlain(data?.charset ?? null),
disposition: clonePlain(data?.disposition ?? null),
cid: clonePlain(data?.cid ?? null),
language: clonePlain(data?.language ?? null),
location: clonePlain(data?.location ?? null),
content: clonePlain(data?.content ?? null),
subParts: clonePlain(data?.subParts ?? []),
};
}
fromJson(data: MessagePartInterface): MessagePartObject {
this._data = data;
this._data = clonePlain(data);
this._subParts = [];
return this;
}
toJson(): MessagePartInterface {
const json = {
...this._data,
};
if (this._subParts.length > 0) {
json.subParts = this._subParts.map(subPart => subPart.toJson());
}
return json
const json = this._subParts.length > 0
? {
...this._data,
subParts: this._subParts.map(subPart => subPart.toJson()),
}
: this._data;
return clonePlain(json);
}
clone(): MessagePartObject {
return new MessagePartObject(JSON.parse(JSON.stringify(this._data)));
return new MessagePartObject().fromJson(this.toJson());
}
/** Properties */