Moar federation

This commit is contained in:
Tim Zöller 2025-12-03 07:18:43 +01:00
parent 4c9bcc718f
commit 45e9030c1d
2 changed files with 46 additions and 17 deletions

View file

@ -136,49 +136,72 @@ public class ActivityController {
/** /**
* Format activity content for ActivityPub. * Format activity content for ActivityPub.
* Uses plain text with Unicode symbols for maximum compatibility across Fediverse platforms.
*/ */
private String formatActivityContent(Activity activity) { private String formatActivityContent(Activity activity) {
StringBuilder content = new StringBuilder(); StringBuilder content = new StringBuilder();
// Title (if present)
if (activity.getTitle() != null && !activity.getTitle().isEmpty()) { if (activity.getTitle() != null && !activity.getTitle().isEmpty()) {
content.append("<h3>").append(escapeHtml(activity.getTitle())).append("</h3>"); content.append(activity.getTitle()).append("\n\n");
} }
// Description (if present)
if (activity.getDescription() != null && !activity.getDescription().isEmpty()) { if (activity.getDescription() != null && !activity.getDescription().isEmpty()) {
content.append("<p>").append(escapeHtml(activity.getDescription())).append("</p>"); content.append(activity.getDescription()).append("\n\n");
} }
content.append("<p>"); // Activity type with emoji
content.append("<strong>Activity Type:</strong> ").append(activity.getActivityType()).append("<br>"); String activityEmoji = getActivityEmoji(activity.getActivityType());
content.append(activityEmoji).append(" ").append(activity.getActivityType());
// Metrics on separate lines
if (activity.getTotalDistance() != null) { if (activity.getTotalDistance() != null) {
content.append("<strong>Distance:</strong> ") content.append("\n📏 ")
.append(String.format("%.2f km", activity.getTotalDistance().doubleValue() / 1000.0)) .append(String.format("%.2f km", activity.getTotalDistance().doubleValue() / 1000.0));
.append("<br>");
} }
if (activity.getTotalDurationSeconds() != null) { if (activity.getTotalDurationSeconds() != null) {
long hours = activity.getTotalDurationSeconds() / 3600; long hours = activity.getTotalDurationSeconds() / 3600;
long minutes = (activity.getTotalDurationSeconds() % 3600) / 60; long minutes = (activity.getTotalDurationSeconds() % 3600) / 60;
long seconds = activity.getTotalDurationSeconds() % 60; long seconds = activity.getTotalDurationSeconds() % 60;
content.append("<strong>Duration:</strong> "); content.append("\n⏱ ");
if (hours > 0) { if (hours > 0) {
content.append(hours).append("h "); content.append(hours).append("h ");
} }
content.append(minutes).append("m ").append(seconds).append("s<br>"); content.append(minutes).append("m ").append(seconds).append("s");
} }
if (activity.getElevationGain() != null) { if (activity.getElevationGain() != null) {
content.append("<strong>Elevation Gain:</strong> ") content.append("\n⛰ ")
.append(String.format("%.0f m", activity.getElevationGain())) .append(String.format("%.0f m", activity.getElevationGain()));
.append("<br>");
} }
content.append("</p>");
return content.toString(); return content.toString();
} }
/**
* Get an emoji for the activity type.
*/
private String getActivityEmoji(Activity.ActivityType type) {
return switch (type) {
case RUN -> "🏃";
case RIDE -> "🚴";
case HIKE -> "🥾";
case WALK -> "🚶";
case SWIM -> "🏊";
case ALPINE_SKI, BACKCOUNTRY_SKI, NORDIC_SKI -> "⛷️";
case SNOWBOARD -> "🏂";
case ROWING -> "🚣";
case KAYAKING, CANOEING -> "🛶";
case INLINE_SKATING -> "⛸️";
case ROCK_CLIMBING, MOUNTAINEERING -> "🧗";
case YOGA -> "🧘";
case WORKOUT -> "💪";
default -> "🏋️";
};
}
/** /**
* Simple HTML escaping. * Simple HTML escaping.
*/ */

View file

@ -45,7 +45,7 @@
</p> </p>
<p id="activityDescription" class="text-muted"></p> <p id="activityDescription" class="text-muted"></p>
</div> </div>
<div class="btn-group" role="group"> <div class="btn-group" role="group" id="activityActions" style="display: none;">
<a href="#" id="editBtn" class="btn btn-outline-primary"> <a href="#" id="editBtn" class="btn btn-outline-primary">
<i class="bi bi-pencil"></i> Edit <i class="bi bi-pencil"></i> Edit
</a> </a>
@ -315,8 +315,14 @@
document.getElementById('activityDescription').style.display = 'none'; document.getElementById('activityDescription').style.display = 'none';
} }
// Edit button // Show Edit/Delete buttons only if user is logged in and owns the activity
if (FitPubAuth.isAuthenticated()) {
const currentUser = FitPubAuth.getCurrentUser();
if (currentUser && currentUser.id === activity.userId) {
document.getElementById('activityActions').style.display = 'block';
document.getElementById('editBtn').href = `/activities/${activity.id}/edit`; document.getElementById('editBtn').href = `/activities/${activity.id}/edit`;
}
}
// Metrics // Metrics
document.getElementById('metricDistance').textContent = formatDistance(activity.totalDistance); document.getElementById('metricDistance').textContent = formatDistance(activity.totalDistance);