Skip to content

Commit

Permalink
✨ Add configuration option to disable images in social media posts cl…
Browse files Browse the repository at this point in the history
…oses #42

Signed-off-by: Marcus Fihlon <[email protected]>
  • Loading branch information
McPringle committed Apr 10, 2024
1 parent 8cbecf0 commit 5b8b095
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 13 deletions.
23 changes: 12 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,17 +89,18 @@ You can now also attach breakpoints in code for debugging purposes, by clicking

*Apus* can be started without any specific configuration. All configuration options have working default values. To modify these default values just specify environment variables with the following names:

| Variable | Default | Description |
|----------------------|------------------------------------|-----------------------------------------------------------------|
| ADMIN_PASSWORD | | The password to get admin access (empty = disabled). |
| DOAG_EVENT_ID | 0 | The ID of the DOAG event to read the conference agenda. |
| FILTER_REPLIES | true | Hide social media messages which are replies. |
| FILTER_SENSITIVE | true | Hide social media messages which contain sensitive information. |
| FILTER_WORDS | fuck you, motherfucker, cocksucker | Hide social media messages which contain these words. |
| MASTODON_INSTANCE | mastodon.social | The Mastodon instance used to read the posts from. |
| MASTODON_HASHTAG | java | The hashtag for the mastodon wall. |
| MASTODON_IMAGE_LIMIT | 1 | Limit number of images per post. |
| TZ | UTC | The timezone used for date and time calculations. |
| Variable | Default | Description |
|-------------------------|------------------------------------|-----------------------------------------------------------------|
| ADMIN_PASSWORD | | The password to get admin access (empty = disabled). |
| DOAG_EVENT_ID | 0 | The ID of the DOAG event to read the conference agenda. |
| FILTER_REPLIES | true | Hide social media messages which are replies. |
| FILTER_SENSITIVE | true | Hide social media messages which contain sensitive information. |
| FILTER_WORDS | fuck you, motherfucker, cocksucker | Hide social media messages which contain these words. |
| MASTODON_INSTANCE | mastodon.social | The Mastodon instance used to read the posts from. |
| MASTODON_HASHTAG | java | The hashtag for the mastodon wall. |
| MASTODON_IMAGES_ENABLED | true | Enable or disable images in mastodon posts. |
| MASTODON_IMAGE_LIMIT | 1 | Limit number of images per post. |
| TZ | UTC | The timezone used for date and time calculations. |

The environment variables will override the default values.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
*/
package swiss.fihlon.apus.configuration;

public record Mastodon(String instance, String hashtag, int imageLimit) { }
public record Mastodon(String instance, String hashtag, boolean imagesEnabled, int imageLimit) { }
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,14 @@ public final class MastodonAPI {

private final String instance;
private final String hashtag;
private final boolean imagesEnabled;
private final int imageLimit;

public MastodonAPI(@NotNull final Configuration configuration) {
final var mastodonConfig = configuration.getMastodon();
this.instance = mastodonConfig.instance();
this.hashtag = mastodonConfig.hashtag();
this.imagesEnabled = mastodonConfig.imagesEnabled();
this.imageLimit = mastodonConfig.imageLimit();
}

Expand Down Expand Up @@ -81,7 +83,7 @@ private Message convertToMessage(@NotNull final Status status) {
final String avatar = account == null ? "" : account.getAvatar();
final String profile = account == null ? "" : getProfile(account);
final String html = status.getContent();
final List<String> images = getImages(status.getMediaAttachments());
final List<String> images = imagesEnabled ? getImages(status.getMediaAttachments()) : List.of();
final String inReplyToId = status.getInReplyToId();
final boolean isReply = inReplyToId != null && !inReplyToId.isBlank();
final boolean isSensitive = status.isSensitive();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
"type": "java.lang.String",
"description": "The hashtag for the Mastodon wall."
},
{
"name": "apus.mastodon.imagesEnabled",
"type": "java.lang.Boolean",
"description": "Enable or disable images in mastodon posts."
},
{
"name": "apus.mastodon.imageLimit",
"type": "java.lang.Integer",
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ apus.admin.password=${ADMIN_PASSWORD:}
apus.doag.eventId=${DOAG_EVENT_ID:0}
apus.mastodon.instance=${MASTODON_INSTANCE:mastodon.social}
apus.mastodon.hashtag=${MASTODON_HASHTAG:java}
apus.mastodon.imagesEnabled=${MASTODON_IMAGES_ENABLED:true}
apus.mastodon.imageLimit=${MASTODON_IMAGE_LIMIT:1}
apus.filter.replies=${FILTER_REPLIES:true}
apus.filter.sensitive=${FILTER_SENSITIVE:true}
Expand Down

0 comments on commit 5b8b095

Please sign in to comment.