import com.fasterxml.jackson.databind.node.ObjectNode;
import org.apache.http.util.TextUtils;
import org.asamk.Signal;
+import org.asamk.signal.storage.contacts.ContactInfo;
+import org.asamk.signal.storage.contacts.JsonContactsStore;
+import org.asamk.signal.storage.groups.GroupInfo;
+import org.asamk.signal.storage.groups.JsonGroupStore;
+import org.asamk.signal.storage.protocol.JsonIdentityKeyStore;
+import org.asamk.signal.storage.protocol.JsonSignalProtocolStore;
+import org.asamk.signal.storage.threads.JsonThreadStore;
+import org.asamk.signal.storage.threads.ThreadInfo;
+import org.asamk.signal.util.Base64;
+import org.asamk.signal.util.Util;
import org.whispersystems.libsignal.*;
import org.whispersystems.libsignal.ecc.Curve;
import org.whispersystems.libsignal.ecc.ECKeyPair;
}
public void updateAccountAttributes() throws IOException {
- accountManager.setAccountAttributes(signalingKey, signalProtocolStore.getLocalRegistrationId(), false, false,true);
+ accountManager.setAccountAttributes(signalingKey, signalProtocolStore.getLocalRegistrationId(), false, false, true);
}
public void unregister() throws IOException {
public void verifyAccount(String verificationCode) throws IOException {
verificationCode = verificationCode.replace("-", "");
signalingKey = Util.getSecret(52);
- accountManager.verifyAccountWithCode(verificationCode, signalingKey, signalProtocolStore.getLocalRegistrationId(), false, false,true);
+ accountManager.verifyAccountWithCode(verificationCode, signalingKey, signalProtocolStore.getLocalRegistrationId(), false, false, true);
//accountManager.setGcmId(Optional.of(GoogleCloudMessaging.getInstance(this).register(REGISTRATION_ID)));
registered = true;
}
throw new NotAGroupMemberException(groupId, g.name);
}
-
+
public List<GroupInfo> getGroups() {
- return groupStore.getGroups();
+ return groupStore.getGroups();
}
@Override
sendMessage(messageBuilder, recipients);
}
+ @Override
+ public String getContactName(String number) {
+ ContactInfo contact = contactStore.getContact(number);
+ if (contact == null) {
+ return "";
+ } else {
+ return contact.name;
+ }
+ }
+
+ @Override
+ public void setContactName(String number, String name) {
+ ContactInfo contact = contactStore.getContact(number);
+ if (contact == null) {
+ contact = new ContactInfo();
+ contact.number = number;
+ System.out.println("Add contact " + number + " named " + name);
+ } else {
+ System.out.println("Updating contact " + number + " name " + contact.name + " -> " + name);
+ }
+ contact.name = name;
+ contactStore.updateContact(contact);
+ save();
+ }
+
+ @Override
+ public String getGroupName(byte[] groupId) {
+ GroupInfo group = getGroup(groupId);
+ if (group == null) {
+ return "";
+ } else {
+ return group.name;
+ }
+ }
+
+ @Override
+ public List<String> getGroupMembers(byte[] groupId) {
+ GroupInfo group = getGroup(groupId);
+ if (group == null) {
+ return new ArrayList<String>();
+ } else {
+ return new ArrayList<String>(group.members);
+ }
+ }
+
+ @Override
+ public void updateGroup(byte[] groupId, String name, List<String> members, String avatar) throws IOException, EncapsulatedExceptions, GroupNotFoundException, AttachmentInvalidException {
+ if (name.isEmpty()) {
+ name = null;
+ }
+ if (members.size() == 0) {
+ members = null;
+ }
+ if (avatar.isEmpty()) {
+ avatar = null;
+ }
+ sendUpdateGroupMessage(groupId, name, members, avatar);
+ }
+
private void requestSyncGroups() throws IOException {
SignalServiceProtos.SyncMessage.Request r = SignalServiceProtos.SyncMessage.Request.newBuilder().setType(SignalServiceProtos.SyncMessage.Request.Type.GROUPS).build();
SignalServiceSyncMessage message = SignalServiceSyncMessage.forRequest(new RequestMessage(r));
return false;
}
for (JsonIdentityKeyStore.Identity id : ids) {
- if (!Arrays.equals(id.identityKey.serialize(), fingerprint)) {
+ if (!Arrays.equals(id.getIdentityKey().serialize(), fingerprint)) {
continue;
}
- signalProtocolStore.saveIdentity(name, id.identityKey, TrustLevel.TRUSTED_VERIFIED);
+ signalProtocolStore.saveIdentity(name, id.getIdentityKey(), TrustLevel.TRUSTED_VERIFIED);
save();
return true;
}
return false;
}
for (JsonIdentityKeyStore.Identity id : ids) {
- if (!safetyNumber.equals(computeSafetyNumber(name, id.identityKey))) {
+ if (!safetyNumber.equals(computeSafetyNumber(name, id.getIdentityKey()))) {
continue;
}
- signalProtocolStore.saveIdentity(name, id.identityKey, TrustLevel.TRUSTED_VERIFIED);
+ signalProtocolStore.saveIdentity(name, id.getIdentityKey(), TrustLevel.TRUSTED_VERIFIED);
save();
return true;
}
return false;
}
for (JsonIdentityKeyStore.Identity id : ids) {
- if (id.trustLevel == TrustLevel.UNTRUSTED) {
- signalProtocolStore.saveIdentity(name, id.identityKey, TrustLevel.TRUSTED_UNVERIFIED);
+ if (id.getTrustLevel() == TrustLevel.UNTRUSTED) {
+ signalProtocolStore.saveIdentity(name, id.getIdentityKey(), TrustLevel.TRUSTED_UNVERIFIED);
}
}
save();