Skip to content

Commit

Permalink
Implemented separate 'Moderator Event' tab as per Issue #200 (#201)
Browse files Browse the repository at this point in the history
* Upgrade 'sourceCompatibility' from Java 17 to Java 21

* Upgrade 'commonsVersion' dependency to a new commit from faf-java-commons from deb598d to 6e46109

* Added a separate 'Moderator Event' tab next to 'Chat Log'

* Populating the tab 'Moderator Event' with its data

* Update readme for Java 21

* Refactor time formatting method for chat messages

- Renamed the method to better reflect its specific use case and to improve readability

* Update Java version in GitHub Actions workflow from 17 to 21

* Fix typo in Tab text from 'Moderator Event' to 'Moderator Events'
  • Loading branch information
magge-faf authored Mar 26, 2024
1 parent 2b5a593 commit d06c7e8
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
checks:

runs-on: ubuntu-latest
container: eclipse-temurin:17-jdk
container: eclipse-temurin:21-jdk
steps:
- name: Checkout code
uses: actions/checkout@v2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
release:

runs-on: ubuntu-latest
container: eclipse-temurin:17-jdk
container: eclipse-temurin:21-jdk

steps:
- uses: actions/checkout@v2
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ This application enables faforever.com moderators to perform administrative acti
- editing runtime translations

# How to use / run it
- Make sure you have Java 17 or higher installed (JRE or JDK does not matter). Adoptium offers free installation
packages [here](https://adoptium.net/?variant=openjdk17) (other Java flavours like Oracle should also work)
- Make sure you have Java 21 or higher installed (JRE or JDK does not matter). Adoptium offers free installation
packages [here](https://adoptium.net/?variant=openjdk21) (other Java flavours like Oracle should also work)
- Download the right client version for your operating system from the release page
- Unzip it
- Go to the bin folder and run the .bat script (Windows) or the .sh script (Linux)
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ println "Platform is: ${javafxPlatform}"
dependencies {
def springBootVersion = "3.1.5"
def mapStructVersion = "1.5.5.Final"
def commonsVersion = "deb598d"
def commonsVersion = "6e46109"

annotationProcessor(platform("org.springframework.boot:spring-boot-dependencies:${springBootVersion}"))
implementation(platform("org.springframework.boot:spring-boot-dependencies:${springBootVersion}"))
Expand Down Expand Up @@ -71,7 +71,7 @@ mainClassName = 'com.faforever.moderatorclient.Launcher'

group = 'com.faforever'
description = 'faf-moderator-client'
sourceCompatibility = '17'
sourceCompatibility = '21'

tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.faforever.moderatorclient.ui.moderation_reports;

import com.faforever.commons.api.dto.ModerationReportStatus;
import com.faforever.commons.replay.ModeratorEvent;
import com.faforever.commons.replay.ReplayDataParser;
import com.faforever.moderatorclient.api.FafApiCommunicationService;
import com.faforever.moderatorclient.api.domain.ModerationReportService;
Expand Down Expand Up @@ -43,6 +44,7 @@
import java.net.http.HttpResponse;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.stream.Collectors;

import static java.text.MessageFormat.format;
Expand Down Expand Up @@ -72,6 +74,7 @@ public class ModerationReportController implements Controller<Region> {
public Button editReportButton;
public TableView<PlayerFX> reportedPlayerView;
public TextArea chatLogTextArea;
public TextArea moderatorEventTextArea;

private FilteredList<ModerationReportFX> filteredItemList;
private ObservableList<ModerationReportFX> itemList;
Expand Down Expand Up @@ -209,26 +212,49 @@ private void showChatLog(ModerationReportFX report) {
String chatLog = header + replayDataParser.getChatMessages().stream()
.map(message -> {
long timeMillis = message.getTime().toMillis();
String formattedTime;

if (timeMillis >= 0) {
formattedTime = DurationFormatUtils.formatDuration(timeMillis, "HH:mm:ss");
} else {
formattedTime = "N/A"; // replay data contains negative timestamps for whatever reason
}
String formattedChatMessageTime = formatChatMessageTime(timeMillis);

return format("[{0}] from {1} to {2}: {3}",
formattedTime,
formattedChatMessageTime,
message.getSender(), message.getReceiver(), message.getMessage());
})
.collect(Collectors.joining("\n"));

chatLogTextArea.setText(chatLog);

log.debug("Parsing moderatorEvents");

List<ModeratorEvent> moderatorEvents = replayDataParser.getModeratorEvents();
showModeratorEvent(moderatorEvents);
} catch (Exception e) {
log.error("Loading replay {} failed", game, e);
chatLogTextArea.setText(header + format("Loading replay failed due to {0}: \n{1}", e, e.getMessage()));
}

Files.delete(tempFilePath);
}

private void showModeratorEvent(List<ModeratorEvent> moderatorEvents){
String moderatorEventsLog = moderatorEvents.stream()
.map(event -> {
long timeMillis = event.time().toMillis();
String formattedChatMessageTime = formatChatMessageTime(timeMillis);

return format("[{0}] from {1}: {2}",
formattedChatMessageTime,
event.sender(),
event.message());
})
.collect(Collectors.joining("\n"));

moderatorEventTextArea.setText(moderatorEventsLog);
}

private String formatChatMessageTime(long timeMillis) {
if (timeMillis >= 0) {
return DurationFormatUtils.formatDuration(timeMillis, "HH:mm:ss");
} else {
return "N/A"; // replay data contains negative timestamps for whatever reason
}
}
}
3 changes: 3 additions & 0 deletions src/main/resources/ui/main_window/report.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@
<TextArea fx:id="chatLogTextArea" editable="false" prefHeight="200.0" prefWidth="200.0"/>
</content>
</Tab>
<Tab text="Moderator Events">
<TextArea fx:id="moderatorEventTextArea" editable="false" prefHeight="200.0" prefWidth="200.0"/>
</Tab>
</tabs>
</TabPane>
</items>
Expand Down

0 comments on commit d06c7e8

Please sign in to comment.