more type fixes

This commit is contained in:
Aakansha Doshi
2024-03-29 15:27:13 +05:30
parent 799af4e550
commit 2fd6de0af5

View File

@@ -36,7 +36,7 @@ type Actor = {
type Message = { type Message = {
from?: { actor: string }; from?: { actor: string };
to?: { actor: string }; to?: { actor: string };
message?: message:
| string | string
| { | {
start: number; start: number;
@@ -146,19 +146,23 @@ export const addActor = function (
state.records.prevActor = id; state.records.prevActor = id;
}; };
const activationCount = (part?: string) => { const activationCount = (part: string) => {
let i; let i;
let count = 0; let count = 0;
if (!part) {
return 0;
}
for (i = 0; i < state.records.messages.length; i++) { for (i = 0; i < state.records.messages.length; i++) {
if ( if (
state.records.messages[i].type === LINETYPE.ACTIVE_START && state.records.messages[i].type === LINETYPE.ACTIVE_START &&
state.records.messages[i].from?.actor === part state.records.messages[i].from!.actor === part
) { ) {
count++; count++;
} }
if ( if (
state.records.messages[i].type === LINETYPE.ACTIVE_END && state.records.messages[i].type === LINETYPE.ACTIVE_END &&
state.records.messages[i].from?.actor === part state.records.messages[i].from!.actor === part
) { ) {
count--; count--;
} }
@@ -189,7 +193,7 @@ export const addSignal = function (
activate: boolean = false activate: boolean = false
) { ) {
if (messageType === LINETYPE.ACTIVE_END) { if (messageType === LINETYPE.ACTIVE_END) {
const cnt = activationCount(idFrom?.actor); const cnt = activationCount(idFrom?.actor || '');
if (cnt < 1) { if (cnt < 1) {
// Bail out as there is an activation signal from an inactive participant // Bail out as there is an activation signal from an inactive participant
const error = new Error( const error = new Error(
@@ -210,7 +214,7 @@ export const addSignal = function (
state.records.messages.push({ state.records.messages.push({
from: idFrom, from: idFrom,
to: idTo, to: idTo,
message: message?.text, message: message?.text ?? '',
wrap: (message?.wrap === undefined && autoWrap()) || !!message?.wrap, wrap: (message?.wrap === undefined && autoWrap()) || !!message?.wrap,
type: messageType, type: messageType,
activate, activate,