Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add back a way for users to create ephemeral interaction followups #523

Merged
merged 3 commits into from
Aug 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions lib/src/http/managers/interaction_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -275,15 +275,19 @@ class InteractionManager {
Future<void> deleteOriginalResponse(String token) => _deleteResponse(token, '@original');

/// Create a followup to an interaction.
Future<Message> createFollowup(String token, MessageBuilder builder) async {
Future<Message> createFollowup(String token, MessageBuilder builder, {bool? isEphemeral}) async {
final route = HttpRoute()
..webhooks(id: applicationId.toString())
..add(HttpRoutePart(token));

final builtMessagePayload = builder.build();
if (isEphemeral != null) {
builtMessagePayload['flags'] = (builtMessagePayload['flags'] as int? ?? 0) | (isEphemeral ? MessageFlags.ephemeral.value : 0);
}

final HttpRequest request;
if (!identical(builder.attachments, sentinelList) && builder.attachments?.isNotEmpty == true) {
final attachments = builder.attachments!;
final payload = builder.build();

final files = <MultipartFile>[];
for (int i = 0; i < attachments.length; i++) {
Expand All @@ -293,21 +297,21 @@ class InteractionManager {
filename: attachments[i].fileName,
));

((payload['attachments'] as List)[i] as Map)['id'] = i.toString();
((builtMessagePayload['attachments'] as List)[i] as Map)['id'] = i.toString();
}

request = MultipartRequest(
route,
method: 'POST',
jsonPayload: jsonEncode(payload),
jsonPayload: jsonEncode(builtMessagePayload),
files: files,
applyGlobalRateLimit: false,
);
} else {
request = BasicRequest(
route,
method: 'POST',
body: jsonEncode(builder.build()),
body: jsonEncode(builtMessagePayload),
applyGlobalRateLimit: false,
);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/src/models/interaction.dart
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ mixin MessageResponse<T> on Interaction<T> {
Future<void> deleteOriginalResponse() => manager.deleteOriginalResponse(token);

/// Create a followup to this interaction.
Future<Message> createFollowup(MessageBuilder builder) => manager.createFollowup(token, builder);
Future<Message> createFollowup(MessageBuilder builder, {bool? isEphemeral}) => manager.createFollowup(token, builder, isEphemeral: isEphemeral);

/// Fetch a followup to this interaction.
Future<Message> fetchFollowup(Snowflake id) => manager.fetchFollowup(token, id);
Expand Down