prepare message object content editing
This commit is contained in:
Vendored
+36
-30
@@ -508,16 +508,16 @@
|
|||||||
if (channels.indexOf(this.primaryChannel.value) == -1) return;
|
if (channels.indexOf(this.primaryChannel.value) == -1) return;
|
||||||
if (data.subscribed != void 0) this.handleSubscription(data.subscribed);
|
if (data.subscribed != void 0) this.handleSubscription(data.subscribed);
|
||||||
if (!data.messageBody) return;
|
if (!data.messageBody) return;
|
||||||
const { sender, body, channel, isoDate, messageObject } = JSON.parse(
|
const message = JSON.parse(data.messageBody);
|
||||||
data.messageBody
|
const { sender, body, channel, isoDate, messageObjectString } = message;
|
||||||
);
|
if (messageObjectString) {
|
||||||
if (messageObject) {
|
const decryptedMessageObjectString = await decryptString(
|
||||||
const decrypted = await decryptString(
|
messageObjectString,
|
||||||
messageObject,
|
|
||||||
this.encryptionKey.value
|
this.encryptionKey.value
|
||||||
);
|
);
|
||||||
const object = JSON.parse(decrypted);
|
const messageObject = JSON.parse(decryptedMessageObjectString);
|
||||||
if (object.id && object.title) return this.handleMessageObject(object);
|
if (messageObject.id && messageObject.title)
|
||||||
|
return this.handleMessageObject(messageObject);
|
||||||
}
|
}
|
||||||
this.handleMessage({
|
this.handleMessage({
|
||||||
sender,
|
sender,
|
||||||
@@ -545,10 +545,10 @@
|
|||||||
const isSent = await this.sendMessage(message);
|
const isSent = await this.sendMessage(message);
|
||||||
if (isSent == true) this.outbox.remove(message);
|
if (isSent == true) this.outbox.remove(message);
|
||||||
});
|
});
|
||||||
this.objectOutbox.value.forEach(async (object) => {
|
this.objectOutbox.value.forEach(async (messageObject) => {
|
||||||
const chatMessage = await this.createChatMessage("", object);
|
const chatMessage = await this.createChatMessage("", messageObject);
|
||||||
const isSent = await this.sendMessage(chatMessage);
|
const isSent = await this.sendMessage(chatMessage);
|
||||||
if (isSent == true) this.objectOutbox.remove(object.id);
|
if (isSent == true) this.objectOutbox.remove(messageObject.id);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
// messages
|
// messages
|
||||||
@@ -568,7 +568,7 @@
|
|||||||
isoDate: (/* @__PURE__ */ new Date()).toISOString()
|
isoDate: (/* @__PURE__ */ new Date()).toISOString()
|
||||||
};
|
};
|
||||||
if (messageObject)
|
if (messageObject)
|
||||||
chatMessage.messageObject = await encryptString(
|
chatMessage.messageObjectString = await encryptString(
|
||||||
JSON.stringify(messageObject),
|
JSON.stringify(messageObject),
|
||||||
this.encryptionKey.value
|
this.encryptionKey.value
|
||||||
);
|
);
|
||||||
@@ -618,7 +618,7 @@
|
|||||||
return {
|
return {
|
||||||
id: UUID(),
|
id: UUID(),
|
||||||
title,
|
title,
|
||||||
dateLastEdited: /* @__PURE__ */ new Date(),
|
isoDateLastEdited: (/* @__PURE__ */ new Date()).toISOString(),
|
||||||
contentVersions: []
|
contentVersions: []
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
@@ -626,22 +626,22 @@
|
|||||||
this.objects.set(messageObject.id, messageObject);
|
this.objects.set(messageObject.id, messageObject);
|
||||||
};
|
};
|
||||||
updateObject = (id, contents) => {
|
updateObject = (id, contents) => {
|
||||||
const object = this.objects.value.get(id);
|
const messageObject = this.objects.value.get(id);
|
||||||
if (!object) return;
|
if (!messageObject) return;
|
||||||
object.contentVersions.push(contents);
|
messageObject.contentVersions.push(contents);
|
||||||
this.sendObject(object);
|
this.sendObject(messageObject);
|
||||||
};
|
};
|
||||||
addObjectAndSend = (object) => {
|
addObjectAndSend = (messageObject) => {
|
||||||
this.addObject(object);
|
this.addObject(messageObject);
|
||||||
this.sendObject(object);
|
this.sendObject(messageObject);
|
||||||
};
|
};
|
||||||
sendObject = (object) => {
|
sendObject = (messageObject) => {
|
||||||
this.objectOutbox.set(object.id, object);
|
this.objectOutbox.set(messageObject.id, messageObject);
|
||||||
this.sendMessagesInOutbox();
|
this.sendMessagesInOutbox();
|
||||||
};
|
};
|
||||||
deleteObject = (object) => {
|
deleteObject = (messageObject) => {
|
||||||
this.objects.remove(object.id);
|
this.objects.remove(messageObject.id);
|
||||||
this.objectOutbox.remove(object.id);
|
this.objectOutbox.remove(messageObject.id);
|
||||||
};
|
};
|
||||||
resendObjects = () => {
|
resendObjects = () => {
|
||||||
this.objects.value.forEach((messageObject) => {
|
this.objects.value.forEach((messageObject) => {
|
||||||
@@ -653,7 +653,10 @@
|
|||||||
};
|
};
|
||||||
getLatestObjectContent = (messageObject) => {
|
getLatestObjectContent = (messageObject) => {
|
||||||
const versions = messageObject.contentVersions;
|
const versions = messageObject.contentVersions;
|
||||||
if (versions.length == 0) return {};
|
if (versions.length == 0)
|
||||||
|
return {
|
||||||
|
isoDateVersionCreated: (/* @__PURE__ */ new Date()).toISOString()
|
||||||
|
};
|
||||||
return versions[versions.length - 1];
|
return versions[versions.length - 1];
|
||||||
};
|
};
|
||||||
// channel
|
// channel
|
||||||
@@ -976,6 +979,7 @@
|
|||||||
toggleChatTools: "toggle chat tools",
|
toggleChatTools: "toggle chat tools",
|
||||||
objectTitle: "Object title",
|
objectTitle: "Object title",
|
||||||
objectTitlePlaceholder: "My object",
|
objectTitlePlaceholder: "My object",
|
||||||
|
objectVersion: "Object version",
|
||||||
resendObjects: "Resend all objects",
|
resendObjects: "Resend all objects",
|
||||||
deleteObject: "Delete object"
|
deleteObject: "Delete object"
|
||||||
};
|
};
|
||||||
@@ -1187,26 +1191,28 @@
|
|||||||
|
|
||||||
// src/Views/Objects/objectDetailModal.tsx
|
// src/Views/Objects/objectDetailModal.tsx
|
||||||
function ObjectDetailModal(chat, messageObject, isPresented) {
|
function ObjectDetailModal(chat, messageObject, isPresented) {
|
||||||
|
const editingTitle = new State(messageObject.title);
|
||||||
function closeModal() {
|
function closeModal() {
|
||||||
isPresented.value = false;
|
isPresented.value = false;
|
||||||
}
|
}
|
||||||
function saveAndClose() {
|
function saveAndClose() {
|
||||||
messageObject.title = editingTitle.value;
|
messageObject.title = editingTitle.value;
|
||||||
chat.updateObject(messageObject.id, {});
|
chat.updateObject(messageObject.id, {
|
||||||
|
isoDateVersionCreated: (/* @__PURE__ */ new Date()).toISOString()
|
||||||
|
});
|
||||||
closeModal();
|
closeModal();
|
||||||
}
|
}
|
||||||
function deleteAndClose() {
|
function deleteAndClose() {
|
||||||
chat.deleteObject(messageObject);
|
chat.deleteObject(messageObject);
|
||||||
closeModal();
|
closeModal();
|
||||||
}
|
}
|
||||||
const editingTitle = new State(messageObject.title);
|
return /* @__PURE__ */ createElement("div", { class: "modal", "toggle:open": isPresented }, /* @__PURE__ */ createElement("div", null, /* @__PURE__ */ createElement("main", null, /* @__PURE__ */ createElement("h2", null, messageObject.title), /* @__PURE__ */ createElement("span", { class: "secondary" }, messageObject.id), /* @__PURE__ */ createElement("hr", null), /* @__PURE__ */ createElement("label", { class: "tile" }, /* @__PURE__ */ createElement("span", { class: "icon" }, "label"), /* @__PURE__ */ createElement("div", null, /* @__PURE__ */ createElement("span", null, translation.objectTitle), /* @__PURE__ */ createElement(
|
||||||
return /* @__PURE__ */ createElement("div", { class: "modal", "toggle:open": isPresented }, /* @__PURE__ */ createElement("div", null, /* @__PURE__ */ createElement("main", null, /* @__PURE__ */ createElement("h2", null, messageObject.title), /* @__PURE__ */ createElement("div", null, /* @__PURE__ */ createElement("label", { class: "tile" }, /* @__PURE__ */ createElement("span", { class: "icon" }, "label"), /* @__PURE__ */ createElement("div", null, /* @__PURE__ */ createElement("span", null, translation.objectTitle), /* @__PURE__ */ createElement(
|
|
||||||
"input",
|
"input",
|
||||||
{
|
{
|
||||||
"bind:value": editingTitle,
|
"bind:value": editingTitle,
|
||||||
placeholder: translation.objectTitlePlaceholder
|
placeholder: translation.objectTitlePlaceholder
|
||||||
}
|
}
|
||||||
)))), /* @__PURE__ */ createElement("hr", null), /* @__PURE__ */ createElement("button", { class: "danger", "on:click": deleteAndClose }, translation.deleteObject, /* @__PURE__ */ createElement("span", { class: "icon" }, "delete"))), /* @__PURE__ */ createElement("div", { class: "flex-row" }, /* @__PURE__ */ createElement("button", { class: "flex-1 width-100 danger", "on:click": closeModal }, translation.discard), /* @__PURE__ */ createElement("button", { class: "flex-1 width-100 primary", "on:click": saveAndClose }, translation.save, /* @__PURE__ */ createElement("span", { class: "icon" }, "save")))));
|
))), /* @__PURE__ */ createElement("hr", null), /* @__PURE__ */ createElement("label", { class: "tile" }, /* @__PURE__ */ createElement("span", { class: "icon" }, "history"), /* @__PURE__ */ createElement("div", null, /* @__PURE__ */ createElement("span", null, translation.objectVersion), /* @__PURE__ */ createElement("select", null, ...messageObject.contentVersions.map((content) => /* @__PURE__ */ createElement("option", null, new Date(content.isoDateVersionCreated).toLocaleString()))), /* @__PURE__ */ createElement("span", { class: "icon" }, "arrow_drop_down"))), /* @__PURE__ */ createElement("hr", null), /* @__PURE__ */ createElement("button", { class: "danger", "on:click": deleteAndClose }, translation.deleteObject, /* @__PURE__ */ createElement("span", { class: "icon" }, "delete"))), /* @__PURE__ */ createElement("div", { class: "flex-row" }, /* @__PURE__ */ createElement("button", { class: "flex-1 width-100 danger", "on:click": closeModal }, translation.discard), /* @__PURE__ */ createElement("button", { class: "flex-1 width-100 primary", "on:click": saveAndClose }, translation.save, /* @__PURE__ */ createElement("span", { class: "icon" }, "save")))));
|
||||||
}
|
}
|
||||||
|
|
||||||
// src/Views/Objects/objectListEntry.tsx
|
// src/Views/Objects/objectListEntry.tsx
|
||||||
|
|||||||
Vendored
+1
-1
@@ -602,7 +602,7 @@ label.tile:has(> span.icon) {
|
|||||||
padding-left: var(--control-padding);
|
padding-left: var(--control-padding);
|
||||||
}
|
}
|
||||||
|
|
||||||
label.tile:has(> span.icon) input {
|
label.tile:has(> span.icon) :is(input, select) {
|
||||||
padding-left: 0px;
|
padding-left: 0px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+11
-5
@@ -29,11 +29,13 @@ export interface ChatMessage {
|
|||||||
export interface MessageObject {
|
export interface MessageObject {
|
||||||
id: string;
|
id: string;
|
||||||
title: string;
|
title: string;
|
||||||
dateLastEdited: Date;
|
isoDateLastEdited: string;
|
||||||
contentVersions: MessageObjectContent[];
|
contentVersions: MessageObjectContent[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface MessageObjectContent {}
|
export interface MessageObjectContent {
|
||||||
|
isoDateVersionCreated: string;
|
||||||
|
}
|
||||||
|
|
||||||
// chat
|
// chat
|
||||||
export class Chat {
|
export class Chat {
|
||||||
@@ -163,7 +165,8 @@ export class Chat {
|
|||||||
this.encryptionKey.value
|
this.encryptionKey.value
|
||||||
);
|
);
|
||||||
const messageObject = JSON.parse(decryptedMessageObjectString);
|
const messageObject = JSON.parse(decryptedMessageObjectString);
|
||||||
if (messageObject.id && messageObject.title) return this.handleMessageObject(messageObject);
|
if (messageObject.id && messageObject.title)
|
||||||
|
return this.handleMessageObject(messageObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.handleMessage({
|
this.handleMessage({
|
||||||
@@ -296,7 +299,7 @@ export class Chat {
|
|||||||
return {
|
return {
|
||||||
id: React.UUID(),
|
id: React.UUID(),
|
||||||
title,
|
title,
|
||||||
dateLastEdited: new Date(),
|
isoDateLastEdited: new Date().toISOString(),
|
||||||
contentVersions: [],
|
contentVersions: [],
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
@@ -341,7 +344,10 @@ export class Chat {
|
|||||||
messageObject: MessageObject
|
messageObject: MessageObject
|
||||||
): MessageObjectContent => {
|
): MessageObjectContent => {
|
||||||
const versions = messageObject.contentVersions;
|
const versions = messageObject.contentVersions;
|
||||||
if (versions.length == 0) return {};
|
if (versions.length == 0)
|
||||||
|
return {
|
||||||
|
isoDateVersionCreated: new Date().toISOString(),
|
||||||
|
};
|
||||||
return versions[versions.length - 1];
|
return versions[versions.length - 1];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
import * as React from "bloatless-react";
|
import * as React from "bloatless-react";
|
||||||
|
|
||||||
import { Chat, MessageObject } from "../../Model/chatModel";
|
import {
|
||||||
|
Chat,
|
||||||
|
MessageObject,
|
||||||
|
MessageObjectContent,
|
||||||
|
} from "../../Model/chatModel";
|
||||||
|
|
||||||
import { translation } from "../../translations";
|
import { translation } from "../../translations";
|
||||||
|
|
||||||
@@ -9,13 +13,22 @@ export function ObjectDetailModal(
|
|||||||
messageObject: MessageObject,
|
messageObject: MessageObject,
|
||||||
isPresented: React.State<boolean>
|
isPresented: React.State<boolean>
|
||||||
) {
|
) {
|
||||||
|
// state
|
||||||
|
const editingTitle = new React.State(messageObject.title);
|
||||||
|
const selectedMessageObject = new React.State<MessageObjectContent>(
|
||||||
|
chat.getLatestObjectContent(messageObject)
|
||||||
|
);
|
||||||
|
|
||||||
|
// methods
|
||||||
function closeModal() {
|
function closeModal() {
|
||||||
isPresented.value = false;
|
isPresented.value = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
function saveAndClose() {
|
function saveAndClose() {
|
||||||
messageObject.title = editingTitle.value;
|
messageObject.title = editingTitle.value;
|
||||||
chat.updateObject(messageObject.id, {});
|
chat.updateObject(messageObject.id, {
|
||||||
|
isoDateVersionCreated: new Date().toISOString(),
|
||||||
|
});
|
||||||
closeModal();
|
closeModal();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -24,30 +37,46 @@ export function ObjectDetailModal(
|
|||||||
closeModal();
|
closeModal();
|
||||||
}
|
}
|
||||||
|
|
||||||
const editingTitle = new React.State(messageObject.title);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div class="modal" toggle:open={isPresented}>
|
<div class="modal" toggle:open={isPresented}>
|
||||||
<div>
|
<div>
|
||||||
<main>
|
<main>
|
||||||
<h2>{messageObject.title}</h2>
|
<h2>{messageObject.title}</h2>
|
||||||
|
<span class="secondary">{messageObject.id}</span>
|
||||||
<div>
|
|
||||||
<label class="tile">
|
|
||||||
<span class="icon">label</span>
|
|
||||||
<div>
|
|
||||||
<span>{translation.objectTitle}</span>
|
|
||||||
<input
|
|
||||||
bind:value={editingTitle}
|
|
||||||
placeholder={translation.objectTitlePlaceholder}
|
|
||||||
></input>
|
|
||||||
</div>
|
|
||||||
</label>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<hr></hr>
|
<hr></hr>
|
||||||
|
|
||||||
<button class="danger" on:click={deleteAndClose}>
|
<label class="tile">
|
||||||
|
<span class="icon">label</span>
|
||||||
|
<div>
|
||||||
|
<span>{translation.objectTitle}</span>
|
||||||
|
<input
|
||||||
|
bind:value={editingTitle}
|
||||||
|
placeholder={translation.objectTitlePlaceholder}
|
||||||
|
></input>
|
||||||
|
</div>
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<hr></hr>
|
||||||
|
|
||||||
|
<label class="tile">
|
||||||
|
<span class="icon">history</span>
|
||||||
|
<div>
|
||||||
|
<span>{translation.objectVersion}</span>
|
||||||
|
<select>
|
||||||
|
{...messageObject.contentVersions.map((content) => (
|
||||||
|
<option>
|
||||||
|
{new Date(content.isoDateVersionCreated).toLocaleString()}
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
|
</select>
|
||||||
|
<span class="icon">arrow_drop_down</span>
|
||||||
|
</div>
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<hr></hr>
|
||||||
|
|
||||||
|
<button class="danger width-input" on:click={deleteAndClose}>
|
||||||
{translation.deleteObject}
|
{translation.deleteObject}
|
||||||
<span class="icon">delete</span>
|
<span class="icon">delete</span>
|
||||||
</button>
|
</button>
|
||||||
|
|||||||
@@ -71,6 +71,8 @@ const englishTranslations = {
|
|||||||
|
|
||||||
objectTitle: "Object title",
|
objectTitle: "Object title",
|
||||||
objectTitlePlaceholder: "My object",
|
objectTitlePlaceholder: "My object",
|
||||||
|
|
||||||
|
objectVersion: "Object version",
|
||||||
|
|
||||||
resendObjects: "Resend all objects",
|
resendObjects: "Resend all objects",
|
||||||
deleteObject: "Delete object",
|
deleteObject: "Delete object",
|
||||||
|
|||||||
Reference in New Issue
Block a user