return null;
}
Sone sone = addLocalSone(ownIdentity);
- sone.getOptions().addBooleanOption("AutoFollow", new DefaultOption<Boolean>(false));
- sone.getOptions().addBooleanOption("EnableSoneInsertNotifications", new DefaultOption<Boolean>(false));
- sone.getOptions().addBooleanOption("ShowNotification/NewSones", new DefaultOption<Boolean>(true));
- sone.getOptions().addBooleanOption("ShowNotification/NewPosts", new DefaultOption<Boolean>(true));
- sone.getOptions().addBooleanOption("ShowNotification/NewReplies", new DefaultOption<Boolean>(true));
- sone.getOptions().addEnumOption("ShowCustomAvatars", new DefaultOption<ShowCustomAvatars>(ShowCustomAvatars.NEVER));
followSone(sone, "nwa8lHa271k2QvJ8aa0Ov7IHAV-DFOCFgmDt3X6BpCI");
touchConfiguration();
if (newSone) {
eventBus.post(new NewSoneFoundEvent(sone));
for (Sone localSone : getLocalSones()) {
- if (localSone.getOptions().getBooleanOption("AutoFollow").get()) {
+ if (localSone.getOptions().isAutoFollow()) {
followSone(localSone, sone.getId());
}
}
}
logger.info(String.format("Loading local Sone: %s", sone));
- /* initialize options. */
- sone.getOptions().addBooleanOption("AutoFollow", new DefaultOption<Boolean>(false));
- sone.getOptions().addBooleanOption("EnableSoneInsertNotifications", new DefaultOption<Boolean>(false));
- sone.getOptions().addBooleanOption("ShowNotification/NewSones", new DefaultOption<Boolean>(true));
- sone.getOptions().addBooleanOption("ShowNotification/NewPosts", new DefaultOption<Boolean>(true));
- sone.getOptions().addBooleanOption("ShowNotification/NewReplies", new DefaultOption<Boolean>(true));
- sone.getOptions().addEnumOption("ShowCustomAvatars", new DefaultOption<ShowCustomAvatars>(ShowCustomAvatars.NEVER));
-
/* load Sone. */
String sonePrefix = "Sone/" + sone.getId();
Long soneTime = configuration.getLongValue(sonePrefix + "/Time").getValue(null);
}
/* load options. */
- sone.getOptions().getBooleanOption("AutoFollow").set(configuration.getBooleanValue(sonePrefix + "/Options/AutoFollow").getValue(null));
- sone.getOptions().getBooleanOption("EnableSoneInsertNotifications").set(configuration.getBooleanValue(sonePrefix + "/Options/EnableSoneInsertNotifications").getValue(null));
- sone.getOptions().getBooleanOption("ShowNotification/NewSones").set(configuration.getBooleanValue(sonePrefix + "/Options/ShowNotification/NewSones").getValue(null));
- sone.getOptions().getBooleanOption("ShowNotification/NewPosts").set(configuration.getBooleanValue(sonePrefix + "/Options/ShowNotification/NewPosts").getValue(null));
- sone.getOptions().getBooleanOption("ShowNotification/NewReplies").set(configuration.getBooleanValue(sonePrefix + "/Options/ShowNotification/NewReplies").getValue(null));
- sone.getOptions().<ShowCustomAvatars> getEnumOption("ShowCustomAvatars").set(ShowCustomAvatars.valueOf(configuration.getStringValue(sonePrefix + "/Options/ShowCustomAvatars").getValue(ShowCustomAvatars.NEVER.name())));
+ sone.getOptions().setAutoFollow(configuration.getBooleanValue(sonePrefix + "/Options/AutoFollow").getValue(null));
+ sone.getOptions().setSoneInsertNotificationEnabled(configuration.getBooleanValue(sonePrefix + "/Options/EnableSoneInsertNotifications").getValue(null));
+ sone.getOptions().setShowNewSoneNotifications(configuration.getBooleanValue(sonePrefix + "/Options/ShowNotification/NewSones").getValue(null));
+ sone.getOptions().setShowNewPostNotifications(configuration.getBooleanValue(sonePrefix + "/Options/ShowNotification/NewPosts").getValue(null));
+ sone.getOptions().setShowNewReplyNotifications(configuration.getBooleanValue(sonePrefix + "/Options/ShowNotification/NewReplies").getValue(null));
+ sone.getOptions().setShowCustomAvatars(ShowCustomAvatars.valueOf(configuration.getStringValue(sonePrefix + "/Options/ShowCustomAvatars").getValue(ShowCustomAvatars.NEVER.name())));
/* if we’re still here, Sone was loaded successfully. */
synchronized (sone) {
configuration.getStringValue(sonePrefix + "/Images/" + imageCounter + "/ID").setValue(null);
/* save options. */
- configuration.getBooleanValue(sonePrefix + "/Options/AutoFollow").setValue(sone.getOptions().getBooleanOption("AutoFollow").getReal());
- configuration.getBooleanValue(sonePrefix + "/Options/ShowNotification/NewSones").setValue(sone.getOptions().getBooleanOption("ShowNotification/NewSones").getReal());
- configuration.getBooleanValue(sonePrefix + "/Options/ShowNotification/NewPosts").setValue(sone.getOptions().getBooleanOption("ShowNotification/NewPosts").getReal());
- configuration.getBooleanValue(sonePrefix + "/Options/ShowNotification/NewReplies").setValue(sone.getOptions().getBooleanOption("ShowNotification/NewReplies").getReal());
- configuration.getBooleanValue(sonePrefix + "/Options/EnableSoneInsertNotifications").setValue(sone.getOptions().getBooleanOption("EnableSoneInsertNotifications").getReal());
- configuration.getStringValue(sonePrefix + "/Options/ShowCustomAvatars").setValue(sone.getOptions().<ShowCustomAvatars> getEnumOption("ShowCustomAvatars").get().name());
+ configuration.getBooleanValue(sonePrefix + "/Options/AutoFollow").setValue(sone.getOptions().isAutoFollow());
+ configuration.getBooleanValue(sonePrefix + "/Options/EnableSoneInsertNotifications").setValue(sone.getOptions().isSoneInsertNotificationEnabled());
+ configuration.getBooleanValue(sonePrefix + "/Options/ShowNotification/NewSones").setValue(sone.getOptions().isShowNewSoneNotifications());
+ configuration.getBooleanValue(sonePrefix + "/Options/ShowNotification/NewPosts").setValue(sone.getOptions().isShowNewPostNotifications());
+ configuration.getBooleanValue(sonePrefix + "/Options/ShowNotification/NewReplies").setValue(sone.getOptions().isShowNewReplyNotifications());
+ configuration.getStringValue(sonePrefix + "/Options/ShowCustomAvatars").setValue(sone.getOptions().getShowCustomAvatars().name());
configuration.save();
*
* @return The options of this Sone
*/
- Options getOptions();
+ SoneOptions getOptions();
/**
* Sets the options of this Sone.
* The options of this Sone
*/
/* TODO - remove this method again, maybe add an option provider */
- void setOptions(Options options);
+ void setOptions(SoneOptions options);
}
import java.util.logging.Level;
import java.util.logging.Logger;
-import net.pterodactylus.sone.core.Options;
+import net.pterodactylus.sone.data.SoneOptions.DefaultSoneOptions;
import net.pterodactylus.sone.freenet.wot.Identity;
import net.pterodactylus.util.logging.Logging;
private final Album rootAlbum = new AlbumImpl().setSone(this);
/** Sone-specific options. */
- private Options options = new Options();
+ private SoneOptions options = new DefaultSoneOptions();
/**
* Creates a new Sone.
*
* @return The options of this Sone
*/
- public Options getOptions() {
+ public SoneOptions getOptions() {
return options;
}
* The options of this Sone
*/
/* TODO - remove this method again, maybe add an option provider */
- public void setOptions(Options options) {
+ public void setOptions(SoneOptions options) {
this.options = options;
}
--- /dev/null
+package net.pterodactylus.sone.data;
+
+import static net.pterodactylus.sone.data.Sone.ShowCustomAvatars.NEVER;
+
+import net.pterodactylus.sone.data.Sone.ShowCustomAvatars;
+
+/**
+ * All Sone-specific options.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+public interface SoneOptions {
+
+ boolean isAutoFollow();
+ void setAutoFollow(boolean autoFollow);
+
+ boolean isSoneInsertNotificationEnabled();
+ void setSoneInsertNotificationEnabled(boolean soneInsertNotificationEnabled);
+
+ boolean isShowNewSoneNotifications();
+ void setShowNewSoneNotifications(boolean showNewSoneNotifications);
+
+ boolean isShowNewPostNotifications();
+ void setShowNewPostNotifications(boolean showNewPostNotifications);
+
+ boolean isShowNewReplyNotifications();
+ void setShowNewReplyNotifications(boolean showNewReplyNotifications);
+
+ ShowCustomAvatars getShowCustomAvatars();
+ void setShowCustomAvatars(ShowCustomAvatars showCustomAvatars);
+
+ /**
+ * {@link SoneOptions} implementation.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+ public class DefaultSoneOptions implements SoneOptions {
+
+ private boolean autoFollow = false;
+ private boolean soneInsertNotificationsEnabled = false;
+ private boolean showNewSoneNotifications = true;
+ private boolean showNewPostNotifications = true;
+ private boolean showNewReplyNotifications = true;
+ private ShowCustomAvatars showCustomAvatars = NEVER;
+
+ @Override
+ public boolean isAutoFollow() {
+ return autoFollow;
+ }
+
+ @Override
+ public void setAutoFollow(boolean autoFollow) {
+ this.autoFollow = autoFollow;
+ }
+
+ @Override
+ public boolean isSoneInsertNotificationEnabled() {
+ return soneInsertNotificationsEnabled;
+ }
+
+ @Override
+ public void setSoneInsertNotificationEnabled(boolean soneInsertNotificationEnabled) {
+ this.soneInsertNotificationsEnabled = soneInsertNotificationEnabled;
+ }
+
+ @Override
+ public boolean isShowNewSoneNotifications() {
+ return showNewSoneNotifications;
+ }
+
+ @Override
+ public void setShowNewSoneNotifications(boolean showNewSoneNotifications) {
+ this.showNewSoneNotifications = showNewSoneNotifications;
+ }
+
+ @Override
+ public boolean isShowNewPostNotifications() {
+ return showNewPostNotifications;
+ }
+
+ @Override
+ public void setShowNewPostNotifications(boolean showNewPostNotifications) {
+ this.showNewPostNotifications = showNewPostNotifications;
+ }
+
+ @Override
+ public boolean isShowNewReplyNotifications() {
+ return showNewReplyNotifications;
+ }
+
+ @Override
+ public void setShowNewReplyNotifications(boolean showNewReplyNotifications) {
+ this.showNewReplyNotifications = showNewReplyNotifications;
+ }
+
+ @Override
+ public ShowCustomAvatars getShowCustomAvatars() {
+ return showCustomAvatars;
+ }
+
+ @Override
+ public void setShowCustomAvatars(ShowCustomAvatars showCustomAvatars) {
+ this.showCustomAvatars = showCustomAvatars;
+ }
+
+ }
+
+}
List<Notification> filteredNotifications = new ArrayList<Notification>();
for (Notification notification : notifications) {
if (notification.getId().equals("new-sone-notification")) {
- if ((currentSone != null) && (!currentSone.getOptions().getBooleanOption("ShowNotification/NewSones").get())) {
+ if ((currentSone != null) && !currentSone.getOptions().isShowNewSoneNotifications()) {
continue;
}
filteredNotifications.add(notification);
} else if (notification.getId().equals("new-post-notification")) {
- if ((currentSone != null) && (!currentSone.getOptions().getBooleanOption("ShowNotification/NewPosts").get())) {
+ if ((currentSone != null) && !currentSone.getOptions().isShowNewPostNotifications()) {
continue;
}
ListNotification<Post> filteredNotification = filterNewPostNotification((ListNotification<Post>) notification, currentSone, true);
filteredNotifications.add(filteredNotification);
}
} else if (notification.getId().equals("new-reply-notification")) {
- if ((currentSone != null) && (!currentSone.getOptions().getBooleanOption("ShowNotification/NewReplies").get())) {
+ if ((currentSone != null) && !currentSone.getOptions().isShowNewReplyNotifications()) {
continue;
}
ListNotification<PostReply> filteredNotification = filterNewReplyNotification((ListNotification<PostReply>) notification, currentSone);
/* always show your own avatars. */
return avatarId;
}
- ShowCustomAvatars showCustomAvatars = currentSone.getOptions().<ShowCustomAvatars> getEnumOption("ShowCustomAvatars").get();
+ ShowCustomAvatars showCustomAvatars = currentSone.getOptions().getShowCustomAvatars();
if (showCustomAvatars == ShowCustomAvatars.NEVER) {
return null;
}
List<String> fieldErrors = new ArrayList<String>();
if (currentSone != null) {
boolean autoFollow = request.getHttpRequest().isPartSet("auto-follow");
- currentSone.getOptions().getBooleanOption("AutoFollow").set(autoFollow);
+ currentSone.getOptions().setAutoFollow(autoFollow);
boolean enableSoneInsertNotifications = request.getHttpRequest().isPartSet("enable-sone-insert-notifications");
- currentSone.getOptions().getBooleanOption("EnableSoneInsertNotifications").set(enableSoneInsertNotifications);
+ currentSone.getOptions().setSoneInsertNotificationEnabled(enableSoneInsertNotifications);
boolean showNotificationNewSones = request.getHttpRequest().isPartSet("show-notification-new-sones");
- currentSone.getOptions().getBooleanOption("ShowNotification/NewSones").set(showNotificationNewSones);
+ currentSone.getOptions().setShowNewSoneNotifications(showNotificationNewSones);
boolean showNotificationNewPosts = request.getHttpRequest().isPartSet("show-notification-new-posts");
- currentSone.getOptions().getBooleanOption("ShowNotification/NewPosts").set(showNotificationNewPosts);
+ currentSone.getOptions().setShowNewPostNotifications(showNotificationNewPosts);
boolean showNotificationNewReplies = request.getHttpRequest().isPartSet("show-notification-new-replies");
- currentSone.getOptions().getBooleanOption("ShowNotification/NewReplies").set(showNotificationNewReplies);
+ currentSone.getOptions().setShowNewReplyNotifications(showNotificationNewReplies);
String showCustomAvatars = request.getHttpRequest().getPartAsStringFailsafe("show-custom-avatars", 32);
- currentSone.getOptions().<ShowCustomAvatars> getEnumOption("ShowCustomAvatars").set(ShowCustomAvatars.valueOf(showCustomAvatars));
+ currentSone.getOptions().setShowCustomAvatars(ShowCustomAvatars.valueOf(showCustomAvatars));
webInterface.getCore().touchConfiguration();
}
Integer insertionDelay = Numbers.safeParseInteger(request.getHttpRequest().getPartAsStringFailsafe("insertion-delay", 16));
templateContext.set("fieldErrors", fieldErrors);
}
if (currentSone != null) {
- templateContext.set("auto-follow", currentSone.getOptions().getBooleanOption("AutoFollow").get());
- templateContext.set("enable-sone-insert-notifications", currentSone.getOptions().getBooleanOption("EnableSoneInsertNotifications").get());
- templateContext.set("show-notification-new-sones", currentSone.getOptions().getBooleanOption("ShowNotification/NewSones").get());
- templateContext.set("show-notification-new-posts", currentSone.getOptions().getBooleanOption("ShowNotification/NewPosts").get());
- templateContext.set("show-notification-new-replies", currentSone.getOptions().getBooleanOption("ShowNotification/NewReplies").get());
- templateContext.set("show-custom-avatars", currentSone.getOptions().<ShowCustomAvatars> getEnumOption("ShowCustomAvatars").get().name());
+ templateContext.set("auto-follow", currentSone.getOptions().isAutoFollow());
+ templateContext.set("enable-sone-insert-notifications", currentSone.getOptions().isSoneInsertNotificationEnabled());
+ templateContext.set("show-notification-new-sones", currentSone.getOptions().isShowNewSoneNotifications());
+ templateContext.set("show-notification-new-posts", currentSone.getOptions().isShowNewPostNotifications());
+ templateContext.set("show-notification-new-replies", currentSone.getOptions().isShowNewReplyNotifications());
+ templateContext.set("show-custom-avatars", currentSone.getOptions().getShowCustomAvatars().name());
}
templateContext.set("insertion-delay", preferences.getInsertionDelay());
templateContext.set("posts-per-page", preferences.getPostsPerPage());
public void soneInserting(SoneInsertingEvent soneInsertingEvent) {
TemplateNotification soneInsertNotification = getSoneInsertNotification(soneInsertingEvent.sone());
soneInsertNotification.set("soneStatus", "inserting");
- if (soneInsertingEvent.sone().getOptions().getBooleanOption("EnableSoneInsertNotifications").get()) {
+ if (soneInsertingEvent.sone().getOptions().isSoneInsertNotificationEnabled()) {
notificationManager.addNotification(soneInsertNotification);
}
}
TemplateNotification soneInsertNotification = getSoneInsertNotification(soneInsertedEvent.sone());
soneInsertNotification.set("soneStatus", "inserted");
soneInsertNotification.set("insertDuration", soneInsertedEvent.insertDuration() / 1000);
- if (soneInsertedEvent.sone().getOptions().getBooleanOption("EnableSoneInsertNotifications").get()) {
+ if (soneInsertedEvent.sone().getOptions().isSoneInsertNotificationEnabled()) {
notificationManager.addNotification(soneInsertNotification);
}
}
TemplateNotification soneInsertNotification = getSoneInsertNotification(soneInsertAbortedEvent.sone());
soneInsertNotification.set("soneStatus", "insert-aborted");
soneInsertNotification.set("insert-error", soneInsertAbortedEvent.cause());
- if (soneInsertAbortedEvent.sone().getOptions().getBooleanOption("EnableSoneInsertNotifications").get()) {
+ if (soneInsertAbortedEvent.sone().getOptions().isSoneInsertNotificationEnabled()) {
notificationManager.addNotification(soneInsertNotification);
}
}
private static JsonNode createJsonOptions(Sone currentSone) {
ObjectNode options = new ObjectNode(instance);
if (currentSone != null) {
- options.put("ShowNotification/NewSones", currentSone.getOptions().getBooleanOption("ShowNotification/NewSones").get());
- options.put("ShowNotification/NewPosts", currentSone.getOptions().getBooleanOption("ShowNotification/NewPosts").get());
- options.put("ShowNotification/NewReplies", currentSone.getOptions().getBooleanOption("ShowNotification/NewReplies").get());
+ options.put("ShowNotification/NewSones", currentSone.getOptions().isShowNewSoneNotifications());
+ options.put("ShowNotification/NewPosts", currentSone.getOptions().isShowNewPostNotifications());
+ options.put("ShowNotification/NewReplies", currentSone.getOptions().isShowNewReplyNotifications());
}
return options;
}
private static JsonNode createJsonOptions(Sone currentSone) {
ObjectNode options = new ObjectNode(instance);
if (currentSone != null) {
- options.put("ShowNotification/NewSones", currentSone.getOptions().getBooleanOption("ShowNotification/NewSones").get());
- options.put("ShowNotification/NewPosts", currentSone.getOptions().getBooleanOption("ShowNotification/NewPosts").get());
- options.put("ShowNotification/NewReplies", currentSone.getOptions().getBooleanOption("ShowNotification/NewReplies").get());
+ options.put("ShowNotification/NewSones", currentSone.getOptions().isShowNewSoneNotifications());
+ options.put("ShowNotification/NewPosts", currentSone.getOptions().isShowNewPostNotifications());
+ options.put("ShowNotification/NewReplies", currentSone.getOptions().isShowNewReplyNotifications());
}
return options;
}