Skip to content

Commit

Permalink
Show own forum groups in the correct tree
Browse files Browse the repository at this point in the history
Also disables unsubscribe from own forums. There should be a way to delete them though.
  • Loading branch information
zapek committed Aug 20, 2023
1 parent 3a9dba0 commit 0fbc1f4
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ public static ForumGroupDTO toDTO(ForumGroupItem forumGroupItem)
forumGroupItem.getGxsId(),
forumGroupItem.getName(),
forumGroupItem.getDescription(),
forumGroupItem.isSubscribed()
forumGroupItem.isSubscribed(),
forumGroupItem.isExternal()
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ public record ForumGroupDTO(
GxsId gxsId,
String name,
String description,
boolean subscribed
boolean subscribed,
boolean external
)
{
}
11 changes: 11 additions & 0 deletions common/src/main/java/io/xeres/common/message/forum/ForumGroup.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class ForumGroup
private GxsId gxsId;
private String description;
private boolean subscribed;
private boolean external;

public ForumGroup()
{
Expand Down Expand Up @@ -93,6 +94,16 @@ public void setSubscribed(boolean subscribed)
this.subscribed = subscribed;
}

public boolean isExternal()
{
return external;
}

public void setExternal(boolean external)
{
this.external = external;
}

@Override
public String toString()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import java.io.IOException;
import java.time.Instant;
import java.util.*;
import java.util.stream.Stream;

import static javafx.scene.control.TreeTableColumn.SortType.DESCENDING;

Expand Down Expand Up @@ -203,7 +204,7 @@ private void createForumTreeContextMenu()
.filter(menuItem -> menuItem.getId().equals(UNSUBSCRIBE_MENU_ID))
.findFirst().ifPresent(menuItem -> menuItem.setDisable(!forumGroup.isSubscribed()));

return forumGroup.isReal();
return forumGroup.isReal() && forumGroup.isExternal();
});
}

Expand Down Expand Up @@ -280,12 +281,17 @@ private void getForumGroups()

private void addForumGroups(List<ForumGroup> forumGroups)
{
var ownTree = ownForums.getChildren();
var subscribedTree = subscribedForums.getChildren();
var popularTree = popularForums.getChildren();
var otherTree = otherForums.getChildren();

forumGroups.forEach(forumGroup -> {
if (forumGroup.isSubscribed())
if (!forumGroup.isExternal())
{
addOrUpdate(ownTree, forumGroup);
}
else if (forumGroup.isSubscribed())
{
addOrUpdate(subscribedTree, forumGroup);
}
Expand Down Expand Up @@ -352,7 +358,7 @@ private void changeSelectedForumGroup(ForumGroup forumGroup)
selectedForumGroup = forumGroup;
selectedForumMessage = null;

getSubscribedTreeItem(forumGroup.getId()).ifPresentOrElse(forumGroupTreeItem -> forumClient.getForumMessages(forumGroup.getId()).collectList()
getBrowsableTreeItem(forumGroup.getId()).ifPresentOrElse(forumGroupTreeItem -> forumClient.getForumMessages(forumGroup.getId()).collectList()
.doOnSuccess(forumMessages -> Platform.runLater(() -> {
forumMessagesRoot.getChildren().clear();
forumMessagesRoot.getChildren().addAll(toTreeItemForumMessages(forumMessages));
Expand Down Expand Up @@ -384,9 +390,9 @@ private void add(ForumMessage forumMessage)
forumMessagesRoot.getChildren().add(new TreeItem<>(forumMessage));
}

private Optional<TreeItem<ForumGroup>> getSubscribedTreeItem(long forumId)
private Optional<TreeItem<ForumGroup>> getBrowsableTreeItem(long forumId)
{
return subscribedForums.getChildren().stream()
return Stream.concat(subscribedForums.getChildren().stream(), ownForums.getChildren().stream())
.filter(forumGroupTreeItem -> forumGroupTreeItem.getValue().getId() == forumId)
.findFirst();
}
Expand Down
1 change: 1 addition & 0 deletions ui/src/main/java/io/xeres/ui/model/forum/ForumMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public static ForumGroup fromDTO(ForumGroupDTO dto)
forumGroup.setGxsId(dto.gxsId());
forumGroup.setDescription(dto.description());
forumGroup.setSubscribed(dto.subscribed());
forumGroup.setExternal(dto.external());
return forumGroup;
}

Expand Down

0 comments on commit 0fbc1f4

Please sign in to comment.