Update RefreshPreKeysJob.

This commit is contained in:
Mikunj 2019-06-04 15:00:27 +10:00
parent 96efb5d296
commit 384a5ba35d
3 changed files with 25 additions and 2 deletions

View File

@ -36,6 +36,8 @@ import org.thoughtcrime.securesms.database.SmsDatabase;
import org.thoughtcrime.securesms.database.ThreadDatabase; import org.thoughtcrime.securesms.database.ThreadDatabase;
import org.thoughtcrime.securesms.jobs.RefreshPreKeysJob; import org.thoughtcrime.securesms.jobs.RefreshPreKeysJob;
import org.thoughtcrime.securesms.loki.LokiAPIDatabase; import org.thoughtcrime.securesms.loki.LokiAPIDatabase;
import org.thoughtcrime.securesms.loki.LokiContactPreKeyDatabase;
import org.thoughtcrime.securesms.loki.LokiPreKeyBundleDatabase;
import org.thoughtcrime.securesms.notifications.NotificationChannels; import org.thoughtcrime.securesms.notifications.NotificationChannels;
import org.thoughtcrime.securesms.service.KeyCachingService; import org.thoughtcrime.securesms.service.KeyCachingService;
import org.thoughtcrime.securesms.util.TextSecurePreferences; import org.thoughtcrime.securesms.util.TextSecurePreferences;
@ -116,6 +118,8 @@ public class SQLCipherOpenHelper extends SQLiteOpenHelper {
db.execSQL(LokiAPIDatabase.getCreateSwarmCacheTableCommand()); db.execSQL(LokiAPIDatabase.getCreateSwarmCacheTableCommand());
db.execSQL(LokiAPIDatabase.getCreateLastMessageHashValueTableCommand()); db.execSQL(LokiAPIDatabase.getCreateLastMessageHashValueTableCommand());
db.execSQL(LokiAPIDatabase.getCreateReceivedMessageHashValuesTableCommand()); db.execSQL(LokiAPIDatabase.getCreateReceivedMessageHashValuesTableCommand());
db.execSQL(LokiPreKeyBundleDatabase.getCreateTableCommand());
db.execSQL(LokiContactPreKeyDatabase.getCreateTableCommand());
executeStatements(db, SmsDatabase.CREATE_INDEXS); executeStatements(db, SmsDatabase.CREATE_INDEXS);
executeStatements(db, MmsDatabase.CREATE_INDEXS); executeStatements(db, MmsDatabase.CREATE_INDEXS);

View File

@ -55,6 +55,26 @@ public class RefreshPreKeysJob extends BaseJob implements InjectableType {
return KEY; return KEY;
} }
@Override
public void onRun() throws IOException {
if (!TextSecurePreferences.isPushRegistered(context)) return;
if (TextSecurePreferences.isSignedPreKeyRegistered(context)) {
Log.i(TAG, "Already have a signed pre key set");
return;
}
Log.i(TAG, "Registering new signed pre key...");
IdentityKeyPair identityKey = IdentityKeyUtil.getIdentityKeyPair(context);
PreKeyUtil.generateSignedPreKey(context, identityKey, true);
TextSecurePreferences.setSignedPreKeyRegistered(context, true);
ApplicationContext.getInstance(context)
.getJobManager()
.add(new CleanPreKeysJob());
}
/* Loki - Original Code
@Override @Override
public void onRun() throws IOException { public void onRun() throws IOException {
if (!TextSecurePreferences.isPushRegistered(context)) return; if (!TextSecurePreferences.isPushRegistered(context)) return;
@ -81,6 +101,7 @@ public class RefreshPreKeysJob extends BaseJob implements InjectableType {
.getJobManager() .getJobManager()
.add(new CleanPreKeysJob()); .add(new CleanPreKeysJob());
} }
*/
@Override @Override
public boolean onShouldRetry(Exception exception) { public boolean onShouldRetry(Exception exception) {

View File

@ -50,9 +50,7 @@ class LokiPreKeyBundleDatabase(context: Context, helper: SQLCipherOpenHelper) :
* @return PreKeyBundle? A pre key bundle or `null` if something went wrong. * @return PreKeyBundle? A pre key bundle or `null` if something went wrong.
*/ */
fun generatePreKeyBundle(pubKey: String): PreKeyBundle? { fun generatePreKeyBundle(pubKey: String): PreKeyBundle? {
// TODO: Check if we have pre keys
val identityKeyPair = IdentityKeyUtil.getIdentityKeyPair(context) val identityKeyPair = IdentityKeyUtil.getIdentityKeyPair(context)
val signedPreKey = PreKeyUtil.getActiveSignedPreKey(context) ?: return null val signedPreKey = PreKeyUtil.getActiveSignedPreKey(context) ?: return null
val preKeyRecord = DatabaseFactory.getLokiContactPreKeyDatabase(context).getOrCreatePreKey(pubKey) val preKeyRecord = DatabaseFactory.getLokiContactPreKeyDatabase(context).getOrCreatePreKey(pubKey)