mirror of
https://github.com/oxen-io/session-android.git
synced 2025-10-25 12:08:36 +00:00
Refactor group messaging protocol.
// FREEBIE
This commit is contained in:
@@ -66,12 +66,16 @@ public class GroupDatabase extends Database {
|
||||
super(context, databaseHelper);
|
||||
}
|
||||
|
||||
public Reader getGroup(byte[] groupId) {
|
||||
public GroupRecord getGroup(byte[] groupId) {
|
||||
Cursor cursor = databaseHelper.getReadableDatabase().query(TABLE_NAME, null, GROUP_ID + " = ?",
|
||||
new String[] {GroupUtil.getEncodedId(groupId)},
|
||||
null, null, null);
|
||||
|
||||
return new Reader(cursor);
|
||||
Reader reader = new Reader(cursor);
|
||||
GroupRecord record = reader.getNext();
|
||||
|
||||
reader.close();
|
||||
return record;
|
||||
}
|
||||
|
||||
public Recipients getGroupMembers(byte[] groupId) {
|
||||
@@ -107,7 +111,6 @@ public class GroupDatabase extends Database {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ContentValues contentValues = new ContentValues();
|
||||
contentValues.put(GROUP_ID, GroupUtil.getEncodedId(groupId));
|
||||
contentValues.put(OWNER, owner);
|
||||
|
||||
@@ -532,9 +532,8 @@ public class MmsDatabase extends Database implements MmsSmsColumns {
|
||||
}
|
||||
|
||||
if (message.isGroup()) {
|
||||
if (((OutgoingGroupMediaMessage)message).isGroupAdd()) type |= Types.GROUP_ADD_MEMBERS_BIT;
|
||||
if (((OutgoingGroupMediaMessage)message).isGroupUpdate()) type |= Types.GROUP_UPDATE_BIT;
|
||||
else if (((OutgoingGroupMediaMessage)message).isGroupQuit()) type |= Types.GROUP_QUIT_BIT;
|
||||
else if (((OutgoingGroupMediaMessage)message).isGroupModify()) type |= Types.GROUP_MODIFY_BIT;
|
||||
}
|
||||
|
||||
SendReq sendRequest = new SendReq();
|
||||
|
||||
@@ -41,9 +41,8 @@ public interface MmsSmsColumns {
|
||||
protected static final long PUSH_MESSAGE_BIT = 0x200000;
|
||||
|
||||
// Group Message Information
|
||||
protected static final long GROUP_ADD_MEMBERS_BIT = 0x10000;
|
||||
protected static final long GROUP_QUIT_BIT = 0x20000;
|
||||
protected static final long GROUP_MODIFY_BIT = 0x40000;
|
||||
protected static final long GROUP_UPDATE_BIT = 0x10000;
|
||||
protected static final long GROUP_QUIT_BIT = 0x20000;
|
||||
|
||||
// Encrypted Storage Information
|
||||
protected static final long ENCRYPTION_MASK = 0xFF000000;
|
||||
@@ -116,12 +115,8 @@ public interface MmsSmsColumns {
|
||||
return (type & KEY_EXCHANGE_IDENTITY_UPDATE_BIT) != 0;
|
||||
}
|
||||
|
||||
public static boolean isGroupAdd(long type) {
|
||||
return (type & GROUP_ADD_MEMBERS_BIT) != 0;
|
||||
}
|
||||
|
||||
public static boolean isGroupModify(long type) {
|
||||
return (type & GROUP_MODIFY_BIT) != 0;
|
||||
public static boolean isGroupUpdate(long type) {
|
||||
return (type & GROUP_UPDATE_BIT) != 0;
|
||||
}
|
||||
|
||||
public static boolean isGroupQuit(long type) {
|
||||
|
||||
@@ -262,9 +262,8 @@ public class SmsDatabase extends Database implements MmsSmsColumns {
|
||||
type |= Types.ENCRYPTION_REMOTE_BIT;
|
||||
} else if (message.isGroup()) {
|
||||
type |= Types.SECURE_MESSAGE_BIT;
|
||||
if (((IncomingGroupMessage)message).isAdd()) type |= Types.GROUP_ADD_MEMBERS_BIT;
|
||||
if (((IncomingGroupMessage)message).isUpdate()) type |= Types.GROUP_UPDATE_BIT;
|
||||
else if (((IncomingGroupMessage)message).isQuit()) type |= Types.GROUP_QUIT_BIT;
|
||||
else if (((IncomingGroupMessage)message).isModify()) type |= Types.GROUP_MODIFY_BIT;
|
||||
} else if (message.isEndSession()) {
|
||||
type |= Types.SECURE_MESSAGE_BIT;
|
||||
type |= Types.END_SESSION_BIT;
|
||||
|
||||
@@ -83,12 +83,8 @@ public abstract class DisplayRecord {
|
||||
return SmsDatabase.Types.isEndSessionType(type);
|
||||
}
|
||||
|
||||
public boolean isGroupAdd() {
|
||||
return SmsDatabase.Types.isGroupAdd(type);
|
||||
}
|
||||
|
||||
public boolean isGroupModify() {
|
||||
return SmsDatabase.Types.isGroupModify(type);
|
||||
public boolean isGroupUpdate() {
|
||||
return SmsDatabase.Types.isGroupUpdate(type);
|
||||
}
|
||||
|
||||
public boolean isGroupQuit() {
|
||||
@@ -96,7 +92,7 @@ public abstract class DisplayRecord {
|
||||
}
|
||||
|
||||
public boolean isGroupAction() {
|
||||
return isGroupAdd() || isGroupModify() || isGroupQuit();
|
||||
return isGroupUpdate() || isGroupQuit();
|
||||
}
|
||||
|
||||
public static class Body {
|
||||
|
||||
@@ -84,12 +84,10 @@ public abstract class MessageRecord extends DisplayRecord {
|
||||
|
||||
@Override
|
||||
public SpannableString getDisplayBody() {
|
||||
if (isGroupAdd()) {
|
||||
return emphasisAdded(context.getString(R.string.ConversationItem_group_action_joined, Util.join(GroupUtil.getSerializedArgumentMembers(getBody().getBody()), ", ")));
|
||||
if (isGroupUpdate()) {
|
||||
return emphasisAdded(GroupUtil.getDescription(getBody().getBody()));
|
||||
} else if (isGroupQuit()) {
|
||||
return emphasisAdded(context.getString(R.string.ConversationItem_group_action_left, getIndividualRecipient().toShortString()));
|
||||
} else if (isGroupModify()) {
|
||||
return emphasisAdded(context.getString(R.string.ConversationItem_group_action_modify, getIndividualRecipient().toShortString()));
|
||||
}
|
||||
|
||||
return new SpannableString(getBody().getBody());
|
||||
|
||||
@@ -56,12 +56,10 @@ public class ThreadRecord extends DisplayRecord {
|
||||
// TODO jake is going to fill these in
|
||||
if (SmsDatabase.Types.isDecryptInProgressType(type)) {
|
||||
return emphasisAdded(context.getString(R.string.MessageDisplayHelper_decrypting_please_wait));
|
||||
} else if (isGroupAdd()) {
|
||||
return emphasisAdded(Util.join(GroupUtil.getSerializedArgumentMembers(getBody().getBody()), ", ") + " have joined the group");
|
||||
} else if (isGroupUpdate()) {
|
||||
return emphasisAdded(GroupUtil.getDescription(getBody().getBody()));
|
||||
} else if (isGroupQuit()) {
|
||||
return emphasisAdded(getRecipients().toShortString() + " left the group.");
|
||||
} else if (isGroupModify()) {
|
||||
return emphasisAdded(getRecipients().toShortString() + " modified the group.");
|
||||
} else if (isKeyExchange()) {
|
||||
return emphasisAdded(context.getString(R.string.ConversationListItem_key_exchange_message));
|
||||
} else if (SmsDatabase.Types.isFailedDecryptType(type)) {
|
||||
|
||||
Reference in New Issue
Block a user