mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-13 11:19:04 +01:00
Remove Visibility from JoinMessageHeader and Item
This commit is contained in:
@@ -2,7 +2,6 @@ package org.briarproject.briar.android.privategroup.conversation;
|
||||
|
||||
import org.briarproject.briar.R;
|
||||
import org.briarproject.briar.api.privategroup.JoinMessageHeader;
|
||||
import org.briarproject.briar.api.privategroup.Visibility;
|
||||
|
||||
import javax.annotation.concurrent.NotThreadSafe;
|
||||
|
||||
@@ -13,12 +12,10 @@ import androidx.annotation.UiThread;
|
||||
@NotThreadSafe
|
||||
class JoinMessageItem extends GroupMessageItem {
|
||||
|
||||
private Visibility visibility;
|
||||
private final boolean isInitial;
|
||||
|
||||
JoinMessageItem(JoinMessageHeader h, String text) {
|
||||
super(h, text);
|
||||
this.visibility = h.getVisibility();
|
||||
this.isInitial = h.isInitial();
|
||||
}
|
||||
|
||||
@@ -33,14 +30,6 @@ class JoinMessageItem extends GroupMessageItem {
|
||||
return R.layout.list_item_group_join_notice;
|
||||
}
|
||||
|
||||
Visibility getVisibility() {
|
||||
return visibility;
|
||||
}
|
||||
|
||||
void setVisibility(Visibility visibility) {
|
||||
this.visibility = visibility;
|
||||
}
|
||||
|
||||
boolean isInitial() {
|
||||
return isInitial;
|
||||
}
|
||||
|
||||
@@ -8,21 +8,14 @@ import javax.annotation.concurrent.Immutable;
|
||||
@NotNullByDefault
|
||||
public class JoinMessageHeader extends GroupMessageHeader {
|
||||
|
||||
private final Visibility visibility;
|
||||
private final boolean isInitial;
|
||||
|
||||
public JoinMessageHeader(GroupMessageHeader h, Visibility visibility,
|
||||
boolean isInitial) {
|
||||
public JoinMessageHeader(GroupMessageHeader h, boolean isInitial) {
|
||||
super(h.getGroupId(), h.getId(), h.getParentId(), h.getTimestamp(),
|
||||
h.getAuthor(), h.getAuthorInfo(), h.isRead());
|
||||
this.visibility = visibility;
|
||||
this.isInitial = isInitial;
|
||||
}
|
||||
|
||||
public Visibility getVisibility() {
|
||||
return visibility;
|
||||
}
|
||||
|
||||
public boolean isInitial() {
|
||||
return isInitial;
|
||||
}
|
||||
|
||||
@@ -145,7 +145,7 @@ class PrivateGroupManagerImpl extends BdfIncomingMessageHook
|
||||
addMember(txn, m.getMessage().getGroupId(), m.getMember(), VISIBLE);
|
||||
setPreviousMsgId(txn, m.getMessage().getGroupId(),
|
||||
m.getMessage().getId());
|
||||
attachJoinMessageAddedEvent(txn, m.getMessage(), meta, true, VISIBLE);
|
||||
attachJoinMessageAddedEvent(txn, m.getMessage(), meta, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -354,16 +354,12 @@ class PrivateGroupManagerImpl extends BdfIncomingMessageHook
|
||||
for (AuthorId id : authors) {
|
||||
authorInfos.put(id, authorManager.getAuthorInfo(txn, id));
|
||||
}
|
||||
// get current visibilities for join messages
|
||||
Map<Author, Visibility> visibilities = getMembers(txn, g);
|
||||
// parse the metadata
|
||||
for (Entry<MessageId, BdfDictionary> entry : metadata.entrySet()) {
|
||||
BdfDictionary meta = entry.getValue();
|
||||
if (meta.getLong(KEY_TYPE) == JOIN.getInt()) {
|
||||
Author member = getAuthor(meta);
|
||||
Visibility v = visibilities.get(member);
|
||||
headers.add(getJoinMessageHeader(txn, g, entry.getKey(),
|
||||
meta, authorInfos, v));
|
||||
meta, authorInfos));
|
||||
} else {
|
||||
headers.add(getGroupMessageHeader(txn, g, entry.getKey(),
|
||||
meta, authorInfos));
|
||||
@@ -401,13 +397,13 @@ class PrivateGroupManagerImpl extends BdfIncomingMessageHook
|
||||
|
||||
private JoinMessageHeader getJoinMessageHeader(Transaction txn, GroupId g,
|
||||
MessageId id, BdfDictionary meta,
|
||||
Map<AuthorId, AuthorInfo> authorInfos, Visibility v)
|
||||
Map<AuthorId, AuthorInfo> authorInfos)
|
||||
throws DbException, FormatException {
|
||||
|
||||
GroupMessageHeader header =
|
||||
getGroupMessageHeader(txn, g, id, meta, authorInfos);
|
||||
boolean creator = meta.getBoolean(KEY_INITIAL_JOIN_MSG);
|
||||
return new JoinMessageHeader(header, v, creator);
|
||||
return new JoinMessageHeader(header, creator);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -556,7 +552,7 @@ class PrivateGroupManagerImpl extends BdfIncomingMessageHook
|
||||
addMember(txn, m.getGroupId(), member, v);
|
||||
// track message and broadcast event
|
||||
messageTracker.trackIncomingMessage(txn, m);
|
||||
attachJoinMessageAddedEvent(txn, m, meta, false, v);
|
||||
attachJoinMessageAddedEvent(txn, m, meta, false);
|
||||
}
|
||||
|
||||
private void handleGroupMessage(Transaction txn, Message m,
|
||||
@@ -606,10 +602,10 @@ class PrivateGroupManagerImpl extends BdfIncomingMessageHook
|
||||
}
|
||||
|
||||
private void attachJoinMessageAddedEvent(Transaction txn, Message m,
|
||||
BdfDictionary meta, boolean local, Visibility v)
|
||||
BdfDictionary meta, boolean local)
|
||||
throws DbException, FormatException {
|
||||
JoinMessageHeader header = getJoinMessageHeader(txn, m.getGroupId(),
|
||||
m.getId(), meta, Collections.emptyMap(), v);
|
||||
m.getId(), meta, Collections.emptyMap());
|
||||
txn.attach(new GroupMessageAddedEvent(m.getGroupId(), header, "",
|
||||
local));
|
||||
}
|
||||
|
||||
@@ -124,10 +124,8 @@ public class PrivateGroupManagerIntegrationTest
|
||||
addGroup();
|
||||
|
||||
// create and add test message with no previousMsgId
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
GroupMessage msg = groupMessageFactory
|
||||
.createGroupMessage(groupId0, clock.currentTimeMillis(), null,
|
||||
author0, "test", null);
|
||||
GroupMessage msg = groupMessageFactory.createGroupMessage(groupId0,
|
||||
clock.currentTimeMillis(), null, author0, "test", null);
|
||||
groupManager0.addLocalMessage(msg);
|
||||
|
||||
// sync test message
|
||||
@@ -342,23 +340,19 @@ public class PrivateGroupManagerIntegrationTest
|
||||
Collection<GroupMember> members0 = groupManager0.getMembers(groupId0);
|
||||
assertEquals(2, members0.size());
|
||||
for (GroupMember m : members0) {
|
||||
if (m.getAuthor().equals(author0)) {
|
||||
assertEquals(VISIBLE, m.getVisibility());
|
||||
} else {
|
||||
if (!m.getAuthor().equals(author0)) {
|
||||
assertEquals(author1, m.getAuthor());
|
||||
assertEquals(VISIBLE, m.getVisibility());
|
||||
}
|
||||
assertEquals(VISIBLE, m.getVisibility());
|
||||
}
|
||||
|
||||
Collection<GroupMember> members1 = groupManager1.getMembers(groupId0);
|
||||
assertEquals(2, members1.size());
|
||||
for (GroupMember m : members1) {
|
||||
if (m.getAuthor().equals(author1)) {
|
||||
assertEquals(VISIBLE, m.getVisibility());
|
||||
} else {
|
||||
if (!m.getAuthor().equals(author1)) {
|
||||
assertEquals(author0, m.getAuthor());
|
||||
assertEquals(VISIBLE, m.getVisibility());
|
||||
}
|
||||
assertEquals(VISIBLE, m.getVisibility());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -368,27 +362,11 @@ public class PrivateGroupManagerIntegrationTest
|
||||
|
||||
Collection<GroupMessageHeader> headers0 =
|
||||
groupManager0.getHeaders(groupId0);
|
||||
for (GroupMessageHeader h : headers0) {
|
||||
if (h instanceof JoinMessageHeader) {
|
||||
JoinMessageHeader j = (JoinMessageHeader) h;
|
||||
// all relationships of the creator are visible
|
||||
assertEquals(VISIBLE, j.getVisibility());
|
||||
}
|
||||
}
|
||||
assertEquals(2, headers0.size());
|
||||
|
||||
Collection<GroupMessageHeader> headers1 =
|
||||
groupManager1.getHeaders(groupId0);
|
||||
for (GroupMessageHeader h : headers1) {
|
||||
if (h instanceof JoinMessageHeader) {
|
||||
JoinMessageHeader j = (JoinMessageHeader) h;
|
||||
if (h.getAuthor().equals(author1))
|
||||
// we are visible to ourselves
|
||||
assertEquals(VISIBLE, j.getVisibility());
|
||||
else
|
||||
// our relationship to the creator is visible
|
||||
assertEquals(VISIBLE, j.getVisibility());
|
||||
}
|
||||
}
|
||||
assertEquals(2, headers1.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -463,34 +441,6 @@ public class PrivateGroupManagerIntegrationTest
|
||||
assertEquals(REVEALED_BY_CONTACT, m.getVisibility());
|
||||
}
|
||||
}
|
||||
|
||||
// assert that join messages reflect revealed relationship
|
||||
Collection<GroupMessageHeader> headers1 =
|
||||
groupManager1.getHeaders(groupId0);
|
||||
for (GroupMessageHeader h : headers1) {
|
||||
if (h instanceof JoinMessageHeader) {
|
||||
JoinMessageHeader j = (JoinMessageHeader) h;
|
||||
if (h.getAuthor().equals(author2))
|
||||
// 1 revealed the relationship to 2
|
||||
assertEquals(REVEALED_BY_US, j.getVisibility());
|
||||
else
|
||||
// 1's other relationship (to 1 and creator) are visible
|
||||
assertEquals(VISIBLE, j.getVisibility());
|
||||
}
|
||||
}
|
||||
Collection<GroupMessageHeader> headers2 =
|
||||
groupManager2.getHeaders(groupId0);
|
||||
for (GroupMessageHeader h : headers2) {
|
||||
if (h instanceof JoinMessageHeader) {
|
||||
JoinMessageHeader j = (JoinMessageHeader) h;
|
||||
if (h.getAuthor().equals(author1))
|
||||
// 2's relationship was revealed by 1
|
||||
assertEquals(REVEALED_BY_CONTACT, j.getVisibility());
|
||||
else
|
||||
// 2's other relationship (to 2 and creator) are visible
|
||||
assertEquals(VISIBLE, j.getVisibility());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user