-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
99 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -143,6 +143,8 @@ | |
import java.util.concurrent.ExecutorService; | ||
import java.util.concurrent.Executors; | ||
import java.util.concurrent.Future; | ||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
import java.util.stream.Stream; | ||
|
||
import static java.util.Collections.singletonList; | ||
|
@@ -208,6 +210,34 @@ public User getUser(Identify id) { | |
}); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
* https://misskey.io/@syuilo | ||
* https://misskey.io/@[email protected] | ||
*/ | ||
@Override | ||
public User getUser(String url) { | ||
return proceed(() -> { | ||
Service service = getAccount().getService(); | ||
Pattern regex = Pattern.compile("https://(.+?)/@(.+)"); | ||
Matcher matcher = regex.matcher(url); | ||
|
||
if (matcher.matches()) { | ||
String host = matcher.group(1); | ||
String identify = matcher.group(2); | ||
|
||
if (identify.contains("@")) { | ||
String format = ("@" + identify); | ||
return getUser(new Identify(service, format)); | ||
} else { | ||
String format = ("@" + identify + "@" + host); | ||
return getUser(new Identify(service, format)); | ||
} | ||
} | ||
throw new SocialHubException("this url is not supported format."); | ||
}); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
|
@@ -574,7 +604,6 @@ public Pageable<Comment> getSearchTimeLine(String query, Paging paging) { | |
* {@inheritDoc} | ||
*/ | ||
@Override | ||
@SuppressWarnings("unchecked") | ||
public void postComment(CommentForm req) { | ||
if (req.isMessage()) { | ||
postMessage(req); | ||
|
@@ -661,6 +690,28 @@ public Comment getComment(Identify id) { | |
}); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
* Parse Misskey Post's url, like: | ||
* https://misskey.io/notes/8axwbcxiff | ||
*/ | ||
@Override | ||
public Comment getComment(String url) { | ||
return proceed(() -> { | ||
Service service = getAccount().getService(); | ||
Pattern regex = Pattern.compile("https://(.+?)/notes/(.+)"); | ||
Matcher matcher = regex.matcher(url); | ||
|
||
if (matcher.matches()) { | ||
String id = matcher.group(2); | ||
Identify identify = new Identify(service, id); | ||
return getComment(identify); | ||
} | ||
|
||
throw new SocialHubException("this url is not supported format."); | ||
}); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,4 +51,25 @@ public void getCommentFromUrlMastodon() { | |
System.out.println(comment.getDisplayComment().getText().getDisplayText()); | ||
} | ||
} | ||
|
||
@Test | ||
public void getUserFromUrlMisskey() { | ||
Account account = SocialAuthUtil.getMisskeyAccount(); | ||
{ | ||
User user = account.action().getUser("https://misskey.io/@syuilo"); | ||
System.out.println(user.getName()); | ||
} | ||
{ | ||
User user = account.action().getUser("https://misskey.io/@[email protected]"); | ||
System.out.println(user.getName()); | ||
} | ||
} | ||
|
||
@Test | ||
public void getCommentFromUrlMisskey() { | ||
Account account = SocialAuthUtil.getMisskeyAccount(); | ||
Comment comment = account.action().getComment( | ||
"https://misskey.io/notes/8axwbcxiff"); | ||
System.out.println(comment.getDisplayComment().getText().getDisplayText()); | ||
} | ||
} |