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