Fix issues

This commit is contained in:
Henry Hiles 2025-08-03 00:55:00 -04:00
commit 3eb61e3107
No known key found for this signature in database
2 changed files with 40 additions and 20 deletions

View file

@ -76,17 +76,18 @@ void main(List<String> argsRaw) async {
"✉️ Sending...", "✉️ Sending...",
); );
final from = mail.MailAddress(settings.mailName, settings.email); await container
final mailClient = await container.read( .read(MailClientController.provider.notifier)
MailClientController.provider.future, .sendMessage(
);
await mailClient.sendMessageBuilder(
mail.MessageBuilder.prepareMultipartAlternativeMessage(
plainText: plainText:
"""Your registration for Federated Nexus has been accepted! Your credentials are: """Your registration for Federated Nexus has been accepted! Your credentials are:
Username: ${registration.username}. Username: ${registration.username}.
Password: $password""", Password: $password
htmlText: markdownToHtml(
If you have any questions, check out our documentation: https://federated.nexus/services/matrix/.
If you have any issues, reply to this email.""",
markdown:
"""# Your registration for Federated Nexus has been accepted! """# Your registration for Federated Nexus has been accepted!
## Your credentials are: ## Your credentials are:
- ### Username: ${registration.username}. - ### Username: ${registration.username}.
@ -95,14 +96,11 @@ Password: $password""",
If you have any questions, check out [our documentation](https://federated.nexus/services/matrix/). If you have any questions, check out [our documentation](https://federated.nexus/services/matrix/).
If you have any issues, reply to this email.""", If you have any issues, reply to this email.""",
), subject:
)..subject = "Your registration for Federated Nexus has been accepted!", "Your registration for Federated Nexus has been accepted!",
from: from, from: mail.MailAddress(settings.mailName, settings.email),
recipients: [ to: mail.MailAddress(registration.username, registration.email),
mail.MailAddress(registration.username, registration.email),
],
); );
await event.room.redactEvent(reactionEvent!); await event.room.redactEvent(reactionEvent!);
await event.room.sendReaction(event.eventId, "✉️ Sent!"); await event.room.sendReaction(event.eventId, "✉️ Sent!");
} }
@ -114,7 +112,9 @@ If you have any issues, reply to this email.""",
(Router()..post("/", (Request request) async { (Router()..post("/", (Request request) async {
final body = await request.readAsString(); final body = await request.readAsString();
final registration = Registration.fromJson( final registration = Registration.fromJson(
Uri.splitQueryString(body), Uri.splitQueryString(
body,
).map((key, value) => MapEntry(key, value.toLowerCase())),
); );
final client = await container.read( final client = await container.read(

View file

@ -1,5 +1,6 @@
import "dart:io"; import "dart:io";
import "package:enough_mail/enough_mail.dart"; import "package:enough_mail/enough_mail.dart";
import "package:markdown/markdown.dart";
import "package:nexusbot/controllers/settings_controller.dart"; import "package:nexusbot/controllers/settings_controller.dart";
import "package:riverpod/riverpod.dart"; import "package:riverpod/riverpod.dart";
@ -20,6 +21,25 @@ class MailClientController extends AsyncNotifier<MailClient> {
return client; return client;
} }
Future<void> sendMessage({
required String plainText,
required String markdown,
required String subject,
required MailAddress from,
required MailAddress to,
}) async {
final client = await future;
return await client.sendMessageBuilder(
MessageBuilder.prepareMultipartAlternativeMessage(
plainText: plainText,
htmlText: markdownToHtml(markdown),
)
..subject = subject
..from = [from]
..to = [to],
);
}
static final provider = static final provider =
AsyncNotifierProvider<MailClientController, MailClient>( AsyncNotifierProvider<MailClientController, MailClient>(
MailClientController.new, MailClientController.new,