updated protocols
This commit is contained in:
parent
7283e3f6f9
commit
531a32a5a5
37 changed files with 682 additions and 650 deletions
95
src/uiState.ts
Normal file
95
src/uiState.ts
Normal file
|
|
@ -0,0 +1,95 @@
|
|||
import { ipcEmit } from "@/composables/useEmitter";
|
||||
|
||||
class Profile implements Profile{
|
||||
crimata_id = "";
|
||||
name = "";
|
||||
photo = "";
|
||||
}
|
||||
|
||||
export default class UIState {
|
||||
|
||||
profile: Profile;
|
||||
messages: Message[];
|
||||
|
||||
constructor() {
|
||||
this.profile = new Profile();
|
||||
this.messages = [];
|
||||
}
|
||||
|
||||
emit() {
|
||||
ipcEmit("set-profile", this.profile);
|
||||
ipcEmit("init-messages", this.messages);
|
||||
}
|
||||
|
||||
set (message: Init) {
|
||||
this.profile = message.profile;
|
||||
this.messages = message.messages;
|
||||
this.emit();
|
||||
}
|
||||
|
||||
update(update: Update) {
|
||||
|
||||
if (update.name === "profile") {
|
||||
this.profile = update.data as Profile;
|
||||
ipcEmit("set-profile", this.profile);
|
||||
}
|
||||
|
||||
else if (update.name === "add") {
|
||||
this.messages.push(update.data as Message);
|
||||
ipcEmit("add-message", update.data);
|
||||
}
|
||||
|
||||
else if (update.name === "annotate") {
|
||||
this._annotate(update.data as Annotation);
|
||||
ipcEmit("update-message", update.data);
|
||||
}
|
||||
|
||||
else {
|
||||
this._delete(update.data as string);
|
||||
ipcEmit("delete-message", update.data);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
reset() {
|
||||
this.profile = new Profile();
|
||||
this.messages = [];
|
||||
this.emit();
|
||||
}
|
||||
|
||||
_annotate(annotation: Annotation) {
|
||||
|
||||
for (const i in this.messages) {
|
||||
|
||||
if (this.messages[i].uid == annotation.uid) {
|
||||
|
||||
if (annotation.name == "content") {
|
||||
this.messages[i].content = annotation.data as Content[];
|
||||
}
|
||||
|
||||
if (annotation.name == "context") {
|
||||
this.messages[i].context = annotation.data as Context;
|
||||
}
|
||||
|
||||
if (annotation.name == "seen") {
|
||||
this.messages[i].seen = annotation.data as boolean;
|
||||
}
|
||||
|
||||
ipcEmit("update-message", annotation);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
_delete(uid: string) {
|
||||
for (let i = 0; i < this.messages.length; i++) {
|
||||
if (this.messages[i].uid === uid) {
|
||||
this.messages.splice(i, 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in a new issue