2018-10-19 20:43:38 +02:00
|
|
|
package eu.siacs.conversations.services;
|
|
|
|
|
2018-10-19 23:29:17 +02:00
|
|
|
|
|
|
|
import android.util.Log;
|
|
|
|
|
2018-10-20 16:37:59 +02:00
|
|
|
import java.security.SecureRandom;
|
2018-10-19 23:29:17 +02:00
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.Set;
|
|
|
|
import java.util.WeakHashMap;
|
|
|
|
|
|
|
|
import eu.siacs.conversations.Config;
|
|
|
|
import eu.siacs.conversations.entities.Account;
|
2018-10-20 16:37:59 +02:00
|
|
|
import eu.siacs.conversations.utils.CryptoHelper;
|
2018-10-19 23:29:17 +02:00
|
|
|
import eu.siacs.conversations.utils.PhoneNumberUtilWrapper;
|
|
|
|
import io.michaelrocks.libphonenumber.android.Phonenumber;
|
|
|
|
import rocks.xmpp.addr.Jid;
|
2018-10-19 20:43:38 +02:00
|
|
|
|
|
|
|
public class QuickConversationsService {
|
|
|
|
|
|
|
|
private final XmppConnectionService service;
|
|
|
|
|
2018-10-19 23:29:17 +02:00
|
|
|
private final Set<OnVerificationRequested> mOnVerificationRequested = Collections.newSetFromMap(new WeakHashMap<>());
|
|
|
|
private final Set<OnVerified> mOnVerified = Collections.newSetFromMap(new WeakHashMap<>());
|
|
|
|
|
2018-10-19 20:43:38 +02:00
|
|
|
QuickConversationsService(XmppConnectionService xmppConnectionService) {
|
|
|
|
this.service = xmppConnectionService;
|
|
|
|
}
|
2018-10-19 23:29:17 +02:00
|
|
|
|
|
|
|
public void addOnVerificationRequestedListener(OnVerificationRequested onVerificationRequested) {
|
|
|
|
synchronized (mOnVerificationRequested) {
|
|
|
|
mOnVerificationRequested.add(onVerificationRequested);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void removeOnVerificationRequestedListener(OnVerificationRequested onVerificationRequested) {
|
|
|
|
synchronized (mOnVerificationRequested) {
|
|
|
|
mOnVerificationRequested.remove(onVerificationRequested);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void requestVerification(Phonenumber.PhoneNumber phoneNumber) {
|
|
|
|
String local = PhoneNumberUtilWrapper.normalize(service, phoneNumber);
|
|
|
|
Log.d(Config.LOGTAG,"requesting verification for "+PhoneNumberUtilWrapper.normalize(service,phoneNumber));
|
2018-10-20 16:37:59 +02:00
|
|
|
Account account = new Account(Jid.of(local,"quick.conversations.im",null), CryptoHelper.createPassword(new SecureRandom()));
|
|
|
|
account.setOption(Account.OPTION_DISABLED, true);
|
|
|
|
account.setOption(Account.OPTION_UNVERIFIED, true);
|
2018-10-19 23:29:17 +02:00
|
|
|
service.createAccount(account);
|
|
|
|
synchronized (mOnVerificationRequested) {
|
|
|
|
for(OnVerificationRequested onVerificationRequested : mOnVerificationRequested) {
|
|
|
|
onVerificationRequested.onVerificationRequested();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public interface OnVerificationRequested {
|
|
|
|
void onVerificationRequestFailed(int code);
|
|
|
|
void onVerificationRequested();
|
|
|
|
}
|
|
|
|
|
|
|
|
public interface OnVerified {
|
|
|
|
void onVerificationFailed();
|
|
|
|
void onVerificationSucceeded();
|
|
|
|
}
|
2018-10-19 20:43:38 +02:00
|
|
|
}
|