2014-02-20 05:06:54 +00:00
|
|
|
package org.thoughtcrime.securesms.mms;
|
|
|
|
|
2015-10-13 01:25:05 +00:00
|
|
|
import android.support.annotation.NonNull;
|
|
|
|
import android.support.annotation.Nullable;
|
2014-02-20 05:06:54 +00:00
|
|
|
|
2015-10-13 01:25:05 +00:00
|
|
|
import org.thoughtcrime.securesms.attachments.Attachment;
|
2014-02-20 05:06:54 +00:00
|
|
|
import org.thoughtcrime.securesms.database.ThreadDatabase;
|
2017-08-01 15:56:00 +00:00
|
|
|
import org.thoughtcrime.securesms.recipients.Recipient;
|
2015-10-24 10:58:21 +00:00
|
|
|
import org.thoughtcrime.securesms.util.Base64;
|
2016-03-23 17:34:41 +00:00
|
|
|
import org.whispersystems.signalservice.internal.push.SignalServiceProtos.GroupContext;
|
2014-02-20 05:06:54 +00:00
|
|
|
|
2015-10-13 01:25:05 +00:00
|
|
|
import java.io.IOException;
|
|
|
|
import java.util.LinkedList;
|
|
|
|
import java.util.List;
|
2014-02-20 05:06:54 +00:00
|
|
|
|
|
|
|
public class OutgoingGroupMediaMessage extends OutgoingSecureMediaMessage {
|
|
|
|
|
|
|
|
private final GroupContext group;
|
|
|
|
|
2017-08-01 15:56:00 +00:00
|
|
|
public OutgoingGroupMediaMessage(@NonNull Recipient recipient,
|
2015-10-13 01:25:05 +00:00
|
|
|
@NonNull String encodedGroupContext,
|
|
|
|
@NonNull List<Attachment> avatar,
|
2016-08-16 03:23:56 +00:00
|
|
|
long sentTimeMillis,
|
|
|
|
long expiresIn)
|
2015-10-13 01:25:05 +00:00
|
|
|
throws IOException
|
2014-02-20 05:06:54 +00:00
|
|
|
{
|
2017-08-01 15:56:00 +00:00
|
|
|
super(recipient, encodedGroupContext, avatar, sentTimeMillis,
|
2016-08-16 03:23:56 +00:00
|
|
|
ThreadDatabase.DistributionTypes.CONVERSATION, expiresIn);
|
2014-02-20 05:06:54 +00:00
|
|
|
|
2015-10-13 01:25:05 +00:00
|
|
|
this.group = GroupContext.parseFrom(Base64.decode(encodedGroupContext));
|
|
|
|
}
|
|
|
|
|
2017-08-01 15:56:00 +00:00
|
|
|
public OutgoingGroupMediaMessage(@NonNull Recipient recipient,
|
2015-10-13 01:25:05 +00:00
|
|
|
@NonNull GroupContext group,
|
2015-10-16 00:10:54 +00:00
|
|
|
@Nullable final Attachment avatar,
|
2016-08-16 03:23:56 +00:00
|
|
|
long sentTimeMillis,
|
|
|
|
long expireIn)
|
2015-10-13 01:25:05 +00:00
|
|
|
{
|
2017-08-01 15:56:00 +00:00
|
|
|
super(recipient, Base64.encodeBytes(group.toByteArray()),
|
2015-10-13 01:25:05 +00:00
|
|
|
new LinkedList<Attachment>() {{if (avatar != null) add(avatar);}},
|
|
|
|
System.currentTimeMillis(),
|
2016-08-16 03:23:56 +00:00
|
|
|
ThreadDatabase.DistributionTypes.CONVERSATION, expireIn);
|
2014-02-20 05:06:54 +00:00
|
|
|
|
2015-10-13 01:25:05 +00:00
|
|
|
this.group = group;
|
2014-02-20 05:06:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isGroup() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-02-22 01:51:25 +00:00
|
|
|
public boolean isGroupUpdate() {
|
|
|
|
return group.getType().getNumber() == GroupContext.Type.UPDATE_VALUE;
|
2014-02-20 05:06:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isGroupQuit() {
|
|
|
|
return group.getType().getNumber() == GroupContext.Type.QUIT_VALUE;
|
|
|
|
}
|
2015-10-13 01:25:05 +00:00
|
|
|
|
|
|
|
public GroupContext getGroupContext() {
|
|
|
|
return group;
|
|
|
|
}
|
2014-02-20 05:06:54 +00:00
|
|
|
}
|