Skip to content

Commit

Permalink
fix(telegram-presenter): multiline logic
Browse files Browse the repository at this point in the history
  • Loading branch information
aldy505 committed Apr 7, 2024
1 parent b6a2e15 commit f96ae55
Show file tree
Hide file tree
Showing 2 changed files with 277 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/presentation/TelegramPresenter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,27 @@ export class TelegramPresenter implements IPresenter {
}

if (currentMessage.length + item.payload.length + MAGIC_DELIMITER_NUMBER >= 4096) {
// Push everything that's contained in currentMessages to messages.

Check warning on line 43 in src/presentation/TelegramPresenter.ts

View check run for this annotation

Codecov / codecov/patch

src/presentation/TelegramPresenter.ts#L43

Added line #L43 was not covered by tests
messages.push(currentMessage);
// Reset the currentMessage to current item payload.

Check warning on line 45 in src/presentation/TelegramPresenter.ts

View check run for this annotation

Codecov / codecov/patch

src/presentation/TelegramPresenter.ts#L45

Added line #L45 was not covered by tests
currentMessage = item.payload;
// See if currentMessage exceeds 4096, we'll just push it.
if (currentMessage.length >= 4096) {
messages.push(currentMessage.slice(0, 4096));
// Then we reset the currentMessage
currentMessage = "";
}

Check warning on line 52 in src/presentation/TelegramPresenter.ts

View check run for this annotation

Codecov / codecov/patch

src/presentation/TelegramPresenter.ts#L47-L52

Added lines #L47 - L52 were not covered by tests
continue;
}

currentMessage += `\n${"-".repeat(20)}\n\n`;
currentMessage += item.payload;
}

if (currentMessage !== "") {
messages.push(currentMessage);
}

Check warning on line 63 in src/presentation/TelegramPresenter.ts

View check run for this annotation

Codecov / codecov/patch

src/presentation/TelegramPresenter.ts#L60-L63

Added lines #L60 - L63 were not covered by tests
for (const message of messages) {
try {
await this._bot.api.sendMessage(info[0]!.targetId.toString(), message, {

Check warning on line 66 in src/presentation/TelegramPresenter.ts

View workflow job for this annotation

GitHub Actions / Check

Unexpected `await` inside a loop
Expand Down
Loading

0 comments on commit f96ae55

Please sign in to comment.