group updates do things

// FREEBIE
This commit is contained in:
Jake McGinty 2014-02-23 21:18:08 -08:00
parent 0ae1004142
commit 86b3de2a93
6 changed files with 67 additions and 10 deletions

View File

@ -103,7 +103,6 @@ import org.whispersystems.textsecure.crypto.MasterCipher;
import org.whispersystems.textsecure.crypto.MasterSecret;
import org.whispersystems.textsecure.directory.Directory;
import org.whispersystems.textsecure.directory.NotInDirectoryException;
import org.whispersystems.textsecure.push.PushMessageProtos;
import org.whispersystems.textsecure.storage.RecipientDevice;
import org.whispersystems.textsecure.storage.Session;
import org.whispersystems.textsecure.storage.SessionRecordV2;
@ -226,7 +225,7 @@ public class ConversationActivity extends PassphraseRequiredSherlockFragmentActi
@Override
public void onActivityResult(int reqCode, int resultCode, Intent data) {
Log.w("ComposeMessageActivity", "onActivityResult called: " + resultCode + " , " + data);
Log.w(TAG, "onActivityResult called: " + reqCode + ", " + resultCode + " , " + data);
super.onActivityResult(reqCode, resultCode, data);
if (data == null || resultCode != RESULT_OK) return;
@ -249,7 +248,7 @@ public class ConversationActivity extends PassphraseRequiredSherlockFragmentActi
addContactInfo(data.getData());
break;
case GROUP_EDIT:
this.recipients = RecipientFactory.getRecipientsForIds(this, String.valueOf(getRecipients().getPrimaryRecipient().getRecipientId()), false);
this.recipients = data.getParcelableExtra(GroupCreateActivity.GROUP_RECIPIENT_EXTRA);
initializeTitleBar();
break;
}
@ -947,7 +946,7 @@ public class ConversationActivity extends PassphraseRequiredSherlockFragmentActi
byte[] groupId = GroupUtil.getDecodedId(getRecipients().getPrimaryRecipient().getNumber());
GroupRecord record = DatabaseFactory.getGroupDatabase(this).getGroup(groupId);
return record.isActive();
return record != null && record.isActive();
} catch (IOException e) {
Log.w("ConversationActivity", e);
return false;

View File

@ -37,7 +37,6 @@ import org.thoughtcrime.securesms.database.ThreadDatabase;
import org.thoughtcrime.securesms.recipients.Recipient;
import org.thoughtcrime.securesms.recipients.RecipientFactory;
import org.thoughtcrime.securesms.recipients.RecipientFormattingException;
import org.thoughtcrime.securesms.recipients.RecipientProvider;
import org.thoughtcrime.securesms.recipients.Recipients;
import org.thoughtcrime.securesms.sms.MessageSender;
import org.thoughtcrime.securesms.mms.OutgoingGroupMediaMessage;
@ -583,6 +582,26 @@ public class GroupCreateActivity extends PassphraseRequiredSherlockFragmentActiv
return new Pair<Long,Recipients>(RES_BAD_NUMBER, null);
}
}
@Override
protected void onPostExecute(Pair<Long, Recipients> groupInfo) {
final long threadId = groupInfo.first;
final Recipients recipients = groupInfo.second;
if (threadId > -1) {
Intent intent = getIntent();
intent.putExtra(GROUP_THREAD_EXTRA, threadId);
intent.putExtra(GROUP_RECIPIENT_EXTRA, recipients);
setResult(RESULT_OK, intent);
finish();
} else if (threadId == RES_BAD_NUMBER) {
Toast.makeText(getApplicationContext(), R.string.GroupCreateActivity_contacts_invalid_number, Toast.LENGTH_LONG).show();
disableWhisperGroupCreatingUi();
} else if (threadId == RES_MMS_EXCEPTION) {
Toast.makeText(getApplicationContext(), R.string.GroupCreateActivity_contacts_mms_exception, Toast.LENGTH_LONG).show();
setResult(RESULT_CANCELED);
finish();
}
}
}
private class CreateWhisperGroupAsyncTask extends AsyncTask<Void,Void,Pair<Long,Recipients>> {

View File

@ -7,6 +7,7 @@ import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.util.Log;
import org.thoughtcrime.securesms.recipients.Recipient;
@ -27,6 +28,7 @@ import java.util.List;
import static org.whispersystems.textsecure.push.PushMessageProtos.PushMessageContent.AttachmentPointer;
public class GroupDatabase extends Database {
private static final String TAG = GroupDatabase.class.getSimpleName();
private static final String TABLE_NAME = "groups";
private static final String ID = "_id";
@ -128,7 +130,7 @@ public class GroupDatabase extends Database {
public void update(byte[] groupId, String title, AttachmentPointer avatar) {
ContentValues contentValues = new ContentValues();
if (title != null) contentValues.put(TITLE, title);
if (title != null) contentValues.put(TITLE, title);
if (avatar != null) {
contentValues.put(AVATAR_ID, avatar.getId());
@ -139,6 +141,8 @@ public class GroupDatabase extends Database {
databaseHelper.getWritableDatabase().update(TABLE_NAME, contentValues,
GROUP_ID + " = ?",
new String[] {GroupUtil.getEncodedId(groupId)});
if (title != null) updateGroupRecipientTitle(groupId, title);
}
public void updateTitle(byte[] groupId, String title) {
@ -146,13 +150,21 @@ public class GroupDatabase extends Database {
contentValues.put(TITLE, title);
databaseHelper.getWritableDatabase().update(TABLE_NAME, contentValues, GROUP_ID + " = ?",
new String[] {GroupUtil.getEncodedId(groupId)});
if (title != null) updateGroupRecipientTitle(groupId, title);
}
public void updateAvatar(byte[] groupId, Bitmap avatar) {
updateAvatar(groupId, BitmapUtil.toByteArray(avatar));
updateAvatarInDatabase(groupId, BitmapUtil.toByteArray(avatar));
updateGroupRecipientAvatar(groupId, avatar);
}
public void updateAvatar(byte[] groupId, byte[] avatar) {
updateAvatarInDatabase(groupId, avatar);
updateGroupRecipientAvatar(groupId, BitmapFactory.decodeByteArray(avatar, 0, avatar.length));
}
private void updateAvatarInDatabase(byte[] groupId, byte[] avatar) {
ContentValues contentValues = new ContentValues();
contentValues.put(AVATAR, avatar);
@ -330,4 +342,28 @@ public class GroupDatabase extends Database {
return active;
}
}
private Recipient getGroupRecipient(byte[] groupId) {
try {
return RecipientFactory.getRecipientsFromString(context, GroupUtil.getEncodedId(groupId), true)
.getPrimaryRecipient();
} catch (RecipientFormattingException e) {
Log.w(TAG, e);
return null;
}
}
private void updateGroupRecipientTitle(byte[] groupId, String title) {
Recipient groupRecipient = getGroupRecipient(groupId);
Log.i(TAG, "updating group recipient title for recipient " + System.identityHashCode(groupRecipient));
if (groupRecipient != null) groupRecipient.setName(title);
else Log.w(TAG, "Couldn't update group title because recipient couldn't be found.");
}
private void updateGroupRecipientAvatar(byte[] groupId, Bitmap photo) {
Recipient groupRecipient = getGroupRecipient(groupId);
if (groupRecipient != null) groupRecipient.setContactPhoto(photo);
else Log.w(TAG, "Couldn't update group title because recipient couldn't be found.");
}
}

View File

@ -110,6 +110,12 @@ public class Recipient implements Parcelable, CanonicalRecipient {
public synchronized void setContactPhoto(Bitmap bitmap) {
this.contactPhoto = bitmap;
notifyListeners();
}
public synchronized void setName(String name) {
this.name = name;
notifyListeners();
}
public synchronized String getName() {
@ -203,5 +209,4 @@ public class Recipient implements Parcelable, CanonicalRecipient {
public static interface RecipientModifiedListener {
public void onModified(Recipient recipient);
}
}

View File

@ -21,7 +21,6 @@ import android.util.Log;
import org.thoughtcrime.securesms.contacts.ContactPhotoFactory;
import org.thoughtcrime.securesms.database.CanonicalAddressDatabase;
import org.thoughtcrime.securesms.database.DatabaseFactory;
import org.thoughtcrime.securesms.util.NumberUtil;
import org.whispersystems.textsecure.push.IncomingPushMessage;
import org.whispersystems.textsecure.util.Util;

View File

@ -61,7 +61,6 @@ public class AvatarDownloader {
Recipient groupRecipient = RecipientFactory.getRecipientsFromString(context, GroupUtil.getEncodedId(groupId), true)
.getPrimaryRecipient();
groupRecipient.setContactPhoto(avatar);
groupRecipient.notifyListeners();
} catch (RecipientFormattingException e) {
Log.w("AvatarDownloader", e);
}