Handle end session messages

This commit is contained in:
AsamK 2015-07-07 12:19:10 +02:00
parent 01702276c5
commit 1b0df2c7e7
3 changed files with 10 additions and 7 deletions

View file

@ -7,10 +7,7 @@ import org.whispersystems.libaxolotl.state.SessionRecord;
import org.whispersystems.libaxolotl.state.SessionStore;
import java.io.IOException;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.*;
public class JsonSessionStore implements SessionStore {
@ -85,7 +82,7 @@ public class JsonSessionStore implements SessionStore {
@Override
public synchronized void deleteAllSessions(String name) {
for (AxolotlAddress key : sessions.keySet()) {
for (AxolotlAddress key : new ArrayList<>(sessions.keySet())) {
if (key.getName().equals(name)) {
sessions.remove(key);
}

View file

@ -188,9 +188,11 @@ public class Main {
} else {
if (content.getDataMessage().isPresent()) {
TextSecureDataMessage message = content.getDataMessage().get();
System.out.println("Body: " + message.getBody().get());
if (message.getAttachments().isPresent()) {
if (message.isEndSession()) {
m.handleEndSession(envelope.getSource());
} else if (message.getAttachments().isPresent()) {
System.out.println("Attachments: ");
for (TextSecureAttachment attachment : message.getAttachments().get()) {
System.out.println("- " + attachment.getContentType() + " (" + (attachment.isPointer() ? "Pointer" : "") + (attachment.isStream() ? "Stream" : "") + ")");

View file

@ -179,6 +179,10 @@ public class Manager {
}
}
public void handleEndSession(String source) {
axolotlStore.deleteAllSessions(source);
}
public interface ReceiveMessageHandler {
void handleMessage(TextSecureEnvelope envelope);
}