Skip to content

Commit

Permalink
fix: interaction metadata user is an object now (#668)
Browse files Browse the repository at this point in the history
* fix: interaction metadata user is an object now

- See : discord/discord-api-docs#6815

* Shame on me, i forgor to update the test

* Fix invalid cast

* fix: CI

---------

Co-authored-by: Mylo Fawcett <[email protected]>
  • Loading branch information
Lexedia and abitofevrything committed Jul 7, 2024
1 parent 672cd3d commit ecf79e1
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
5 changes: 4 additions & 1 deletion lib/src/http/managers/message_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -325,10 +325,13 @@ class MessageManager extends Manager<Message> {
}

MessageInteractionMetadata parseMessageInteractionMetadata(Map<String, Object?> raw) {
final user = client.users.parse(raw['user'] as Map<String, Object?>);

return MessageInteractionMetadata(
id: Snowflake.parse(raw['id']!),
type: InteractionType(raw['type'] as int),
userId: Snowflake.parse(raw['user_id']!),
userId: user.id,
user: user,
authorizingIntegrationOwners: {
for (final MapEntry(:key, :value) in (raw['authorizing_integration_owners'] as Map<String, Object?>).entries)
ApplicationIntegrationType(int.parse(key)): Snowflake.parse(value!),
Expand Down
4 changes: 4 additions & 0 deletions lib/src/models/message/message.dart
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,9 @@ class MessageInteractionMetadata with ToStringHelper {
/// ID of the user that triggered the interaction.
final Snowflake userId;

/// The user that triggered the interaction.
final User user;

/// IDs for installation context(s) related to an interaction.
final Map<ApplicationIntegrationType, Snowflake> authorizingIntegrationOwners;

Expand All @@ -435,6 +438,7 @@ class MessageInteractionMetadata with ToStringHelper {
required this.id,
required this.type,
required this.userId,
required this.user,
required this.authorizingIntegrationOwners,
required this.originalResponseMessageId,
required this.interactedMessageId,
Expand Down
27 changes: 26 additions & 1 deletion test/unit/http/managers/message_manager_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,14 @@ void checkCrosspostedMessage(Message message) {
final sampleMessageInteractionMetadata = {
"id": "1234567891234567800",
"type": 2,
"user_id": "1234567891234567801",
"user": {
"id": "1234567891234567801",
"username": "rizzedskibidi",
"discriminator": "0",
"global_name": "Read if cute",
"flags": 256,
"avatar": "a_abc123",
},
"authorizing_integration_owners": {
"0": "1234567891234567802",
"1": "1234567891234567803",
Expand All @@ -154,6 +161,14 @@ final sampleMessageInteractionMetadata = {
"id": "1234567891234567806",
"type": 2,
"user_id": "1234567891234567807",
"user": {
"username": "nocap-fr",
"discriminator": "0",
"id": "1234567891234567807",
"avatar": "a_abc123",
"global_name": "Iloaf",
"flags": 256,
},
"authorizing_integration_owners": {
"0": "1234567891234567808",
"1": "1234567891234567809",
Expand All @@ -165,6 +180,11 @@ void checkMessageInteractionMetadata(MessageInteractionMetadata metadata) {
expect(metadata.id, equals(Snowflake(1234567891234567800)));
expect(metadata.type, equals(InteractionType.applicationCommand));
expect(metadata.userId, equals(Snowflake(1234567891234567801)));
expect(metadata.user.username, equals('rizzedskibidi'));
expect(metadata.user.discriminator, equals('0'));
expect(metadata.user.globalName, equals('Read if cute'));
expect(metadata.user.flags, equals(UserFlags(256)));
expect(metadata.user.avatarHash, equals('a_abc123'));
expect(
metadata.authorizingIntegrationOwners,
equals({
Expand All @@ -178,6 +198,11 @@ void checkMessageInteractionMetadata(MessageInteractionMetadata metadata) {
expect(metadata2.id, equals(Snowflake(1234567891234567806)));
expect(metadata2.type, equals(InteractionType.applicationCommand));
expect(metadata2.userId, equals(Snowflake(1234567891234567807)));
expect(metadata2.user.username, equals('nocap-fr'));
expect(metadata2.user.discriminator, equals('0'));
expect(metadata2.user.globalName, equals('Iloaf'));
expect(metadata2.user.flags, equals(UserFlags(256)));
expect(metadata2.user.avatarHash, equals('a_abc123'));
expect(
metadata2.authorizingIntegrationOwners,
equals({
Expand Down

0 comments on commit ecf79e1

Please sign in to comment.