cleanup, add button to resend messages

This commit is contained in:
marlon-erler
2024-07-10 15:08:06 +02:00
parent 62ce36e017
commit dd8e86688b
6 changed files with 76 additions and 28 deletions
+22 -9
View File
@@ -38,6 +38,7 @@ export class Chat {
primaryChannelInput: React.State<string>;
cannotSendMessage: React.State<boolean>;
cannotResendMessage: React.State<boolean>;
cannotAddSecondaryChannel: React.State<boolean>;
cannotSetChannel: React.State<boolean>;
cannotUndoChannel: React.State<boolean>;
@@ -84,6 +85,14 @@ export class Chat {
this.isSubscribed.value == false ||
isConnected.value == false
);
this.cannotResendMessage = React.createProxyState(
[this.primaryChannel, this.isSubscribed, isConnected, senderName],
() =>
this.primaryChannel.value == "" ||
senderName.value == "" ||
this.isSubscribed.value == false ||
isConnected.value == false
);
this.cannotAddSecondaryChannel = React.createProxyState(
[this.newSecondaryChannelName],
() => this.newSecondaryChannelName.value == ""
@@ -141,9 +150,19 @@ export class Chat {
};
// messages
sendMessage = async (): Promise<void> => {
sendNewMessage = async (): Promise<void> => {
if (this.cannotSendMessage.value == true) return;
this.sendMessageText(this.composingMessage.value);
this.composingMessage.value = "";
};
resendMessage = (message: ChatMessage) => {
if (this.cannotResendMessage.value == true) return;
this.sendMessageText(message.body);
};
sendMessageText = async (messageText: string): Promise<void> => {
// get channels
const secondaryChannelNames: string[] = [
...this.secondaryChannels.value.values(),
@@ -156,11 +175,8 @@ export class Chat {
// encrypt
const encrypted =
this.encryptionKey.value == ""
? this.composingMessage.value
: (await encryptString(
this.composingMessage.value,
this.encryptionKey.value
)) || this.composingMessage.value;
? messageText
: await encryptString(messageText, this.encryptionKey.value);
// create object
const joinedChannelName = allChannelNames.join("/");
@@ -174,9 +190,6 @@ export class Chat {
// send
UDN.sendMessage(joinedChannelName, messageString);
// clear
this.composingMessage.value = "";
};
clearMessages = (): void => {