mirror of
https://github.com/oxen-io/session-android.git
synced 2025-12-07 20:54:00 +00:00
Refactor group database model and flow.
1) Use existing DB types instead of adding new columns. 2) Store group attributes in message body, like everything else.
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
package org.thoughtcrime.securesms.mms;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import org.thoughtcrime.securesms.database.ThreadDatabase;
|
||||
import org.thoughtcrime.securesms.recipients.Recipients;
|
||||
import org.whispersystems.textsecure.util.Base64;
|
||||
|
||||
import ws.com.google.android.mms.ContentType;
|
||||
import ws.com.google.android.mms.pdu.PduBody;
|
||||
import ws.com.google.android.mms.pdu.PduPart;
|
||||
|
||||
import static org.whispersystems.textsecure.push.PushMessageProtos.PushMessageContent.GroupContext;
|
||||
|
||||
public class OutgoingGroupMediaMessage extends OutgoingSecureMediaMessage {
|
||||
|
||||
private final GroupContext group;
|
||||
|
||||
public OutgoingGroupMediaMessage(Context context, Recipients recipients,
|
||||
GroupContext group, byte[] avatar)
|
||||
{
|
||||
super(context, recipients, new PduBody(), Base64.encodeBytes(group.toByteArray()),
|
||||
ThreadDatabase.DistributionTypes.CONVERSATION);
|
||||
|
||||
this.group = group;
|
||||
|
||||
PduPart part = new PduPart();
|
||||
part.setData(avatar);
|
||||
part.setContentType(ContentType.IMAGE_PNG.getBytes());
|
||||
part.setContentId((System.currentTimeMillis()+"").getBytes());
|
||||
part.setName(("Image" + System.currentTimeMillis()).getBytes());
|
||||
body.addPart(part);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isGroup() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean isGroupAdd() {
|
||||
return
|
||||
group.getType().getNumber() == GroupContext.Type.ADD_VALUE ||
|
||||
group.getType().getNumber() == GroupContext.Type.CREATE_VALUE;
|
||||
}
|
||||
|
||||
public boolean isGroupQuit() {
|
||||
return group.getType().getNumber() == GroupContext.Type.QUIT_VALUE;
|
||||
}
|
||||
|
||||
public boolean isGroupModify() {
|
||||
return group.getType().getNumber() == GroupContext.Type.MODIFY_VALUE;
|
||||
}
|
||||
}
|
||||
60
src/org/thoughtcrime/securesms/mms/OutgoingMediaMessage.java
Normal file
60
src/org/thoughtcrime/securesms/mms/OutgoingMediaMessage.java
Normal file
@@ -0,0 +1,60 @@
|
||||
package org.thoughtcrime.securesms.mms;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import org.thoughtcrime.securesms.recipients.Recipients;
|
||||
import org.whispersystems.textsecure.util.Util;
|
||||
|
||||
import ws.com.google.android.mms.pdu.PduBody;
|
||||
|
||||
public class OutgoingMediaMessage {
|
||||
|
||||
private final Recipients recipients;
|
||||
protected final PduBody body;
|
||||
private final int distributionType;
|
||||
|
||||
public OutgoingMediaMessage(Context context, Recipients recipients, PduBody body,
|
||||
String message, int distributionType)
|
||||
{
|
||||
this.recipients = recipients;
|
||||
this.body = body;
|
||||
this.distributionType = distributionType;
|
||||
|
||||
if (!Util.isEmpty(message)) {
|
||||
this.body.addPart(new TextSlide(context, message).getPart());
|
||||
}
|
||||
}
|
||||
|
||||
public OutgoingMediaMessage(Context context, Recipients recipients, SlideDeck slideDeck,
|
||||
String message, int distributionType)
|
||||
{
|
||||
this(context, recipients, slideDeck.toPduBody(), message, distributionType);
|
||||
}
|
||||
|
||||
public OutgoingMediaMessage(OutgoingMediaMessage that) {
|
||||
this.recipients = that.getRecipients();
|
||||
this.body = that.body;
|
||||
this.distributionType = that.distributionType;
|
||||
}
|
||||
|
||||
public Recipients getRecipients() {
|
||||
return recipients;
|
||||
}
|
||||
|
||||
public PduBody getPduBody() {
|
||||
return body;
|
||||
}
|
||||
|
||||
public int getDistributionType() {
|
||||
return distributionType;
|
||||
}
|
||||
|
||||
public boolean isSecure() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isGroup() {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package org.thoughtcrime.securesms.mms;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import org.thoughtcrime.securesms.recipients.Recipients;
|
||||
|
||||
import ws.com.google.android.mms.pdu.PduBody;
|
||||
|
||||
public class OutgoingSecureMediaMessage extends OutgoingMediaMessage {
|
||||
|
||||
public OutgoingSecureMediaMessage(Context context, Recipients recipients, PduBody body,
|
||||
String message, int distributionType)
|
||||
{
|
||||
super(context, recipients, body, message, distributionType);
|
||||
}
|
||||
|
||||
public OutgoingSecureMediaMessage(OutgoingMediaMessage base) {
|
||||
super(base);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSecure() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user