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.pull/1/head
parent
0cdc6fd87d
commit
9614dc9055
@ -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;
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
package org.thoughtcrime.securesms.sms;
|
||||
|
||||
import com.google.protobuf.ByteString;
|
||||
|
||||
import org.thoughtcrime.securesms.util.GroupUtil;
|
||||
import org.whispersystems.textsecure.push.PushMessageProtos;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.whispersystems.textsecure.push.PushMessageProtos.PushMessageContent.GroupContext;
|
||||
|
||||
public class IncomingGroupMessage extends IncomingTextMessage {
|
||||
|
||||
private final GroupContext groupContext;
|
||||
|
||||
public IncomingGroupMessage(IncomingTextMessage base, GroupContext groupContext, String body) {
|
||||
super(base, body);
|
||||
this.groupContext = groupContext;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IncomingGroupMessage withMessageBody(String body) {
|
||||
return new IncomingGroupMessage(this, groupContext, body);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isGroup() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean isAdd() {
|
||||
return
|
||||
groupContext.getType().getNumber() == GroupContext.Type.ADD_VALUE ||
|
||||
groupContext.getType().getNumber() == GroupContext.Type.CREATE_VALUE;
|
||||
}
|
||||
|
||||
public boolean isQuit() {
|
||||
return groupContext.getType().getNumber() == GroupContext.Type.QUIT_VALUE;
|
||||
}
|
||||
|
||||
public boolean isModify() {
|
||||
return groupContext.getType().getNumber() == GroupContext.Type.MODIFY_VALUE;
|
||||
}
|
||||
|
||||
public static IncomingGroupMessage createForQuit(String groupId, String user) throws IOException {
|
||||
IncomingTextMessage base = new IncomingTextMessage(user, groupId);
|
||||
GroupContext context = GroupContext.newBuilder()
|
||||
.setType(GroupContext.Type.QUIT)
|
||||
.setId(ByteString.copyFrom(GroupUtil.getDecodedId(groupId)))
|
||||
.build();
|
||||
|
||||
return new IncomingGroupMessage(base, context, "");
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue