Skip to content

Commit

Permalink
Merge pull request #230 from jlewis13/null_address_fix
Browse files Browse the repository at this point in the history
Null address fix
  • Loading branch information
jlewis13 authored Nov 27, 2017
2 parents 33380d3 + 9962aea commit 726e32d
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 18 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ android {
applicationId 'io.forsta.relay'
minSdkVersion 14
targetSdkVersion 22
versionName "0.1.73"
versionCode 173
versionName "0.1.76"
versionCode 176
multiDexEnabled true
buildConfigField "long", "BUILD_TIMESTAMP", getLastCommitTimestamp() + "L"
resValue "string", "forsta_authorities", applicationId + '.provider.ccsm'
Expand Down
18 changes: 12 additions & 6 deletions src/io/forsta/ccsm/database/ContactDb.java
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,6 @@ public Set<String> getAddresses() {
try {
Cursor c = getRecords(TABLE_NAME, allColumns, null, null, UID);
while (c.moveToNext()) {
String address = c.getString(c.getColumnIndex(UID));
String name = c.getString(c.getColumnIndex(NAME));
String number = c.getString(c.getColumnIndex(NUMBER));
addresses.add(c.getString(c.getColumnIndex(UID)));
}
c.close();
Expand Down Expand Up @@ -242,10 +239,19 @@ public void updateUsers(List<ForstaUser> users, boolean removeExisting) {
values.put(ContactDb.EMAIL, user.email);
values.put(ContactDb.TSREGISTERED, user.tsRegistered);
if (uids.containsKey(user.uid)) {
String id = uids.get(user.uid);
db.update(TABLE_NAME, values, ID + "=?", new String[] { id });
String id = uids.get(user.getUid());
if (TextUtils.isEmpty(user.getUid())) {
Log.w(TAG, "Existing user with empty UID!: " + user.slug);
db.delete(TABLE_NAME, ID + " = ?", new String[] { id });
} else {
db.update(TABLE_NAME, values, ID + " = ?", new String[] { id });
}
} else {
db.insert(TABLE_NAME, null, values);
if (TextUtils.isEmpty(user.getUid())) {
Log.w(TAG, "New user with empty UID!: " + user.slug);
} else {
db.insert(TABLE_NAME, null, values);
}
}
uids.remove(user.uid);
}
Expand Down
11 changes: 11 additions & 0 deletions src/io/forsta/securesms/ContactSelectionListFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package io.forsta.securesms;


import android.content.DialogInterface;
import android.database.Cursor;
import android.graphics.Canvas;
import android.graphics.Rect;
Expand All @@ -29,6 +30,7 @@
import android.support.v4.content.Loader;
import android.support.v4.view.ViewCompat;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.AlertDialog;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
Expand Down Expand Up @@ -139,6 +141,7 @@ private void initializeCursor() {
ContactSelectionListAdapter adapter = new ContactSelectionListAdapter(getActivity(),
null,
new ListClickListener(),
new ListLongClickListener(),
isMulti());
selectedContacts = adapter.getSelectedContacts();
selectedAddresses = adapter.getSelectedAddresses();
Expand Down Expand Up @@ -203,6 +206,14 @@ public void onLoaderReset(Loader<Cursor> loader) {
fastScroller.setVisibility(View.GONE);
}

private class ListLongClickListener implements ContactSelectionListAdapter.ItemLongClickListener {

@Override
public void onItemLongClick(ContactSelectionListItem item) {
// TODO Show recipient details in Activity or dialog. Allow delete?
}
}

private class ListClickListener implements ContactSelectionListAdapter.ItemClickListener {
@Override
public void onItemClick(ContactSelectionListItem contact) {
Expand Down
21 changes: 18 additions & 3 deletions src/io/forsta/securesms/contacts/ContactSelectionListAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,19 +65,28 @@ public class ContactSelectionListAdapter extends CursorRecyclerViewAdapter<ViewH
private final LayoutInflater li;
private final TypedArray drawables;
private final ItemClickListener clickListener;
private final ItemLongClickListener longClickListener;

private final HashMap<Long, String> selectedContacts = new HashMap<>();
private final Set<String> selectedAddresses = new HashSet();

public static class ViewHolder extends RecyclerView.ViewHolder {
public ViewHolder(@NonNull final View itemView,
@Nullable final ItemClickListener clickListener)
@Nullable final ItemClickListener itemClickListener,
@Nullable final ItemLongClickListener itemLongClickListener)
{
super(itemView);
itemView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (clickListener != null) clickListener.onItemClick(getView());
if (itemClickListener != null) itemClickListener.onItemClick(getView());
}
});
itemView.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View view) {
if (itemLongClickListener != null) itemLongClickListener.onItemLongClick(getView());
return true;
}
});
}
Expand All @@ -96,13 +105,15 @@ public HeaderViewHolder(View itemView) {
public ContactSelectionListAdapter(@NonNull Context context,
@Nullable Cursor cursor,
@Nullable ItemClickListener clickListener,
@Nullable ItemLongClickListener longClickListener,
boolean multiSelect)
{
super(context, cursor);
this.li = LayoutInflater.from(context);
this.drawables = context.obtainStyledAttributes(STYLE_ATTRIBUTES);
this.multiSelect = multiSelect;
this.clickListener = clickListener;
this.longClickListener = longClickListener;
}

@Override
Expand All @@ -112,7 +123,7 @@ public long getHeaderId(int i) {

@Override
public ViewHolder onCreateItemViewHolder(ViewGroup parent, int viewType) {
return new ViewHolder(li.inflate(R.layout.contact_selection_list_item, parent, false), clickListener);
return new ViewHolder(li.inflate(R.layout.contact_selection_list_item, parent, false), clickListener, longClickListener);
}

@Override
Expand Down Expand Up @@ -196,4 +207,8 @@ private boolean isPush(int position) {
public interface ItemClickListener {
void onItemClick(ContactSelectionListItem item);
}

public interface ItemLongClickListener {
void onItemLongClick(ContactSelectionListItem item);
}
}
19 changes: 12 additions & 7 deletions src/io/forsta/securesms/util/DirectoryHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,11 @@ public static void refreshDirectory(@NonNull Context context, @Nullable MasterSe
TextSecureCommunicationFactory.createManager(context),
TextSecurePreferences.getLocalNumber(context));

if (!newUsers.isEmpty() && TextSecurePreferences.isMultiDevice(context)) {
ApplicationContext.getInstance(context)
.getJobManager()
.add(new MultiDeviceContactUpdateJob(context));
}
// if (!newUsers.isEmpty() && TextSecurePreferences.isMultiDevice(context)) {
// ApplicationContext.getInstance(context)
// .getJobManager()
// .add(new MultiDeviceContactUpdateJob(context));
// }

// notifyNewUsers(context, masterSecret, newUsers);
context.sendBroadcast(new Intent(ForstaSyncAdapter.FORSTA_SYNC_COMPLETE));
Expand All @@ -108,7 +108,13 @@ public static void refreshDirectory(@NonNull Context context, @Nullable MasterSe
{
ContactDb contactsDb = DbFactory.getContactDb(context);
Set<String> eligibleContactAddresses = contactsDb.getAddresses();
eligibleContactAddresses.add(TextUtils.isEmpty(localNumber) ? TextSecurePreferences.getLocalNumber(context) : localNumber);
// Two devices had crashes because of a null UID value in the contactsDb
if (eligibleContactAddresses.contains(null)) {
Log.e(TAG, "Null number in contactsDb!");
eligibleContactAddresses.remove(null);
}

eligibleContactAddresses.add(localNumber);
eligibleContactAddresses.add(BuildConfig.FORSTA_SYNC_NUMBER);

TextSecureDirectory directory = TextSecureDirectory.getInstance(context);
Expand All @@ -123,7 +129,6 @@ public static void refreshDirectory(@NonNull Context context, @Nullable MasterSe
directory.setNumbers(activeTokens, eligibleContactAddresses);
// Update the forsta contacts db to set active users.
contactsDb.setActiveForstaAddresses(activeTokens, eligibleContactAddresses);
contactsDb.close();
}

return new LinkedList<>();
Expand Down

0 comments on commit 726e32d

Please sign in to comment.