mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-15 04:18:53 +01:00
Don't add threaded messages to the UI before their parents.
This commit is contained in:
@@ -107,4 +107,8 @@ public class MessageTreeImpl<T extends MessageTree.MessageNode>
|
||||
return orderedList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(MessageId m) {
|
||||
return nodeMap.containsKey(m);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,7 +45,6 @@ import javax.annotation.Nullable;
|
||||
import javax.annotation.concurrent.ThreadSafe;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import static org.briarproject.bramble.api.identity.Author.Status.ANONYMOUS;
|
||||
import static org.briarproject.bramble.api.identity.Author.Status.OURSELVES;
|
||||
import static org.briarproject.briar.api.forum.ForumConstants.KEY_AUTHOR;
|
||||
import static org.briarproject.briar.api.forum.ForumConstants.KEY_ID;
|
||||
@@ -85,9 +84,10 @@ class ForumManagerImpl extends BdfIncomingMessageHook implements ForumManager {
|
||||
|
||||
messageTracker.trackIncomingMessage(txn, m);
|
||||
|
||||
ForumPostHeader post = getForumPostHeader(txn, m.getId(), meta);
|
||||
ForumPostHeader header = getForumPostHeader(txn, m.getId(), meta);
|
||||
String postBody = getPostBody(body);
|
||||
ForumPostReceivedEvent event =
|
||||
new ForumPostReceivedEvent(post, m.getGroupId());
|
||||
new ForumPostReceivedEvent(m.getGroupId(), header, postBody);
|
||||
txn.attach(event);
|
||||
|
||||
// share message
|
||||
@@ -215,14 +215,19 @@ class ForumManagerImpl extends BdfIncomingMessageHook implements ForumManager {
|
||||
public String getPostBody(MessageId m) throws DbException {
|
||||
try {
|
||||
// Parent ID, author, forum post body, signature
|
||||
BdfList message = clientHelper.getMessageAsList(m);
|
||||
if (message == null) throw new DbException();
|
||||
return message.getString(2);
|
||||
BdfList body = clientHelper.getMessageAsList(m);
|
||||
if (body == null) throw new DbException();
|
||||
return getPostBody(body);
|
||||
} catch (FormatException e) {
|
||||
throw new DbException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private String getPostBody(BdfList body) throws FormatException {
|
||||
// Parent ID, author, forum post body, signature
|
||||
return body.getString(2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ForumPostHeader> getPostHeaders(GroupId g)
|
||||
throws DbException {
|
||||
@@ -294,24 +299,17 @@ class ForumManagerImpl extends BdfIncomingMessageHook implements ForumManager {
|
||||
throws DbException, FormatException {
|
||||
|
||||
long timestamp = meta.getLong(KEY_TIMESTAMP);
|
||||
Author author = null;
|
||||
Status status = ANONYMOUS;
|
||||
MessageId parentId = null;
|
||||
if (meta.containsKey(KEY_PARENT))
|
||||
parentId = new MessageId(meta.getRaw(KEY_PARENT));
|
||||
// TODO: Remove support for anonymous forum posts
|
||||
BdfDictionary d1 = meta.getDictionary(KEY_AUTHOR, null);
|
||||
if (d1 != null) {
|
||||
AuthorId authorId = new AuthorId(d1.getRaw(KEY_ID));
|
||||
String name = d1.getString(KEY_NAME);
|
||||
byte[] publicKey = d1.getRaw(KEY_PUBLIC_NAME);
|
||||
author = new Author(authorId, name, publicKey);
|
||||
if (statuses.containsKey(authorId)) {
|
||||
status = statuses.get(authorId);
|
||||
} else {
|
||||
status = identityManager.getAuthorStatus(txn, author.getId());
|
||||
}
|
||||
}
|
||||
BdfDictionary authorDict = meta.getDictionary(KEY_AUTHOR);
|
||||
AuthorId authorId = new AuthorId(authorDict.getRaw(KEY_ID));
|
||||
String name = authorDict.getString(KEY_NAME);
|
||||
byte[] publicKey = authorDict.getRaw(KEY_PUBLIC_NAME);
|
||||
Author author = new Author(authorId, name, publicKey);
|
||||
Status status = statuses.get(authorId);
|
||||
if (status == null)
|
||||
status = identityManager.getAuthorStatus(txn, author.getId());
|
||||
boolean read = meta.getBoolean(MSG_KEY_READ);
|
||||
|
||||
return new ForumPostHeader(id, parentId, timestamp, author, status,
|
||||
|
||||
@@ -307,16 +307,20 @@ class PrivateGroupManagerImpl extends BdfIncomingMessageHook
|
||||
@Override
|
||||
public String getMessageBody(MessageId m) throws DbException {
|
||||
try {
|
||||
// type(0), member_name(1), member_public_key(2), parent_id(3),
|
||||
// previous_message_id(4), content(5), signature(6)
|
||||
BdfList body = clientHelper.getMessageAsList(m);
|
||||
if (body == null) throw new DbException();
|
||||
return body.getString(5);
|
||||
return getMessageBody(body);
|
||||
} catch (FormatException e) {
|
||||
throw new DbException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private String getMessageBody(BdfList body) throws FormatException {
|
||||
// type(0), member_name(1), member_public_key(2), parent_id(3),
|
||||
// previous_message_id(4), content(5), signature(6)
|
||||
return body.getString(5);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<GroupMessageHeader> getHeaders(GroupId g)
|
||||
throws DbException {
|
||||
@@ -579,21 +583,20 @@ class PrivateGroupManagerImpl extends BdfIncomingMessageHook
|
||||
private void attachGroupMessageAddedEvent(Transaction txn, Message m,
|
||||
BdfDictionary meta, boolean local)
|
||||
throws DbException, FormatException {
|
||||
GroupMessageHeader h =
|
||||
getGroupMessageHeader(txn, m.getGroupId(), m.getId(), meta,
|
||||
Collections.<AuthorId, Status>emptyMap());
|
||||
Event e = new GroupMessageAddedEvent(m.getGroupId(), h, local);
|
||||
txn.attach(e);
|
||||
GroupMessageHeader header = getGroupMessageHeader(txn, m.getGroupId(),
|
||||
m.getId(), meta, Collections.<AuthorId, Status>emptyMap());
|
||||
String body = getMessageBody(clientHelper.toList(m));
|
||||
txn.attach(new GroupMessageAddedEvent(m.getGroupId(), header, body,
|
||||
local));
|
||||
}
|
||||
|
||||
private void attachJoinMessageAddedEvent(Transaction txn, Message m,
|
||||
BdfDictionary meta, boolean local, Visibility v)
|
||||
throws DbException, FormatException {
|
||||
JoinMessageHeader h =
|
||||
getJoinMessageHeader(txn, m.getGroupId(), m.getId(), meta,
|
||||
Collections.<AuthorId, Status>emptyMap(), v);
|
||||
Event e = new GroupMessageAddedEvent(m.getGroupId(), h, local);
|
||||
txn.attach(e);
|
||||
JoinMessageHeader header = getJoinMessageHeader(txn, m.getGroupId(),
|
||||
m.getId(), meta, Collections.<AuthorId, Status>emptyMap(), v);
|
||||
txn.attach(new GroupMessageAddedEvent(m.getGroupId(), header, "",
|
||||
local));
|
||||
}
|
||||
|
||||
private void addMember(Transaction txn, GroupId g, Author a, Visibility v)
|
||||
|
||||
Reference in New Issue
Block a user