Skip to content
Snippets Groups Projects
Verified Commit a9f77f0f authored by akwizgran's avatar akwizgran
Browse files

Add a method for getting a client's visibility.

parent cc6fed02
No related branches found
No related tags found
No related merge requests found
package org.briarproject.bramble.api.sync; package org.briarproject.bramble.api.sync;
import org.briarproject.bramble.api.contact.Contact; import org.briarproject.bramble.api.contact.Contact;
import org.briarproject.bramble.api.contact.ContactId;
import org.briarproject.bramble.api.db.DbException; import org.briarproject.bramble.api.db.DbException;
import org.briarproject.bramble.api.db.Transaction; import org.briarproject.bramble.api.db.Transaction;
import org.briarproject.bramble.api.lifecycle.LifecycleManager; import org.briarproject.bramble.api.lifecycle.LifecycleManager;
...@@ -34,6 +35,13 @@ public interface ClientVersioningManager { ...@@ -34,6 +35,13 @@ public interface ClientVersioningManager {
void registerClientVersioningHook(ClientId clientId, int clientVersion, void registerClientVersioningHook(ClientId clientId, int clientVersion,
ClientVersioningHook hook); ClientVersioningHook hook);
/**
* Returns the visibility of the given client with respect to the given
* contact.
*/
Visibility getClientVisibility(Transaction txn, ContactId contactId,
ClientId clientId, int clientVersion) throws DbException;
interface ClientVersioningHook { interface ClientVersioningHook {
void onClientVisibilityChanging(Transaction txn, Contact c, void onClientVisibilityChanging(Transaction txn, Contact c,
......
...@@ -89,6 +89,28 @@ class ClientVersioningManagerImpl implements ClientVersioningManager, Client, ...@@ -89,6 +89,28 @@ class ClientVersioningManagerImpl implements ClientVersioningManager, Client,
hooks.put(new ClientVersion(clientId, clientVersion), hook); hooks.put(new ClientVersion(clientId, clientVersion), hook);
} }
@Override
public Visibility getClientVisibility(Transaction txn,
ContactId contactId, ClientId clientId, int clientVersion)
throws DbException {
try {
Contact contact = db.getContact(txn, contactId);
Group g = getContactGroup(contact);
LatestUpdates latest = findLatestUpdates(txn, g.getId());
if (latest.local == null) throw new DbException();
if (latest.remote == null) return INVISIBLE;
Update localUpdate = loadUpdate(txn, latest.local.messageId);
Update remoteUpdate = loadUpdate(txn, latest.remote.messageId);
Map<ClientVersion, Visibility> visibilities =
getVisibilities(localUpdate.states, remoteUpdate.states);
ClientVersion cv = new ClientVersion(clientId, clientVersion);
Visibility v = visibilities.get(cv);
return v == null ? INVISIBLE : v;
} catch (FormatException e) {
throw new DbException(e);
}
}
@Override @Override
public void createLocalState(Transaction txn) throws DbException { public void createLocalState(Transaction txn) throws DbException {
if (db.containsGroup(txn, localGroup.getId())) return; if (db.containsGroup(txn, localGroup.getId())) return;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment