2011-12-20 18:20:44 +00:00
|
|
|
/**
|
|
|
|
* Copyright (C) 2011 Whisper Systems
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
package org.thoughtcrime.securesms.mms;
|
|
|
|
|
Major storage layer refactoring to set the stage for clean GCM.
1) We now try to hand out cursors at a minimum. There has always been
a fairly clean insertion layer that handles encrypting message bodies,
but the process of decrypting message bodies has always been less than
ideal. Here we introduce a "Reader" interface that will decrypt message
bodies when appropriate and return objects that encapsulate record state.
No more MessageDisplayHelper. The MmsSmsDatabase interface is also more
sane.
2) We finally rid ourselves of the technical debt associated with TextSecure's
initial usage of the default SMS DB. In that world, we weren't able to use
anything other than the default "Inbox, Outbox, Sent" types to describe a
message, and had to overload the message content itself with a set of
local "prefixes" to describe what it was (encrypted, asymetric encrypted,
remote encrypted, a key exchange, procssed key exchange), and so on.
This includes a major schema update that transforms the "type" field into
a bitmask that describes everything that used to be encoded in a prefix,
and prefixes have been completely eliminated from the system.
No more Prefix.java
3) Refactoring of the MultipartMessageHandler code. It's less of a mess, and
hopefully more clear as to what's going on.
The next step is to remove what we can from SmsTransportDetails and genericize
that interface for a GCM equivalent.
2013-04-20 19:22:04 +00:00
|
|
|
import android.content.Context;
|
2015-12-18 22:37:11 +00:00
|
|
|
import android.support.annotation.NonNull;
|
2015-08-10 16:33:57 +00:00
|
|
|
import android.support.annotation.Nullable;
|
Major storage layer refactoring to set the stage for clean GCM.
1) We now try to hand out cursors at a minimum. There has always been
a fairly clean insertion layer that handles encrypting message bodies,
but the process of decrypting message bodies has always been less than
ideal. Here we introduce a "Reader" interface that will decrypt message
bodies when appropriate and return objects that encapsulate record state.
No more MessageDisplayHelper. The MmsSmsDatabase interface is also more
sane.
2) We finally rid ourselves of the technical debt associated with TextSecure's
initial usage of the default SMS DB. In that world, we weren't able to use
anything other than the default "Inbox, Outbox, Sent" types to describe a
message, and had to overload the message content itself with a set of
local "prefixes" to describe what it was (encrypted, asymetric encrypted,
remote encrypted, a key exchange, procssed key exchange), and so on.
This includes a major schema update that transforms the "type" field into
a bitmask that describes everything that used to be encoded in a prefix,
and prefixes have been completely eliminated from the system.
No more Prefix.java
3) Refactoring of the MultipartMessageHandler code. It's less of a mess, and
hopefully more clear as to what's going on.
The next step is to remove what we can from SmsTransportDetails and genericize
that interface for a GCM equivalent.
2013-04-20 19:22:04 +00:00
|
|
|
|
2018-11-09 07:33:37 +00:00
|
|
|
import com.annimon.stream.Stream;
|
|
|
|
|
2015-10-13 01:25:05 +00:00
|
|
|
import org.thoughtcrime.securesms.attachments.Attachment;
|
2015-01-19 02:11:30 +00:00
|
|
|
import org.thoughtcrime.securesms.util.MediaUtil;
|
2016-03-23 17:34:41 +00:00
|
|
|
import org.whispersystems.libsignal.util.guava.Optional;
|
Major storage layer refactoring to set the stage for clean GCM.
1) We now try to hand out cursors at a minimum. There has always been
a fairly clean insertion layer that handles encrypting message bodies,
but the process of decrypting message bodies has always been less than
ideal. Here we introduce a "Reader" interface that will decrypt message
bodies when appropriate and return objects that encapsulate record state.
No more MessageDisplayHelper. The MmsSmsDatabase interface is also more
sane.
2) We finally rid ourselves of the technical debt associated with TextSecure's
initial usage of the default SMS DB. In that world, we weren't able to use
anything other than the default "Inbox, Outbox, Sent" types to describe a
message, and had to overload the message content itself with a set of
local "prefixes" to describe what it was (encrypted, asymetric encrypted,
remote encrypted, a key exchange, procssed key exchange), and so on.
This includes a major schema update that transforms the "type" field into
a bitmask that describes everything that used to be encoded in a prefix,
and prefixes have been completely eliminated from the system.
No more Prefix.java
3) Refactoring of the MultipartMessageHandler code. It's less of a mess, and
hopefully more clear as to what's going on.
The next step is to remove what we can from SmsTransportDetails and genericize
that interface for a GCM equivalent.
2013-04-20 19:22:04 +00:00
|
|
|
|
2011-12-20 18:20:44 +00:00
|
|
|
import java.util.LinkedList;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
public class SlideDeck {
|
2014-11-08 19:35:58 +00:00
|
|
|
|
|
|
|
private final List<Slide> slides = new LinkedList<>();
|
|
|
|
|
2018-02-07 22:01:37 +00:00
|
|
|
public SlideDeck(@NonNull Context context, @NonNull List<? extends Attachment> attachments) {
|
2015-10-13 01:25:05 +00:00
|
|
|
for (Attachment attachment : attachments) {
|
|
|
|
Slide slide = MediaUtil.getSlideForAttachment(context, attachment);
|
2015-01-19 02:11:30 +00:00
|
|
|
if (slide != null) slides.add(slide);
|
2011-12-20 18:20:44 +00:00
|
|
|
}
|
|
|
|
}
|
Major storage layer refactoring to set the stage for clean GCM.
1) We now try to hand out cursors at a minimum. There has always been
a fairly clean insertion layer that handles encrypting message bodies,
but the process of decrypting message bodies has always been less than
ideal. Here we introduce a "Reader" interface that will decrypt message
bodies when appropriate and return objects that encapsulate record state.
No more MessageDisplayHelper. The MmsSmsDatabase interface is also more
sane.
2) We finally rid ourselves of the technical debt associated with TextSecure's
initial usage of the default SMS DB. In that world, we weren't able to use
anything other than the default "Inbox, Outbox, Sent" types to describe a
message, and had to overload the message content itself with a set of
local "prefixes" to describe what it was (encrypted, asymetric encrypted,
remote encrypted, a key exchange, procssed key exchange), and so on.
This includes a major schema update that transforms the "type" field into
a bitmask that describes everything that used to be encoded in a prefix,
and prefixes have been completely eliminated from the system.
No more Prefix.java
3) Refactoring of the MultipartMessageHandler code. It's less of a mess, and
hopefully more clear as to what's going on.
The next step is to remove what we can from SmsTransportDetails and genericize
that interface for a GCM equivalent.
2013-04-20 19:22:04 +00:00
|
|
|
|
2018-02-07 22:01:37 +00:00
|
|
|
public SlideDeck(@NonNull Context context, @NonNull Attachment attachment) {
|
2015-10-21 22:32:19 +00:00
|
|
|
Slide slide = MediaUtil.getSlideForAttachment(context, attachment);
|
|
|
|
if (slide != null) slides.add(slide);
|
|
|
|
}
|
|
|
|
|
2011-12-20 18:20:44 +00:00
|
|
|
public SlideDeck() {
|
|
|
|
}
|
2014-06-28 21:06:15 +00:00
|
|
|
|
2011-12-20 18:20:44 +00:00
|
|
|
public void clear() {
|
|
|
|
slides.clear();
|
|
|
|
}
|
2014-12-01 17:45:37 +00:00
|
|
|
|
2015-12-18 22:37:11 +00:00
|
|
|
@NonNull
|
|
|
|
public String getBody() {
|
|
|
|
String body = "";
|
|
|
|
|
|
|
|
for (Slide slide : slides) {
|
|
|
|
Optional<String> slideBody = slide.getBody();
|
|
|
|
|
|
|
|
if (slideBody.isPresent()) {
|
|
|
|
body = slideBody.get();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return body;
|
|
|
|
}
|
|
|
|
|
|
|
|
@NonNull
|
2015-10-13 01:25:05 +00:00
|
|
|
public List<Attachment> asAttachments() {
|
|
|
|
List<Attachment> attachments = new LinkedList<>();
|
Major storage layer refactoring to set the stage for clean GCM.
1) We now try to hand out cursors at a minimum. There has always been
a fairly clean insertion layer that handles encrypting message bodies,
but the process of decrypting message bodies has always been less than
ideal. Here we introduce a "Reader" interface that will decrypt message
bodies when appropriate and return objects that encapsulate record state.
No more MessageDisplayHelper. The MmsSmsDatabase interface is also more
sane.
2) We finally rid ourselves of the technical debt associated with TextSecure's
initial usage of the default SMS DB. In that world, we weren't able to use
anything other than the default "Inbox, Outbox, Sent" types to describe a
message, and had to overload the message content itself with a set of
local "prefixes" to describe what it was (encrypted, asymetric encrypted,
remote encrypted, a key exchange, procssed key exchange), and so on.
This includes a major schema update that transforms the "type" field into
a bitmask that describes everything that used to be encoded in a prefix,
and prefixes have been completely eliminated from the system.
No more Prefix.java
3) Refactoring of the MultipartMessageHandler code. It's less of a mess, and
hopefully more clear as to what's going on.
The next step is to remove what we can from SmsTransportDetails and genericize
that interface for a GCM equivalent.
2013-04-20 19:22:04 +00:00
|
|
|
|
|
|
|
for (Slide slide : slides) {
|
2015-10-13 01:25:05 +00:00
|
|
|
attachments.add(slide.asAttachment());
|
Major storage layer refactoring to set the stage for clean GCM.
1) We now try to hand out cursors at a minimum. There has always been
a fairly clean insertion layer that handles encrypting message bodies,
but the process of decrypting message bodies has always been less than
ideal. Here we introduce a "Reader" interface that will decrypt message
bodies when appropriate and return objects that encapsulate record state.
No more MessageDisplayHelper. The MmsSmsDatabase interface is also more
sane.
2) We finally rid ourselves of the technical debt associated with TextSecure's
initial usage of the default SMS DB. In that world, we weren't able to use
anything other than the default "Inbox, Outbox, Sent" types to describe a
message, and had to overload the message content itself with a set of
local "prefixes" to describe what it was (encrypted, asymetric encrypted,
remote encrypted, a key exchange, procssed key exchange), and so on.
This includes a major schema update that transforms the "type" field into
a bitmask that describes everything that used to be encoded in a prefix,
and prefixes have been completely eliminated from the system.
No more Prefix.java
3) Refactoring of the MultipartMessageHandler code. It's less of a mess, and
hopefully more clear as to what's going on.
The next step is to remove what we can from SmsTransportDetails and genericize
that interface for a GCM equivalent.
2013-04-20 19:22:04 +00:00
|
|
|
}
|
2014-06-28 21:06:15 +00:00
|
|
|
|
2015-10-13 01:25:05 +00:00
|
|
|
return attachments;
|
2011-12-20 18:20:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void addSlide(Slide slide) {
|
|
|
|
slides.add(slide);
|
|
|
|
}
|
2014-12-01 17:45:37 +00:00
|
|
|
|
2011-12-20 18:20:44 +00:00
|
|
|
public List<Slide> getSlides() {
|
|
|
|
return slides;
|
|
|
|
}
|
2014-06-12 01:03:01 +00:00
|
|
|
|
|
|
|
public boolean containsMediaSlide() {
|
|
|
|
for (Slide slide : slides) {
|
2019-04-17 14:21:30 +00:00
|
|
|
if (slide.hasImage() || slide.hasVideo() || slide.hasAudio() || slide.hasDocument() || slide.hasSticker()) {
|
2014-06-12 01:03:01 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2014-12-01 17:45:37 +00:00
|
|
|
|
2015-08-10 16:33:57 +00:00
|
|
|
public @Nullable Slide getThumbnailSlide() {
|
2015-01-30 06:37:01 +00:00
|
|
|
for (Slide slide : slides) {
|
|
|
|
if (slide.hasImage()) {
|
|
|
|
return slide;
|
|
|
|
}
|
|
|
|
}
|
2015-10-21 22:32:29 +00:00
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2018-11-09 07:33:37 +00:00
|
|
|
public @NonNull List<Slide> getThumbnailSlides() {
|
|
|
|
return Stream.of(slides).filter(Slide::hasImage).toList();
|
|
|
|
}
|
|
|
|
|
2015-10-21 22:32:29 +00:00
|
|
|
public @Nullable AudioSlide getAudioSlide() {
|
|
|
|
for (Slide slide : slides) {
|
|
|
|
if (slide.hasAudio()) {
|
|
|
|
return (AudioSlide)slide;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-30 06:37:01 +00:00
|
|
|
return null;
|
|
|
|
}
|
2017-03-28 19:05:30 +00:00
|
|
|
|
|
|
|
public @Nullable DocumentSlide getDocumentSlide() {
|
|
|
|
for (Slide slide: slides) {
|
|
|
|
if (slide.hasDocument()) {
|
|
|
|
return (DocumentSlide)slide;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
2019-02-27 03:29:52 +00:00
|
|
|
|
|
|
|
public @Nullable TextSlide getTextSlide() {
|
|
|
|
for (Slide slide: slides) {
|
|
|
|
if (MediaUtil.isLongTextType(slide.getContentType())) {
|
|
|
|
return (TextSlide)slide;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
2019-04-17 14:21:30 +00:00
|
|
|
|
|
|
|
public @Nullable StickerSlide getStickerSlide() {
|
|
|
|
for (Slide slide: slides) {
|
|
|
|
if (slide.hasSticker()) {
|
|
|
|
return (StickerSlide)slide;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
2011-12-20 18:20:44 +00:00
|
|
|
}
|