Skip to content
This repository was archived by the owner on Aug 18, 2020. It is now read-only.

Commit 0986b8c

Browse files
committed
2 parents 85992f5 + d2ce4a4 commit 0986b8c

File tree

76 files changed

+1070
-938
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+1070
-938
lines changed

build.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name := "chatoverflow-api"
33
lazy val sourceGenerator = TaskKey[Unit]("sourceGenerator")
44

55
// Convention: majorVersion++ on api signature update (else: minorVersion ++)
6-
val majorVersion = 1
6+
val majorVersion = 2
77
val minorVersion = 0
88
version := s"$majorVersion.$minorVersion"
99

src/main/java/org/codeoverflow/chatoverflow/api/APIVersion.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
* THIS CLASS IS GENERATED WHILE COMPILING. DO CHANGE THE VERSION NUMBERS IN THE APIS BUILD.SBT!
55
*/
66
public class APIVersion {
7-
public static final int MAJOR_VERSION = 1;
7+
public static final int MAJOR_VERSION = 2;
88
public static final int MINOR_VERSION = 0;
99
}
Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,35 @@
11
package org.codeoverflow.chatoverflow.api.io.dto;
22

3+
/**
4+
* A basic user where we only know a unique identifier and a displayed name
5+
*/
36
public class User implements Identifiable {
4-
private final String id;
7+
private final String identifier;
58
private final String name;
6-
private final String login;
79

810
public User(String name) {
9-
this(name, name, "");
11+
this(name, name);
1012
}
1113

12-
public User(String id, String name) {
13-
this(id, name, "");
14-
}
15-
16-
public User(String id, String name, String login) {
17-
this.id = id;
14+
public User(String identifier, String name) {
15+
this.identifier = identifier;
1816
this.name = name;
19-
this.login = login;
2017
}
2118

2219
/**
23-
* @return unique user id if available, otherwise same as user name
20+
* A unique user identifier:<br>
21+
* An id or the unique login name. May be the same as the users display name
22+
*
23+
* @return the unique identifier of the user
2424
*/
2525
public String getId() {
26-
return id;
26+
return identifier;
2727
}
2828

2929
/**
30-
* @return user display name
30+
* @return users display name
3131
*/
32-
public String getName() {
32+
public String getDisplayName() {
3333
return name;
3434
}
35-
36-
/**
37-
* @return unique user login name
38-
*/
39-
public String getLogin() {
40-
return login;
41-
}
4235
}

src/main/java/org/codeoverflow/chatoverflow/api/io/dto/chat/ChatMessage.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,30 @@
22

33
import org.codeoverflow.chatoverflow.api.io.dto.Formatable;
44

5+
import java.time.OffsetDateTime;
56
import java.util.ArrayList;
67
import java.util.Collections;
78
import java.util.List;
89

910
/**
1011
* A generic message that is send in a chat
1112
*/
12-
public class ChatMessage<T extends ChatMessageAuthor, U extends Channel, V extends ChatEmoticon> implements Formatable {
13+
public class ChatMessage<T extends ChatMessageAuthor, U extends TextChannel, V extends ChatEmoticon> implements Formatable {
1314
private final String message;
1415
private final T author;
15-
private final Long timestamp;
16+
private final OffsetDateTime time;
1617
private final U channel;
1718
private final List<V> emoticons;
1819

19-
public ChatMessage(T author, String message, Long timestamp, U channel) {
20-
this(author, message, timestamp, channel, new ArrayList<>());
20+
public ChatMessage(T author, String message, OffsetDateTime time, U channel) {
21+
this(author, message, time, channel, new ArrayList<>());
2122
}
2223

23-
public ChatMessage(T author, String message, Long timestamp, U channel, List<V> emoticons) {
24+
public ChatMessage(T author, String message, OffsetDateTime time, U channel, List<V> emoticons) {
2425
Collections.sort(emoticons);
2526
this.message = message;
2627
this.author = author;
27-
this.timestamp = timestamp;
28+
this.time = time;
2829
this.channel = channel;
2930
this.emoticons = emoticons;
3031
}
@@ -44,10 +45,10 @@ public T getAuthor() {
4445
}
4546

4647
/**
47-
* @return timestamp when the message was created (value in epoch millis)
48+
* @return time when the message was created
4849
*/
49-
public Long getTimestamp() {
50-
return timestamp;
50+
public OffsetDateTime getTime() {
51+
return time;
5152
}
5253

5354
/**
Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,27 @@
11
package org.codeoverflow.chatoverflow.api.io.dto.chat;
22

33
import org.codeoverflow.chatoverflow.api.io.dto.Formatable;
4+
import org.codeoverflow.chatoverflow.api.io.dto.User;
45

56
/**
67
* The author of a chat message
78
*/
8-
public class ChatMessageAuthor implements Formatable {
9+
public class ChatMessageAuthor extends User implements Formatable {
910

10-
private final String displayName;
1111
private final String color;
1212

13-
public ChatMessageAuthor(String displayName, String color) {
14-
this.displayName = displayName;
13+
public ChatMessageAuthor(String identifier, String name, String color) {
14+
super(identifier, name);
1515
this.color = color;
1616
}
1717

18-
public ChatMessageAuthor(String displayName) {
19-
this(displayName, "#000000");
18+
public ChatMessageAuthor(String identifier, String name) {
19+
this(identifier, name, "#000000");
2020
}
2121

22-
/**
23-
* @return the name of the author that is displayed in chat
24-
*/
25-
public String getDisplayName() {
26-
return displayName;
22+
public ChatMessageAuthor(String displayName) {
23+
super(displayName);
24+
this.color = "#000000";
2725
}
2826

2927
/**
@@ -37,22 +35,22 @@ public String getColor() {
3735
* @return The display name as raw string
3836
*/
3937
public String toString() {
40-
return displayName;
38+
return getDisplayName();
4139
}
4240

4341
/**
4442
* @return The display name in bold, formatted using HTML
4543
*/
4644
@Override
4745
public String toHTMLString() {
48-
return "<span color=\"" + color + "\"><b>" + displayName + "</b></span>";
46+
return "<span color=\"" + color + "\"><b>" + getDisplayName() + "</b></span>";
4947
}
5048

5149
/**
5250
* @return The display name in bold, formatted using markdown
5351
*/
5452
@Override
5553
public String toMarkdownString() {
56-
return "**" + displayName + "**";
54+
return "**" + getDisplayName() + "**";
5755
}
5856
}

src/main/java/org/codeoverflow/chatoverflow/api/io/dto/chat/Channel.java renamed to src/main/java/org/codeoverflow/chatoverflow/api/io/dto/chat/TextChannel.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
/**
44
* A generic channel in which messages are exchanged
55
*/
6-
public class Channel {
6+
public class TextChannel {
77
private final String name;
88

9-
public Channel(String name) {
9+
public TextChannel(String name) {
1010
this.name = name;
1111
}
1212

src/main/java/org/codeoverflow/chatoverflow/api/io/dto/chat/discord/DiscordChatMessage.java

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,48 +2,50 @@
22

33
import org.codeoverflow.chatoverflow.api.io.dto.Identifiable;
44
import org.codeoverflow.chatoverflow.api.io.dto.chat.ChatMessage;
5+
import org.codeoverflow.chatoverflow.api.io.dto.chat.ChatMessageAuthor;
56

7+
import java.time.OffsetDateTime;
68
import java.util.ArrayList;
79
import java.util.List;
810
import java.util.Optional;
911

1012
/**
1113
* A chat message that was send in a discord channel
1214
*/
13-
public class DiscordChatMessage extends ChatMessage<DiscordChatMessageAuthor, DiscordChannel, DiscordChatCustomEmoticon> implements Identifiable {
15+
public class DiscordChatMessage extends ChatMessage<ChatMessageAuthor, DiscordTextChannel, DiscordChatCustomEmoticon> implements Identifiable {
1416

1517
private final String id;
1618
private final DiscordEmbed embed;
1719
private final List<String> attachmentUrls;
1820
private final List<DiscordReaction> reactions;
1921

20-
public DiscordChatMessage(DiscordChatMessageAuthor author, String message, Long timestamp, DiscordChannel channel, String id) {
21-
super(author, message, timestamp, channel);
22+
public DiscordChatMessage(ChatMessageAuthor author, String message, OffsetDateTime time, DiscordTextChannel channel, String id) {
23+
super(author, message, time, channel);
2224
this.id = id;
2325
this.embed = null;
2426
this.attachmentUrls = new ArrayList<>();
2527
reactions = new ArrayList<>();
2628
}
2729

28-
public DiscordChatMessage(DiscordChatMessageAuthor author,
30+
public DiscordChatMessage(ChatMessageAuthor author,
2931
String message,
30-
Long timestamp,
31-
DiscordChannel channel,
32+
OffsetDateTime time,
33+
DiscordTextChannel channel,
3234
List<DiscordChatCustomEmoticon> emoticons,
3335
String id) {
34-
this(author, message, timestamp, channel, emoticons, null, new ArrayList<>(), new ArrayList<>(), id);
36+
this(author, message, time, channel, emoticons, null, new ArrayList<>(), new ArrayList<>(), id);
3537
}
3638

37-
public DiscordChatMessage(DiscordChatMessageAuthor author,
39+
public DiscordChatMessage(ChatMessageAuthor author,
3840
String message,
39-
Long timestamp,
40-
DiscordChannel channel,
41+
OffsetDateTime time,
42+
DiscordTextChannel channel,
4143
List<DiscordChatCustomEmoticon> emoticons,
4244
DiscordEmbed embed,
4345
List<String> attachmentUrls,
4446
List<DiscordReaction> reactions,
4547
String id) {
46-
super(author, message, timestamp, channel, emoticons);
48+
super(author, message, time, channel, emoticons);
4749
this.id = id;
4850
this.reactions = reactions;
4951
this.embed = embed;

src/main/java/org/codeoverflow/chatoverflow/api/io/dto/chat/discord/DiscordChatMessageAuthor.java

Lines changed: 0 additions & 30 deletions
This file was deleted.

src/main/java/org/codeoverflow/chatoverflow/api/io/dto/chat/discord/DiscordEmbed.java

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.codeoverflow.chatoverflow.api.io.dto.chat.discord;
22

33
import java.awt.Color;
4+
import java.time.OffsetDateTime;
45
import java.util.*;
56

67
/**
@@ -20,7 +21,7 @@ public static Builder Builder() {
2021
private final String description;
2122
private final String url;
2223
private final String color;
23-
private final long timestamp;
24+
private final OffsetDateTime time;
2425
private final String footerIconUrl;
2526
private final String footerText;
2627
private final String thumbnailUrl;
@@ -33,7 +34,7 @@ public static Builder Builder() {
3334
public DiscordEmbed(String title,
3435
String description,
3536
String url, String color,
36-
long timestamp,
37+
OffsetDateTime time,
3738
String footerIconUrl,
3839
String footerText,
3940
String thumbnailUrl,
@@ -46,7 +47,7 @@ public DiscordEmbed(String title,
4647
this.description = description;
4748
this.url = url;
4849
this.color = color;
49-
this.timestamp = timestamp;
50+
this.time = time;
5051
this.footerIconUrl = footerIconUrl;
5152
this.footerText = footerText;
5253
this.thumbnailUrl = thumbnailUrl;
@@ -95,12 +96,12 @@ public Optional<String> getColor() {
9596
}
9697

9798
/**
98-
* Returns the timestamp of the embed (value in epoch millis)
99+
* Returns the time of the embed (value in epoch millis)
99100
*
100-
* @return optional container with the timestamp of the embed or an empty optional if there was none provided
101+
* @return optional container with the time of the embed or an empty optional if there was none provided
101102
*/
102-
public OptionalLong getTimestamp() {
103-
return timestamp < 0 ? OptionalLong.empty() : OptionalLong.of(timestamp);
103+
public Optional<OffsetDateTime> getTime() {
104+
return Optional.ofNullable(time);
104105
}
105106

106107
/**
@@ -257,7 +258,7 @@ public static class Builder {
257258
private StringBuilder description = null;
258259
private String url = null;
259260
private String color = null;
260-
private Long timestamp = Long.MIN_VALUE;
261+
private OffsetDateTime time = null;
261262
private String footerIconUrl = null;
262263
private String footerText = null;
263264
private String thumbnailUrl = null;
@@ -343,17 +344,17 @@ public Builder withColor(Color color) {
343344
}
344345

345346
/**
346-
* Sets the timestamp of the embed.<br>
347-
* If this is not set, the timestamp will not appear in the embed.
347+
* Sets the time of the embed.<br>
348+
* If this is not set, the time will not appear in the embed.
348349
* <p>
349350
* <b>Tip:</b><br>
350-
* Get the current time with {@link Calendar#getTimeInMillis()}
351+
* Get the current time with {@link OffsetDateTime#now()}
351352
*
352-
* @param timestamp the timestamp of the embed (value in epoch millis)
353-
* @return the builder after the timestamp has been set
353+
* @param time the time of the embed (value in epoch millis)
354+
* @return the builder after the time has been set
354355
*/
355-
public Builder withTimestamp(Long timestamp) {
356-
this.timestamp = timestamp;
356+
public Builder withTimestamp(OffsetDateTime time) {
357+
this.time = time;
357358
return this;
358359
}
359360

@@ -470,7 +471,7 @@ public DiscordEmbed build() {
470471
description.toString(),
471472
url,
472473
color,
473-
timestamp,
474+
time,
474475
footerIconUrl,
475476
footerText,
476477
thumbnailUrl,

0 commit comments

Comments
 (0)