-
-
Notifications
You must be signed in to change notification settings - Fork 6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
directory changes to use number instead of token, group ui progress
- Loading branch information
Showing
21 changed files
with
583 additions
and
318 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
library/src/org/whispersystems/textsecure/push/ContactDetails.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package org.whispersystems.textsecure.push; | ||
|
||
import com.google.thoughtcrimegson.Gson; | ||
|
||
public abstract class ContactDetails { | ||
|
||
private String relay; | ||
private boolean supportsSms; | ||
|
||
public ContactDetails() {} | ||
|
||
public ContactDetails(String relay) { | ||
this.relay = relay; | ||
} | ||
|
||
public String getRelay() { | ||
return relay; | ||
} | ||
|
||
public void setRelay(String relay) { | ||
this.relay = relay; | ||
} | ||
|
||
public boolean isSupportsSms() { | ||
return supportsSms; | ||
} | ||
|
||
public String toString() { | ||
return new Gson().toJson(this); | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
library/src/org/whispersystems/textsecure/push/ContactNumberDetails.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package org.whispersystems.textsecure.push; | ||
|
||
import android.util.Log; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class ContactNumberDetails extends ContactDetails { | ||
private static final String TAG = "ContactNumberDetails"; | ||
|
||
private String number; | ||
|
||
public ContactNumberDetails() { super(); } | ||
|
||
public ContactNumberDetails(String number) { | ||
super(); | ||
this.number = number; | ||
} | ||
|
||
public ContactNumberDetails(String number, String relay) { | ||
super(relay); | ||
this.number = number; | ||
} | ||
|
||
public String getNumber() { | ||
return number; | ||
} | ||
|
||
public static List<ContactNumberDetails> fromContactTokenDetailsList(List<ContactTokenDetails> contactTokenDetails, final Map<String, String> tokenMap) { | ||
if (contactTokenDetails == null || tokenMap == null) return null; | ||
|
||
List<ContactNumberDetails> contactNumberDetails = new ArrayList<ContactNumberDetails>(contactTokenDetails.size()); | ||
for (ContactTokenDetails tokenDetails : contactTokenDetails) { | ||
if (tokenMap.containsKey(tokenDetails.getToken())) | ||
contactNumberDetails.add(new ContactNumberDetails(tokenMap.get(tokenDetails.getToken()), tokenDetails.getRelay())); | ||
else | ||
Log.w(TAG, "tokenMap was missing a contact."); | ||
} | ||
return contactNumberDetails; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
library/src/org/whispersystems/textsecure/util/DirectoryUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package org.whispersystems.textsecure.util; | ||
|
||
import java.security.MessageDigest; | ||
import java.security.NoSuchAlgorithmException; | ||
import java.util.Collection; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class DirectoryUtil { | ||
|
||
public static String getDirectoryServerToken(String e164number) { | ||
try { | ||
MessageDigest digest = MessageDigest.getInstance("SHA1"); | ||
byte[] token = Util.trim(digest.digest(e164number.getBytes()), 10); | ||
return Base64.encodeBytesWithoutPadding(token); | ||
} catch (NoSuchAlgorithmException e) { | ||
throw new AssertionError(e); | ||
} | ||
} | ||
|
||
/** | ||
* Get a mapping of directory server tokens to their requested number. | ||
* @param e164numbers | ||
* @return map with token as key, E164 number as value | ||
*/ | ||
public static Map<String, String> getDirectoryServerTokenMap(Collection<String> e164numbers) { | ||
final Map<String,String> tokenMap = new HashMap<String,String>(e164numbers.size()); | ||
for (String number : e164numbers) { | ||
tokenMap.put(getDirectoryServerToken(number), number); | ||
} | ||
return tokenMap; | ||
} | ||
} |
Oops, something went wrong.
In migration code, you can't reference "existing" code. The migration needs to be a duplicate/snapshot of what exists now, because the code itself might change in the future.