2021-07-16 00:37:03 +02:00
|
|
|
|
|
|
|
import javax.swing.JFrame;
|
|
|
|
import javax.swing.JPanel;
|
2021-07-16 01:07:23 +02:00
|
|
|
import javax.swing.JComponent;
|
2022-05-06 09:05:01 +02:00
|
|
|
import javax.swing.ImageIcon;
|
2021-07-16 00:37:03 +02:00
|
|
|
import java.awt.Dimension;
|
2021-07-16 01:07:23 +02:00
|
|
|
import java.awt.BorderLayout;
|
2022-04-12 08:37:39 +02:00
|
|
|
import java.awt.Cursor;
|
2022-04-12 13:52:07 +02:00
|
|
|
import java.awt.Image;
|
2022-05-06 09:05:01 +02:00
|
|
|
import java.awt.FontMetrics;
|
2022-04-12 08:37:39 +02:00
|
|
|
import java.util.List;
|
2022-05-06 09:05:01 +02:00
|
|
|
import java.util.Locale;
|
|
|
|
import java.text.BreakIterator;
|
2022-04-12 08:37:39 +02:00
|
|
|
import java.time.ZonedDateTime;
|
2022-05-06 09:05:01 +02:00
|
|
|
import java.time.ZoneId;
|
|
|
|
import java.time.Period;
|
|
|
|
import java.time.temporal.ChronoUnit;
|
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
|
import java.time.format.DateTimeParseException;
|
2022-05-27 14:28:18 +02:00
|
|
|
import javax.swing.plaf.metal.MetalLookAndFeel;
|
|
|
|
import javax.swing.plaf.metal.DefaultMetalTheme;
|
|
|
|
import javax.swing.plaf.metal.OceanTheme;
|
|
|
|
import javax.swing.plaf.ColorUIResource;
|
|
|
|
import javax.swing.UIDefaults;
|
2022-05-30 09:56:09 +02:00
|
|
|
import java.io.File;
|
2022-04-23 16:19:43 +02:00
|
|
|
import cafe.biskuteri.hinoki.Tree;
|
2022-04-12 08:37:39 +02:00
|
|
|
|
2021-07-16 00:37:03 +02:00
|
|
|
|
|
|
|
class
|
2021-07-16 01:07:23 +02:00
|
|
|
JKomasto {
|
|
|
|
|
2022-04-12 08:37:39 +02:00
|
|
|
private TimelineWindow
|
|
|
|
timelineWindow;
|
|
|
|
|
|
|
|
private ComposeWindow
|
|
|
|
composeWindow;
|
|
|
|
|
|
|
|
private PostWindow
|
|
|
|
autoViewWindow;
|
|
|
|
|
|
|
|
private LoginWindow
|
|
|
|
loginWindow;
|
|
|
|
|
2022-04-12 13:52:07 +02:00
|
|
|
private ImageWindow
|
|
|
|
mediaWindow;
|
|
|
|
|
2022-04-16 16:54:17 +02:00
|
|
|
private NotificationsWindow
|
|
|
|
notificationsWindow;
|
|
|
|
|
2022-05-02 05:05:36 +02:00
|
|
|
private WindowUpdater
|
|
|
|
windowUpdater;
|
2022-04-14 06:38:49 +02:00
|
|
|
|
2022-04-12 08:37:39 +02:00
|
|
|
private MastodonApi
|
|
|
|
api;
|
2021-07-16 00:37:03 +02:00
|
|
|
|
2022-05-06 15:57:17 +02:00
|
|
|
private Image
|
|
|
|
programIcon;
|
|
|
|
|
2021-07-16 00:37:03 +02:00
|
|
|
// ---%-@-%---
|
|
|
|
|
2022-04-12 08:37:39 +02:00
|
|
|
public MastodonApi
|
|
|
|
getMastodonApi() { return api; }
|
|
|
|
|
|
|
|
public void
|
|
|
|
finishedLogin()
|
2021-07-16 00:37:03 +02:00
|
|
|
{
|
2022-04-12 08:37:39 +02:00
|
|
|
timelineWindow.setCursor(new Cursor(Cursor.WAIT_CURSOR));
|
|
|
|
|
2022-04-12 13:52:07 +02:00
|
|
|
timelineWindow.showLatestPage();
|
2022-05-02 05:05:36 +02:00
|
|
|
notificationsWindow.showLatestPage();
|
2022-04-12 08:37:39 +02:00
|
|
|
timelineWindow.setVisible(true);
|
2022-05-02 05:05:36 +02:00
|
|
|
loginWindow.dispose();
|
2022-04-12 08:37:39 +02:00
|
|
|
|
|
|
|
timelineWindow.setCursor(null);
|
2021-07-16 01:07:23 +02:00
|
|
|
}
|
|
|
|
|
2022-04-12 08:37:39 +02:00
|
|
|
public PostWindow
|
|
|
|
getAutoViewWindow() { return autoViewWindow; }
|
2021-07-16 01:07:23 +02:00
|
|
|
|
2022-04-12 08:37:39 +02:00
|
|
|
public ComposeWindow
|
|
|
|
getComposeWindow() { return composeWindow; }
|
2021-07-16 01:07:23 +02:00
|
|
|
|
2022-04-12 13:52:07 +02:00
|
|
|
public ImageWindow
|
|
|
|
getMediaWindow() { return mediaWindow; }
|
|
|
|
|
2022-04-16 16:54:17 +02:00
|
|
|
public NotificationsWindow
|
|
|
|
getNotificationsWindow() { return notificationsWindow; }
|
|
|
|
|
2022-05-02 05:05:36 +02:00
|
|
|
public WindowUpdater
|
|
|
|
getWindowUpdater() { return windowUpdater; }
|
|
|
|
|
2022-05-06 15:57:17 +02:00
|
|
|
public Image
|
|
|
|
getProgramIcon() { return programIcon; }
|
|
|
|
|
2022-05-27 14:28:18 +02:00
|
|
|
// ---%-@-%---
|
|
|
|
|
|
|
|
private static class
|
|
|
|
MetalTheme extends OceanTheme {
|
|
|
|
|
|
|
|
private ColorUIResource
|
|
|
|
lightPink = new ColorUIResource(246, 240, 240),
|
|
|
|
mildPink = new ColorUIResource(238, 233, 233),
|
|
|
|
white = new ColorUIResource(250, 250, 250),
|
|
|
|
darkPink = new ColorUIResource(242, 230, 230),
|
|
|
|
veryDarkPink = new ColorUIResource(164, 160, 160);
|
|
|
|
|
|
|
|
// -=%=-
|
|
|
|
|
|
|
|
public ColorUIResource
|
|
|
|
getPrimary2() { return darkPink; }
|
|
|
|
|
|
|
|
public ColorUIResource
|
|
|
|
getSecondary2() { return white; }
|
|
|
|
|
|
|
|
public ColorUIResource
|
|
|
|
getSecondary3() { return mildPink; }
|
|
|
|
|
|
|
|
public ColorUIResource
|
|
|
|
getSecondary1() { return veryDarkPink; }
|
|
|
|
|
|
|
|
public ColorUIResource
|
|
|
|
getPrimary1() { return veryDarkPink; }
|
|
|
|
|
|
|
|
public void
|
|
|
|
addCustomEntriesToTable(UIDefaults table)
|
|
|
|
{
|
|
|
|
super.addCustomEntriesToTable(table);
|
|
|
|
table.put(
|
|
|
|
"TabbedPane.tabAreaBackground",
|
|
|
|
getPrimary1()
|
|
|
|
);
|
|
|
|
table.put(
|
|
|
|
"TabbedPane.contentAreaColor",
|
|
|
|
getSecondary3()
|
|
|
|
);
|
|
|
|
table.put(
|
|
|
|
"TabbedPane.selected",
|
|
|
|
getSecondary3()
|
|
|
|
);
|
|
|
|
table.put(
|
|
|
|
"MenuBar.gradient",
|
|
|
|
java.util.Arrays.asList(new Object[] {
|
|
|
|
1f, 0f,
|
|
|
|
getWhite(),
|
|
|
|
getSecondary3(),
|
|
|
|
getSecondary1()
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-04-12 08:37:39 +02:00
|
|
|
// ---%-@-%---
|
|
|
|
|
|
|
|
public static void
|
2022-05-02 05:05:36 +02:00
|
|
|
main(String... args)
|
|
|
|
{
|
2022-05-27 14:28:18 +02:00
|
|
|
//System.setProperty("swing.boldMetal", "false");
|
|
|
|
MetalLookAndFeel.setCurrentTheme(new MetalTheme());
|
|
|
|
|
2022-05-02 05:05:36 +02:00
|
|
|
new JKomasto().loginWindow.setVisible(true);
|
|
|
|
}
|
2021-07-16 01:07:23 +02:00
|
|
|
|
2022-04-12 08:37:39 +02:00
|
|
|
// ---%-@-%---
|
|
|
|
|
|
|
|
public
|
|
|
|
JKomasto()
|
|
|
|
{
|
|
|
|
api = new MastodonApi();
|
2022-05-02 05:05:36 +02:00
|
|
|
windowUpdater = new WindowUpdater(this);
|
2022-05-06 15:57:17 +02:00
|
|
|
programIcon = ImageApi.local("kettle");
|
2022-04-12 08:37:39 +02:00
|
|
|
|
|
|
|
timelineWindow = new TimelineWindow(this);
|
|
|
|
composeWindow = new ComposeWindow(this);
|
|
|
|
autoViewWindow = new PostWindow(this);
|
|
|
|
loginWindow = new LoginWindow(this);
|
2022-04-12 13:52:07 +02:00
|
|
|
mediaWindow = new ImageWindow();
|
2022-04-16 16:54:17 +02:00
|
|
|
notificationsWindow = new NotificationsWindow(this);
|
2022-04-12 08:37:39 +02:00
|
|
|
|
2022-05-02 05:05:36 +02:00
|
|
|
autoViewWindow.setTitle("Auto view - JKomasto");
|
|
|
|
|
2022-04-12 08:37:39 +02:00
|
|
|
composeWindow.dispose();
|
|
|
|
autoViewWindow.dispose();
|
|
|
|
timelineWindow.dispose();
|
2022-04-12 13:52:07 +02:00
|
|
|
mediaWindow.dispose();
|
2022-04-16 16:54:17 +02:00
|
|
|
notificationsWindow.dispose();
|
2022-04-14 06:38:49 +02:00
|
|
|
|
2022-05-02 05:05:36 +02:00
|
|
|
timelineWindow.setLocationByPlatform(true);
|
|
|
|
loginWindow.setLocationByPlatform(true);
|
2021-07-16 00:37:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2021-07-16 11:46:17 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
2021-07-17 13:17:14 +02:00
|
|
|
enum
|
|
|
|
PostVisibility {
|
|
|
|
|
|
|
|
PUBLIC,
|
2022-04-12 08:37:39 +02:00
|
|
|
UNLISTED,
|
2021-07-17 13:17:14 +02:00
|
|
|
FOLLOWERS,
|
|
|
|
MENTIONED
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
enum
|
|
|
|
TimelineType {
|
|
|
|
|
|
|
|
FEDERATED,
|
|
|
|
LOCAL,
|
|
|
|
HOME,
|
2022-05-06 09:05:01 +02:00
|
|
|
LIST,
|
|
|
|
PROFILE
|
2021-07-17 13:17:14 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-04-16 16:54:17 +02:00
|
|
|
enum
|
|
|
|
NotificationType {
|
|
|
|
|
|
|
|
MENTION,
|
|
|
|
BOOST,
|
|
|
|
FAVOURITE,
|
|
|
|
FOLLOW,
|
|
|
|
FOLLOWREQ,
|
|
|
|
POLL,
|
|
|
|
ALERT
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-07-17 13:17:14 +02:00
|
|
|
|
|
|
|
|
2021-07-16 11:46:17 +02:00
|
|
|
class
|
2022-04-12 08:37:39 +02:00
|
|
|
TimelinePage {
|
2021-07-16 11:46:17 +02:00
|
|
|
|
2021-07-17 13:17:14 +02:00
|
|
|
public TimelineType
|
|
|
|
type;
|
|
|
|
|
2022-04-14 06:38:49 +02:00
|
|
|
public String
|
2022-04-16 16:54:17 +02:00
|
|
|
accountNumId, listId;
|
2022-04-14 06:38:49 +02:00
|
|
|
|
2022-05-06 09:05:01 +02:00
|
|
|
public Post[]
|
2022-04-23 16:19:43 +02:00
|
|
|
posts;
|
2022-04-12 08:37:39 +02:00
|
|
|
|
2022-05-06 09:05:01 +02:00
|
|
|
// ---%-@-%---
|
|
|
|
|
|
|
|
public
|
|
|
|
TimelinePage() { }
|
|
|
|
|
|
|
|
public
|
|
|
|
TimelinePage(Tree<String> entity)
|
|
|
|
{
|
|
|
|
posts = new Post[entity.size()];
|
|
|
|
for (int o = 0; o < posts.length; ++o)
|
|
|
|
posts[o] = new Post(entity.get(o));
|
|
|
|
}
|
|
|
|
|
2021-07-16 11:46:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-04-16 16:54:17 +02:00
|
|
|
class
|
|
|
|
Notification {
|
|
|
|
|
|
|
|
public NotificationType
|
|
|
|
type;
|
|
|
|
|
|
|
|
public String
|
|
|
|
id;
|
|
|
|
|
|
|
|
public String
|
|
|
|
postId, postText, actorNumId, actorName;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-04-12 13:52:07 +02:00
|
|
|
|
2022-05-06 09:05:01 +02:00
|
|
|
|
|
|
|
class
|
|
|
|
Post {
|
|
|
|
|
|
|
|
public String
|
|
|
|
id,
|
|
|
|
uri;
|
|
|
|
|
|
|
|
public Account
|
|
|
|
author;
|
|
|
|
|
|
|
|
public PostVisibility
|
|
|
|
visibility;
|
|
|
|
|
|
|
|
public String
|
|
|
|
text,
|
|
|
|
approximateText;
|
|
|
|
|
|
|
|
public String
|
|
|
|
contentWarning;
|
|
|
|
|
|
|
|
public ZonedDateTime
|
|
|
|
dateTime;
|
|
|
|
|
|
|
|
public String
|
|
|
|
date, time, relativeTime;
|
|
|
|
|
|
|
|
public boolean
|
|
|
|
boosted,
|
|
|
|
favourited;
|
|
|
|
|
|
|
|
public Post
|
|
|
|
boostedPost;
|
|
|
|
|
|
|
|
public Attachment[]
|
|
|
|
attachments;
|
|
|
|
|
|
|
|
public String[][]
|
|
|
|
emojiUrls;
|
|
|
|
|
2022-05-28 03:41:12 +02:00
|
|
|
public String[]
|
|
|
|
mentions;
|
|
|
|
|
2022-05-06 09:05:01 +02:00
|
|
|
// - -%- -
|
|
|
|
|
|
|
|
private static final DateTimeFormatter
|
|
|
|
DATE_FORMAT = DateTimeFormatter.ofPattern("d LLLL ''uu"),
|
|
|
|
TIME_FORMAT = DateTimeFormatter.ofPattern("HH:mm");
|
|
|
|
|
|
|
|
// ---%-@-%---
|
|
|
|
|
|
|
|
public void
|
|
|
|
resolveApproximateText()
|
|
|
|
{
|
|
|
|
assert text != null;
|
|
|
|
if (approximateText != null) return;
|
|
|
|
|
|
|
|
Tree<String> nodes;
|
|
|
|
nodes = RudimentaryHTMLParser.depthlessRead(text);
|
|
|
|
if (nodes.size() == 0)
|
|
|
|
{
|
|
|
|
approximateText = "-";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
StringBuilder b = new StringBuilder();
|
|
|
|
Tree<String> first = nodes.get(0);
|
|
|
|
for (Tree<String> node: nodes)
|
|
|
|
{
|
|
|
|
if (node.key.equals("tag"))
|
|
|
|
{
|
|
|
|
if (node.get(0).key.equals("br"))
|
|
|
|
b.append("; ");
|
|
|
|
if (node.get(0).key.equals("p") && node != first)
|
|
|
|
b.append("; ");
|
|
|
|
}
|
|
|
|
if (node.key.equals("emoji"))
|
|
|
|
{
|
|
|
|
b.append(":" + node.value + ":");
|
|
|
|
}
|
|
|
|
if (node.key.equals("text"))
|
|
|
|
{
|
|
|
|
b.append(node.value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
approximateText = b.toString();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void
|
|
|
|
resolveRelativeTime()
|
|
|
|
{
|
|
|
|
assert date != null;
|
|
|
|
|
|
|
|
ZonedDateTime now = ZonedDateTime.now();
|
|
|
|
long d = ChronoUnit.SECONDS.between(dateTime, now);
|
|
|
|
long s = Math.abs(d);
|
|
|
|
if (s < 30) relativeTime = "now";
|
|
|
|
else if (s < 60) relativeTime = d + "s";
|
|
|
|
else if (s < 3600) relativeTime = (d / 60) + "m";
|
|
|
|
else if (s < 86400) relativeTime = (d / 3600) + "h";
|
|
|
|
else relativeTime = (d / 86400) + "d";
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---%-@-%---
|
|
|
|
|
|
|
|
public
|
|
|
|
Post() { }
|
|
|
|
|
|
|
|
public
|
|
|
|
Post(Tree<String> entity)
|
|
|
|
{
|
|
|
|
id = entity.get("id").value;
|
|
|
|
|
|
|
|
uri = entity.get("url").value;
|
|
|
|
if (uri == null) uri = entity.get("uri").value;
|
|
|
|
|
|
|
|
author = new Account(entity.get("account"));
|
|
|
|
|
|
|
|
String v = entity.get("visibility").value;
|
|
|
|
boolean p = v.equals("public");
|
|
|
|
boolean u = v.equals("unlisted");
|
|
|
|
boolean f = v.equals("private");
|
|
|
|
boolean m = v.equals("direct");
|
|
|
|
if (p) visibility = PostVisibility.PUBLIC;
|
|
|
|
if (u) visibility = PostVisibility.UNLISTED;
|
|
|
|
if (f) visibility = PostVisibility.FOLLOWERS;
|
|
|
|
if (m) visibility = PostVisibility.MENTIONED;
|
|
|
|
|
|
|
|
dateTime =
|
|
|
|
ZonedDateTime.parse(entity.get("created_at").value)
|
|
|
|
.withZoneSameInstant(ZoneId.systemDefault());
|
|
|
|
date = DATE_FORMAT.format(dateTime);
|
|
|
|
time = TIME_FORMAT.format(dateTime);
|
|
|
|
|
|
|
|
text = entity.get("content").value;
|
|
|
|
String st = entity.get("spoiler_text").value;
|
|
|
|
contentWarning = st.trim().isEmpty() ? null : st;
|
|
|
|
|
|
|
|
String favourited = entity.get("favourited").value;
|
|
|
|
String boosted = entity.get("reblogged").value;
|
|
|
|
this.favourited = favourited.equals("true");
|
|
|
|
this.boosted = boosted.equals("true");
|
|
|
|
|
|
|
|
Tree<String> media = entity.get("media_attachments");
|
|
|
|
attachments = new Attachment[media.size()];
|
|
|
|
for (int o = 0; o < attachments.length; ++o)
|
|
|
|
{
|
|
|
|
attachments[o] = new Attachment(media.get(o));
|
|
|
|
}
|
|
|
|
|
|
|
|
Tree<String> emojis = entity.get("emojis");
|
|
|
|
emojiUrls = new String[emojis.size()][];
|
|
|
|
for (int o = 0; o < emojiUrls.length; ++o)
|
|
|
|
{
|
|
|
|
Tree<String> emoji = emojis.get(o);
|
|
|
|
String[] mapping = emojiUrls[o] = new String[2];
|
2022-05-13 16:32:11 +02:00
|
|
|
mapping[0] = ":" + emoji.get("shortcode").value + ":";
|
2022-05-06 09:05:01 +02:00
|
|
|
mapping[1] = emoji.get("url").value;
|
|
|
|
}
|
|
|
|
|
|
|
|
Tree<String> boostedPost = entity.get("reblog");
|
|
|
|
if (boostedPost.size() > 0)
|
|
|
|
this.boostedPost = new Post(boostedPost);
|
2022-05-28 03:41:12 +02:00
|
|
|
|
|
|
|
Tree<String> mentions = entity.get("mentions");
|
|
|
|
this.mentions = new String[mentions.size()];
|
|
|
|
for (int o = 0; o < mentions.size(); ++o)
|
|
|
|
{
|
|
|
|
String acct = mentions.get(o).get("acct").value;
|
|
|
|
this.mentions[o] = acct;
|
|
|
|
}
|
2022-05-06 09:05:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class
|
|
|
|
Account {
|
|
|
|
|
|
|
|
public String
|
|
|
|
numId;
|
|
|
|
|
|
|
|
public String
|
|
|
|
id,
|
|
|
|
name;
|
|
|
|
|
|
|
|
public List<RichTextPane.Segment>
|
|
|
|
formattedName;
|
|
|
|
|
|
|
|
public String
|
|
|
|
avatarUrl;
|
|
|
|
|
|
|
|
public Image
|
|
|
|
avatar;
|
|
|
|
|
2022-05-13 16:32:11 +02:00
|
|
|
public ZonedDateTime
|
|
|
|
creationDate;
|
|
|
|
|
|
|
|
public int
|
|
|
|
followedCount,
|
|
|
|
followerCount;
|
|
|
|
|
|
|
|
public int
|
|
|
|
postCount;
|
|
|
|
|
|
|
|
public String[][]
|
|
|
|
fields;
|
|
|
|
|
|
|
|
public String
|
|
|
|
description;
|
|
|
|
|
2022-05-06 09:05:01 +02:00
|
|
|
// ---%-@-%---
|
|
|
|
|
|
|
|
public void
|
|
|
|
resolveFormattedName()
|
|
|
|
{
|
|
|
|
assert name != null;
|
|
|
|
formattedName =
|
|
|
|
new RichTextPane.Builder().text(name).finish();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void
|
|
|
|
resolveAvatar()
|
|
|
|
{
|
|
|
|
assert avatarUrl != null;
|
|
|
|
if (avatar != null) return;
|
|
|
|
avatar = ImageApi.remote(avatarUrl);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---%-@-%---
|
|
|
|
|
|
|
|
public
|
|
|
|
Account() { }
|
|
|
|
|
|
|
|
public
|
|
|
|
Account(Tree<String> entity)
|
|
|
|
{
|
|
|
|
numId = entity.get("id").value;
|
|
|
|
id = entity.get("acct").value;
|
|
|
|
|
|
|
|
String displayName = entity.get("display_name").value;
|
|
|
|
String username = entity.get("username").value;
|
|
|
|
name = displayName.isEmpty() ? username : displayName;
|
|
|
|
|
|
|
|
avatarUrl = entity.get("avatar").value;
|
2022-05-13 16:32:11 +02:00
|
|
|
|
|
|
|
creationDate =
|
|
|
|
ZonedDateTime.parse(entity.get("created_at").value)
|
|
|
|
.withZoneSameInstant(ZoneId.systemDefault());
|
|
|
|
|
|
|
|
String c1 = entity.get("following_count").value;
|
|
|
|
String c2 = entity.get("followers_count").value;
|
|
|
|
String c3 = entity.get("statuses_count").value;
|
|
|
|
try {
|
|
|
|
followedCount = (int)Double.parseDouble(c1);
|
|
|
|
followerCount = (int)Double.parseDouble(c2);
|
|
|
|
postCount = (int)Double.parseDouble(c3);
|
|
|
|
}
|
|
|
|
catch (NumberFormatException eNf) {
|
|
|
|
assert false;
|
|
|
|
}
|
|
|
|
|
|
|
|
Tree<String> fs = entity.get("fields");
|
|
|
|
fields = new String[fs.size()][];
|
|
|
|
for (int o = 0; o < fields.length; ++o)
|
|
|
|
{
|
|
|
|
Tree<String> f = fs.get(o);
|
|
|
|
String[] field = fields[o] = new String[3];
|
|
|
|
field[0] = f.get("name").value;
|
|
|
|
field[1] = f.get("value").value;
|
|
|
|
boolean v = f.get("verified_at").value != null;
|
|
|
|
field[2] = Boolean.toString(v);
|
|
|
|
}
|
|
|
|
|
|
|
|
description = entity.get("note").value;
|
2022-05-06 09:05:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-04-12 13:52:07 +02:00
|
|
|
class
|
|
|
|
Attachment {
|
|
|
|
|
2022-05-06 09:05:01 +02:00
|
|
|
public String
|
|
|
|
id;
|
|
|
|
|
2022-04-12 13:52:07 +02:00
|
|
|
public String
|
|
|
|
type;
|
|
|
|
|
|
|
|
public String
|
|
|
|
url;
|
|
|
|
|
2022-04-14 06:38:49 +02:00
|
|
|
public String
|
|
|
|
description;
|
|
|
|
|
2022-04-12 13:52:07 +02:00
|
|
|
public Image
|
|
|
|
image;
|
|
|
|
|
2022-05-30 09:56:09 +02:00
|
|
|
public File
|
|
|
|
uploadee;
|
|
|
|
|
2022-05-06 09:05:01 +02:00
|
|
|
// ---%-@-%---
|
|
|
|
|
|
|
|
public void
|
|
|
|
resolveImage()
|
|
|
|
{
|
|
|
|
assert url != null;
|
|
|
|
if (image != null) return;
|
|
|
|
if (!type.equals("image")) return;
|
|
|
|
image = ImageApi.remote(url);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---%-@-%---
|
|
|
|
|
|
|
|
public
|
|
|
|
Attachment() { }
|
|
|
|
|
|
|
|
public
|
|
|
|
Attachment(Tree<String> entity)
|
|
|
|
{
|
2022-05-13 16:32:11 +02:00
|
|
|
url = entity.get("remote_url").value;
|
|
|
|
if (url == null) url = entity.get("url").value;
|
2022-05-06 09:05:01 +02:00
|
|
|
|
2022-05-13 16:32:11 +02:00
|
|
|
id = entity.get("id").value;
|
2022-05-06 09:05:01 +02:00
|
|
|
type = entity.get("type").value;
|
|
|
|
description = entity.get("description").value;
|
|
|
|
}
|
|
|
|
|
2021-07-16 11:46:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class
|
|
|
|
Composition {
|
|
|
|
|
2021-07-17 13:17:14 +02:00
|
|
|
public String
|
2022-04-14 06:38:49 +02:00
|
|
|
text,
|
|
|
|
contentWarning;
|
2021-07-17 13:17:14 +02:00
|
|
|
|
|
|
|
public PostVisibility
|
|
|
|
visibility;
|
|
|
|
|
|
|
|
public String
|
|
|
|
replyToPostId;
|
|
|
|
|
2022-05-22 03:41:46 +02:00
|
|
|
public Attachment[]
|
|
|
|
attachments;
|
|
|
|
|
2022-05-30 09:56:09 +02:00
|
|
|
private File
|
|
|
|
uploadee;
|
|
|
|
|
2022-05-06 09:05:01 +02:00
|
|
|
// ---%-@-%---
|
|
|
|
|
|
|
|
public
|
|
|
|
Composition() { }
|
|
|
|
|
|
|
|
public static Composition
|
|
|
|
reply(Tree<String> entity, String ownNumId)
|
|
|
|
{
|
|
|
|
Composition c = new Composition();
|
|
|
|
|
|
|
|
Tree<String> boosted = entity.get("reblog");
|
|
|
|
if (boosted.size() > 0) entity = boosted;
|
|
|
|
|
|
|
|
String st = entity.get("spoiler_text").value;
|
|
|
|
String ri = entity.get("id").value;
|
|
|
|
c.contentWarning = st.trim().isEmpty() ? null : st;
|
|
|
|
c.replyToPostId = ri.trim().isEmpty() ? null : ri;
|
|
|
|
|
|
|
|
Tree<String> author = entity.get("account");
|
|
|
|
String authorId = author.get("acct").value;
|
|
|
|
String authorNumId = author.get("id").value;
|
|
|
|
c.text = "";
|
|
|
|
if (!authorNumId.equals(ownNumId))
|
|
|
|
c.text = "@" + authorId + " ";
|
|
|
|
|
|
|
|
String visibility = entity.get("visibility").value;
|
|
|
|
boolean p = visibility.equals("public");
|
|
|
|
boolean u = visibility.equals("unlisted");
|
|
|
|
boolean f = visibility.equals("private");
|
|
|
|
boolean m = visibility.equals("direct");
|
|
|
|
assert p || u || f || m;
|
|
|
|
if (p) c.visibility = PostVisibility.PUBLIC;
|
|
|
|
if (u) c.visibility = PostVisibility.UNLISTED;
|
|
|
|
if (f) c.visibility = PostVisibility.FOLLOWERS;
|
|
|
|
if (m) c.visibility = PostVisibility.MENTIONED;
|
|
|
|
// Less eye strain arranged this way.
|
|
|
|
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Composition
|
|
|
|
recover(Tree<String> entity)
|
|
|
|
{
|
|
|
|
assert entity.get("text") != null;
|
|
|
|
|
|
|
|
Composition c = new Composition();
|
|
|
|
c.text = entity.get("text").value;
|
|
|
|
c.contentWarning = entity.get("spoiler_text").value;
|
|
|
|
c.replyToPostId = entity.get("in_reply_to_id").value;
|
|
|
|
|
|
|
|
String visibility = entity.get("visibility").value;
|
|
|
|
boolean p = visibility.equals("public");
|
|
|
|
boolean u = visibility.equals("unlisted");
|
|
|
|
boolean f = visibility.equals("private");
|
|
|
|
boolean m = visibility.equals("direct");
|
|
|
|
assert p || u || f || m;
|
|
|
|
if (p) c.visibility = PostVisibility.PUBLIC;
|
|
|
|
if (u) c.visibility = PostVisibility.UNLISTED;
|
|
|
|
if (f) c.visibility = PostVisibility.FOLLOWERS;
|
|
|
|
if (m) c.visibility = PostVisibility.MENTIONED;
|
|
|
|
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Composition
|
2022-05-28 03:41:12 +02:00
|
|
|
reply(Post post, String ownId)
|
2022-05-06 09:05:01 +02:00
|
|
|
{
|
|
|
|
if (post.boostedPost != null) post = post.boostedPost;
|
|
|
|
|
|
|
|
Composition c = new Composition();
|
|
|
|
c.replyToPostId = post.id;
|
|
|
|
c.visibility = post.visibility;
|
|
|
|
c.contentWarning = post.contentWarning;
|
2022-05-28 03:41:12 +02:00
|
|
|
|
|
|
|
StringBuilder text = new StringBuilder();
|
|
|
|
for (String id: post.mentions)
|
|
|
|
{
|
|
|
|
if (id.equals(ownId)) continue;
|
|
|
|
text.append("@" + id);
|
|
|
|
}
|
|
|
|
if (!post.author.id.equals(ownId))
|
|
|
|
{
|
|
|
|
text.append("@" + post.author.id);
|
|
|
|
}
|
|
|
|
|
|
|
|
c.text = text.toString();
|
|
|
|
|
2022-05-06 09:05:01 +02:00
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
2021-07-16 11:46:17 +02:00
|
|
|
}
|