Skip to content

Commit

Permalink
Fix the initial availability of contacts upon load
Browse files Browse the repository at this point in the history
Also temporarily fix jpackage generation.
  • Loading branch information
zapek committed Dec 15, 2024
1 parent 5d3af46 commit 582eb62
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 23 deletions.
40 changes: 20 additions & 20 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -133,26 +133,26 @@ jpackage {
input = "${base.libsDirectory.get()}"
destination = "${base.distsDirectory.get()}"
mainJar = bootJar.archiveFileName.get()
// The following saves around 27 MB
addModules = ['java.base',
'java.desktop',
'java.sql',
'java.xml',
'java.management',
'java.datatransfer',
'java.prefs',
'java.naming',
'java.security.jgss',
'java.instrument',
'java.logging',
'java.compiler',
'java.scripting',
'java.transaction.xa',
'jdk.net',
'java.rmi',
'jdk.unsupported',
'java.sql.rowset',
'java.net.http']
// The following saves around 27 MB (but it's brittle, so removed for now)
// addModules = ['java.base',
// 'java.desktop',
// 'java.sql',
// 'java.xml',
// 'java.management',
// 'java.datatransfer',
// 'java.prefs',
// 'java.naming',
// 'java.security.jgss',
// 'java.instrument',
// 'java.logging',
// 'java.compiler',
// 'java.scripting',
// 'java.transaction.xa',
// 'jdk.net',
// 'java.rmi',
// 'jdk.unsupported',
// 'java.sql.rowset',
// 'java.net.http']
if (project.hasProperty("jpackage.portable")) {
type = ImageType.APP_IMAGE
} else {
Expand Down
12 changes: 12 additions & 0 deletions app/src/main/java/io/xeres/app/database/model/profile/Profile.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import io.xeres.app.database.converter.TrustConverter;
import io.xeres.app.database.model.location.Location;
import io.xeres.common.id.ProfileFingerprint;
import io.xeres.common.location.Availability;
import io.xeres.common.pgp.Trust;
import jakarta.persistence.*;
import jakarta.validation.constraints.NotNull;
Expand All @@ -36,6 +37,7 @@
import java.io.IOException;
import java.time.Instant;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

import static io.xeres.common.dto.profile.ProfileConstants.*;
Expand Down Expand Up @@ -267,6 +269,16 @@ public boolean isConnected()
return getLocations().stream().anyMatch(Location::isConnected);
}

public Availability getBestAvailability()
{
return getLocations().stream()
.filter(Location::isConnected)
.min(Comparator.comparing(location -> location.getAvailability().ordinal()))
.map(Location::getAvailability)
.orElse(Availability.OFFLINE);

}

@Override
public String toString()
{
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/io/xeres/app/service/ContactService.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ public Contact toContact(Profile profile)

private Availability getAvailability(Profile profile)
{
if (profile != null && profile.isConnected())
if (profile != null)
{
return Availability.AVAILABLE;
return profile.getBestAvailability();
}
return Availability.OFFLINE;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -779,7 +779,10 @@ private void updateContactConnection(long profileId, long locationId, Availabili
profileClient.findById(profileId)
.doOnSuccess(profile -> Platform.runLater(() -> {
existing.setValue(Contact.withAvailability(existing.getValue(), profile.getLocations().stream()
.anyMatch(Location::isConnected) ? Availability.AVAILABLE : Availability.OFFLINE));
.filter(Location::isConnected)
.min(Comparator.comparing(location -> location.getAvailability().ordinal()))
.map(Location::getAvailability)
.orElse(Availability.OFFLINE)));
refreshContactIfNeeded(existing);
}))
.subscribe();
Expand Down

0 comments on commit 582eb62

Please sign in to comment.