mirror of
https://github.com/oxen-io/session-android.git
synced 2025-02-25 12:17:19 +00:00
group updates do things
// FREEBIE
This commit is contained in:
parent
0ae1004142
commit
86b3de2a93
@ -103,7 +103,6 @@ import org.whispersystems.textsecure.crypto.MasterCipher;
|
|||||||
import org.whispersystems.textsecure.crypto.MasterSecret;
|
import org.whispersystems.textsecure.crypto.MasterSecret;
|
||||||
import org.whispersystems.textsecure.directory.Directory;
|
import org.whispersystems.textsecure.directory.Directory;
|
||||||
import org.whispersystems.textsecure.directory.NotInDirectoryException;
|
import org.whispersystems.textsecure.directory.NotInDirectoryException;
|
||||||
import org.whispersystems.textsecure.push.PushMessageProtos;
|
|
||||||
import org.whispersystems.textsecure.storage.RecipientDevice;
|
import org.whispersystems.textsecure.storage.RecipientDevice;
|
||||||
import org.whispersystems.textsecure.storage.Session;
|
import org.whispersystems.textsecure.storage.Session;
|
||||||
import org.whispersystems.textsecure.storage.SessionRecordV2;
|
import org.whispersystems.textsecure.storage.SessionRecordV2;
|
||||||
@ -226,7 +225,7 @@ public class ConversationActivity extends PassphraseRequiredSherlockFragmentActi
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onActivityResult(int reqCode, int resultCode, Intent data) {
|
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);
|
super.onActivityResult(reqCode, resultCode, data);
|
||||||
|
|
||||||
if (data == null || resultCode != RESULT_OK) return;
|
if (data == null || resultCode != RESULT_OK) return;
|
||||||
@ -249,7 +248,7 @@ public class ConversationActivity extends PassphraseRequiredSherlockFragmentActi
|
|||||||
addContactInfo(data.getData());
|
addContactInfo(data.getData());
|
||||||
break;
|
break;
|
||||||
case GROUP_EDIT:
|
case GROUP_EDIT:
|
||||||
this.recipients = RecipientFactory.getRecipientsForIds(this, String.valueOf(getRecipients().getPrimaryRecipient().getRecipientId()), false);
|
this.recipients = data.getParcelableExtra(GroupCreateActivity.GROUP_RECIPIENT_EXTRA);
|
||||||
initializeTitleBar();
|
initializeTitleBar();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -947,7 +946,7 @@ public class ConversationActivity extends PassphraseRequiredSherlockFragmentActi
|
|||||||
byte[] groupId = GroupUtil.getDecodedId(getRecipients().getPrimaryRecipient().getNumber());
|
byte[] groupId = GroupUtil.getDecodedId(getRecipients().getPrimaryRecipient().getNumber());
|
||||||
GroupRecord record = DatabaseFactory.getGroupDatabase(this).getGroup(groupId);
|
GroupRecord record = DatabaseFactory.getGroupDatabase(this).getGroup(groupId);
|
||||||
|
|
||||||
return record.isActive();
|
return record != null && record.isActive();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Log.w("ConversationActivity", e);
|
Log.w("ConversationActivity", e);
|
||||||
return false;
|
return false;
|
||||||
|
@ -37,7 +37,6 @@ import org.thoughtcrime.securesms.database.ThreadDatabase;
|
|||||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||||
import org.thoughtcrime.securesms.recipients.RecipientFactory;
|
import org.thoughtcrime.securesms.recipients.RecipientFactory;
|
||||||
import org.thoughtcrime.securesms.recipients.RecipientFormattingException;
|
import org.thoughtcrime.securesms.recipients.RecipientFormattingException;
|
||||||
import org.thoughtcrime.securesms.recipients.RecipientProvider;
|
|
||||||
import org.thoughtcrime.securesms.recipients.Recipients;
|
import org.thoughtcrime.securesms.recipients.Recipients;
|
||||||
import org.thoughtcrime.securesms.sms.MessageSender;
|
import org.thoughtcrime.securesms.sms.MessageSender;
|
||||||
import org.thoughtcrime.securesms.mms.OutgoingGroupMediaMessage;
|
import org.thoughtcrime.securesms.mms.OutgoingGroupMediaMessage;
|
||||||
@ -583,6 +582,26 @@ public class GroupCreateActivity extends PassphraseRequiredSherlockFragmentActiv
|
|||||||
return new Pair<Long,Recipients>(RES_BAD_NUMBER, null);
|
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>> {
|
private class CreateWhisperGroupAsyncTask extends AsyncTask<Void,Void,Pair<Long,Recipients>> {
|
||||||
|
@ -7,6 +7,7 @@ import android.database.Cursor;
|
|||||||
import android.database.sqlite.SQLiteDatabase;
|
import android.database.sqlite.SQLiteDatabase;
|
||||||
import android.database.sqlite.SQLiteOpenHelper;
|
import android.database.sqlite.SQLiteOpenHelper;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
|
import android.graphics.BitmapFactory;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||||
@ -27,6 +28,7 @@ import java.util.List;
|
|||||||
import static org.whispersystems.textsecure.push.PushMessageProtos.PushMessageContent.AttachmentPointer;
|
import static org.whispersystems.textsecure.push.PushMessageProtos.PushMessageContent.AttachmentPointer;
|
||||||
|
|
||||||
public class GroupDatabase extends Database {
|
public class GroupDatabase extends Database {
|
||||||
|
private static final String TAG = GroupDatabase.class.getSimpleName();
|
||||||
|
|
||||||
private static final String TABLE_NAME = "groups";
|
private static final String TABLE_NAME = "groups";
|
||||||
private static final String ID = "_id";
|
private static final String ID = "_id";
|
||||||
@ -139,6 +141,8 @@ public class GroupDatabase extends Database {
|
|||||||
databaseHelper.getWritableDatabase().update(TABLE_NAME, contentValues,
|
databaseHelper.getWritableDatabase().update(TABLE_NAME, contentValues,
|
||||||
GROUP_ID + " = ?",
|
GROUP_ID + " = ?",
|
||||||
new String[] {GroupUtil.getEncodedId(groupId)});
|
new String[] {GroupUtil.getEncodedId(groupId)});
|
||||||
|
|
||||||
|
if (title != null) updateGroupRecipientTitle(groupId, title);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateTitle(byte[] groupId, String title) {
|
public void updateTitle(byte[] groupId, String title) {
|
||||||
@ -146,13 +150,21 @@ public class GroupDatabase extends Database {
|
|||||||
contentValues.put(TITLE, title);
|
contentValues.put(TITLE, title);
|
||||||
databaseHelper.getWritableDatabase().update(TABLE_NAME, contentValues, GROUP_ID + " = ?",
|
databaseHelper.getWritableDatabase().update(TABLE_NAME, contentValues, GROUP_ID + " = ?",
|
||||||
new String[] {GroupUtil.getEncodedId(groupId)});
|
new String[] {GroupUtil.getEncodedId(groupId)});
|
||||||
|
|
||||||
|
if (title != null) updateGroupRecipientTitle(groupId, title);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateAvatar(byte[] groupId, Bitmap avatar) {
|
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) {
|
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 contentValues = new ContentValues();
|
||||||
contentValues.put(AVATAR, avatar);
|
contentValues.put(AVATAR, avatar);
|
||||||
|
|
||||||
@ -330,4 +342,28 @@ public class GroupDatabase extends Database {
|
|||||||
return active;
|
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.");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -110,6 +110,12 @@ public class Recipient implements Parcelable, CanonicalRecipient {
|
|||||||
|
|
||||||
public synchronized void setContactPhoto(Bitmap bitmap) {
|
public synchronized void setContactPhoto(Bitmap bitmap) {
|
||||||
this.contactPhoto = bitmap;
|
this.contactPhoto = bitmap;
|
||||||
|
notifyListeners();
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized String getName() {
|
public synchronized String getName() {
|
||||||
@ -203,5 +209,4 @@ public class Recipient implements Parcelable, CanonicalRecipient {
|
|||||||
public static interface RecipientModifiedListener {
|
public static interface RecipientModifiedListener {
|
||||||
public void onModified(Recipient recipient);
|
public void onModified(Recipient recipient);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,6 @@ import android.util.Log;
|
|||||||
|
|
||||||
import org.thoughtcrime.securesms.contacts.ContactPhotoFactory;
|
import org.thoughtcrime.securesms.contacts.ContactPhotoFactory;
|
||||||
import org.thoughtcrime.securesms.database.CanonicalAddressDatabase;
|
import org.thoughtcrime.securesms.database.CanonicalAddressDatabase;
|
||||||
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
|
||||||
import org.thoughtcrime.securesms.util.NumberUtil;
|
import org.thoughtcrime.securesms.util.NumberUtil;
|
||||||
import org.whispersystems.textsecure.push.IncomingPushMessage;
|
import org.whispersystems.textsecure.push.IncomingPushMessage;
|
||||||
import org.whispersystems.textsecure.util.Util;
|
import org.whispersystems.textsecure.util.Util;
|
||||||
|
@ -61,7 +61,6 @@ public class AvatarDownloader {
|
|||||||
Recipient groupRecipient = RecipientFactory.getRecipientsFromString(context, GroupUtil.getEncodedId(groupId), true)
|
Recipient groupRecipient = RecipientFactory.getRecipientsFromString(context, GroupUtil.getEncodedId(groupId), true)
|
||||||
.getPrimaryRecipient();
|
.getPrimaryRecipient();
|
||||||
groupRecipient.setContactPhoto(avatar);
|
groupRecipient.setContactPhoto(avatar);
|
||||||
groupRecipient.notifyListeners();
|
|
||||||
} catch (RecipientFormattingException e) {
|
} catch (RecipientFormattingException e) {
|
||||||
Log.w("AvatarDownloader", e);
|
Log.w("AvatarDownloader", e);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user