mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-15 12:19:54 +01:00
Add method for deleting a contact from own mailbox
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package org.briarproject.bramble.mailbox;
|
||||
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
|
||||
import org.briarproject.bramble.api.contact.ContactId;
|
||||
import org.briarproject.bramble.api.mailbox.MailboxProperties;
|
||||
|
||||
@@ -35,10 +37,17 @@ interface MailboxApi {
|
||||
* (contact was already added).
|
||||
*/
|
||||
void addContact(MailboxProperties properties, MailboxContact contact)
|
||||
throws IOException, ApiException,
|
||||
TolerableFailureException;
|
||||
throws IOException, ApiException, TolerableFailureException;
|
||||
|
||||
/**
|
||||
* Deletes a contact from the mailbox.
|
||||
* This should get called after a contact was removed from Briar.
|
||||
*/
|
||||
void deleteContact(MailboxProperties properties, ContactId contactId)
|
||||
throws IOException, ApiException;
|
||||
|
||||
@Immutable
|
||||
@JsonSerialize
|
||||
class MailboxContact {
|
||||
public final int contactId;
|
||||
public final String token, inboxId, outboxId;
|
||||
|
||||
@@ -5,6 +5,7 @@ import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.json.JsonMapper;
|
||||
|
||||
import org.briarproject.bramble.api.WeakSingletonProvider;
|
||||
import org.briarproject.bramble.api.contact.ContactId;
|
||||
import org.briarproject.bramble.api.mailbox.MailboxProperties;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
|
||||
@@ -111,6 +112,21 @@ class MailboxApiImpl implements MailboxApi {
|
||||
if (!response.isSuccessful()) throw new ApiException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteContact(MailboxProperties properties, ContactId contactId)
|
||||
throws IOException, ApiException {
|
||||
if (!properties.isOwner()) throw new IllegalArgumentException();
|
||||
String url = properties.getOnionAddress() + "/contacts/" +
|
||||
contactId.getInt();
|
||||
Request request = getRequestBuilder(properties.getAuthToken())
|
||||
.delete()
|
||||
.url(url)
|
||||
.build();
|
||||
OkHttpClient client = httpClientProvider.get();
|
||||
Response response = client.newCall(request).execute();
|
||||
if (response.code() != 200) throw new ApiException();
|
||||
}
|
||||
|
||||
private Request.Builder getRequestBuilder(String token) {
|
||||
return new Request.Builder()
|
||||
.addHeader("Authorization", "Bearer " + token);
|
||||
|
||||
Reference in New Issue
Block a user