cleanup, add button to resend messages
This commit is contained in:
+22
-9
@@ -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 => {
|
||||
|
||||
Reference in New Issue
Block a user