2017-11-14 03:01:05 +01:00
/ *
2011-12-20 19:20:44 +01:00
* Copyright ( C ) 2011 Whisper Systems
2017-11-14 03:01:05 +01:00
* Copyright ( C ) 2013 - 2017 Open Whisper Systems
2012-09-10 01:10:46 +02:00
*
2011-12-20 19:20:44 +01:00
* 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 .
2012-09-10 01:10:46 +02:00
*
2011-12-20 19:20:44 +01:00
* 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.database ;
2022-03-10 06:29:44 +01:00
import static org.session.libsession.utilities.GroupUtil.CLOSED_GROUP_PREFIX ;
2021-12-07 05:39:31 +01:00
import static org.session.libsession.utilities.GroupUtil.OPEN_GROUP_PREFIX ;
import static org.thoughtcrime.securesms.database.GroupDatabase.GROUP_ID ;
2011-12-20 19:20:44 +01:00
import android.content.ContentValues ;
import android.content.Context ;
import android.database.Cursor ;
2015-04-02 19:02:19 +02:00
import android.database.MergeCursor ;
2015-10-16 22:59:40 +02:00
import android.net.Uri ;
2021-03-04 06:21:25 +01:00
2020-08-19 02:06:26 +02:00
import androidx.annotation.NonNull ;
import androidx.annotation.Nullable ;
2011-12-20 19:20:44 +01:00
2017-08-07 06:43:11 +02:00
import com.annimon.stream.Stream ;
2018-01-25 04:17:44 +01:00
import net.sqlcipher.database.SQLiteDatabase ;
2022-09-04 13:03:32 +02:00
import org.jetbrains.annotations.NotNull ;
2021-05-18 08:11:38 +02:00
import org.session.libsession.utilities.Address ;
2021-07-20 09:34:07 +02:00
import org.session.libsession.utilities.Contact ;
2021-03-04 06:21:25 +01:00
import org.session.libsession.utilities.DelimiterUtil ;
2021-07-20 09:34:07 +02:00
import org.session.libsession.utilities.DistributionTypes ;
import org.session.libsession.utilities.GroupRecord ;
2021-03-04 06:21:25 +01:00
import org.session.libsession.utilities.TextSecurePreferences ;
import org.session.libsession.utilities.Util ;
2021-07-20 09:34:07 +02:00
import org.session.libsession.utilities.recipients.Recipient ;
import org.session.libsession.utilities.recipients.Recipient.RecipientSettings ;
2022-08-10 10:17:48 +02:00
import org.session.libsignal.utilities.IdPrefix ;
2021-07-20 09:34:07 +02:00
import org.session.libsignal.utilities.Log ;
2021-05-18 01:26:08 +02:00
import org.session.libsignal.utilities.Pair ;
import org.session.libsignal.utilities.guava.Optional ;
2022-01-16 18:02:39 +01:00
import org.thoughtcrime.securesms.ApplicationContext ;
2018-06-21 01:37:14 +02:00
import org.thoughtcrime.securesms.contactshare.ContactUtil ;
2016-10-10 20:13:37 +02:00
import org.thoughtcrime.securesms.database.MessagingDatabase.MarkedMessageInfo ;
2018-01-25 04:17:44 +01:00
import org.thoughtcrime.securesms.database.helpers.SQLCipherOpenHelper ;
2015-10-16 22:59:40 +02:00
import org.thoughtcrime.securesms.database.model.MediaMmsMessageRecord ;
2013-04-26 20:23:43 +02:00
import org.thoughtcrime.securesms.database.model.MessageRecord ;
2018-06-27 18:43:02 +02:00
import org.thoughtcrime.securesms.database.model.MmsMessageRecord ;
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 21:22:04 +02:00
import org.thoughtcrime.securesms.database.model.ThreadRecord ;
2021-10-04 09:51:19 +02:00
import org.thoughtcrime.securesms.dependencies.DatabaseComponent ;
2022-09-04 13:03:32 +02:00
import org.thoughtcrime.securesms.groups.OpenGroupMigrator ;
2015-10-16 22:59:40 +02:00
import org.thoughtcrime.securesms.mms.Slide ;
import org.thoughtcrime.securesms.mms.SlideDeck ;
2022-01-16 18:02:39 +01:00
import org.thoughtcrime.securesms.notifications.MarkReadReceiver ;
2021-07-20 09:34:07 +02:00
import org.thoughtcrime.securesms.util.SessionMetaProtocol ;
2021-01-13 07:11:30 +01:00
2018-04-07 03:15:24 +02:00
import java.io.Closeable ;
2022-09-04 13:03:32 +02:00
import java.util.ArrayList ;
import java.util.Collections ;
2019-12-04 01:28:12 +01:00
import java.util.HashMap ;
2015-04-02 19:02:19 +02:00
import java.util.LinkedList ;
2012-09-10 01:10:46 +02:00
import java.util.List ;
2019-12-04 01:28:12 +01:00
import java.util.Map ;
2012-09-10 01:10:46 +02:00
import java.util.Set ;
2011-12-20 19:20:44 +01:00
public class ThreadDatabase extends Database {
2015-10-16 22:59:40 +02:00
private static final String TAG = ThreadDatabase . class . getSimpleName ( ) ;
2021-05-21 03:09:03 +02:00
private final Map < Long , Address > addressCache = new HashMap < > ( ) ;
2019-12-04 01:28:12 +01:00
2018-06-22 01:48:46 +02:00
public static final String TABLE_NAME = " thread " ;
2017-09-16 07:38:53 +02:00
public static final String ID = " _id " ;
public static final String DATE = " date " ;
public static final String MESSAGE_COUNT = " message_count " ;
public static final String ADDRESS = " recipient_ids " ;
public static final String SNIPPET = " snippet " ;
private static final String SNIPPET_CHARSET = " snippet_cs " ;
public static final String READ = " read " ;
2017-11-14 03:01:05 +01:00
public static final String UNREAD_COUNT = " unread_count " ;
2017-09-16 07:38:53 +02:00
public static final String TYPE = " type " ;
private static final String ERROR = " error " ;
public static final String SNIPPET_TYPE = " snippet_type " ;
public static final String SNIPPET_URI = " snippet_uri " ;
public static final String ARCHIVED = " archived " ;
public static final String STATUS = " status " ;
public static final String DELIVERY_RECEIPT_COUNT = " delivery_receipt_count " ;
public static final String READ_RECEIPT_COUNT = " read_receipt_count " ;
public static final String EXPIRES_IN = " expires_in " ;
public static final String LAST_SEEN = " last_seen " ;
2022-03-10 06:29:44 +01:00
public static final String HAS_SENT = " has_sent " ;
2021-12-10 00:18:56 +01:00
public static final String IS_PINNED = " is_pinned " ;
2019-06-05 04:42:06 +02:00
2015-11-24 16:06:41 +01:00
public static final String CREATE_TABLE = " CREATE TABLE " + TABLE_NAME + " ( " +
ID + " INTEGER PRIMARY KEY, " + DATE + " INTEGER DEFAULT 0, " +
2017-09-16 07:38:53 +02:00
MESSAGE_COUNT + " INTEGER DEFAULT 0, " + ADDRESS + " TEXT, " + SNIPPET + " TEXT, " +
2015-11-24 16:06:41 +01:00
SNIPPET_CHARSET + " INTEGER DEFAULT 0, " + READ + " INTEGER DEFAULT 1, " +
TYPE + " INTEGER DEFAULT 0, " + ERROR + " INTEGER DEFAULT 0, " +
SNIPPET_TYPE + " INTEGER DEFAULT 0, " + SNIPPET_URI + " TEXT DEFAULT NULL, " +
ARCHIVED + " INTEGER DEFAULT 0, " + STATUS + " INTEGER DEFAULT 0, " +
2017-09-16 07:38:53 +02:00
DELIVERY_RECEIPT_COUNT + " INTEGER DEFAULT 0, " + EXPIRES_IN + " INTEGER DEFAULT 0, " +
LAST_SEEN + " INTEGER DEFAULT 0, " + HAS_SENT + " INTEGER DEFAULT 0, " +
2019-06-17 03:57:40 +02:00
READ_RECEIPT_COUNT + " INTEGER DEFAULT 0, " + UNREAD_COUNT + " INTEGER DEFAULT 0); " ;
2011-12-20 19:20:44 +01:00
2018-01-25 04:17:44 +01:00
public static final String [ ] CREATE_INDEXS = {
2017-08-01 17:56:00 +02:00
" CREATE INDEX IF NOT EXISTS thread_recipient_ids_index ON " + TABLE_NAME + " ( " + ADDRESS + " ); " ,
2017-05-20 03:01:40 +02:00
" CREATE INDEX IF NOT EXISTS archived_count_index ON " + TABLE_NAME + " ( " + ARCHIVED + " , " + MESSAGE_COUNT + " ); " ,
2012-10-30 01:41:06 +01:00
} ;
2017-08-07 06:43:11 +02:00
private static final String [ ] THREAD_PROJECTION = {
2017-11-14 03:01:05 +01:00
ID , DATE , MESSAGE_COUNT , ADDRESS , SNIPPET , SNIPPET_CHARSET , READ , UNREAD_COUNT , TYPE , ERROR , SNIPPET_TYPE ,
2021-12-10 00:18:56 +01:00
SNIPPET_URI , ARCHIVED , STATUS , DELIVERY_RECEIPT_COUNT , EXPIRES_IN , LAST_SEEN , READ_RECEIPT_COUNT , IS_PINNED
2017-08-07 06:43:11 +02:00
} ;
private static final List < String > TYPED_THREAD_PROJECTION = Stream . of ( THREAD_PROJECTION )
. map ( columnName - > TABLE_NAME + " . " + columnName )
. toList ( ) ;
2017-08-08 01:47:38 +02:00
private static final List < String > COMBINED_THREAD_RECIPIENT_GROUP_PROJECTION = Stream . concat ( Stream . concat ( Stream . of ( TYPED_THREAD_PROJECTION ) ,
2017-08-22 03:37:39 +02:00
Stream . of ( RecipientDatabase . TYPED_RECIPIENT_PROJECTION ) ) ,
2017-08-08 01:47:38 +02:00
Stream . of ( GroupDatabase . TYPED_GROUP_PROJECTION ) )
. toList ( ) ;
2017-08-07 06:43:11 +02:00
2021-12-10 00:18:56 +01:00
public static String getCreatePinnedCommand ( ) {
return " ALTER TABLE " + TABLE_NAME + " " +
" ADD COLUMN " + IS_PINNED + " INTEGER DEFAULT 0; " ;
}
2018-01-25 04:17:44 +01:00
public ThreadDatabase ( Context context , SQLCipherOpenHelper databaseHelper ) {
2011-12-20 19:20:44 +01:00
super ( context , databaseHelper ) ;
}
2017-08-01 17:56:00 +02:00
private long createThreadForRecipient ( Address address , boolean group , int distributionType ) {
2011-12-20 19:20:44 +01:00
ContentValues contentValues = new ContentValues ( 4 ) ;
long date = System . currentTimeMillis ( ) ;
2012-09-10 01:10:46 +02:00
2011-12-20 19:20:44 +01:00
contentValues . put ( DATE , date - date % 1000 ) ;
2017-08-01 17:56:00 +02:00
contentValues . put ( ADDRESS , address . serialize ( ) ) ;
2012-09-10 01:10:46 +02:00
2017-08-01 17:56:00 +02:00
if ( group )
2013-04-26 03:59:49 +02:00
contentValues . put ( TYPE , distributionType ) ;
2012-09-10 01:10:46 +02:00
2011-12-20 19:20:44 +01:00
contentValues . put ( MESSAGE_COUNT , 0 ) ;
SQLiteDatabase db = databaseHelper . getWritableDatabase ( ) ;
return db . insert ( TABLE_NAME , null , contentValues ) ;
}
2015-11-24 16:06:41 +01:00
private void updateThread ( long threadId , long count , String body , @Nullable Uri attachment ,
2017-09-16 07:38:53 +02:00
long date , int status , int deliveryReceiptCount , long type , boolean unarchive ,
long expiresIn , int readReceiptCount )
2014-02-15 00:59:57 +01:00
{
2015-11-24 16:06:41 +01:00
ContentValues contentValues = new ContentValues ( 7 ) ;
2011-12-20 19:20:44 +01:00
contentValues . put ( DATE , date - date % 1000 ) ;
contentValues . put ( MESSAGE_COUNT , count ) ;
2019-07-19 05:23:19 +02:00
if ( ! body . isEmpty ( ) ) {
contentValues . put ( SNIPPET , body ) ;
}
2015-10-16 22:59:40 +02:00
contentValues . put ( SNIPPET_URI , attachment = = null ? null : attachment . toString ( ) ) ;
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 21:22:04 +02:00
contentValues . put ( SNIPPET_TYPE , type ) ;
2015-11-24 16:06:41 +01:00
contentValues . put ( STATUS , status ) ;
2017-09-16 07:38:53 +02:00
contentValues . put ( DELIVERY_RECEIPT_COUNT , deliveryReceiptCount ) ;
contentValues . put ( READ_RECEIPT_COUNT , readReceiptCount ) ;
2016-08-16 05:23:56 +02:00
contentValues . put ( EXPIRES_IN , expiresIn ) ;
2012-09-10 01:10:46 +02:00
2015-11-24 00:07:41 +01:00
if ( unarchive ) {
contentValues . put ( ARCHIVED , 0 ) ;
}
2019-12-05 00:51:54 +01:00
SQLiteDatabase db = databaseHelper . getWritableDatabase ( ) ;
db . update ( TABLE_NAME , contentValues , ID + " = ? " , new String [ ] { threadId + " " } ) ;
notifyConversationListListeners ( ) ;
2011-12-20 19:20:44 +01:00
}
2012-09-10 01:10:46 +02:00
2015-11-24 00:07:41 +01:00
public void updateSnippet ( long threadId , String snippet , @Nullable Uri attachment , long date , long type , boolean unarchive ) {
2015-11-24 16:06:41 +01:00
ContentValues contentValues = new ContentValues ( 4 ) ;
2015-04-06 22:44:18 +02:00
contentValues . put ( DATE , date - date % 1000 ) ;
2019-07-19 05:23:19 +02:00
if ( ! snippet . isEmpty ( ) ) {
contentValues . put ( SNIPPET , snippet ) ;
}
2014-12-12 02:13:01 +01:00
contentValues . put ( SNIPPET_TYPE , type ) ;
2015-10-16 22:59:40 +02:00
contentValues . put ( SNIPPET_URI , attachment = = null ? null : attachment . toString ( ) ) ;
2015-11-24 00:07:41 +01:00
if ( unarchive ) {
contentValues . put ( ARCHIVED , 0 ) ;
}
2014-12-12 02:13:01 +01:00
SQLiteDatabase db = databaseHelper . getWritableDatabase ( ) ;
db . update ( TABLE_NAME , contentValues , ID + " = ? " , new String [ ] { threadId + " " } ) ;
notifyConversationListListeners ( ) ;
}
2011-12-20 19:20:44 +01:00
private void deleteThread ( long threadId ) {
SQLiteDatabase db = databaseHelper . getWritableDatabase ( ) ;
2015-10-16 22:59:40 +02:00
db . delete ( TABLE_NAME , ID_WHERE , new String [ ] { threadId + " " } ) ;
2019-12-05 00:51:54 +01:00
addressCache . remove ( threadId ) ;
2011-12-20 19:20:44 +01:00
notifyConversationListListeners ( ) ;
}
2012-09-10 01:10:46 +02:00
2011-12-20 19:20:44 +01:00
private void deleteThreads ( Set < Long > threadIds ) {
SQLiteDatabase db = databaseHelper . getWritableDatabase ( ) ;
String where = " " ;
2012-09-10 01:10:46 +02:00
2011-12-20 19:20:44 +01:00
for ( long threadId : threadIds ) {
where + = ID + " = ' " + threadId + " ' OR " ;
}
2012-09-10 01:10:46 +02:00
2011-12-20 19:20:44 +01:00
where = where . substring ( 0 , where . length ( ) - 4 ) ;
2012-09-10 01:10:46 +02:00
2011-12-20 19:20:44 +01:00
db . delete ( TABLE_NAME , where , null ) ;
2019-12-05 00:51:54 +01:00
for ( long threadId : threadIds ) {
addressCache . remove ( threadId ) ;
}
2011-12-20 19:20:44 +01:00
notifyConversationListListeners ( ) ;
}
2012-09-10 01:10:46 +02:00
2011-12-20 19:20:44 +01:00
private void deleteAllThreads ( ) {
SQLiteDatabase db = databaseHelper . getWritableDatabase ( ) ;
2012-09-10 01:10:46 +02:00
db . delete ( TABLE_NAME , null , null ) ;
2019-12-05 00:51:54 +01:00
addressCache . clear ( ) ;
2012-09-10 01:10:46 +02:00
notifyConversationListListeners ( ) ;
2011-12-20 19:20:44 +01:00
}
2012-09-10 01:10:46 +02:00
2013-01-10 06:06:56 +01:00
public void trimAllThreads ( int length , ProgressListener listener ) {
Cursor cursor = null ;
int threadCount = 0 ;
int complete = 0 ;
try {
cursor = this . getConversationList ( ) ;
if ( cursor ! = null )
threadCount = cursor . getCount ( ) ;
while ( cursor ! = null & & cursor . moveToNext ( ) ) {
long threadId = cursor . getLong ( cursor . getColumnIndexOrThrow ( ID ) ) ;
trimThread ( threadId , length ) ;
listener . onProgress ( + + complete , threadCount ) ;
}
} finally {
if ( cursor ! = null )
cursor . close ( ) ;
}
}
public void trimThread ( long threadId , int length ) {
2018-08-02 15:25:33 +02:00
Log . i ( " ThreadDatabase " , " Trimming thread: " + threadId + " to: " + length ) ;
2013-01-10 06:06:56 +01:00
Cursor cursor = null ;
try {
2022-03-04 07:46:39 +01:00
cursor = DatabaseComponent . get ( context ) . mmsSmsDatabase ( ) . getConversation ( threadId , true ) ;
2013-01-10 06:06:56 +01:00
2015-09-29 01:39:39 +02:00
if ( cursor ! = null & & length > 0 & & cursor . getCount ( ) > length ) {
2013-01-10 06:06:56 +01:00
Log . w ( " ThreadDatabase " , " Cursor count is greater than length! " ) ;
2015-09-29 01:39:39 +02:00
cursor . moveToPosition ( length - 1 ) ;
2013-01-10 06:06:56 +01: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 21:22:04 +02:00
long lastTweetDate = cursor . getLong ( cursor . getColumnIndexOrThrow ( MmsSmsColumns . NORMALIZED_DATE_RECEIVED ) ) ;
2013-01-10 06:06:56 +01:00
2018-08-02 15:25:33 +02:00
Log . i ( " ThreadDatabase " , " Cut off tweet date: " + lastTweetDate ) ;
2013-01-10 06:06:56 +01:00
2021-10-04 09:51:19 +02:00
DatabaseComponent . get ( context ) . smsDatabase ( ) . deleteMessagesInThreadBeforeDate ( threadId , lastTweetDate ) ;
DatabaseComponent . get ( context ) . mmsDatabase ( ) . deleteMessagesInThreadBeforeDate ( threadId , lastTweetDate ) ;
2013-01-10 06:06:56 +01:00
2015-11-24 00:07:41 +01:00
update ( threadId , false ) ;
2013-01-10 06:06:56 +01:00
notifyConversationListeners ( threadId ) ;
}
} finally {
if ( cursor ! = null )
cursor . close ( ) ;
}
}
2022-09-13 07:01:15 +02:00
public void trimThreadBefore ( long threadId , long timestamp ) {
Log . i ( " ThreadDatabase " , " Trimming thread: " + threadId + " before : " + timestamp ) ;
DatabaseComponent . get ( context ) . smsDatabase ( ) . deleteMessagesInThreadBeforeDate ( threadId , timestamp ) ;
DatabaseComponent . get ( context ) . mmsDatabase ( ) . deleteMessagesInThreadBeforeDate ( threadId , timestamp ) ;
update ( threadId , false ) ;
notifyConversationListeners ( threadId ) ;
}
2017-02-23 00:05:35 +01:00
public List < MarkedMessageInfo > setRead ( long threadId , boolean lastSeen ) {
2011-12-20 19:20:44 +01:00
ContentValues contentValues = new ContentValues ( 1 ) ;
contentValues . put ( READ , 1 ) ;
2017-11-14 03:01:05 +01:00
contentValues . put ( UNREAD_COUNT , 0 ) ;
2011-12-20 19:20:44 +01:00
2017-02-23 00:05:35 +01:00
if ( lastSeen ) {
contentValues . put ( LAST_SEEN , System . currentTimeMillis ( ) ) ;
}
2011-12-20 19:20:44 +01:00
SQLiteDatabase db = databaseHelper . getWritableDatabase ( ) ;
db . update ( TABLE_NAME , contentValues , ID_WHERE , new String [ ] { threadId + " " } ) ;
2012-09-10 01:10:46 +02:00
2021-10-04 09:51:19 +02:00
final List < MarkedMessageInfo > smsRecords = DatabaseComponent . get ( context ) . smsDatabase ( ) . setMessagesRead ( threadId ) ;
final List < MarkedMessageInfo > mmsRecords = DatabaseComponent . get ( context ) . mmsDatabase ( ) . setMessagesRead ( threadId ) ;
2016-02-20 02:07:41 +01:00
2011-12-20 19:20:44 +01:00
notifyConversationListListeners ( ) ;
2016-02-20 02:07:41 +01:00
2016-10-10 20:13:37 +02:00
return new LinkedList < MarkedMessageInfo > ( ) { {
2016-02-20 02:07:41 +01:00
addAll ( smsRecords ) ;
addAll ( mmsRecords ) ;
} } ;
2011-12-20 19:20:44 +01:00
}
2012-09-10 01:10:46 +02:00
2017-11-14 03:01:05 +01:00
public void incrementUnread ( long threadId , int amount ) {
2013-04-26 03:59:49 +02:00
SQLiteDatabase db = databaseHelper . getWritableDatabase ( ) ;
2017-11-14 03:01:05 +01:00
db . execSQL ( " UPDATE " + TABLE_NAME + " SET " + READ + " = 0, " +
UNREAD_COUNT + " = " + UNREAD_COUNT + " + ? WHERE " + ID + " = ? " ,
new String [ ] { String . valueOf ( amount ) ,
String . valueOf ( threadId ) } ) ;
2013-04-26 03:59:49 +02:00
}
2021-08-12 06:14:37 +02:00
public void decrementUnread ( long threadId , int amount ) {
SQLiteDatabase db = databaseHelper . getWritableDatabase ( ) ;
db . execSQL ( " UPDATE " + TABLE_NAME + " SET " + READ + " = 0, " +
2021-08-12 08:37:53 +02:00
UNREAD_COUNT + " = " + UNREAD_COUNT + " - ? WHERE " + ID + " = ? AND " + UNREAD_COUNT + " > 0 " ,
2021-08-12 06:14:37 +02:00
new String [ ] { String . valueOf ( amount ) ,
String . valueOf ( threadId ) } ) ;
}
2013-04-26 03:59:49 +02:00
public void setDistributionType ( long threadId , int distributionType ) {
ContentValues contentValues = new ContentValues ( 1 ) ;
contentValues . put ( TYPE , distributionType ) ;
2011-12-20 19:20:44 +01:00
SQLiteDatabase db = databaseHelper . getWritableDatabase ( ) ;
2015-10-16 22:59:40 +02:00
db . update ( TABLE_NAME , contentValues , ID_WHERE , new String [ ] { threadId + " " } ) ;
2012-09-10 01:10:46 +02:00
notifyConversationListListeners ( ) ;
2011-12-20 19:20:44 +01:00
}
2012-09-10 01:10:46 +02:00
2017-08-01 17:56:00 +02:00
public int getDistributionType ( long threadId ) {
SQLiteDatabase db = databaseHelper . getReadableDatabase ( ) ;
Cursor cursor = db . query ( TABLE_NAME , new String [ ] { TYPE } , ID_WHERE , new String [ ] { String . valueOf ( threadId ) } , null , null , null ) ;
try {
if ( cursor ! = null & & cursor . moveToNext ( ) ) {
return cursor . getInt ( cursor . getColumnIndexOrThrow ( TYPE ) ) ;
}
return DistributionTypes . DEFAULT ;
} finally {
if ( cursor ! = null ) cursor . close ( ) ;
}
}
2022-02-07 07:06:27 +01:00
public Cursor searchConversationAddresses ( String addressQuery ) {
if ( addressQuery = = null | | addressQuery . isEmpty ( ) ) {
return null ;
}
SQLiteDatabase db = databaseHelper . getReadableDatabase ( ) ;
String selection = TABLE_NAME + " . " + ADDRESS + " LIKE ? AND " + TABLE_NAME + " . " + MESSAGE_COUNT + " != 0 " ;
String [ ] selectionArgs = new String [ ] { addressQuery + " % " } ;
String query = createQuery ( selection , 0 ) ;
Cursor cursor = db . rawQuery ( query , selectionArgs ) ;
return cursor ;
}
2017-09-07 22:52:25 +02:00
public Cursor getFilteredConversationList ( @Nullable List < Address > filter ) {
2011-12-20 19:20:44 +01:00
if ( filter = = null | | filter . size ( ) = = 0 )
return null ;
2012-09-10 01:10:46 +02:00
2017-07-26 18:59:15 +02:00
SQLiteDatabase db = databaseHelper . getReadableDatabase ( ) ;
List < List < Address > > partitionedAddresses = Util . partition ( filter , 900 ) ;
List < Cursor > cursors = new LinkedList < > ( ) ;
2012-09-10 01:10:46 +02:00
2017-07-26 18:59:15 +02:00
for ( List < Address > addresses : partitionedAddresses ) {
2017-09-07 22:52:25 +02:00
String selection = TABLE_NAME + " . " + ADDRESS + " = ? " ;
2017-07-26 18:59:15 +02:00
String [ ] selectionArgs = new String [ addresses . size ( ) ] ;
2012-09-10 01:10:46 +02:00
2017-07-26 18:59:15 +02:00
for ( int i = 0 ; i < addresses . size ( ) - 1 ; i + + )
2017-09-07 22:52:25 +02:00
selection + = ( " OR " + TABLE_NAME + " . " + ADDRESS + " = ? " ) ;
2015-04-02 19:02:19 +02:00
int i = 0 ;
2017-07-26 18:59:15 +02:00
for ( Address address : addresses ) {
2017-08-02 20:04:10 +02:00
selectionArgs [ i + + ] = DelimiterUtil . escape ( address . serialize ( ) , ' ' ) ;
2015-04-02 19:02:19 +02:00
}
2017-11-17 00:21:46 +01:00
String query = createQuery ( selection , 0 ) ;
2017-09-07 22:52:25 +02:00
cursors . add ( db . rawQuery ( query , selectionArgs ) ) ;
2011-12-20 19:20:44 +01:00
}
2012-09-10 01:10:46 +02:00
2015-04-02 19:02:19 +02:00
Cursor cursor = cursors . size ( ) > 1 ? new MergeCursor ( cursors . toArray ( new Cursor [ cursors . size ( ) ] ) ) : cursors . get ( 0 ) ;
2012-09-10 01:10:46 +02:00
setNotifyConverationListListeners ( cursor ) ;
2011-12-20 19:20:44 +01:00
return cursor ;
}
2012-09-10 01:10:46 +02:00
2017-11-17 00:21:46 +01:00
public Cursor getRecentConversationList ( int limit ) {
SQLiteDatabase db = databaseHelper . getReadableDatabase ( ) ;
String query = createQuery ( MESSAGE_COUNT + " != 0 " , limit ) ;
return db . rawQuery ( query , null ) ;
}
2022-03-04 07:46:39 +01:00
public int getUnapprovedConversationCount ( ) {
SQLiteDatabase db = databaseHelper . getReadableDatabase ( ) ;
Cursor cursor = null ;
try {
String query = " SELECT COUNT (*) FROM " + TABLE_NAME +
" LEFT OUTER JOIN " + RecipientDatabase . TABLE_NAME +
" ON " + TABLE_NAME + " . " + ADDRESS + " = " + RecipientDatabase . TABLE_NAME + " . " + RecipientDatabase . ADDRESS +
" LEFT OUTER JOIN " + GroupDatabase . TABLE_NAME +
" ON " + TABLE_NAME + " . " + ADDRESS + " = " + GroupDatabase . TABLE_NAME + " . " + GROUP_ID +
" WHERE " + MESSAGE_COUNT + " != 0 AND " + ARCHIVED + " = 0 AND " + HAS_SENT + " = 0 AND " + MESSAGE_COUNT + " = " + UNREAD_COUNT + " AND " +
RecipientDatabase . TABLE_NAME + " . " + RecipientDatabase . BLOCK + " = 0 AND " +
RecipientDatabase . TABLE_NAME + " . " + RecipientDatabase . APPROVED + " = 0 AND " +
GroupDatabase . TABLE_NAME + " . " + GROUP_ID + " IS NULL " ;
cursor = db . rawQuery ( query , null ) ;
if ( cursor ! = null & & cursor . moveToFirst ( ) )
return cursor . getInt ( 0 ) ;
} finally {
if ( cursor ! = null )
cursor . close ( ) ;
}
return 0 ;
}
public long getLatestUnapprovedConversationTimestamp ( ) {
SQLiteDatabase db = databaseHelper . getReadableDatabase ( ) ;
Cursor cursor = null ;
try {
String where = " SELECT " + DATE + " FROM " + TABLE_NAME +
" LEFT OUTER JOIN " + RecipientDatabase . TABLE_NAME +
" ON " + TABLE_NAME + " . " + ADDRESS + " = " + RecipientDatabase . TABLE_NAME + " . " + RecipientDatabase . ADDRESS +
" LEFT OUTER JOIN " + GroupDatabase . TABLE_NAME +
" ON " + TABLE_NAME + " . " + ADDRESS + " = " + GroupDatabase . TABLE_NAME + " . " + GROUP_ID +
" WHERE " + MESSAGE_COUNT + " != 0 AND " + ARCHIVED + " = 0 AND " + HAS_SENT + " = 0 AND " +
RecipientDatabase . TABLE_NAME + " . " + RecipientDatabase . BLOCK + " = 0 AND " +
RecipientDatabase . TABLE_NAME + " . " + RecipientDatabase . APPROVED + " = 0 AND " +
GroupDatabase . TABLE_NAME + " . " + GROUP_ID + " IS NULL ORDER BY " + DATE + " DESC LIMIT 1 " ;
cursor = db . rawQuery ( where , null ) ;
if ( cursor ! = null & & cursor . moveToFirst ( ) )
return cursor . getLong ( 0 ) ;
} finally {
if ( cursor ! = null )
cursor . close ( ) ;
}
return 0 ;
}
2012-09-10 01:10:46 +02:00
public Cursor getConversationList ( ) {
2022-03-04 07:46:39 +01:00
String where = " ( " + MESSAGE_COUNT + " != 0 OR " + GroupDatabase . TABLE_NAME + " . " + GROUP_ID + " LIKE ' " + OPEN_GROUP_PREFIX + " %') " +
" AND " + ARCHIVED + " = 0 " ;
return getConversationList ( where ) ;
}
2022-08-10 10:17:48 +02:00
public Cursor getBlindedConversationList ( ) {
String where = TABLE_NAME + " . " + ADDRESS + " LIKE ' " + IdPrefix . BLINDED . getValue ( ) + " %' " ;
return getConversationList ( where ) ;
}
2022-03-04 07:46:39 +01:00
public Cursor getApprovedConversationList ( ) {
2022-03-10 06:29:44 +01:00
String where = " (( " + MESSAGE_COUNT + " != 0 AND ( " + HAS_SENT + " = 1 OR " + RecipientDatabase . APPROVED + " = 1 OR " + GroupDatabase . TABLE_NAME + " . " + GROUP_ID + " LIKE ' " + CLOSED_GROUP_PREFIX + " %')) OR " + GroupDatabase . TABLE_NAME + " . " + GROUP_ID + " LIKE ' " + OPEN_GROUP_PREFIX + " %') " +
2022-03-04 07:46:39 +01:00
" AND " + ARCHIVED + " = 0 " ;
return getConversationList ( where ) ;
}
public Cursor getUnapprovedConversationList ( ) {
String where = MESSAGE_COUNT + " != 0 AND " + ARCHIVED + " = 0 AND " + HAS_SENT + " = 0 AND " +
RecipientDatabase . TABLE_NAME + " . " + RecipientDatabase . APPROVED + " = 0 AND " +
RecipientDatabase . TABLE_NAME + " . " + RecipientDatabase . BLOCK + " = 0 AND " +
GroupDatabase . TABLE_NAME + " . " + GROUP_ID + " IS NULL " ;
return getConversationList ( where ) ;
2015-11-24 00:07:41 +01:00
}
public Cursor getArchivedConversationList ( ) {
2022-03-04 07:46:39 +01:00
String where = " ( " + MESSAGE_COUNT + " != 0 OR " + GroupDatabase . TABLE_NAME + " . " + GROUP_ID + " LIKE ' " + OPEN_GROUP_PREFIX + " %') " +
" AND " + ARCHIVED + " = 1 " ;
return getConversationList ( where ) ;
2017-08-07 06:43:11 +02:00
}
2022-03-04 07:46:39 +01:00
private Cursor getConversationList ( String where ) {
2017-09-15 19:36:33 +02:00
SQLiteDatabase db = databaseHelper . getReadableDatabase ( ) ;
2021-12-07 05:39:31 +01:00
String query = createQuery ( where , 0 ) ;
2022-03-04 07:46:39 +01:00
Cursor cursor = db . rawQuery ( query , null ) ;
2015-11-24 00:07:41 +01:00
2011-12-20 19:20:44 +01:00
setNotifyConverationListListeners ( cursor ) ;
2015-11-24 00:07:41 +01:00
2011-12-20 19:20:44 +01:00
return cursor ;
}
2012-09-10 01:10:46 +02:00
2017-01-12 04:54:19 +01:00
public Cursor getDirectShareList ( ) {
2017-09-15 19:36:33 +02:00
SQLiteDatabase db = databaseHelper . getReadableDatabase ( ) ;
2017-11-17 00:21:46 +01:00
String query = createQuery ( MESSAGE_COUNT + " != 0 " , 0 ) ;
2017-08-07 06:43:11 +02:00
2017-09-15 19:36:33 +02:00
return db . rawQuery ( query , null ) ;
2017-01-12 04:54:19 +01:00
}
2022-12-19 01:29:05 +01:00
public void setLastSeen ( long threadId , long timestamp ) {
2017-02-14 07:35:47 +01:00
SQLiteDatabase db = databaseHelper . getWritableDatabase ( ) ;
ContentValues contentValues = new ContentValues ( 1 ) ;
2022-12-19 01:29:05 +01:00
if ( timestamp = = - 1 ) {
contentValues . put ( LAST_SEEN , System . currentTimeMillis ( ) ) ;
} else {
contentValues . put ( LAST_SEEN , timestamp ) ;
}
2017-02-14 07:35:47 +01:00
db . update ( TABLE_NAME , contentValues , ID_WHERE , new String [ ] { String . valueOf ( threadId ) } ) ;
notifyConversationListListeners ( ) ;
}
2022-12-19 01:29:05 +01:00
public void setLastSeen ( long threadId ) {
setLastSeen ( threadId , - 1 ) ;
}
2017-08-19 02:28:56 +02:00
public Pair < Long , Boolean > getLastSeenAndHasSent ( long threadId ) {
2017-02-14 07:35:47 +01:00
SQLiteDatabase db = databaseHelper . getReadableDatabase ( ) ;
2017-08-19 02:28:56 +02:00
Cursor cursor = db . query ( TABLE_NAME , new String [ ] { LAST_SEEN , HAS_SENT } , ID_WHERE , new String [ ] { String . valueOf ( threadId ) } , null , null , null ) ;
2017-02-14 07:35:47 +01:00
try {
if ( cursor ! = null & & cursor . moveToFirst ( ) ) {
2017-08-19 02:28:56 +02:00
return new Pair < > ( cursor . getLong ( 0 ) , cursor . getLong ( 1 ) = = 1 ) ;
2017-02-14 07:35:47 +01:00
}
2017-08-19 02:28:56 +02:00
return new Pair < > ( - 1L , false ) ;
2017-02-14 07:35:47 +01:00
} finally {
if ( cursor ! = null ) cursor . close ( ) ;
}
}
2021-05-21 03:09:03 +02:00
public Long getLastUpdated ( long threadId ) {
SQLiteDatabase db = databaseHelper . getReadableDatabase ( ) ;
Cursor cursor = db . query ( TABLE_NAME , new String [ ] { DATE } , ID_WHERE , new String [ ] { String . valueOf ( threadId ) } , null , null , null ) ;
try {
if ( cursor ! = null & & cursor . moveToFirst ( ) ) {
return cursor . getLong ( 0 ) ;
}
return - 1L ;
} finally {
if ( cursor ! = null ) cursor . close ( ) ;
}
}
2022-03-04 07:46:39 +01:00
public int getMessageCount ( long threadId ) {
SQLiteDatabase db = databaseHelper . getReadableDatabase ( ) ;
String [ ] columns = new String [ ] { MESSAGE_COUNT } ;
String [ ] args = new String [ ] { String . valueOf ( threadId ) } ;
try ( Cursor cursor = db . query ( TABLE_NAME , columns , ID_WHERE , args , null , null , null ) ) {
if ( cursor ! = null & & cursor . moveToFirst ( ) ) {
return cursor . getInt ( 0 ) ;
}
return 0 ;
}
}
2011-12-20 19:20:44 +01:00
public void deleteConversation ( long threadId ) {
2021-10-04 09:51:19 +02:00
DatabaseComponent . get ( context ) . smsDatabase ( ) . deleteThread ( threadId ) ;
DatabaseComponent . get ( context ) . mmsDatabase ( ) . deleteThread ( threadId ) ;
DatabaseComponent . get ( context ) . draftDatabase ( ) . clearDrafts ( threadId ) ;
DatabaseComponent . get ( context ) . lokiMessageDatabase ( ) . deleteThread ( threadId ) ;
2011-12-20 19:20:44 +01:00
deleteThread ( threadId ) ;
notifyConversationListeners ( threadId ) ;
notifyConversationListListeners ( ) ;
2021-05-06 05:28:58 +02:00
SessionMetaProtocol . clearReceivedMessages ( ) ;
2012-09-10 01:10:46 +02:00
}
Add one on one calls over clearnet (#864)
* feat: adding basic webrtc deps and test activity
* more testing code
* feat: add protos and bump version
* feat: added basic call functionality
* feat: adding UI and flipping cameras
* feat: add stats and starting call bottom sheet
* feat: hanging up and bottom sheet behaviors should work now
* feat: add call stats report on frontend
* feat: add relay toggle for answer and offer
* fix: add keep screen on and more end call message on back pressed / on finish
* refactor: removing and replacing dagger 1 dep with android hilt
* feat: include latest proto
* feat: update to utilise call ID
* feat: add stun and turn
* refactor: playing around with deps and transport types
* feat: adding call service functionality and permissions for calls
* feat: add call manager and more static intent building functions for WebRtcCallService.kt
* feat: adding ringers and more audio boilerplate
* feat: audio manager call service boilerplate
* feat: update kotlin and add in call view model and more management functions
* refactor: moving call code around to service and viewmodel interactions
* feat: plugging CallManager.kt into view model and service, fixing up dependencies
* feat: implementing more WebRtcCallService.kt functions and handlers for actions as well as lifecycle
* feat: adding more lifecycle vm and callmanager / call service functionality
* feat: adding more command handlers in WebRtcCallService.kt
* feat: more commands handled, adding lock manager and bluetooth permissions
* feat: adding remainder of basic functionality to services and CallManager.kt
* feat: hooking up calls and fixing broken dependencies and compile errors
* fix: add timestamp to incoming call
* feat: some connection and service launching / ring lifecycle
* feat: call establishing and displaying
* fix: fixing call connect flows
* feat: ringers and better state handling
* feat: updating call layout
* feat: add fixes to bluetooth and begin the network renegotiation
* feat: add call related permissions and more network handover tests
* fix: don't display call option in conversation and don't show notification if option not enabled
* fix: incoming ringer fix on receiving call, call notification priorities and notification channel update
* build: update build number for testing
* fix: bluetooth auto-connection and re-connection fixes, removing finished todos, allowing self-send call messages for deduping answers
* feat: add pre-offer information and action handling in web rtc call service
* refactor: discard offer messages from non-matching pre-offers we are already expecting
* build: build numbers and version name update
* feat: handle discarding pending calls from linked devices
* feat: add signing props to release config build
* docs: fix comment on time being 300s (5m) instead of 30s
* feat: adding call messages for incoming/outgoing/missed
* refactor: handle in-thread call notifications better and replace deny button intent with denyCallIntent instead of hangup
* feat: add a hangup via data channel message
* feat: process microphone enabled events and remove debuggable from build.gradle
* feat: add first call notification
* refactor: set the buttons to match iOS in terms of enable disable and colours
* refactor: change the call logos in control messages
* refactor: more bluetooth improvements
* refactor: move start ringer and init of audio manager to CallManager.kt and string fix up
* build: remove debuggable for release build
* refactor: replace call icons
* feat: adding a call time display
* refactor: change the call time to update every second
* refactor: testing out the full screen intents
* refactor: wrapper use corrected session description, set title to recipient displayName, indicate session calls
* fix: crash on view with a parent already attached
* refactor: aspect ratio fit preserved
* refactor: add wantsToAnswer ability in pre-init for fullscreenintent
* refactor: prevent calls from non hasSent participants
* build: update gradle code
* refactor: replace timeout schedule with a seconds count
* fix: various bug fixes for calls
* fix: remove end call from busy
* refactor: use answerCall instead of manual intent building again
* build: new version
* feat: add silenced notifications for call notification builder. check pre-offer and connecting state for pending connection
* build: update build number
* fix: text color uses overridden style value
* fix: remove wrap content for renderers and look more at recovering from network switches
* build: update build number
* refactor: remove whitespace
* build: update build number
* refactor: used shared number for BatchMessageReceiveJob.kt parameter across pollers
* fix: glide in update crash
* fix: bug fixes for self-send answer / hangup messages
* build: update build number
* build: update build.gradle number
* refactor: compile errors and refactoring to view binding
* fix: set the content to binding.root view
* build: increase build number
* build: update build numbers
* feat: adding base for rotation and picking random subset of turn servers
* feat: starting the screen rotation processing
* feat: setting up rotation for the remote render view
* refactor: applying rotation and mirroring based on front / rear cameras that wraps nicely, only scale reworking needed
* refactor: calls video stretching but consistent
* refactor: state machine and tests for the transition events
* feat: new call state processing
* refactor: adding reconnecting logic and visuals
* feat: state machine reconnect logic wip
* feat: add reconnecting and merge fixes
* feat: check new session based off current state
* feat: reconnection logic works correctly now
* refactor: reduce TIMEOUT_SECONDS to 30 from 90
* feat: reset peer connection on DC to prevent ICE messages from old connection or stale state in reconnecting
* refactor: add null case
* fix: set approved on new outgoing threads, use approved more deeply and invalidate the options menu on recipient modified. Add approvedMe flag toggles for visible message receive
* fix: add name update in action bar on modified, change where approvedMe is set
* build: increment build number
* build: update build number
* fix: merge compile errors and increment build number
* refactor: remove negotiation based on which party dropped connection
* refactor: call reconnection improvement tested cross platform to re-establish
* refactor: failed and disconnect events only handled if either the reconnect or the timeout runnables are not set
* build: update version number
* fix: reduce timeout
* fix: fixes the incoming hangup logic for linked devices
* refactor: match iOS styling for call activity closer
* chore: upgrade build numbers
* feat: add in call settings dialog for if calls is disabled in conversation
* feat: add a first call missed control message and info popup with link to privacy settings
* fix: looking at crash for specific large transaction in NotificationManager
* refactor: removing the people in case transaction size reduces to fix notif crash
* fix: comment out the entire send multiple to see if it fixes the issue
* refactor: revert to including the full notification process in a try/catch to handle weird responses from NotificationManager
* fix: add in notification settings prompt for calls and try to fall back to dirty full screen intent / start activity if we're allowed
* build: upgrade build number
2022-04-19 06:25:40 +02:00
public long getThreadIdIfExistsFor ( String address ) {
2017-08-01 17:56:00 +02:00
SQLiteDatabase db = databaseHelper . getReadableDatabase ( ) ;
String where = ADDRESS + " = ? " ;
Add one on one calls over clearnet (#864)
* feat: adding basic webrtc deps and test activity
* more testing code
* feat: add protos and bump version
* feat: added basic call functionality
* feat: adding UI and flipping cameras
* feat: add stats and starting call bottom sheet
* feat: hanging up and bottom sheet behaviors should work now
* feat: add call stats report on frontend
* feat: add relay toggle for answer and offer
* fix: add keep screen on and more end call message on back pressed / on finish
* refactor: removing and replacing dagger 1 dep with android hilt
* feat: include latest proto
* feat: update to utilise call ID
* feat: add stun and turn
* refactor: playing around with deps and transport types
* feat: adding call service functionality and permissions for calls
* feat: add call manager and more static intent building functions for WebRtcCallService.kt
* feat: adding ringers and more audio boilerplate
* feat: audio manager call service boilerplate
* feat: update kotlin and add in call view model and more management functions
* refactor: moving call code around to service and viewmodel interactions
* feat: plugging CallManager.kt into view model and service, fixing up dependencies
* feat: implementing more WebRtcCallService.kt functions and handlers for actions as well as lifecycle
* feat: adding more lifecycle vm and callmanager / call service functionality
* feat: adding more command handlers in WebRtcCallService.kt
* feat: more commands handled, adding lock manager and bluetooth permissions
* feat: adding remainder of basic functionality to services and CallManager.kt
* feat: hooking up calls and fixing broken dependencies and compile errors
* fix: add timestamp to incoming call
* feat: some connection and service launching / ring lifecycle
* feat: call establishing and displaying
* fix: fixing call connect flows
* feat: ringers and better state handling
* feat: updating call layout
* feat: add fixes to bluetooth and begin the network renegotiation
* feat: add call related permissions and more network handover tests
* fix: don't display call option in conversation and don't show notification if option not enabled
* fix: incoming ringer fix on receiving call, call notification priorities and notification channel update
* build: update build number for testing
* fix: bluetooth auto-connection and re-connection fixes, removing finished todos, allowing self-send call messages for deduping answers
* feat: add pre-offer information and action handling in web rtc call service
* refactor: discard offer messages from non-matching pre-offers we are already expecting
* build: build numbers and version name update
* feat: handle discarding pending calls from linked devices
* feat: add signing props to release config build
* docs: fix comment on time being 300s (5m) instead of 30s
* feat: adding call messages for incoming/outgoing/missed
* refactor: handle in-thread call notifications better and replace deny button intent with denyCallIntent instead of hangup
* feat: add a hangup via data channel message
* feat: process microphone enabled events and remove debuggable from build.gradle
* feat: add first call notification
* refactor: set the buttons to match iOS in terms of enable disable and colours
* refactor: change the call logos in control messages
* refactor: more bluetooth improvements
* refactor: move start ringer and init of audio manager to CallManager.kt and string fix up
* build: remove debuggable for release build
* refactor: replace call icons
* feat: adding a call time display
* refactor: change the call time to update every second
* refactor: testing out the full screen intents
* refactor: wrapper use corrected session description, set title to recipient displayName, indicate session calls
* fix: crash on view with a parent already attached
* refactor: aspect ratio fit preserved
* refactor: add wantsToAnswer ability in pre-init for fullscreenintent
* refactor: prevent calls from non hasSent participants
* build: update gradle code
* refactor: replace timeout schedule with a seconds count
* fix: various bug fixes for calls
* fix: remove end call from busy
* refactor: use answerCall instead of manual intent building again
* build: new version
* feat: add silenced notifications for call notification builder. check pre-offer and connecting state for pending connection
* build: update build number
* fix: text color uses overridden style value
* fix: remove wrap content for renderers and look more at recovering from network switches
* build: update build number
* refactor: remove whitespace
* build: update build number
* refactor: used shared number for BatchMessageReceiveJob.kt parameter across pollers
* fix: glide in update crash
* fix: bug fixes for self-send answer / hangup messages
* build: update build number
* build: update build.gradle number
* refactor: compile errors and refactoring to view binding
* fix: set the content to binding.root view
* build: increase build number
* build: update build numbers
* feat: adding base for rotation and picking random subset of turn servers
* feat: starting the screen rotation processing
* feat: setting up rotation for the remote render view
* refactor: applying rotation and mirroring based on front / rear cameras that wraps nicely, only scale reworking needed
* refactor: calls video stretching but consistent
* refactor: state machine and tests for the transition events
* feat: new call state processing
* refactor: adding reconnecting logic and visuals
* feat: state machine reconnect logic wip
* feat: add reconnecting and merge fixes
* feat: check new session based off current state
* feat: reconnection logic works correctly now
* refactor: reduce TIMEOUT_SECONDS to 30 from 90
* feat: reset peer connection on DC to prevent ICE messages from old connection or stale state in reconnecting
* refactor: add null case
* fix: set approved on new outgoing threads, use approved more deeply and invalidate the options menu on recipient modified. Add approvedMe flag toggles for visible message receive
* fix: add name update in action bar on modified, change where approvedMe is set
* build: increment build number
* build: update build number
* fix: merge compile errors and increment build number
* refactor: remove negotiation based on which party dropped connection
* refactor: call reconnection improvement tested cross platform to re-establish
* refactor: failed and disconnect events only handled if either the reconnect or the timeout runnables are not set
* build: update version number
* fix: reduce timeout
* fix: fixes the incoming hangup logic for linked devices
* refactor: match iOS styling for call activity closer
* chore: upgrade build numbers
* feat: add in call settings dialog for if calls is disabled in conversation
* feat: add a first call missed control message and info popup with link to privacy settings
* fix: looking at crash for specific large transaction in NotificationManager
* refactor: removing the people in case transaction size reduces to fix notif crash
* fix: comment out the entire send multiple to see if it fixes the issue
* refactor: revert to including the full notification process in a try/catch to handle weird responses from NotificationManager
* fix: add in notification settings prompt for calls and try to fall back to dirty full screen intent / start activity if we're allowed
* build: upgrade build number
2022-04-19 06:25:40 +02:00
String [ ] recipientsArg = new String [ ] { address } ;
2017-08-01 17:56:00 +02:00
Cursor cursor = null ;
2012-09-10 01:10:46 +02:00
2011-12-20 19:20:44 +01:00
try {
cursor = db . query ( TABLE_NAME , new String [ ] { ID } , where , recipientsArg , null , null , null ) ;
2012-09-10 01:10:46 +02:00
2011-12-20 19:20:44 +01:00
if ( cursor ! = null & & cursor . moveToFirst ( ) )
2012-10-01 04:56:29 +02:00
return cursor . getLong ( cursor . getColumnIndexOrThrow ( ID ) ) ;
2011-12-20 19:20:44 +01:00
else
2012-10-01 04:56:29 +02:00
return - 1L ;
2011-12-20 19:20:44 +01:00
} finally {
if ( cursor ! = null )
2012-10-01 04:56:29 +02:00
cursor . close ( ) ;
2011-12-20 19:20:44 +01:00
}
}
2012-09-10 01:10:46 +02:00
Add one on one calls over clearnet (#864)
* feat: adding basic webrtc deps and test activity
* more testing code
* feat: add protos and bump version
* feat: added basic call functionality
* feat: adding UI and flipping cameras
* feat: add stats and starting call bottom sheet
* feat: hanging up and bottom sheet behaviors should work now
* feat: add call stats report on frontend
* feat: add relay toggle for answer and offer
* fix: add keep screen on and more end call message on back pressed / on finish
* refactor: removing and replacing dagger 1 dep with android hilt
* feat: include latest proto
* feat: update to utilise call ID
* feat: add stun and turn
* refactor: playing around with deps and transport types
* feat: adding call service functionality and permissions for calls
* feat: add call manager and more static intent building functions for WebRtcCallService.kt
* feat: adding ringers and more audio boilerplate
* feat: audio manager call service boilerplate
* feat: update kotlin and add in call view model and more management functions
* refactor: moving call code around to service and viewmodel interactions
* feat: plugging CallManager.kt into view model and service, fixing up dependencies
* feat: implementing more WebRtcCallService.kt functions and handlers for actions as well as lifecycle
* feat: adding more lifecycle vm and callmanager / call service functionality
* feat: adding more command handlers in WebRtcCallService.kt
* feat: more commands handled, adding lock manager and bluetooth permissions
* feat: adding remainder of basic functionality to services and CallManager.kt
* feat: hooking up calls and fixing broken dependencies and compile errors
* fix: add timestamp to incoming call
* feat: some connection and service launching / ring lifecycle
* feat: call establishing and displaying
* fix: fixing call connect flows
* feat: ringers and better state handling
* feat: updating call layout
* feat: add fixes to bluetooth and begin the network renegotiation
* feat: add call related permissions and more network handover tests
* fix: don't display call option in conversation and don't show notification if option not enabled
* fix: incoming ringer fix on receiving call, call notification priorities and notification channel update
* build: update build number for testing
* fix: bluetooth auto-connection and re-connection fixes, removing finished todos, allowing self-send call messages for deduping answers
* feat: add pre-offer information and action handling in web rtc call service
* refactor: discard offer messages from non-matching pre-offers we are already expecting
* build: build numbers and version name update
* feat: handle discarding pending calls from linked devices
* feat: add signing props to release config build
* docs: fix comment on time being 300s (5m) instead of 30s
* feat: adding call messages for incoming/outgoing/missed
* refactor: handle in-thread call notifications better and replace deny button intent with denyCallIntent instead of hangup
* feat: add a hangup via data channel message
* feat: process microphone enabled events and remove debuggable from build.gradle
* feat: add first call notification
* refactor: set the buttons to match iOS in terms of enable disable and colours
* refactor: change the call logos in control messages
* refactor: more bluetooth improvements
* refactor: move start ringer and init of audio manager to CallManager.kt and string fix up
* build: remove debuggable for release build
* refactor: replace call icons
* feat: adding a call time display
* refactor: change the call time to update every second
* refactor: testing out the full screen intents
* refactor: wrapper use corrected session description, set title to recipient displayName, indicate session calls
* fix: crash on view with a parent already attached
* refactor: aspect ratio fit preserved
* refactor: add wantsToAnswer ability in pre-init for fullscreenintent
* refactor: prevent calls from non hasSent participants
* build: update gradle code
* refactor: replace timeout schedule with a seconds count
* fix: various bug fixes for calls
* fix: remove end call from busy
* refactor: use answerCall instead of manual intent building again
* build: new version
* feat: add silenced notifications for call notification builder. check pre-offer and connecting state for pending connection
* build: update build number
* fix: text color uses overridden style value
* fix: remove wrap content for renderers and look more at recovering from network switches
* build: update build number
* refactor: remove whitespace
* build: update build number
* refactor: used shared number for BatchMessageReceiveJob.kt parameter across pollers
* fix: glide in update crash
* fix: bug fixes for self-send answer / hangup messages
* build: update build number
* build: update build.gradle number
* refactor: compile errors and refactoring to view binding
* fix: set the content to binding.root view
* build: increase build number
* build: update build numbers
* feat: adding base for rotation and picking random subset of turn servers
* feat: starting the screen rotation processing
* feat: setting up rotation for the remote render view
* refactor: applying rotation and mirroring based on front / rear cameras that wraps nicely, only scale reworking needed
* refactor: calls video stretching but consistent
* refactor: state machine and tests for the transition events
* feat: new call state processing
* refactor: adding reconnecting logic and visuals
* feat: state machine reconnect logic wip
* feat: add reconnecting and merge fixes
* feat: check new session based off current state
* feat: reconnection logic works correctly now
* refactor: reduce TIMEOUT_SECONDS to 30 from 90
* feat: reset peer connection on DC to prevent ICE messages from old connection or stale state in reconnecting
* refactor: add null case
* fix: set approved on new outgoing threads, use approved more deeply and invalidate the options menu on recipient modified. Add approvedMe flag toggles for visible message receive
* fix: add name update in action bar on modified, change where approvedMe is set
* build: increment build number
* build: update build number
* fix: merge compile errors and increment build number
* refactor: remove negotiation based on which party dropped connection
* refactor: call reconnection improvement tested cross platform to re-establish
* refactor: failed and disconnect events only handled if either the reconnect or the timeout runnables are not set
* build: update version number
* fix: reduce timeout
* fix: fixes the incoming hangup logic for linked devices
* refactor: match iOS styling for call activity closer
* chore: upgrade build numbers
* feat: add in call settings dialog for if calls is disabled in conversation
* feat: add a first call missed control message and info popup with link to privacy settings
* fix: looking at crash for specific large transaction in NotificationManager
* refactor: removing the people in case transaction size reduces to fix notif crash
* fix: comment out the entire send multiple to see if it fixes the issue
* refactor: revert to including the full notification process in a try/catch to handle weird responses from NotificationManager
* fix: add in notification settings prompt for calls and try to fall back to dirty full screen intent / start activity if we're allowed
* build: upgrade build number
2022-04-19 06:25:40 +02:00
public long getThreadIdIfExistsFor ( Recipient recipient ) {
return getThreadIdIfExistsFor ( recipient . getAddress ( ) . serialize ( ) ) ;
}
2020-11-20 08:59:13 +01:00
public long getOrCreateThreadIdFor ( Recipient recipient ) {
return getOrCreateThreadIdFor ( recipient , DistributionTypes . DEFAULT ) ;
2013-04-26 03:59:49 +02:00
}
Performance improvements and bug fixes (#869)
* refactor: fail on testSnode instead of recursively using up snode list. add call timeout on http client
* refactor: refactoring batch message receives and pollers
* refactor: reduce thread utils pool count to a 2 thread fixed pool. Do a check against pubkey instead of room names for oxenHostedOpenGroup
* refactor: caching lib with potential loader fixes and no-cache for giphy
* refactor: remove store and instead use ConcurrentHashMap with a backing update coroutine
* refactor: queue trim thread jobs instead of add every message processed
* fix: wrapping auth token and initial sync for open groups in a threadutils queued runnable, getting initial sync times down
* fix: fixing the user contacts cache in ConversationAdapter.kt
* refactor: improve polling and initial sync, move group joins from config messages into a background job fetching image.
* refactor: improving the job queuing for open groups, replacing placeholder avatar generation with a custom glide loader and archiving initial sync of open groups
* feat: add OpenGroupDeleteJob.kt
* feat: add open group delete job to process deletions after batch adding
* feat: add vacuum and fix job queue re-adding jobs forever, only try to set message hash values in DB if they have changed
* refactor: remove redundant inflation for profile image views throughout app
* refactor(wip): reducing layout inflation and starting to refactor the open group deletion issues taking a long time
* refactor(wip): refactoring group deletion to not iterate through and delete messages individually
* refactor(wip): refactoring group deletion to not iterate through and delete messages individually
* fix: group deletion optimisation
* build: bump build number
* build: bump build number and fix batch message receive retry logic
* fix: clear out open group deletes
* fix: update visible ConversationAdapter.kt binding for initial contact fetching and better traces for debugging background jobs
* fix: add in check for / force sync latest encryption key pair from linked devices if we already have that closed group
* Rename .java to .kt
* refactor: change MmsDatabase to kotlin to make list operations easier
* fix: nullable type
* fix: compilation issues and constants in .kt instead of .java
* fix: bug fix expiration timer on closed group recipient
* feat: use the job queue properly across executors
* feat: start on open group dispatcher-specific logic, probably a queue factory based on openGroupId if that is the same across new message and deletion jobs to ensure consistent entry and removal
* refactor: removing redundant code and fixing jobqueue per opengroup
* fix: allow attachments in note to self
* fix: make the minWidth in quote view bind max of text / title and body, wrapped ?
* fix: fixing up layouts and code view layouts
* fix: remove TODO, remove timestamp binding
* feat: fix view logic, avatars and padding, downloading attachments lazily (on bind), fixing potential crash, add WindowDebouncer.kt
* fix: NPE on viewModel recipient from removed thread while tearing down the Recipient observer in ConversationActivityV2.kt
* refactor: replace conversation notification debouncer handler with handlerthread, same as conversation list debouncer
* refactor: UI for groups and poller improvements
* fix: revert some changes in poller
* feat: add header back in for message requests
* refactor: remove Trace calls, add more conditions to the HomeDiffUtil for updating more efficiently
* feat: try update the home adapter if we get a profile picture modified event
* feat: bump build numbers
* fix: try to start with list in homeViewModel if we don't have already, render quotes to be width of attachment slide view instead of fixed
* fix: set channel to be conflated instead of no buffer
* fix: set unreads based off last local user message vs incrementing unreads to be all amount
* feat: add profile update flag, update build number
* fix: link preview thumbnails download on bind
* fix: centercrop placeholder in glide request
* feat: recycle the contact selection list and profile image in unbind
* fix: try to prevent user KP crash at weird times
* fix: remove additional log, improve attachment download success rate, fix share logs dialog issue
2022-06-08 09:12:34 +02:00
public void setThreadArchived ( long threadId ) {
ContentValues contentValues = new ContentValues ( 1 ) ;
contentValues . put ( ARCHIVED , 1 ) ;
databaseHelper . getWritableDatabase ( ) . update ( TABLE_NAME , contentValues , ID_WHERE ,
new String [ ] { String . valueOf ( threadId ) } ) ;
notifyConversationListListeners ( ) ;
notifyConversationListeners ( threadId ) ;
}
2020-11-20 08:59:13 +01:00
public long getOrCreateThreadIdFor ( Recipient recipient , int distributionType ) {
2017-07-26 18:59:15 +02:00
SQLiteDatabase db = databaseHelper . getReadableDatabase ( ) ;
2017-08-01 17:56:00 +02:00
String where = ADDRESS + " = ? " ;
String [ ] recipientsArg = new String [ ] { recipient . getAddress ( ) . serialize ( ) } ;
2017-07-26 18:59:15 +02:00
Cursor cursor = null ;
2012-09-10 01:10:46 +02:00
2011-12-20 19:20:44 +01:00
try {
cursor = db . query ( TABLE_NAME , new String [ ] { ID } , where , recipientsArg , null , null , null ) ;
2012-09-10 01:10:46 +02:00
2017-07-26 18:59:15 +02:00
if ( cursor ! = null & & cursor . moveToFirst ( ) ) {
2012-10-01 04:56:29 +02:00
return cursor . getLong ( cursor . getColumnIndexOrThrow ( ID ) ) ;
2017-07-26 18:59:15 +02:00
} else {
2021-10-04 09:51:19 +02:00
DatabaseComponent . get ( context ) . recipientDatabase ( ) . setProfileSharing ( recipient , true ) ;
2017-08-01 17:56:00 +02:00
return createThreadForRecipient ( recipient . getAddress ( ) , recipient . isGroupRecipient ( ) , distributionType ) ;
2017-07-26 18:59:15 +02:00
}
2011-12-20 19:20:44 +01:00
} finally {
if ( cursor ! = null )
2012-10-01 04:56:29 +02:00
cursor . close ( ) ;
2011-12-20 19:20:44 +01:00
}
}
2012-09-10 01:10:46 +02:00
2017-08-01 17:56:00 +02:00
public @Nullable Recipient getRecipientForThreadId ( long threadId ) {
2019-12-04 01:28:12 +01:00
if ( addressCache . containsKey ( threadId ) & & addressCache . get ( threadId ) ! = null ) {
return Recipient . from ( context , addressCache . get ( threadId ) , false ) ;
}
2013-02-10 00:17:55 +01:00
SQLiteDatabase db = databaseHelper . getReadableDatabase ( ) ;
Cursor cursor = null ;
try {
cursor = db . query ( TABLE_NAME , null , ID + " = ? " , new String [ ] { threadId + " " } , null , null , null ) ;
if ( cursor ! = null & & cursor . moveToFirst ( ) ) {
2021-02-17 06:09:36 +01:00
Address address = Address . fromSerialized ( cursor . getString ( cursor . getColumnIndexOrThrow ( ADDRESS ) ) ) ;
2019-12-04 01:28:12 +01:00
addressCache . put ( threadId , address ) ;
2017-08-22 03:32:38 +02:00
return Recipient . from ( context , address , false ) ;
2013-02-10 00:17:55 +01:00
}
} finally {
if ( cursor ! = null )
cursor . close ( ) ;
}
return null ;
}
2017-08-19 02:28:56 +02:00
public void setHasSent ( long threadId , boolean hasSent ) {
ContentValues contentValues = new ContentValues ( 1 ) ;
contentValues . put ( HAS_SENT , hasSent ? 1 : 0 ) ;
databaseHelper . getWritableDatabase ( ) . update ( TABLE_NAME , contentValues , ID_WHERE ,
new String [ ] { String . valueOf ( threadId ) } ) ;
notifyConversationListeners ( threadId ) ;
}
2015-11-24 00:07:41 +01:00
public boolean update ( long threadId , boolean unarchive ) {
2021-10-04 09:51:19 +02:00
MmsSmsDatabase mmsSmsDatabase = DatabaseComponent . get ( context ) . mmsSmsDatabase ( ) ;
2011-12-20 19:20:44 +01:00
long count = mmsSmsDatabase . getConversationCount ( threadId ) ;
2012-09-10 01:10:46 +02:00
2021-05-20 07:43:29 +02:00
boolean shouldDeleteEmptyThread = deleteThreadOnEmpty ( threadId ) ;
2021-03-05 03:17:08 +01:00
2021-05-20 07:43:29 +02:00
if ( count = = 0 & & shouldDeleteEmptyThread ) {
2011-12-20 19:20:44 +01:00
deleteThread ( threadId ) ;
notifyConversationListListeners ( ) ;
2015-03-31 22:36:04 +02:00
return true ;
2011-12-20 19:20:44 +01:00
}
2012-09-10 01:10:46 +02:00
2013-04-26 20:23:43 +02:00
MmsSmsDatabase . Reader reader = null ;
2012-09-10 01:10:46 +02:00
2011-12-20 19:20:44 +01:00
try {
2014-06-12 17:59:54 +02:00
reader = mmsSmsDatabase . readerFor ( mmsSmsDatabase . getConversationSnippet ( threadId ) ) ;
2021-08-12 06:14:37 +02:00
MessageRecord record = null ;
if ( reader ! = null ) {
record = reader . getNext ( ) ;
while ( record ! = null & & record . isDeleted ( ) ) {
record = reader . getNext ( ) ;
}
}
if ( record ! = null & & ! record . isDeleted ( ) ) {
2018-06-21 01:37:14 +02:00
updateThread ( threadId , count , getFormattedBodyFor ( record ) , getAttachmentUriFor ( record ) ,
2017-09-16 07:38:53 +02:00
record . getTimestamp ( ) , record . getDeliveryStatus ( ) , record . getDeliveryReceiptCount ( ) ,
record . getType ( ) , unarchive , record . getExpiresIn ( ) , record . getReadReceiptCount ( ) ) ;
2015-03-31 22:36:04 +02:00
notifyConversationListListeners ( ) ;
return false ;
2012-10-01 04:56:29 +02:00
} else {
2021-05-20 07:43:29 +02:00
if ( shouldDeleteEmptyThread ) {
deleteThread ( threadId ) ;
notifyConversationListListeners ( ) ;
return true ;
}
return false ;
2012-10-01 04:56:29 +02:00
}
2011-12-20 19:20:44 +01:00
} finally {
2013-04-26 20:23:43 +02:00
if ( reader ! = null )
reader . close ( ) ;
2011-12-20 19:20:44 +01:00
}
}
2013-01-10 06:06:56 +01:00
2021-12-10 00:18:56 +01:00
public void setPinned ( long threadId , boolean pinned ) {
ContentValues contentValues = new ContentValues ( 1 ) ;
contentValues . put ( IS_PINNED , pinned ? 1 : 0 ) ;
databaseHelper . getWritableDatabase ( ) . update ( TABLE_NAME , contentValues , ID_WHERE ,
new String [ ] { String . valueOf ( threadId ) } ) ;
notifyConversationListeners ( threadId ) ;
}
2022-01-16 18:02:39 +01:00
public void markAllAsRead ( long threadId , boolean isGroupRecipient ) {
List < MarkedMessageInfo > messages = setRead ( threadId , true ) ;
if ( isGroupRecipient ) {
for ( MarkedMessageInfo message : messages ) {
MarkReadReceiver . scheduleDeletion ( context , message . getExpirationInfo ( ) ) ;
}
} else {
MarkReadReceiver . process ( context , messages ) ;
}
ApplicationContext . getInstance ( context ) . messageNotifier . updateNotification ( context , false , 0 ) ;
}
2021-05-20 07:43:29 +02:00
private boolean deleteThreadOnEmpty ( long threadId ) {
Recipient threadRecipient = getRecipientForThreadId ( threadId ) ;
return threadRecipient ! = null & & ! threadRecipient . isOpenGroupRecipient ( ) ;
}
2018-06-21 01:37:14 +02:00
private @NonNull String getFormattedBodyFor ( @NonNull MessageRecord messageRecord ) {
2020-09-02 08:59:52 +02:00
if ( messageRecord . isMms ( ) ) {
MmsMessageRecord record = ( MmsMessageRecord ) messageRecord ;
if ( record . getSharedContacts ( ) . size ( ) > 0 ) {
Contact contact = ( ( MmsMessageRecord ) messageRecord ) . getSharedContacts ( ) . get ( 0 ) ;
return ContactUtil . getStringSummary ( context , contact ) . toString ( ) ;
}
2020-09-03 06:41:00 +02:00
String attachmentString = record . getSlideDeck ( ) . getBody ( ) ;
if ( ! attachmentString . isEmpty ( ) ) {
if ( ! messageRecord . getBody ( ) . isEmpty ( ) ) {
attachmentString = attachmentString + " : " + messageRecord . getBody ( ) ;
}
return attachmentString ;
}
2018-06-21 01:37:14 +02:00
}
return messageRecord . getBody ( ) ;
}
2015-10-16 22:59:40 +02:00
private @Nullable Uri getAttachmentUriFor ( MessageRecord record ) {
2021-05-31 07:53:25 +02:00
if ( ! record . isMms ( ) | | record . isMmsNotification ( ) ) return null ;
2015-10-16 22:59:40 +02:00
SlideDeck slideDeck = ( ( MediaMmsMessageRecord ) record ) . getSlideDeck ( ) ;
Slide thumbnail = slideDeck . getThumbnailSlide ( ) ;
2019-04-17 16:21:30 +02:00
if ( thumbnail ! = null ) {
return thumbnail . getThumbnailUri ( ) ;
}
return null ;
2015-10-16 22:59:40 +02:00
}
2017-11-17 00:21:46 +01:00
private @NonNull String createQuery ( @NonNull String where , int limit ) {
2017-09-15 19:36:33 +02:00
String projection = Util . join ( COMBINED_THREAD_RECIPIENT_GROUP_PROJECTION , " , " ) ;
2017-11-17 00:21:46 +01:00
String query =
" SELECT " + projection + " FROM " + TABLE_NAME +
2017-09-15 19:36:33 +02:00
" LEFT OUTER JOIN " + RecipientDatabase . TABLE_NAME +
" ON " + TABLE_NAME + " . " + ADDRESS + " = " + RecipientDatabase . TABLE_NAME + " . " + RecipientDatabase . ADDRESS +
" LEFT OUTER JOIN " + GroupDatabase . TABLE_NAME +
2021-12-07 05:39:31 +01:00
" ON " + TABLE_NAME + " . " + ADDRESS + " = " + GroupDatabase . TABLE_NAME + " . " + GROUP_ID +
2017-09-15 19:36:33 +02:00
" WHERE " + where +
2021-12-10 00:18:56 +01:00
" ORDER BY " + TABLE_NAME + " . " + IS_PINNED + " DESC, " + TABLE_NAME + " . " + DATE + " DESC " ;
2017-11-17 00:21:46 +01:00
if ( limit > 0 ) {
query + = " LIMIT " + limit ;
}
return query ;
2017-09-15 19:36:33 +02:00
}
2022-09-04 13:03:32 +02:00
@NotNull
public List < ThreadRecord > getHttpOxenOpenGroups ( ) {
String where = TABLE_NAME + " . " + ADDRESS + " LIKE ? " ;
String selection = OpenGroupMigrator . HTTP_PREFIX + OpenGroupMigrator . OPEN_GET_SESSION_TRAILING_DOT_ENCODED + " % " ;
SQLiteDatabase db = databaseHelper . getReadableDatabase ( ) ;
String query = createQuery ( where , 0 ) ;
Cursor cursor = db . rawQuery ( query , new String [ ] { selection } ) ;
if ( cursor = = null ) {
return Collections . emptyList ( ) ;
}
List < ThreadRecord > threads = new ArrayList < > ( ) ;
try {
Reader reader = readerFor ( cursor ) ;
ThreadRecord record ;
while ( ( record = reader . getNext ( ) ) ! = null ) {
threads . add ( record ) ;
}
} finally {
cursor . close ( ) ;
}
return threads ;
}
@NotNull
public List < ThreadRecord > getLegacyOxenOpenGroups ( ) {
String where = TABLE_NAME + " . " + ADDRESS + " LIKE ? " ;
String selection = OpenGroupMigrator . LEGACY_GROUP_ENCODED_ID + " % " ;
SQLiteDatabase db = databaseHelper . getReadableDatabase ( ) ;
String query = createQuery ( where , 0 ) ;
Cursor cursor = db . rawQuery ( query , new String [ ] { selection } ) ;
if ( cursor = = null ) {
return Collections . emptyList ( ) ;
}
List < ThreadRecord > threads = new ArrayList < > ( ) ;
try {
Reader reader = readerFor ( cursor ) ;
ThreadRecord record ;
while ( ( record = reader . getNext ( ) ) ! = null ) {
threads . add ( record ) ;
}
} finally {
cursor . close ( ) ;
}
return threads ;
}
@NotNull
public List < ThreadRecord > getHttpsOxenOpenGroups ( ) {
String where = TABLE_NAME + " . " + ADDRESS + " LIKE ? " ;
String selection = OpenGroupMigrator . NEW_GROUP_ENCODED_ID + " % " ;
SQLiteDatabase db = databaseHelper . getReadableDatabase ( ) ;
String query = createQuery ( where , 0 ) ;
Cursor cursor = db . rawQuery ( query , new String [ ] { selection } ) ;
if ( cursor = = null ) {
return Collections . emptyList ( ) ;
}
List < ThreadRecord > threads = new ArrayList < > ( ) ;
try {
Reader reader = readerFor ( cursor ) ;
ThreadRecord record ;
while ( ( record = reader . getNext ( ) ) ! = null ) {
threads . add ( record ) ;
}
} finally {
cursor . close ( ) ;
}
return threads ;
}
public void migrateEncodedGroup ( long threadId , @NotNull String newEncodedGroupId ) {
ContentValues contentValues = new ContentValues ( 1 ) ;
contentValues . put ( ADDRESS , newEncodedGroupId ) ;
SQLiteDatabase db = databaseHelper . getWritableDatabase ( ) ;
db . update ( TABLE_NAME , contentValues , ID_WHERE , new String [ ] { threadId + " " } ) ;
}
public void notifyThreadUpdated ( long threadId ) {
notifyConversationListeners ( threadId ) ;
}
2017-11-14 03:01:05 +01:00
public interface ProgressListener {
void onProgress ( int complete , int total ) ;
2013-01-10 06:06:56 +01: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 21:22:04 +02:00
2018-01-25 04:17:44 +01:00
public Reader readerFor ( Cursor cursor ) {
return new Reader ( cursor ) ;
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 21:22:04 +02:00
}
2018-04-07 03:15:24 +02:00
public class Reader implements Closeable {
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 21:22:04 +02:00
2018-01-25 04:17:44 +01:00
private final Cursor cursor ;
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 21:22:04 +02:00
2018-01-25 04:17:44 +01:00
public Reader ( Cursor cursor ) {
this . cursor = cursor ;
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 21:22:04 +02:00
}
public ThreadRecord getNext ( ) {
if ( cursor = = null | | ! cursor . moveToNext ( ) )
return null ;
return getCurrent ( ) ;
}
public ThreadRecord getCurrent ( ) {
2017-08-16 06:03:31 +02:00
long threadId = cursor . getLong ( cursor . getColumnIndexOrThrow ( ThreadDatabase . ID ) ) ;
int distributionType = cursor . getInt ( cursor . getColumnIndexOrThrow ( ThreadDatabase . TYPE ) ) ;
2021-02-17 06:09:36 +01:00
Address address = Address . fromSerialized ( cursor . getString ( cursor . getColumnIndexOrThrow ( ThreadDatabase . ADDRESS ) ) ) ;
2017-08-16 06:03:31 +02:00
2017-08-22 03:47:37 +02:00
Optional < RecipientSettings > settings ;
Optional < GroupRecord > groupRecord ;
2017-08-16 06:03:31 +02:00
2017-11-13 18:11:58 +01:00
if ( distributionType ! = DistributionTypes . ARCHIVE & & distributionType ! = DistributionTypes . INBOX_ZERO ) {
2021-10-04 09:51:19 +02:00
settings = DatabaseComponent . get ( context ) . recipientDatabase ( ) . getRecipientSettings ( cursor ) ;
groupRecord = DatabaseComponent . get ( context ) . groupDatabase ( ) . getGroup ( cursor ) ;
2017-08-16 06:03:31 +02:00
} else {
2017-08-22 03:47:37 +02:00
settings = Optional . absent ( ) ;
2017-08-16 06:03:31 +02:00
groupRecord = Optional . absent ( ) ;
}
2021-08-03 05:35:38 +02:00
Recipient recipient = Recipient . from ( context , address , settings , groupRecord , true ) ;
2018-02-02 03:29:09 +01:00
String body = cursor . getString ( cursor . getColumnIndexOrThrow ( ThreadDatabase . SNIPPET ) ) ;
2017-09-16 07:38:53 +02:00
long date = cursor . getLong ( cursor . getColumnIndexOrThrow ( ThreadDatabase . DATE ) ) ;
long count = cursor . getLong ( cursor . getColumnIndexOrThrow ( ThreadDatabase . MESSAGE_COUNT ) ) ;
2017-11-14 03:01:05 +01:00
int unreadCount = cursor . getInt ( cursor . getColumnIndexOrThrow ( ThreadDatabase . UNREAD_COUNT ) ) ;
2017-09-16 07:38:53 +02:00
long type = cursor . getLong ( cursor . getColumnIndexOrThrow ( ThreadDatabase . SNIPPET_TYPE ) ) ;
2022-02-07 07:06:27 +01:00
boolean archived = cursor . getInt ( cursor . getColumnIndexOrThrow ( ThreadDatabase . ARCHIVED ) ) ! = 0 ;
2017-09-16 07:38:53 +02:00
int status = cursor . getInt ( cursor . getColumnIndexOrThrow ( ThreadDatabase . STATUS ) ) ;
int deliveryReceiptCount = cursor . getInt ( cursor . getColumnIndexOrThrow ( ThreadDatabase . DELIVERY_RECEIPT_COUNT ) ) ;
int readReceiptCount = cursor . getInt ( cursor . getColumnIndexOrThrow ( ThreadDatabase . READ_RECEIPT_COUNT ) ) ;
long expiresIn = cursor . getLong ( cursor . getColumnIndexOrThrow ( ThreadDatabase . EXPIRES_IN ) ) ;
long lastSeen = cursor . getLong ( cursor . getColumnIndexOrThrow ( ThreadDatabase . LAST_SEEN ) ) ;
Uri snippetUri = getSnippetUri ( cursor ) ;
2022-02-07 07:06:27 +01:00
boolean pinned = cursor . getInt ( cursor . getColumnIndexOrThrow ( ThreadDatabase . IS_PINNED ) ) ! = 0 ;
2017-09-16 07:38:53 +02:00
if ( ! TextSecurePreferences . isReadReceiptsEnabled ( context ) ) {
readReceiptCount = 0 ;
}
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 21:22:04 +02:00
2019-03-13 22:28:16 +01:00
return new ThreadRecord ( body , snippetUri , recipient , date , count ,
2017-11-14 03:01:05 +01:00
unreadCount , threadId , deliveryReceiptCount , status , type ,
2021-12-10 00:18:56 +01:00
distributionType , archived , expiresIn , lastSeen , readReceiptCount , pinned ) ;
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 21:22:04 +02:00
}
2015-10-16 22:59:40 +02:00
private @Nullable Uri getSnippetUri ( Cursor cursor ) {
if ( cursor . isNull ( cursor . getColumnIndexOrThrow ( ThreadDatabase . SNIPPET_URI ) ) ) {
return null ;
}
try {
return Uri . parse ( cursor . getString ( cursor . getColumnIndexOrThrow ( ThreadDatabase . SNIPPET_URI ) ) ) ;
} catch ( IllegalArgumentException e ) {
Log . w ( TAG , e ) ;
return null ;
}
}
2018-04-07 03:15:24 +02:00
@Override
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 21:22:04 +02:00
public void close ( ) {
2018-04-07 03:15:24 +02:00
if ( cursor ! = null ) {
cursor . close ( ) ;
}
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 21:22:04 +02:00
}
}
2011-12-20 19:20:44 +01:00
}