Skip to content

Commit

Permalink
💄 add avatar, author and profile to social media messages closes #5, #6
Browse files Browse the repository at this point in the history
  • Loading branch information
McPringle committed Mar 31, 2024
1 parent 0fb93be commit fc1c943
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 3 deletions.
9 changes: 9 additions & 0 deletions frontend/themes/apus/views/message-view.css
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@
display: none;
}

.message-view header .author-container {
display: inline-block;
margin-left: var(--lumo-space-s);
}

.message-view header .author {
font-weight: bold;
}

.message-view .datetime {
font-size: var(--lumo-font-size-xs);
font-style: italic;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/swiss/fihlon/apus/social/Message.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import java.util.List;

public record Message(@NotNull String id, @NotNull LocalDateTime date,
@NotNull String author, @NotNull String avatar,
@NotNull String author, @NotNull String avatar, @NotNull String profile,
@NotNull String html, @NotNull List<String> images,
boolean isReply, boolean isSensitive)
implements Comparable<Message> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,20 @@ private Message convertToMessage(@NotNull final Status status) {
final LocalDateTime date = LocalDateTime.ofInstant(instant, ZoneId.systemDefault());
final String author = account == null ? "" : account.getDisplayName();
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 String inReplyToId = status.getInReplyToId();
final boolean isReply = inReplyToId != null && !inReplyToId.isBlank();
final boolean isSensitive = status.isSensitive();

return new Message(id, date, author, avatar, html, images, isReply, isSensitive);
return new Message(id, date, author, avatar, profile, html, images, isReply, isSensitive);
}

@NotNull
private String getProfile(@NotNull final Account account) {
final var profile = account.getAcct();
return profile.contains("@") ? profile : profile.concat("@").concat(instance);
}

private List<String> getImages(@NotNull final List<MediaAttachment> mediaAttachments) {
Expand Down
17 changes: 16 additions & 1 deletion src/main/java/swiss/fihlon/apus/ui/view/MessageView.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@
import com.vaadin.flow.component.Html;
import com.vaadin.flow.component.Text;
import com.vaadin.flow.component.UI;
import com.vaadin.flow.component.avatar.Avatar;
import com.vaadin.flow.component.dependency.CssImport;
import com.vaadin.flow.component.html.Div;
import com.vaadin.flow.component.html.Footer;
import com.vaadin.flow.component.html.Header;
import com.vaadin.flow.component.html.Image;
import org.jetbrains.annotations.NotNull;
import org.jsoup.Jsoup;
Expand All @@ -37,11 +40,23 @@ public final class MessageView extends Div {

public MessageView(@NotNull final Message message) {
addClassName("message-view");
add(createHeaderComponent(message));
add(createTextComponent(message));
add(createImageComponents(message));
add(createDateTimeComponent(message));
}

@NotNull Component createHeaderComponent(@NotNull final Message message) {
final var avatar = new Avatar(message.author(), message.avatar());
final var author = new Div(new Text(message.author()));
author.addClassName("author");
final var profile = new Div(new Text(message.profile()));
profile.addClassName("profile");
final var authorContainer = new Div(author, profile);
authorContainer.addClassName("author-container");
return new Header(avatar, authorContainer);
}

@NotNull
private Component createTextComponent(@NotNull final Message message) {
final String messageText = Jsoup.parse(message.html()).text();
Expand All @@ -64,7 +79,7 @@ private Component[] createImageComponents(@NotNull final Message message) {

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

0 comments on commit fc1c943

Please sign in to comment.