Skip to content

Commit

Permalink
Improvements for Forward and PartialMessageData
Browse files Browse the repository at this point in the history
- Created PartialMessageUpdateData for the Update Message response
- Include test for forward message response
- Fixes for PartialMessageData used in Forward
  • Loading branch information
Doc94 committed Aug 31, 2024
1 parent 26151b0 commit 2ccf533
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@ static ImmutablePartialMessageData.Builder builder() {
return ImmutablePartialMessageData.builder();
}

Id id();

@JsonProperty("channel_id")
Id channelId();

@JsonProperty("guild_id")
Possible<Id> guildId();

Expand Down Expand Up @@ -86,4 +81,6 @@ static ImmutablePartialMessageData.Builder builder() {

Possible<MessageInteractionData> interaction();

Possible<List<ComponentData>> components();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package discord4j.discordjson.json;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import discord4j.discordjson.Id;
import org.immutables.value.Value;

@Value.Immutable
@JsonSerialize(as = ImmutablePartialMessageUpdateData.class)
@JsonDeserialize(as = ImmutablePartialMessageUpdateData.class)
public interface PartialMessageUpdateData extends PartialMessageData {

static ImmutablePartialMessageUpdateData.Builder builder() {
return ImmutablePartialMessageUpdateData.builder();
}

Id id();

@JsonProperty("channel_id")
Id channelId();

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.fasterxml.jackson.annotation.JsonUnwrapped;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import discord4j.discordjson.json.PartialMessageData;
import discord4j.discordjson.json.PartialMessageUpdateData;
import org.immutables.value.Value;

@Value.Immutable
Expand All @@ -16,5 +16,5 @@ static ImmutableMessageUpdate.Builder builder() {
}

@JsonUnwrapped
PartialMessageData message();
PartialMessageUpdateData message();
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,18 @@ public void testCreateMessageResponse() throws IOException {
log.info("{}", res);
}

@Test
public void testCreateMessageWithForwardResponse() throws IOException {
MessageData res = read("/rest/CreateMessageWithForwardResponse.json", MessageData.class);
log.info("{}", res);
}

@Test
public void testPartion() throws IOException {
PartialMessageData res = read("/rest/PartialTest.json", PartialMessageData.class);
log.info("{}", res);
}

@Test
public void testMessageCopyingCollectionMethods() throws IOException {
MessageData res = read("/rest/CreateMessageResponse.json", MessageData.class);
Expand Down
55 changes: 55 additions & 0 deletions src/test/resources/rest/CreateMessageWithForwardResponse.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{
"type": 0,
"content": "",
"mentions": [],
"mention_roles": [],
"attachments": [],
"embeds": [],
"timestamp": "2024-08-31T02:38:50.292000+00:00",
"edited_timestamp": null,
"flags": 16384,
"components": [],
"id": "1279269138510118913",
"channel_id": "1088465252804481025",
"author": {
"id": "719574575557509202",
"username": "DoggoFN",
"avatar": "ca9e2a158768a8e7e38861c16c575ffb",
"discriminator": "9425",
"public_flags": 0,
"flags": 0,
"bot": true,
"banner": null,
"accent_color": null,
"global_name": null,
"avatar_decoration_data": null,
"banner_color": null,
"clan": null
},
"pinned": false,
"mention_everyone": false,
"tts": false,
"message_reference": {
"type": 1,
"channel_id": "1088465252804481025",
"message_id": "1265424582311936060",
"guild_id": "405699020564987914"
},
"position": 0,
"message_snapshots": [
{
"message": {
"type": 0,
"content": "What is Lorem Ipsum?\nLorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.",
"mentions": [],
"mention_roles": [],
"attachments": [],
"embeds": [],
"timestamp": "2024-07-23T21:45:30.875000+00:00",
"edited_timestamp": null,
"flags": 0,
"components": []
}
}
]
}

0 comments on commit 2ccf533

Please sign in to comment.