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
Message#getLink method. #535
Conversation
* | ||
* @return The message link. | ||
*/ | ||
default String getLink() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this and the others probably return URL
instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if that's better. I would think it is more convenient to leave it as String. I don't see any use case where it would be better to have it as an URL.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, it is an URL
, that could be reason enough.
But I'll let that decision for @Bastian, I just mentioned it to be thought about. :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have to agree with Vampire. It is a url and thus should return a URL
object.
This is also consistent with all the other methods of Javacord that return a url.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then I will change that :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How should I handle the MalformedURLException?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In other places we just return null
and log a error, but this would be better:
try {
URL url = new URL("");
} catch (MalformedURLException e) {
throw new AssertionError("Message link is malformed", e);
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would have also said catch and transform to AssertionError
.
As we construct the URL and know it is valid, it is a programming error if a MURLE is thrown, so translating it to an AssertionError
is the way to go.
Also you should change the target branch of the PR to |
And you should execute |
javacord-api/src/main/java/org/javacord/api/entity/message/Message.java
Outdated
Show resolved
Hide resolved
Please rebase your branch instead of merging in |
Besides the method return type, this looks good to me. |
It is really helpful to have such a method. Some don't know how the links are composed, and for others it is helpful do just use the Javacord method instead of creating an own.