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