Fix call info expiry

This commit is contained in:
charles 2022-12-22 15:05:33 +11:00
parent 03766d57ee
commit 6769789e9c

View File

@ -383,35 +383,6 @@ public class SmsDatabase extends MessagingDatabase {
} }
protected Optional<InsertResult> insertMessageInbox(IncomingTextMessage message, long type, long serverTimestamp, boolean runIncrement, boolean runThreadUpdate) { protected Optional<InsertResult> insertMessageInbox(IncomingTextMessage message, long type, long serverTimestamp, boolean runIncrement, boolean runThreadUpdate) {
if (message.isSecureMessage()) {
type |= Types.SECURE_MESSAGE_BIT;
} else if (message.isGroup()) {
type |= Types.SECURE_MESSAGE_BIT;
if (((IncomingGroupMessage)message).isUpdateMessage()) type |= Types.GROUP_UPDATE_MESSAGE_BIT;
}
if (message.isPush()) type |= Types.PUSH_MESSAGE_BIT;
if (message.isOpenGroupInvitation()) type |= Types.OPEN_GROUP_INVITATION_BIT;
CallMessageType callMessageType = message.getCallType();
if (callMessageType != null) {
switch (callMessageType) {
case CALL_OUTGOING:
type |= Types.OUTGOING_CALL_TYPE;
break;
case CALL_INCOMING:
type |= Types.INCOMING_CALL_TYPE;
break;
case CALL_MISSED:
type |= Types.MISSED_CALL_TYPE;
break;
case CALL_FIRST_MISSED:
type |= Types.FIRST_MISSED_CALL_TYPE;
break;
}
}
Recipient recipient = Recipient.from(context, message.getSender(), true); Recipient recipient = Recipient.from(context, message.getSender(), true);
Recipient groupRecipient; Recipient groupRecipient;
@ -430,6 +401,24 @@ public class SmsDatabase extends MessagingDatabase {
if (groupRecipient == null) threadId = DatabaseComponent.get(context).threadDatabase().getOrCreateThreadIdFor(recipient); if (groupRecipient == null) threadId = DatabaseComponent.get(context).threadDatabase().getOrCreateThreadIdFor(recipient);
else threadId = DatabaseComponent.get(context).threadDatabase().getOrCreateThreadIdFor(groupRecipient); else threadId = DatabaseComponent.get(context).threadDatabase().getOrCreateThreadIdFor(groupRecipient);
if (message.isSecureMessage()) {
type |= Types.SECURE_MESSAGE_BIT;
} else if (message.isGroup()) {
type |= Types.SECURE_MESSAGE_BIT;
if (((IncomingGroupMessage)message).isUpdateMessage()) type |= Types.GROUP_UPDATE_MESSAGE_BIT;
}
if (message.isPush()) type |= Types.PUSH_MESSAGE_BIT;
if (message.isOpenGroupInvitation()) type |= Types.OPEN_GROUP_INVITATION_BIT;
CallMessageType callMessageType = message.getCallType();
if (callMessageType != null) {
long callMessageTypeMask = getCallMessageTypeMask(callMessageType);
type |= callMessageTypeMask;
deleteInfoMessages(threadId, callMessageTypeMask);
}
ContentValues values = new ContentValues(6); ContentValues values = new ContentValues(6);
values.put(ADDRESS, message.getSender().serialize()); values.put(ADDRESS, message.getSender().serialize());
values.put(ADDRESS_DEVICE_ID, message.getSenderDeviceId()); values.put(ADDRESS_DEVICE_ID, message.getSenderDeviceId());
@ -479,6 +468,25 @@ public class SmsDatabase extends MessagingDatabase {
} }
} }
private long getCallMessageTypeMask(CallMessageType callMessageType) {
long typeMask = 0;
switch (callMessageType) {
case CALL_OUTGOING:
typeMask = Types.OUTGOING_CALL_TYPE;
break;
case CALL_INCOMING:
typeMask = Types.INCOMING_CALL_TYPE;
break;
case CALL_MISSED:
typeMask = Types.MISSED_CALL_TYPE;
break;
case CALL_FIRST_MISSED:
typeMask = Types.FIRST_MISSED_CALL_TYPE;
break;
}
return typeMask;
}
public Optional<InsertResult> insertMessageInbox(IncomingTextMessage message, boolean runIncrement, boolean runThreadUpdate) { public Optional<InsertResult> insertMessageInbox(IncomingTextMessage message, boolean runIncrement, boolean runThreadUpdate) {
return insertMessageInbox(message, Types.BASE_INBOX_TYPE, 0, runIncrement, runThreadUpdate); return insertMessageInbox(message, Types.BASE_INBOX_TYPE, 0, runIncrement, runThreadUpdate);
} }
@ -618,6 +626,12 @@ public class SmsDatabase extends MessagingDatabase {
return getMessage(messageId); return getMessage(messageId);
} }
public void deleteInfoMessages(long threadId, long type) {
String where = THREAD_ID + " = ? AND (" + TYPE + " & " + type + ") <> 0";
int updated = getWritableDatabase().delete(TABLE_NAME, where, new String[] {threadId+""});
notifyConversationListeners(threadId);
}
private boolean isDuplicate(IncomingTextMessage message, long threadId) { private boolean isDuplicate(IncomingTextMessage message, long threadId) {
SQLiteDatabase database = databaseHelper.getReadableDatabase(); SQLiteDatabase database = databaseHelper.getReadableDatabase();
Cursor cursor = database.query(TABLE_NAME, null, DATE_SENT + " = ? AND " + ADDRESS + " = ? AND " + THREAD_ID + " = ?", Cursor cursor = database.query(TABLE_NAME, null, DATE_SENT + " = ? AND " + ADDRESS + " = ? AND " + THREAD_ID + " = ?",