mirror of
https://github.com/oxen-io/session-android.git
synced 2025-10-25 00:49:32 +00:00
Log calls to conversations
// FREEBIE
This commit is contained in:
@@ -19,6 +19,10 @@ public interface MmsSmsColumns {
|
||||
// Base Types
|
||||
protected static final long BASE_TYPE_MASK = 0x1F;
|
||||
|
||||
protected static final long INCOMING_CALL_TYPE = 1;
|
||||
protected static final long OUTGOING_CALL_TYPE = 2;
|
||||
protected static final long MISSED_CALL_TYPE = 3;
|
||||
|
||||
protected static final long BASE_INBOX_TYPE = 20;
|
||||
protected static final long BASE_OUTBOX_TYPE = 21;
|
||||
protected static final long BASE_SENDING_TYPE = 22;
|
||||
@@ -150,6 +154,22 @@ public interface MmsSmsColumns {
|
||||
return (type & KEY_EXCHANGE_IDENTITY_UPDATE_BIT) != 0;
|
||||
}
|
||||
|
||||
public static boolean isCallLog(long type) {
|
||||
return type == INCOMING_CALL_TYPE || type == OUTGOING_CALL_TYPE || type == MISSED_CALL_TYPE;
|
||||
}
|
||||
|
||||
public static boolean isIncomingCall(long type) {
|
||||
return type == INCOMING_CALL_TYPE;
|
||||
}
|
||||
|
||||
public static boolean isOutgoingCall(long type) {
|
||||
return type == OUTGOING_CALL_TYPE;
|
||||
}
|
||||
|
||||
public static boolean isMissedCall(long type) {
|
||||
return type == MISSED_CALL_TYPE;
|
||||
}
|
||||
|
||||
public static boolean isGroupUpdate(long type) {
|
||||
return (type & GROUP_UPDATE_BIT) != 0;
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ import android.database.Cursor;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.database.sqlite.SQLiteOpenHelper;
|
||||
import android.database.sqlite.SQLiteStatement;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.telephony.PhoneNumberUtils;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
@@ -343,6 +344,45 @@ public class SmsDatabase extends MessagingDatabase {
|
||||
return new Pair<>(newMessageId, record.getThreadId());
|
||||
}
|
||||
|
||||
public @NonNull Pair<Long, Long> insertReceivedCall(@NonNull String number) {
|
||||
return insertCallLog(number, Types.INCOMING_CALL_TYPE, false);
|
||||
}
|
||||
|
||||
public @NonNull Pair<Long, Long> insertOutgoingCall(@NonNull String number) {
|
||||
return insertCallLog(number, Types.OUTGOING_CALL_TYPE, false);
|
||||
}
|
||||
|
||||
public @NonNull Pair<Long, Long> insertMissedCall(@NonNull String number) {
|
||||
return insertCallLog(number, Types.MISSED_CALL_TYPE, true);
|
||||
}
|
||||
|
||||
private @NonNull Pair<Long, Long> insertCallLog(@NonNull String number, long type, boolean unread) {
|
||||
Recipients recipients = RecipientFactory.getRecipientsFromString(context, number, true);
|
||||
long threadId = DatabaseFactory.getThreadDatabase(context).getThreadIdFor(recipients);
|
||||
|
||||
ContentValues values = new ContentValues(6);
|
||||
values.put(ADDRESS, number);
|
||||
values.put(ADDRESS_DEVICE_ID, 1);
|
||||
values.put(DATE_RECEIVED, System.currentTimeMillis());
|
||||
values.put(DATE_SENT, System.currentTimeMillis());
|
||||
values.put(READ, unread ? 0 : 1);
|
||||
values.put(TYPE, type);
|
||||
values.put(THREAD_ID, threadId);
|
||||
|
||||
SQLiteDatabase db = databaseHelper.getWritableDatabase();
|
||||
long messageId = db.insert(TABLE_NAME, null, values);
|
||||
|
||||
DatabaseFactory.getThreadDatabase(context).update(threadId);
|
||||
notifyConversationListeners(threadId);
|
||||
jobManager.add(new TrimThreadJob(context, threadId));
|
||||
|
||||
if (unread) {
|
||||
DatabaseFactory.getThreadDatabase(context).setUnread(threadId);
|
||||
}
|
||||
|
||||
return new Pair<>(messageId, threadId);
|
||||
}
|
||||
|
||||
protected Pair<Long, Long> insertMessageInbox(IncomingTextMessage message, long type) {
|
||||
if (message.isPreKeyBundle()) {
|
||||
type |= Types.KEY_EXCHANGE_BIT | Types.KEY_EXCHANGE_BUNDLE_BIT;
|
||||
|
||||
@@ -95,6 +95,22 @@ public abstract class DisplayRecord {
|
||||
return isGroupUpdate() || isGroupQuit();
|
||||
}
|
||||
|
||||
public boolean isCallLog() {
|
||||
return SmsDatabase.Types.isCallLog(type);
|
||||
}
|
||||
|
||||
public boolean isIncomingCall() {
|
||||
return SmsDatabase.Types.isIncomingCall(type);
|
||||
}
|
||||
|
||||
public boolean isOutgoingCall() {
|
||||
return SmsDatabase.Types.isOutgoingCall(type);
|
||||
}
|
||||
|
||||
public boolean isMissedCall() {
|
||||
return SmsDatabase.Types.isMissedCall(type);
|
||||
}
|
||||
|
||||
public static class Body {
|
||||
private final String body;
|
||||
private final boolean plaintext;
|
||||
|
||||
@@ -115,6 +115,12 @@ public abstract class MessageRecord extends DisplayRecord {
|
||||
return emphasisAdded(context.getString(R.string.MessageRecord_left_group));
|
||||
} else if (isGroupQuit()) {
|
||||
return emphasisAdded(context.getString(R.string.ConversationItem_group_action_left, getIndividualRecipient().toShortString()));
|
||||
} else if (isIncomingCall()) {
|
||||
return emphasisAdded(String.format("%s called you", getIndividualRecipient().toShortString()));
|
||||
} else if (isOutgoingCall()) {
|
||||
return emphasisAdded(String.format("Called %s", getIndividualRecipient().toShortString()));
|
||||
} else if (isMissedCall()) {
|
||||
return emphasisAdded(String.format("Missed call from %s", getIndividualRecipient().toShortString()));
|
||||
} else if (getBody().getBody().length() > MAX_DISPLAY_LENGTH) {
|
||||
return new SpannableString(getBody().getBody().substring(0, MAX_DISPLAY_LENGTH));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user