-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Marcus Fihlon <[email protected]>
- Loading branch information
Showing
12 changed files
with
342 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* Apus - A social wall for conferences with additional features. | ||
* Copyright (C) Marcus Fihlon and the individual contributors to Apus. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published | ||
* by the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
.post-view { | ||
background-color: #84ddee; | ||
border-radius: 5px; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* | ||
* Apus - A social wall for conferences with additional features. | ||
* Copyright (C) Marcus Fihlon and the individual contributors to Apus. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published | ||
* by the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
This directory is automatically generated by Vaadin and contains the pre-compiled | ||
frontend files/resources for your project (frontend development bundle). | ||
|
||
It should be added to Version Control System and committed, so that other developers | ||
do not have to compile it again. | ||
|
||
Frontend development bundle is automatically updated when needed: | ||
- an npm/pnpm package is added with @NpmPackage or directly into package.json | ||
- CSS, JavaScript or TypeScript files are added with @CssImport, @JsModule or @JavaScript | ||
- Vaadin add-on with front-end customizations is added | ||
- Custom theme imports/assets added into 'theme.json' file | ||
- Exported web component is added. | ||
|
||
If your project development needs a hot deployment of the frontend changes, | ||
you can switch Flow to use Vite development server (default in Vaadin 23.3 and earlier versions): | ||
- set `vaadin.frontend.hotdeploy=true` in `application.properties` | ||
- configure `vaadin-maven-plugin`: | ||
``` | ||
<configuration> | ||
<frontendHotdeploy>true</frontendHotdeploy> | ||
</configuration> | ||
``` | ||
- configure `jetty-maven-plugin`: | ||
``` | ||
<configuration> | ||
<systemProperties> | ||
<vaadin.frontend.hotdeploy>true</vaadin.frontend.hotdeploy> | ||
</systemProperties> | ||
</configuration> | ||
``` | ||
|
||
Read more [about Vaadin development mode](https://vaadin.com/docs/next/configuration/development-mode/#pre-compiled-front-end-bundle-for-faster-start-up). |
Binary file not shown.
41 changes: 41 additions & 0 deletions
41
src/main/java/swiss/fihlon/apus/service/SocialService.java
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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Apus - A social wall for conferences with additional features. | ||
* Copyright (C) Marcus Fihlon and the individual contributors to Apus. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published | ||
* by the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package swiss.fihlon.apus.service; | ||
|
||
import org.springframework.stereotype.Service; | ||
import swiss.fihlon.apus.social.Post; | ||
import swiss.fihlon.apus.social.mastodon.MastodonAPI; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
@Service | ||
public final class SocialService { | ||
|
||
private final List<Post> posts; | ||
|
||
public SocialService() { | ||
final MastodonAPI mastodonAPI = new MastodonAPI("mastodon.social"); | ||
posts = mastodonAPI.getPosts("java"); | ||
} | ||
|
||
public List<Post> getPosts() { | ||
return Collections.unmodifiableList(posts); | ||
} | ||
|
||
} |
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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Apus - A social wall for conferences with additional features. | ||
* Copyright (C) Marcus Fihlon and the individual contributors to Apus. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published | ||
* by the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package swiss.fihlon.apus.social; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
public record Post(String id, LocalDateTime date, String author, String avatar, String html) | ||
implements Comparable<Post> { | ||
@Override | ||
public int compareTo(@NotNull final Post other) { | ||
return date.compareTo(other.date); | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
src/main/java/swiss/fihlon/apus/social/mastodon/MastodonAPI.java
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 |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* Apus - A social wall for conferences with additional features. | ||
* Copyright (C) Marcus Fihlon and the individual contributors to Apus. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published | ||
* by the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package swiss.fihlon.apus.social.mastodon; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
import social.bigbone.MastodonClient; | ||
import social.bigbone.api.Pageable; | ||
import social.bigbone.api.entity.Account; | ||
import social.bigbone.api.entity.Status; | ||
import social.bigbone.api.exception.BigBoneRequestException; | ||
import swiss.fihlon.apus.social.Post; | ||
|
||
import java.time.Instant; | ||
import java.time.LocalDateTime; | ||
import java.time.ZoneId; | ||
import java.util.List; | ||
|
||
import static social.bigbone.api.method.TimelineMethods.StatusOrigin.LOCAL_AND_REMOTE; | ||
|
||
public final class MastodonAPI { | ||
|
||
private final String instance; | ||
|
||
public MastodonAPI(@NotNull final String instance) { | ||
this.instance = instance; | ||
} | ||
|
||
public List<Post> getPosts(@NotNull final String hashtag) { | ||
try { | ||
final MastodonClient client = new MastodonClient.Builder(instance).build(); | ||
final Pageable<Status> statuses = client.timelines().getTagTimeline(hashtag, LOCAL_AND_REMOTE).execute(); | ||
return statuses.getPart().stream() | ||
.map(this::convertToPost) | ||
.sorted() | ||
.toList() | ||
.reversed(); | ||
} catch (final BigBoneRequestException e) { | ||
// TODO | ||
} | ||
return List.of(); | ||
} | ||
|
||
private Post convertToPost(@NotNull final Status status) { | ||
final Account account = status.getAccount(); | ||
final Instant instant = status.getCreatedAt().mostPreciseInstantOrNull(); | ||
final LocalDateTime date = LocalDateTime.ofInstant(instant, ZoneId.systemDefault()); | ||
return new Post( | ||
status.getId(), | ||
date, | ||
account.getDisplayName(), | ||
account.getAvatar(), | ||
status.getContent()); | ||
} | ||
|
||
} |
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Apus - A social wall for conferences with additional features. | ||
* Copyright (C) Marcus Fihlon and the individual contributors to Apus. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published | ||
* by the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package swiss.fihlon.apus.ui.view; | ||
|
||
import com.vaadin.flow.component.Html; | ||
import com.vaadin.flow.component.dependency.CssImport; | ||
import com.vaadin.flow.component.html.Div; | ||
import org.jetbrains.annotations.NotNull; | ||
import swiss.fihlon.apus.social.Post; | ||
|
||
@CssImport(value = "./themes/apus/views/post-view.css") | ||
public final class PostView extends Div { | ||
|
||
public PostView(@NotNull final Post post) { | ||
addClassName("post-view"); | ||
add(new Html("<div>" + post.html() + "</div>")); | ||
} | ||
|
||
} |
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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Apus - A social wall for conferences with additional features. | ||
* Copyright (C) Marcus Fihlon and the individual contributors to Apus. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published | ||
* by the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package swiss.fihlon.apus.ui.view; | ||
|
||
import com.vaadin.flow.component.dependency.CssImport; | ||
import com.vaadin.flow.component.orderedlayout.VerticalLayout; | ||
import org.jetbrains.annotations.NotNull; | ||
import swiss.fihlon.apus.service.SocialService; | ||
import swiss.fihlon.apus.social.Post; | ||
|
||
@CssImport(value = "./themes/apus/views/posts-view.css") | ||
public final class PostsView extends VerticalLayout { | ||
|
||
public PostsView(@NotNull final SocialService socialService) { | ||
setId("posts"); | ||
for (final Post post : socialService.getPosts()) { | ||
add(new PostView(post)); | ||
} | ||
} | ||
|
||
} |
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
38 changes: 38 additions & 0 deletions
38
src/test/java/swiss/fihlon/apus/social/mastodon/MastodonAPITest.java
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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Apus - A social wall for conferences with additional features. | ||
* Copyright (C) Marcus Fihlon and the individual contributors to Apus. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published | ||
* by the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package swiss.fihlon.apus.social.mastodon; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import swiss.fihlon.apus.social.Post; | ||
|
||
import java.util.List; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
|
||
class MastodonAPITest { | ||
|
||
@Test | ||
void getPosts() { | ||
final MastodonAPI mastodonAPI = new MastodonAPI("mastodon.social"); | ||
final List<Post> posts = mastodonAPI.getPosts("java"); | ||
assertNotNull(posts); | ||
for (final Post post : posts) { | ||
System.out.println(post); | ||
} | ||
} | ||
} |