Skip to content

Commit

Permalink
✨ add posting time to social media messages closes #7
Browse files Browse the repository at this point in the history
  • Loading branch information
McPringle committed Mar 31, 2024
1 parent 70cacae commit e904837
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
5 changes: 5 additions & 0 deletions frontend/themes/apus/views/message-view.css
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,8 @@
.message-view .invisible {
display: none;
}

.message-view .datetime {
font-size: var(--lumo-font-size-xs);
text-align: right;
}
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,11 @@
<artifactId>jsoup</artifactId>
<version>1.17.2</version>
</dependency>
<dependency>
<groupId>org.ocpsoft.prettytime</groupId>
<artifactId>prettytime</artifactId>
<version>5.0.7.Final</version>
</dependency>
<dependency>
<groupId>social.bigbone</groupId>
<artifactId>bigbone</artifactId>
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/swiss/fihlon/apus/ui/view/MessageView.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,16 @@
*/
package swiss.fihlon.apus.ui.view;

import com.vaadin.flow.component.Component;
import com.vaadin.flow.component.Html;
import com.vaadin.flow.component.Text;
import com.vaadin.flow.component.UI;
import com.vaadin.flow.component.dependency.CssImport;
import com.vaadin.flow.component.html.Div;
import com.vaadin.flow.component.html.Image;
import org.jetbrains.annotations.NotNull;
import org.jsoup.Jsoup;
import org.ocpsoft.prettytime.PrettyTime;
import swiss.fihlon.apus.social.Message;

@CssImport(value = "./themes/apus/views/message-view.css")
Expand All @@ -40,10 +44,20 @@ public MessageView(@NotNull final Message message) {
for (final String image : message.images()) {
add(new Image(image, image));
}
add(createDateTimeComponent(message));
}

@NotNull
private String truncateMessageText(@NotNull final String messageText) {
return "<p>" + messageText.substring(0, MAX_LENGTH) + TRUNC_INDICATOR + "</p>";
}

@NotNull
private Component createDateTimeComponent(@NotNull final Message message) {
final var dateTimeComponent = new Div();
dateTimeComponent.addClassName("datetime");
final var prettyTime = new PrettyTime(UI.getCurrent().getLocale());
dateTimeComponent.add(new Text(prettyTime.format(message.date())));
return dateTimeComponent;
}
}

0 comments on commit e904837

Please sign in to comment.