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