mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-19 14:19:53 +01:00
Allow to add forum/group posts in transaction
This commit is contained in:
@@ -60,6 +60,12 @@ public interface ForumManager {
|
|||||||
*/
|
*/
|
||||||
ForumPostHeader addLocalPost(ForumPost p) throws DbException;
|
ForumPostHeader addLocalPost(ForumPost p) throws DbException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stores a local forum post.
|
||||||
|
*/
|
||||||
|
ForumPostHeader addLocalPost(Transaction txn, ForumPost p)
|
||||||
|
throws DbException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the forum with the given ID.
|
* Returns the forum with the given ID.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -82,6 +82,12 @@ public interface PrivateGroupManager {
|
|||||||
*/
|
*/
|
||||||
GroupMessageHeader addLocalMessage(GroupMessage p) throws DbException;
|
GroupMessageHeader addLocalMessage(GroupMessage p) throws DbException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stores and sends a local private group message.
|
||||||
|
*/
|
||||||
|
GroupMessageHeader addLocalMessage(Transaction txn, GroupMessage p)
|
||||||
|
throws DbException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the private group with the given ID.
|
* Returns the private group with the given ID.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -126,29 +126,30 @@ class ForumManagerImpl extends BdfIncomingMessageHook implements ForumManager {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ForumPostHeader addLocalPost(ForumPost p) throws DbException {
|
public ForumPostHeader addLocalPost(ForumPost p) throws DbException {
|
||||||
return db.transactionWithResult(false, txn -> {
|
return db.transactionWithResult(false, txn -> addLocalPost(txn, p));
|
||||||
try {
|
|
||||||
return addLocalPost(txn, p);
|
|
||||||
} catch (FormatException e) {
|
|
||||||
throw new AssertionError(e);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private ForumPostHeader addLocalPost(Transaction txn, ForumPost p)
|
@Override
|
||||||
throws DbException, FormatException {
|
public ForumPostHeader addLocalPost(Transaction txn, ForumPost p)
|
||||||
BdfDictionary meta = new BdfDictionary();
|
throws DbException {
|
||||||
meta.put(KEY_TIMESTAMP, p.getMessage().getTimestamp());
|
try {
|
||||||
if (p.getParent() != null) meta.put(KEY_PARENT, p.getParent());
|
BdfDictionary meta = new BdfDictionary();
|
||||||
Author a = p.getAuthor();
|
meta.put(KEY_TIMESTAMP, p.getMessage().getTimestamp());
|
||||||
meta.put(KEY_AUTHOR, clientHelper.toList(a));
|
if (p.getParent() != null) meta.put(KEY_PARENT, p.getParent());
|
||||||
meta.put(KEY_LOCAL, true);
|
Author a = p.getAuthor();
|
||||||
meta.put(MSG_KEY_READ, true);
|
meta.put(KEY_AUTHOR, clientHelper.toList(a));
|
||||||
clientHelper.addLocalMessage(txn, p.getMessage(), meta, true, false);
|
meta.put(KEY_LOCAL, true);
|
||||||
messageTracker.trackOutgoingMessage(txn, p.getMessage());
|
meta.put(MSG_KEY_READ, true);
|
||||||
AuthorInfo authorInfo = authorManager.getMyAuthorInfo(txn);
|
clientHelper
|
||||||
return new ForumPostHeader(p.getMessage().getId(), p.getParent(),
|
.addLocalMessage(txn, p.getMessage(), meta, true, false);
|
||||||
p.getMessage().getTimestamp(), p.getAuthor(), authorInfo, true);
|
messageTracker.trackOutgoingMessage(txn, p.getMessage());
|
||||||
|
AuthorInfo authorInfo = authorManager.getMyAuthorInfo(txn);
|
||||||
|
return new ForumPostHeader(p.getMessage().getId(), p.getParent(),
|
||||||
|
p.getMessage().getTimestamp(), p.getAuthor(), authorInfo,
|
||||||
|
true);
|
||||||
|
} catch (FormatException e) {
|
||||||
|
throw new AssertionError(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -210,34 +210,35 @@ class PrivateGroupManagerImpl extends BdfIncomingMessageHook
|
|||||||
@Override
|
@Override
|
||||||
public GroupMessageHeader addLocalMessage(GroupMessage m)
|
public GroupMessageHeader addLocalMessage(GroupMessage m)
|
||||||
throws DbException {
|
throws DbException {
|
||||||
return db.transactionWithResult(false, txn -> {
|
return db.transactionWithResult(false, txn -> addLocalMessage(txn, m));
|
||||||
try {
|
|
||||||
return addLocalMessage(txn, m);
|
|
||||||
} catch (FormatException e) {
|
|
||||||
throw new DbException(e);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private GroupMessageHeader addLocalMessage(Transaction txn, GroupMessage m)
|
@Override
|
||||||
throws DbException, FormatException {
|
public GroupMessageHeader addLocalMessage(Transaction txn, GroupMessage m)
|
||||||
// store message and metadata
|
throws DbException {
|
||||||
BdfDictionary meta = new BdfDictionary();
|
try {
|
||||||
meta.put(KEY_TYPE, POST.getInt());
|
// store message and metadata
|
||||||
if (m.getParent() != null)
|
BdfDictionary meta = new BdfDictionary();
|
||||||
meta.put(KEY_PARENT_MSG_ID, m.getParent());
|
meta.put(KEY_TYPE, POST.getInt());
|
||||||
addMessageMetadata(meta, m);
|
if (m.getParent() != null)
|
||||||
GroupId g = m.getMessage().getGroupId();
|
meta.put(KEY_PARENT_MSG_ID, m.getParent());
|
||||||
clientHelper.addLocalMessage(txn, m.getMessage(), meta, true, false);
|
addMessageMetadata(meta, m);
|
||||||
// track message
|
GroupId g = m.getMessage().getGroupId();
|
||||||
setPreviousMsgId(txn, g, m.getMessage().getId());
|
clientHelper
|
||||||
messageTracker.trackOutgoingMessage(txn, m.getMessage());
|
.addLocalMessage(txn, m.getMessage(), meta, true, false);
|
||||||
// broadcast event
|
// track message
|
||||||
attachGroupMessageAddedEvent(txn, m.getMessage(), meta, true);
|
setPreviousMsgId(txn, g, m.getMessage().getId());
|
||||||
AuthorInfo authorInfo = authorManager.getMyAuthorInfo(txn);
|
messageTracker.trackOutgoingMessage(txn, m.getMessage());
|
||||||
return new GroupMessageHeader(m.getMessage().getGroupId(),
|
// broadcast event
|
||||||
m.getMessage().getId(), m.getParent(),
|
attachGroupMessageAddedEvent(txn, m.getMessage(), meta, true);
|
||||||
m.getMessage().getTimestamp(), m.getMember(), authorInfo, true);
|
AuthorInfo authorInfo = authorManager.getMyAuthorInfo(txn);
|
||||||
|
return new GroupMessageHeader(m.getMessage().getGroupId(),
|
||||||
|
m.getMessage().getId(), m.getParent(),
|
||||||
|
m.getMessage().getTimestamp(), m.getMember(), authorInfo,
|
||||||
|
true);
|
||||||
|
} catch (FormatException e) {
|
||||||
|
throw new DbException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addMessageMetadata(BdfDictionary meta, GroupMessage m) {
|
private void addMessageMetadata(BdfDictionary meta, GroupMessage m) {
|
||||||
|
|||||||
Reference in New Issue
Block a user