Merge branch 'message-terminology' into 'master'

Use "text" to refer to message text

See merge request briar/briar!948
This commit is contained in:
Torsten Grote
2018-10-15 13:22:31 +00:00
145 changed files with 750 additions and 764 deletions

View File

@@ -51,7 +51,7 @@ abstract class BaseControllerImpl extends DbControllerImpl
protected final IdentityManager identityManager; protected final IdentityManager identityManager;
protected final BlogManager blogManager; protected final BlogManager blogManager;
private final Map<MessageId, String> bodyCache = new ConcurrentHashMap<>(); private final Map<MessageId, String> textCache = new ConcurrentHashMap<>();
private final Map<MessageId, BlogPostHeader> headerCache = private final Map<MessageId, BlogPostHeader> headerCache =
new ConcurrentHashMap<>(); new ConcurrentHashMap<>();
@@ -129,17 +129,17 @@ abstract class BaseControllerImpl extends DbControllerImpl
public void loadBlogPost(BlogPostHeader header, public void loadBlogPost(BlogPostHeader header,
ResultExceptionHandler<BlogPostItem, DbException> handler) { ResultExceptionHandler<BlogPostItem, DbException> handler) {
String body = bodyCache.get(header.getId()); String text = textCache.get(header.getId());
if (body != null) { if (text != null) {
LOG.info("Loaded body from cache"); LOG.info("Loaded text from cache");
handler.onResult(new BlogPostItem(header, body)); handler.onResult(new BlogPostItem(header, text));
return; return;
} }
runOnDbThread(() -> { runOnDbThread(() -> {
try { try {
long start = now(); long start = now();
BlogPostItem item = getItem(header); BlogPostItem item = getItem(header);
logDuration(LOG, "Loading body", start); logDuration(LOG, "Loading text", start);
handler.onResult(item); handler.onResult(item);
} catch (DbException e) { } catch (DbException e) {
logException(LOG, WARNING, e); logException(LOG, WARNING, e);
@@ -200,28 +200,28 @@ abstract class BaseControllerImpl extends DbControllerImpl
@DatabaseExecutor @DatabaseExecutor
private BlogPostItem getItem(BlogPostHeader h) throws DbException { private BlogPostItem getItem(BlogPostHeader h) throws DbException {
String body; String text;
if (h instanceof BlogCommentHeader) { if (h instanceof BlogCommentHeader) {
BlogCommentHeader c = (BlogCommentHeader) h; BlogCommentHeader c = (BlogCommentHeader) h;
BlogCommentItem item = new BlogCommentItem(c); BlogCommentItem item = new BlogCommentItem(c);
body = getPostBody(item.getPostHeader().getId()); text = getPostText(item.getPostHeader().getId());
item.setBody(body); item.setText(text);
return item; return item;
} else { } else {
body = getPostBody(h.getId()); text = getPostText(h.getId());
return new BlogPostItem(h, body); return new BlogPostItem(h, text);
} }
} }
@DatabaseExecutor @DatabaseExecutor
private String getPostBody(MessageId m) throws DbException { private String getPostText(MessageId m) throws DbException {
String body = bodyCache.get(m); String text = textCache.get(m);
if (body == null) { if (text == null) {
body = HtmlUtils.clean(blogManager.getPostBody(m), ARTICLE); text = HtmlUtils.clean(blogManager.getPostText(m), ARTICLE);
bodyCache.put(m, body); textCache.put(m, text);
} }
//noinspection ConstantConditions //noinspection ConstantConditions
return body; return text;
} }
} }

View File

@@ -34,8 +34,8 @@ class BlogCommentItem extends BlogPostItem {
} }
} }
public void setBody(String body) { public void setText(String text) {
this.body = body; this.text = text;
} }
@Override @Override

View File

@@ -15,12 +15,12 @@ import javax.annotation.concurrent.NotThreadSafe;
public class BlogPostItem implements Comparable<BlogPostItem> { public class BlogPostItem implements Comparable<BlogPostItem> {
private final BlogPostHeader header; private final BlogPostHeader header;
protected String body; protected String text;
private boolean read; private boolean read;
BlogPostItem(BlogPostHeader header, @Nullable String body) { BlogPostItem(BlogPostHeader header, @Nullable String text) {
this.header = header; this.header = header;
this.body = body; this.text = text;
this.read = header.isRead(); this.read = header.isRead();
} }
@@ -44,8 +44,8 @@ public class BlogPostItem implements Comparable<BlogPostItem> {
return header.getAuthorStatus(); return header.getAuthorStatus();
} }
public String getBody() { public String getText() {
return body; return text;
} }
public boolean isRssFeed() { public boolean isRssFeed() {

View File

@@ -41,7 +41,7 @@ class BlogPostViewHolder extends RecyclerView.ViewHolder {
private final AuthorView reblogger; private final AuthorView reblogger;
private final AuthorView author; private final AuthorView author;
private final ImageButton reblogButton; private final ImageButton reblogButton;
private final TextView body; private final TextView text;
private final ViewGroup commentContainer; private final ViewGroup commentContainer;
private final boolean fullText; private final boolean fullText;
@@ -63,7 +63,7 @@ class BlogPostViewHolder extends RecyclerView.ViewHolder {
reblogger = v.findViewById(R.id.rebloggerView); reblogger = v.findViewById(R.id.rebloggerView);
author = v.findViewById(R.id.authorView); author = v.findViewById(R.id.authorView);
reblogButton = v.findViewById(R.id.commentView); reblogButton = v.findViewById(R.id.commentView);
body = v.findViewById(R.id.bodyView); text = v.findViewById(R.id.textView);
commentContainer = v.findViewById(R.id.commentContainer); commentContainer = v.findViewById(R.id.commentContainer);
} }
@@ -111,17 +111,17 @@ class BlogPostViewHolder extends RecyclerView.ViewHolder {
author.setAuthorNotClickable(); author.setAuthorNotClickable();
} }
// post body // post text
Spanned bodyText = getSpanned(item.getBody()); Spanned postText = getSpanned(item.getText());
if (fullText) { if (fullText) {
body.setText(bodyText); text.setText(postText);
body.setTextIsSelectable(true); text.setTextIsSelectable(true);
makeLinksClickable(body, fragmentManager); makeLinksClickable(text, fragmentManager);
} else { } else {
body.setTextIsSelectable(false); text.setTextIsSelectable(false);
if (bodyText.length() > TEASER_LENGTH) if (postText.length() > TEASER_LENGTH)
bodyText = getTeaser(ctx, bodyText); postText = getTeaser(ctx, postText);
body.setText(bodyText); text.setText(postText);
} }
// reblog button // reblog button
@@ -163,15 +163,15 @@ class BlogPostViewHolder extends RecyclerView.ViewHolder {
commentContainer, false); commentContainer, false);
AuthorView author = v.findViewById(R.id.authorView); AuthorView author = v.findViewById(R.id.authorView);
TextView body = v.findViewById(R.id.bodyView); TextView text = v.findViewById(R.id.textView);
author.setAuthor(c.getAuthor()); author.setAuthor(c.getAuthor());
author.setAuthorStatus(c.getAuthorStatus()); author.setAuthorStatus(c.getAuthorStatus());
author.setDate(c.getTimestamp()); author.setDate(c.getTimestamp());
// TODO make author clickable #624 // TODO make author clickable #624
body.setText(c.getComment()); text.setText(c.getComment());
if (fullText) body.setTextIsSelectable(true); if (fullText) text.setTextIsSelectable(true);
commentContainer.addView(v); commentContainer.addView(v);
} }

View File

@@ -35,7 +35,7 @@ import static android.view.View.GONE;
import static android.view.View.VISIBLE; import static android.view.View.VISIBLE;
import static java.util.logging.Level.WARNING; import static java.util.logging.Level.WARNING;
import static org.briarproject.bramble.util.LogUtils.logException; import static org.briarproject.bramble.util.LogUtils.logException;
import static org.briarproject.briar.api.blog.BlogConstants.MAX_BLOG_POST_BODY_LENGTH; import static org.briarproject.briar.api.blog.BlogConstants.MAX_BLOG_POST_TEXT_LENGTH;
public class WriteBlogPostActivity extends BriarActivity public class WriteBlogPostActivity extends BriarActivity
implements OnEditorActionListener, TextInputListener { implements OnEditorActionListener, TextInputListener {
@@ -70,7 +70,7 @@ public class WriteBlogPostActivity extends BriarActivity
setContentView(R.layout.activity_write_blog_post); setContentView(R.layout.activity_write_blog_post);
input = findViewById(R.id.bodyInput); input = findViewById(R.id.textInput);
input.setSendButtonEnabled(false); input.setSendButtonEnabled(false);
input.addTextChangedListener(new TextWatcher() { input.addTextChangedListener(new TextWatcher() {
@Override @Override
@@ -132,23 +132,23 @@ public class WriteBlogPostActivity extends BriarActivity
} }
@Override @Override
public void onSendClick(String body) { public void onSendClick(String text) {
// hide publish button, show progress bar // hide publish button, show progress bar
input.hideSoftKeyboard(); input.hideSoftKeyboard();
input.setVisibility(GONE); input.setVisibility(GONE);
progressBar.setVisibility(VISIBLE); progressBar.setVisibility(VISIBLE);
body = StringUtils.truncateUtf8(body, MAX_BLOG_POST_BODY_LENGTH); text = StringUtils.truncateUtf8(text, MAX_BLOG_POST_TEXT_LENGTH);
storePost(body); storePost(text);
} }
private void storePost(String body) { private void storePost(String text) {
runOnDbThread(() -> { runOnDbThread(() -> {
long timestamp = System.currentTimeMillis(); long timestamp = System.currentTimeMillis();
try { try {
LocalAuthor author = identityManager.getLocalAuthor(); LocalAuthor author = identityManager.getLocalAuthor();
BlogPost p = blogPostFactory BlogPost p = blogPostFactory
.createBlogPost(groupId, timestamp, null, author, body); .createBlogPost(groupId, timestamp, null, author, text);
blogManager.addLocalPost(p); blogManager.addLocalPost(p);
postPublished(); postPublished();
} catch (DbException | GeneralSecurityException } catch (DbException | GeneralSecurityException

View File

@@ -53,7 +53,7 @@ import org.briarproject.briar.android.activity.ActivityComponent;
import org.briarproject.briar.android.activity.BriarActivity; import org.briarproject.briar.android.activity.BriarActivity;
import org.briarproject.briar.android.blog.BlogActivity; import org.briarproject.briar.android.blog.BlogActivity;
import org.briarproject.briar.android.contact.ConversationAdapter.ConversationListener; import org.briarproject.briar.android.contact.ConversationAdapter.ConversationListener;
import org.briarproject.briar.android.contact.ConversationVisitor.BodyCache; import org.briarproject.briar.android.contact.ConversationVisitor.TextCache;
import org.briarproject.briar.android.forum.ForumActivity; import org.briarproject.briar.android.forum.ForumActivity;
import org.briarproject.briar.android.introduction.IntroductionActivity; import org.briarproject.briar.android.introduction.IntroductionActivity;
import org.briarproject.briar.android.privategroup.conversation.GroupActivity; import org.briarproject.briar.android.privategroup.conversation.GroupActivity;
@@ -105,7 +105,7 @@ import static org.briarproject.briar.android.activity.RequestCodes.REQUEST_INTRO
import static org.briarproject.briar.android.settings.SettingsFragment.SETTINGS_NAMESPACE; import static org.briarproject.briar.android.settings.SettingsFragment.SETTINGS_NAMESPACE;
import static org.briarproject.briar.android.util.UiUtils.getAvatarTransitionName; import static org.briarproject.briar.android.util.UiUtils.getAvatarTransitionName;
import static org.briarproject.briar.android.util.UiUtils.getBulbTransitionName; import static org.briarproject.briar.android.util.UiUtils.getBulbTransitionName;
import static org.briarproject.briar.api.messaging.MessagingConstants.MAX_PRIVATE_MESSAGE_BODY_LENGTH; import static org.briarproject.briar.api.messaging.MessagingConstants.MAX_PRIVATE_MESSAGE_TEXT_LENGTH;
import static uk.co.samuelwall.materialtaptargetprompt.MaterialTapTargetPrompt.STATE_DISMISSED; import static uk.co.samuelwall.materialtaptargetprompt.MaterialTapTargetPrompt.STATE_DISMISSED;
import static uk.co.samuelwall.materialtaptargetprompt.MaterialTapTargetPrompt.STATE_FINISHED; import static uk.co.samuelwall.materialtaptargetprompt.MaterialTapTargetPrompt.STATE_FINISHED;
@@ -113,7 +113,7 @@ import static uk.co.samuelwall.materialtaptargetprompt.MaterialTapTargetPrompt.S
@ParametersNotNullByDefault @ParametersNotNullByDefault
public class ConversationActivity extends BriarActivity public class ConversationActivity extends BriarActivity
implements EventListener, ConversationListener, TextInputListener, implements EventListener, ConversationListener, TextInputListener,
BodyCache { TextCache {
public static final String CONTACT_ID = "briar.CONTACT_ID"; public static final String CONTACT_ID = "briar.CONTACT_ID";
@@ -130,7 +130,7 @@ public class ConversationActivity extends BriarActivity
@CryptoExecutor @CryptoExecutor
Executor cryptoExecutor; Executor cryptoExecutor;
private final Map<MessageId, String> bodyCache = new ConcurrentHashMap<>(); private final Map<MessageId, String> textCache = new ConcurrentHashMap<>();
private final MutableLiveData<String> contactName = new MutableLiveData<>(); private final MutableLiveData<String> contactName = new MutableLiveData<>();
private ConversationVisitor visitor; private ConversationVisitor visitor;
@@ -370,28 +370,28 @@ public class ConversationActivity extends BriarActivity
return items; return items;
} }
private void loadMessageBody(MessageId m) { private void loadMessageText(MessageId m) {
runOnDbThread(() -> { runOnDbThread(() -> {
try { try {
long start = now(); long start = now();
String body = messagingManager.getMessageBody(m); String text = messagingManager.getMessageText(m);
logDuration(LOG, "Loading body", start); logDuration(LOG, "Loading text", start);
displayMessageBody(m, body); displayMessageText(m, text);
} catch (DbException e) { } catch (DbException e) {
logException(LOG, WARNING, e); logException(LOG, WARNING, e);
} }
}); });
} }
private void displayMessageBody(MessageId m, String body) { private void displayMessageText(MessageId m, String text) {
runOnUiThreadUnlessDestroyed(() -> { runOnUiThreadUnlessDestroyed(() -> {
bodyCache.put(m, body); textCache.put(m, text);
SparseArray<ConversationItem> messages = SparseArray<ConversationItem> messages =
adapter.getPrivateMessages(); adapter.getPrivateMessages();
for (int i = 0; i < messages.size(); i++) { for (int i = 0; i < messages.size(); i++) {
ConversationItem item = messages.valueAt(i); ConversationItem item = messages.valueAt(i);
if (item.getId().equals(m)) { if (item.getId().equals(m)) {
item.setBody(body); item.setText(text);
adapter.notifyItemChanged(messages.keyAt(i)); adapter.notifyItemChanged(messages.keyAt(i));
list.scrollToPosition(adapter.getItemCount() - 1); list.scrollToPosition(adapter.getItemCount() - 1);
return; return;
@@ -470,7 +470,7 @@ public class ConversationActivity extends BriarActivity
} }
} else { } else {
addConversationItem(h.accept(visitor)); addConversationItem(h.accept(visitor));
loadMessageBody(h.getId()); loadMessageText(h.getId());
} }
}); });
} }
@@ -495,8 +495,8 @@ public class ConversationActivity extends BriarActivity
@Override @Override
public void onSendClick(String text) { public void onSendClick(String text) {
if (text.equals("")) return; if (text.isEmpty()) return;
text = StringUtils.truncateUtf8(text, MAX_PRIVATE_MESSAGE_BODY_LENGTH); text = StringUtils.truncateUtf8(text, MAX_PRIVATE_MESSAGE_TEXT_LENGTH);
long timestamp = System.currentTimeMillis(); long timestamp = System.currentTimeMillis();
timestamp = Math.max(timestamp, getMinTimestampForNewMessage()); timestamp = Math.max(timestamp, getMinTimestampForNewMessage());
if (messagingGroupId == null) loadGroupId(text, timestamp); if (messagingGroupId == null) loadGroupId(text, timestamp);
@@ -510,12 +510,12 @@ public class ConversationActivity extends BriarActivity
return item == null ? 0 : item.getTime() + 1; return item == null ? 0 : item.getTime() + 1;
} }
private void loadGroupId(String body, long timestamp) { private void loadGroupId(String text, long timestamp) {
runOnDbThread(() -> { runOnDbThread(() -> {
try { try {
messagingGroupId = messagingGroupId =
messagingManager.getConversationId(contactId); messagingManager.getConversationId(contactId);
createMessage(body, timestamp); createMessage(text, timestamp);
} catch (DbException e) { } catch (DbException e) {
logException(LOG, WARNING, e); logException(LOG, WARNING, e);
} }
@@ -523,19 +523,19 @@ public class ConversationActivity extends BriarActivity
}); });
} }
private void createMessage(String body, long timestamp) { private void createMessage(String text, long timestamp) {
cryptoExecutor.execute(() -> { cryptoExecutor.execute(() -> {
try { try {
//noinspection ConstantConditions init in loadGroupId() //noinspection ConstantConditions init in loadGroupId()
storeMessage(privateMessageFactory.createPrivateMessage( storeMessage(privateMessageFactory.createPrivateMessage(
messagingGroupId, timestamp, body), body); messagingGroupId, timestamp, text), text);
} catch (FormatException e) { } catch (FormatException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
}); });
} }
private void storeMessage(PrivateMessage m, String body) { private void storeMessage(PrivateMessage m, String text) {
runOnDbThread(() -> { runOnDbThread(() -> {
try { try {
long start = now(); long start = now();
@@ -545,7 +545,7 @@ public class ConversationActivity extends BriarActivity
PrivateMessageHeader h = new PrivateMessageHeader( PrivateMessageHeader h = new PrivateMessageHeader(
message.getId(), message.getGroupId(), message.getId(), message.getGroupId(),
message.getTimestamp(), true, false, false, false); message.getTimestamp(), true, false, false, false);
bodyCache.put(message.getId(), body); textCache.put(message.getId(), text);
addConversationItem(h.accept(visitor)); addConversationItem(h.accept(visitor));
} catch (DbException e) { } catch (DbException e) {
logException(LOG, WARNING, e); logException(LOG, WARNING, e);
@@ -761,9 +761,9 @@ public class ConversationActivity extends BriarActivity
@Nullable @Nullable
@Override @Override
public String getBody(MessageId m) { public String getText(MessageId m) {
String body = bodyCache.get(m); String text = textCache.get(m);
if (body == null) loadMessageBody(m); if (text == null) loadMessageText(m);
return body; return text;
} }
} }

View File

@@ -14,17 +14,17 @@ import javax.annotation.concurrent.NotThreadSafe;
abstract class ConversationItem { abstract class ConversationItem {
@Nullable @Nullable
protected String body; protected String text;
private final MessageId id; private final MessageId id;
private final GroupId groupId; private final GroupId groupId;
private final long time; private final long time;
private boolean read; private boolean read;
ConversationItem(MessageId id, GroupId groupId, @Nullable String body, ConversationItem(MessageId id, GroupId groupId, @Nullable String text,
long time, boolean read) { long time, boolean read) {
this.id = id; this.id = id;
this.groupId = groupId; this.groupId = groupId;
this.body = body; this.text = text;
this.time = time; this.time = time;
this.read = read; this.read = read;
} }
@@ -37,13 +37,13 @@ abstract class ConversationItem {
return groupId; return groupId;
} }
void setBody(String body) { void setText(String text) {
this.body = body; this.text = text;
} }
@Nullable @Nullable
public String getBody() { public String getText() {
return body; return text;
} }
long getTime() { long getTime() {

View File

@@ -29,10 +29,10 @@ class ConversationItemViewHolder extends ViewHolder {
@CallSuper @CallSuper
void bind(ConversationItem item) { void bind(ConversationItem item) {
if (item.getBody() == null) { if (item.getText() == null) {
text.setText("\u2026"); text.setText("\u2026");
} else { } else {
text.setText(StringUtils.trim(item.getBody())); text.setText(StringUtils.trim(item.getText()));
} }
long timestamp = item.getTime(); long timestamp = item.getTime();

View File

@@ -29,13 +29,13 @@ class ConversationNoticeInViewHolder extends ConversationItemViewHolder {
ConversationNoticeInItem item = ConversationNoticeInItem item =
(ConversationNoticeInItem) conversationItem; (ConversationNoticeInItem) conversationItem;
String message = item.getMsgText(); String text = item.getMsgText();
if (StringUtils.isNullOrEmpty(message)) { if (StringUtils.isNullOrEmpty(text)) {
msgText.setVisibility(GONE); msgText.setVisibility(GONE);
layout.setBackgroundResource(R.drawable.notice_in); layout.setBackgroundResource(R.drawable.notice_in);
} else { } else {
msgText.setVisibility(VISIBLE); msgText.setVisibility(VISIBLE);
msgText.setText(StringUtils.trim(message)); msgText.setText(StringUtils.trim(text));
layout.setBackgroundResource(R.drawable.notice_in_bottom); layout.setBackgroundResource(R.drawable.notice_in_bottom);
} }
} }

View File

@@ -20,7 +20,7 @@ class ConversationNoticeOutItem extends ConversationOutItem {
ConversationNoticeOutItem(String text, PrivateRequest r) { ConversationNoticeOutItem(String text, PrivateRequest r) {
super(r.getId(), r.getGroupId(), text, r.getTimestamp(), r.isSent(), super(r.getId(), r.getGroupId(), text, r.getTimestamp(), r.isSent(),
r.isSeen()); r.isSeen());
this.msgText = r.getMessage(); this.msgText = r.getText();
} }
ConversationNoticeOutItem(String text, PrivateResponse r) { ConversationNoticeOutItem(String text, PrivateResponse r) {

View File

@@ -29,13 +29,13 @@ class ConversationNoticeOutViewHolder extends ConversationOutItemViewHolder {
ConversationNoticeOutItem item = ConversationNoticeOutItem item =
(ConversationNoticeOutItem) conversationItem; (ConversationNoticeOutItem) conversationItem;
String message = item.getMsgText(); String text = item.getMsgText();
if (StringUtils.isNullOrEmpty(message)) { if (StringUtils.isNullOrEmpty(text)) {
msgText.setVisibility(GONE); msgText.setVisibility(GONE);
layout.setBackgroundResource(R.drawable.notice_out); layout.setBackgroundResource(R.drawable.notice_out);
} else { } else {
msgText.setVisibility(VISIBLE); msgText.setVisibility(VISIBLE);
msgText.setText(StringUtils.trim(message)); msgText.setText(StringUtils.trim(text));
layout.setBackgroundResource(R.drawable.notice_out_bottom); layout.setBackgroundResource(R.drawable.notice_out_bottom);
} }
} }

View File

@@ -27,7 +27,7 @@ class ConversationRequestItem extends ConversationNoticeInItem {
private boolean answered; private boolean answered;
ConversationRequestItem(String text, RequestType type, PrivateRequest r) { ConversationRequestItem(String text, RequestType type, PrivateRequest r) {
super(r.getId(), r.getGroupId(), text, r.getMessage(), super(r.getId(), r.getGroupId(), text, r.getText(),
r.getTimestamp(), r.isRead()); r.getTimestamp(), r.isRead());
this.requestType = type; this.requestType = type;
this.sessionId = r.getSessionId(); this.sessionId = r.getSessionId();

View File

@@ -30,13 +30,13 @@ import static org.briarproject.briar.android.contact.ConversationRequestItem.Req
class ConversationVisitor implements PrivateMessageVisitor<ConversationItem> { class ConversationVisitor implements PrivateMessageVisitor<ConversationItem> {
private final Context ctx; private final Context ctx;
private final BodyCache bodyCache; private final TextCache textCache;
private final LiveData<String> contactName; private final LiveData<String> contactName;
ConversationVisitor(Context ctx, BodyCache bodyCache, ConversationVisitor(Context ctx, TextCache textCache,
LiveData<String> contactName) { LiveData<String> contactName) {
this.ctx = ctx; this.ctx = ctx;
this.bodyCache = bodyCache; this.textCache = textCache;
this.contactName = contactName; this.contactName = contactName;
} }
@@ -45,8 +45,8 @@ class ConversationVisitor implements PrivateMessageVisitor<ConversationItem> {
ConversationItem item; ConversationItem item;
if (h.isLocal()) item = new ConversationMessageOutItem(h); if (h.isLocal()) item = new ConversationMessageOutItem(h);
else item = new ConversationMessageInItem(h); else item = new ConversationMessageInItem(h);
String body = bodyCache.getBody(h.getId()); String text = textCache.getText(h.getId());
if (body != null) item.setBody(body); if (text != null) item.setText(text);
return item; return item;
} }
@@ -239,8 +239,8 @@ class ConversationVisitor implements PrivateMessageVisitor<ConversationItem> {
} }
} }
interface BodyCache { interface TextCache {
@Nullable @Nullable
String getBody(MessageId m); String getText(MessageId m);
} }
} }

View File

@@ -33,7 +33,7 @@ import javax.inject.Inject;
import static android.content.Intent.FLAG_ACTIVITY_CLEAR_TOP; import static android.content.Intent.FLAG_ACTIVITY_CLEAR_TOP;
import static android.widget.Toast.LENGTH_SHORT; import static android.widget.Toast.LENGTH_SHORT;
import static org.briarproject.briar.android.activity.RequestCodes.REQUEST_SHARE_FORUM; import static org.briarproject.briar.android.activity.RequestCodes.REQUEST_SHARE_FORUM;
import static org.briarproject.briar.api.forum.ForumConstants.MAX_FORUM_POST_BODY_LENGTH; import static org.briarproject.briar.api.forum.ForumConstants.MAX_FORUM_POST_TEXT_LENGTH;
@MethodsNotNullByDefault @MethodsNotNullByDefault
@ParametersNotNullByDefault @ParametersNotNullByDefault
@@ -130,8 +130,8 @@ public class ForumActivity extends
} }
@Override @Override
protected int getMaxBodyLength() { protected int getMaxTextLength() {
return MAX_FORUM_POST_BODY_LENGTH; return MAX_FORUM_POST_TEXT_LENGTH;
} }
@Override @Override

View File

@@ -79,7 +79,7 @@ class ForumControllerImpl extends
ForumPostReceivedEvent f = (ForumPostReceivedEvent) e; ForumPostReceivedEvent f = (ForumPostReceivedEvent) e;
if (f.getGroupId().equals(getGroupId())) { if (f.getGroupId().equals(getGroupId())) {
LOG.info("Forum post received, adding..."); LOG.info("Forum post received, adding...");
onForumPostReceived(f.getHeader(), f.getBody()); onForumPostReceived(f.getHeader(), f.getText());
} }
} else if (e instanceof ForumInvitationResponseReceivedEvent) { } else if (e instanceof ForumInvitationResponseReceivedEvent) {
ForumInvitationResponseReceivedEvent f = ForumInvitationResponseReceivedEvent f =
@@ -109,8 +109,8 @@ class ForumControllerImpl extends
} }
@Override @Override
protected String loadMessageBody(ForumPostHeader h) throws DbException { protected String loadMessageText(ForumPostHeader h) throws DbException {
return forumManager.getPostBody(h.getId()); return forumManager.getPostText(h.getId());
} }
@Override @Override
@@ -137,7 +137,7 @@ class ForumControllerImpl extends
} }
@Override @Override
public void createAndStoreMessage(String body, public void createAndStoreMessage(String text,
@Nullable ForumItem parentItem, @Nullable ForumItem parentItem,
ResultExceptionHandler<ForumItem, DbException> handler) { ResultExceptionHandler<ForumItem, DbException> handler) {
runOnDbThread(() -> { runOnDbThread(() -> {
@@ -148,7 +148,7 @@ class ForumControllerImpl extends
clock.currentTimeMillis()); clock.currentTimeMillis());
MessageId parentId = parentItem != null ? MessageId parentId = parentItem != null ?
parentItem.getId() : null; parentItem.getId() : null;
createMessage(body, timestamp, parentId, author, handler); createMessage(text, timestamp, parentId, author, handler);
} catch (DbException e) { } catch (DbException e) {
logException(LOG, WARNING, e); logException(LOG, WARNING, e);
handler.onException(e); handler.onException(e);
@@ -156,14 +156,14 @@ class ForumControllerImpl extends
}); });
} }
private void createMessage(String body, long timestamp, private void createMessage(String text, long timestamp,
@Nullable MessageId parentId, LocalAuthor author, @Nullable MessageId parentId, LocalAuthor author,
ResultExceptionHandler<ForumItem, DbException> handler) { ResultExceptionHandler<ForumItem, DbException> handler) {
cryptoExecutor.execute(() -> { cryptoExecutor.execute(() -> {
LOG.info("Creating forum post..."); LOG.info("Creating forum post...");
ForumPost msg = forumManager.createLocalPost(getGroupId(), body, ForumPost msg = forumManager.createLocalPost(getGroupId(), text,
timestamp, parentId, author); timestamp, parentId, author);
storePost(msg, body, handler); storePost(msg, text, handler);
}); });
} }
@@ -179,12 +179,12 @@ class ForumControllerImpl extends
} }
@Override @Override
protected ForumItem buildItem(ForumPostHeader header, String body) { protected ForumItem buildItem(ForumPostHeader header, String text) {
return new ForumItem(header, body); return new ForumItem(header, text);
} }
private void onForumPostReceived(ForumPostHeader h, String body) { private void onForumPostReceived(ForumPostHeader h, String text) {
ForumItem item = buildItem(h, body); ForumItem item = buildItem(h, text);
listener.runOnUiThreadUnlessDestroyed( listener.runOnUiThreadUnlessDestroyed(
() -> listener.onItemReceived(item)); () -> listener.onItemReceived(item));
} }

View File

@@ -12,8 +12,8 @@ import javax.annotation.concurrent.NotThreadSafe;
@NotThreadSafe @NotThreadSafe
class ForumItem extends ThreadItem { class ForumItem extends ThreadItem {
ForumItem(ForumPostHeader h, String body) { ForumItem(ForumPostHeader h, String text) {
super(h.getId(), h.getParentId(), body, h.getTimestamp(), h.getAuthor(), super(h.getId(), h.getParentId(), text, h.getTimestamp(), h.getAuthor(),
h.getAuthorStatus(), h.isRead()); h.getAuthorStatus(), h.isRead());
} }

View File

@@ -38,7 +38,7 @@ import static android.view.View.VISIBLE;
import static android.widget.Toast.LENGTH_SHORT; import static android.widget.Toast.LENGTH_SHORT;
import static java.util.logging.Level.WARNING; import static java.util.logging.Level.WARNING;
import static org.briarproject.bramble.util.LogUtils.logException; import static org.briarproject.bramble.util.LogUtils.logException;
import static org.briarproject.briar.api.introduction.IntroductionConstants.MAX_REQUEST_MESSAGE_LENGTH; import static org.briarproject.briar.api.introduction.IntroductionConstants.MAX_INTRODUCTION_TEXT_LENGTH;
public class IntroductionMessageFragment extends BaseFragment public class IntroductionMessageFragment extends BaseFragment
implements TextInputListener { implements TextInputListener {
@@ -187,10 +187,10 @@ public class IntroductionMessageFragment extends BaseFragment
// disable button to prevent accidental double invitations // disable button to prevent accidental double invitations
ui.message.setSendButtonEnabled(false); ui.message.setSendButtonEnabled(false);
String msg = ui.message.getText().toString(); String txt = ui.message.getText().toString();
if (msg.equals("")) msg = null; if (txt.isEmpty()) txt = null;
else msg = StringUtils.truncateUtf8(msg, MAX_REQUEST_MESSAGE_LENGTH); else txt = StringUtils.truncateUtf8(txt, MAX_INTRODUCTION_TEXT_LENGTH);
makeIntroduction(contact1, contact2, msg); makeIntroduction(contact1, contact2, txt);
// don't wait for the introduction to be made before finishing activity // don't wait for the introduction to be made before finishing activity
introductionActivity.hideSoftKeyboard(ui.message); introductionActivity.hideSoftKeyboard(ui.message);
@@ -199,12 +199,12 @@ public class IntroductionMessageFragment extends BaseFragment
} }
private void makeIntroduction(Contact c1, Contact c2, private void makeIntroduction(Contact c1, Contact c2,
@Nullable String msg) { @Nullable String text) {
introductionActivity.runOnDbThread(() -> { introductionActivity.runOnDbThread(() -> {
// actually make the introduction // actually make the introduction
try { try {
long timestamp = System.currentTimeMillis(); long timestamp = System.currentTimeMillis();
introductionManager.makeIntroduction(c1, c2, msg, timestamp); introductionManager.makeIntroduction(c1, c2, text, timestamp);
} catch (DbException e) { } catch (DbException e) {
logException(LOG, WARNING, e); logException(LOG, WARNING, e);
introductionError(); introductionError();

View File

@@ -37,7 +37,7 @@ import javax.inject.Inject;
import static android.view.View.GONE; import static android.view.View.GONE;
import static android.view.View.VISIBLE; import static android.view.View.VISIBLE;
import static org.briarproject.briar.android.activity.RequestCodes.REQUEST_GROUP_INVITE; import static org.briarproject.briar.android.activity.RequestCodes.REQUEST_GROUP_INVITE;
import static org.briarproject.briar.api.privategroup.PrivateGroupConstants.MAX_GROUP_POST_BODY_LENGTH; import static org.briarproject.briar.api.privategroup.PrivateGroupConstants.MAX_GROUP_POST_TEXT_LENGTH;
@MethodsNotNullByDefault @MethodsNotNullByDefault
@ParametersNotNullByDefault @ParametersNotNullByDefault
@@ -179,8 +179,8 @@ public class GroupActivity extends
} }
@Override @Override
protected int getMaxBodyLength() { protected int getMaxTextLength() {
return MAX_GROUP_POST_BODY_LENGTH; return MAX_GROUP_POST_TEXT_LENGTH;
} }
@Override @Override

View File

@@ -84,7 +84,7 @@ class GroupControllerImpl extends
GroupMessageAddedEvent g = (GroupMessageAddedEvent) e; GroupMessageAddedEvent g = (GroupMessageAddedEvent) e;
if (!g.isLocal() && g.getGroupId().equals(getGroupId())) { if (!g.isLocal() && g.getGroupId().equals(getGroupId())) {
LOG.info("Group message received, adding..."); LOG.info("Group message received, adding...");
GroupMessageItem item = buildItem(g.getHeader(), g.getBody()); GroupMessageItem item = buildItem(g.getHeader(), g.getText());
listener.runOnUiThreadUnlessDestroyed( listener.runOnUiThreadUnlessDestroyed(
() -> listener.onItemReceived(item)); () -> listener.onItemReceived(item));
} }
@@ -124,13 +124,13 @@ class GroupControllerImpl extends
} }
@Override @Override
protected String loadMessageBody(GroupMessageHeader header) protected String loadMessageText(GroupMessageHeader header)
throws DbException { throws DbException {
if (header instanceof JoinMessageHeader) { if (header instanceof JoinMessageHeader) {
// will be looked up later // will be looked up later
return ""; return "";
} }
return privateGroupManager.getMessageBody(header.getId()); return privateGroupManager.getMessageText(header.getId());
} }
@Override @Override
@@ -159,7 +159,7 @@ class GroupControllerImpl extends
} }
@Override @Override
public void createAndStoreMessage(String body, public void createAndStoreMessage(String text,
@Nullable GroupMessageItem parentItem, @Nullable GroupMessageItem parentItem,
ResultExceptionHandler<GroupMessageItem, DbException> handler) { ResultExceptionHandler<GroupMessageItem, DbException> handler) {
runOnDbThread(() -> { runOnDbThread(() -> {
@@ -173,7 +173,7 @@ class GroupControllerImpl extends
long timestamp = count.getLatestMsgTime(); long timestamp = count.getLatestMsgTime();
if (parentItem != null) parentId = parentItem.getId(); if (parentItem != null) parentId = parentItem.getId();
timestamp = max(clock.currentTimeMillis(), timestamp + 1); timestamp = max(clock.currentTimeMillis(), timestamp + 1);
createMessage(body, timestamp, parentId, author, previousMsgId, createMessage(text, timestamp, parentId, author, previousMsgId,
handler); handler);
} catch (DbException e) { } catch (DbException e) {
logException(LOG, WARNING, e); logException(LOG, WARNING, e);
@@ -182,7 +182,7 @@ class GroupControllerImpl extends
}); });
} }
private void createMessage(String body, long timestamp, private void createMessage(String text, long timestamp,
@Nullable MessageId parentId, LocalAuthor author, @Nullable MessageId parentId, LocalAuthor author,
MessageId previousMsgId, MessageId previousMsgId,
ResultExceptionHandler<GroupMessageItem, DbException> handler) { ResultExceptionHandler<GroupMessageItem, DbException> handler) {
@@ -190,8 +190,8 @@ class GroupControllerImpl extends
LOG.info("Creating group message..."); LOG.info("Creating group message...");
GroupMessage msg = groupMessageFactory GroupMessage msg = groupMessageFactory
.createGroupMessage(getGroupId(), timestamp, .createGroupMessage(getGroupId(), timestamp,
parentId, author, body, previousMsgId); parentId, author, text, previousMsgId);
storePost(msg, body, handler); storePost(msg, text, handler);
}); });
} }
@@ -208,11 +208,11 @@ class GroupControllerImpl extends
@Override @Override
protected GroupMessageItem buildItem(GroupMessageHeader header, protected GroupMessageItem buildItem(GroupMessageHeader header,
String body) { String text) {
if (header instanceof JoinMessageHeader) { if (header instanceof JoinMessageHeader) {
return new JoinMessageItem((JoinMessageHeader) header, body); return new JoinMessageItem((JoinMessageHeader) header, text);
} }
return new GroupMessageItem(header, body); return new GroupMessageItem(header, text);
} }
@Override @Override

View File

@@ -18,6 +18,6 @@ public interface CreateGroupController
ResultExceptionHandler<GroupId, DbException> result); ResultExceptionHandler<GroupId, DbException> result);
void sendInvitation(GroupId g, Collection<ContactId> contacts, void sendInvitation(GroupId g, Collection<ContactId> contacts,
String message, ResultExceptionHandler<Void, DbException> result); String text, ResultExceptionHandler<Void, DbException> result);
} }

View File

@@ -123,7 +123,7 @@ class CreateGroupControllerImpl extends ContactSelectorControllerImpl
@Override @Override
public void sendInvitation(GroupId g, Collection<ContactId> contactIds, public void sendInvitation(GroupId g, Collection<ContactId> contactIds,
String message, ResultExceptionHandler<Void, DbException> handler) { String text, ResultExceptionHandler<Void, DbException> handler) {
runOnDbThread(() -> { runOnDbThread(() -> {
try { try {
LocalAuthor localAuthor = identityManager.getLocalAuthor(); LocalAuthor localAuthor = identityManager.getLocalAuthor();
@@ -135,7 +135,7 @@ class CreateGroupControllerImpl extends ContactSelectorControllerImpl
// Continue // Continue
} }
} }
signInvitations(g, localAuthor, contacts, message, handler); signInvitations(g, localAuthor, contacts, text, handler);
} catch (DbException e) { } catch (DbException e) {
logException(LOG, WARNING, e); logException(LOG, WARNING, e);
handler.onException(e); handler.onException(e);
@@ -144,7 +144,7 @@ class CreateGroupControllerImpl extends ContactSelectorControllerImpl
} }
private void signInvitations(GroupId g, LocalAuthor localAuthor, private void signInvitations(GroupId g, LocalAuthor localAuthor,
Collection<Contact> contacts, String message, Collection<Contact> contacts, String text,
ResultExceptionHandler<Void, DbException> handler) { ResultExceptionHandler<Void, DbException> handler) {
cryptoExecutor.execute(() -> { cryptoExecutor.execute(() -> {
long timestamp = clock.currentTimeMillis(); long timestamp = clock.currentTimeMillis();
@@ -155,20 +155,20 @@ class CreateGroupControllerImpl extends ContactSelectorControllerImpl
contexts.add(new InvitationContext(c.getId(), timestamp, contexts.add(new InvitationContext(c.getId(), timestamp,
signature)); signature));
} }
sendInvitations(g, contexts, message, handler); sendInvitations(g, contexts, text, handler);
}); });
} }
private void sendInvitations(GroupId g, private void sendInvitations(GroupId g,
Collection<InvitationContext> contexts, String message, Collection<InvitationContext> contexts, String text,
ResultExceptionHandler<Void, DbException> handler) { ResultExceptionHandler<Void, DbException> handler) {
runOnDbThread(() -> { runOnDbThread(() -> {
try { try {
String msg = message.isEmpty() ? null : message; String txt = text.isEmpty() ? null : text;
for (InvitationContext context : contexts) { for (InvitationContext context : contexts) {
try { try {
groupInvitationManager.sendInvitation(g, groupInvitationManager.sendInvitation(g,
context.contactId, msg, context.timestamp, context.contactId, txt, context.timestamp,
context.signature); context.signature);
} catch (NoSuchContactException e) { } catch (NoSuchContactException e) {
// Continue // Continue

View File

@@ -18,7 +18,7 @@ import java.util.Collection;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import javax.inject.Inject; import javax.inject.Inject;
import static org.briarproject.briar.api.privategroup.PrivateGroupConstants.MAX_GROUP_INVITATION_MSG_LENGTH; import static org.briarproject.briar.api.privategroup.PrivateGroupConstants.MAX_GROUP_INVITATION_TEXT_LENGTH;
@MethodsNotNullByDefault @MethodsNotNullByDefault
@ParametersNotNullByDefault @ParametersNotNullByDefault
@@ -55,10 +55,10 @@ public class GroupInviteActivity extends ContactSelectorActivity
} }
@Override @Override
public boolean onButtonClick(String message) { public boolean onButtonClick(String text) {
if (groupId == null) if (groupId == null)
throw new IllegalStateException("GroupId was not initialized"); throw new IllegalStateException("GroupId was not initialized");
controller.sendInvitation(groupId, contacts, message, controller.sendInvitation(groupId, contacts, text,
new UiResultExceptionHandler<Void, DbException>(this) { new UiResultExceptionHandler<Void, DbException>(this) {
@Override @Override
public void onResultUi(Void result) { public void onResultUi(Void result) {
@@ -76,7 +76,7 @@ public class GroupInviteActivity extends ContactSelectorActivity
} }
@Override @Override
public int getMaximumMessageLength() { public int getMaximumTextLength() {
return MAX_GROUP_INVITATION_MSG_LENGTH; return MAX_GROUP_INVITATION_TEXT_LENGTH;
} }
} }

View File

@@ -11,7 +11,6 @@ import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault; import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import org.briarproject.bramble.util.StringUtils;
import org.briarproject.briar.R; import org.briarproject.briar.R;
import org.briarproject.briar.android.fragment.BaseFragment; import org.briarproject.briar.android.fragment.BaseFragment;
import org.briarproject.briar.android.view.LargeTextInputView; import org.briarproject.briar.android.view.LargeTextInputView;
@@ -19,7 +18,8 @@ import org.briarproject.briar.android.view.TextInputView.TextInputListener;
import static android.support.design.widget.Snackbar.LENGTH_SHORT; import static android.support.design.widget.Snackbar.LENGTH_SHORT;
import static org.briarproject.bramble.util.StringUtils.truncateUtf8; import static org.briarproject.bramble.util.StringUtils.truncateUtf8;
import static org.briarproject.briar.api.sharing.SharingConstants.MAX_INVITATION_MESSAGE_LENGTH; import static org.briarproject.bramble.util.StringUtils.utf8IsTooLong;
import static org.briarproject.briar.api.sharing.SharingConstants.MAX_INVITATION_TEXT_LENGTH;
public abstract class BaseMessageFragment extends BaseFragment public abstract class BaseMessageFragment extends BaseFragment
implements TextInputListener { implements TextInputListener {
@@ -76,8 +76,8 @@ public abstract class BaseMessageFragment extends BaseFragment
} }
@Override @Override
public void onSendClick(String msg) { public void onSendClick(String text) {
if (StringUtils.utf8IsTooLong(msg, listener.getMaximumMessageLength())) { if (utf8IsTooLong(text, listener.getMaximumTextLength())) {
Snackbar.make(message, R.string.text_too_long, LENGTH_SHORT).show(); Snackbar.make(message, R.string.text_too_long, LENGTH_SHORT).show();
return; return;
} }
@@ -86,8 +86,8 @@ public abstract class BaseMessageFragment extends BaseFragment
message.setSendButtonEnabled(false); message.setSendButtonEnabled(false);
message.hideSoftKeyboard(); message.hideSoftKeyboard();
msg = truncateUtf8(msg, MAX_INVITATION_MESSAGE_LENGTH); text = truncateUtf8(text, MAX_INVITATION_TEXT_LENGTH);
if(!listener.onButtonClick(msg)) { if(!listener.onButtonClick(text)) {
message.setSendButtonEnabled(true); message.setSendButtonEnabled(true);
message.showSoftKeyboard(); message.showSoftKeyboard();
} }
@@ -102,9 +102,9 @@ public abstract class BaseMessageFragment extends BaseFragment
void setTitle(@StringRes int titleRes); void setTitle(@StringRes int titleRes);
/** Returns true when the button click has been consumed. */ /** Returns true when the button click has been consumed. */
boolean onButtonClick(String message); boolean onButtonClick(String text);
int getMaximumMessageLength(); int getMaximumTextLength();
} }

View File

@@ -41,13 +41,13 @@ public abstract class ShareActivity extends ContactSelectorActivity
@UiThread @UiThread
@Override @Override
public boolean onButtonClick(String message) { public boolean onButtonClick(String text) {
share(contacts, message); share(contacts, text);
setResult(RESULT_OK); setResult(RESULT_OK);
supportFinishAfterTransition(); supportFinishAfterTransition();
return true; return true;
} }
abstract void share(Collection<ContactId> contacts, String msg); abstract void share(Collection<ContactId> contacts, String text);
} }

View File

@@ -17,7 +17,7 @@ import javax.annotation.Nullable;
import javax.inject.Inject; import javax.inject.Inject;
import static android.widget.Toast.LENGTH_SHORT; import static android.widget.Toast.LENGTH_SHORT;
import static org.briarproject.bramble.api.sync.SyncConstants.MAX_MESSAGE_BODY_LENGTH; import static org.briarproject.briar.api.sharing.SharingConstants.MAX_INVITATION_TEXT_LENGTH;
@MethodsNotNullByDefault @MethodsNotNullByDefault
@ParametersNotNullByDefault @ParametersNotNullByDefault
@@ -46,13 +46,13 @@ public class ShareBlogActivity extends ShareActivity {
} }
@Override @Override
public int getMaximumMessageLength() { public int getMaximumTextLength() {
return MAX_MESSAGE_BODY_LENGTH; return MAX_INVITATION_TEXT_LENGTH;
} }
@Override @Override
void share(Collection<ContactId> contacts, String msg) { void share(Collection<ContactId> contacts, String text) {
controller.share(groupId, contacts, msg, controller.share(groupId, contacts, text,
new UiExceptionHandler<DbException>(this) { new UiExceptionHandler<DbException>(this) {
@Override @Override
public void onExceptionUi(DbException exception) { public void onExceptionUi(DbException exception) {

View File

@@ -12,7 +12,7 @@ import java.util.Collection;
public interface ShareBlogController public interface ShareBlogController
extends ContactSelectorController<SelectableContactItem> { extends ContactSelectorController<SelectableContactItem> {
void share(GroupId g, Collection<ContactId> contacts, String msg, void share(GroupId g, Collection<ContactId> contacts, String text,
ExceptionHandler<DbException> handler); ExceptionHandler<DbException> handler);
} }

View File

@@ -56,17 +56,17 @@ class ShareBlogControllerImpl extends ContactSelectorControllerImpl
} }
@Override @Override
public void share(GroupId g, Collection<ContactId> contacts, String message, public void share(GroupId g, Collection<ContactId> contacts, String text,
ExceptionHandler<DbException> handler) { ExceptionHandler<DbException> handler) {
runOnDbThread(() -> { runOnDbThread(() -> {
try { try {
String msg = isNullOrEmpty(message) ? null : message; String txt = isNullOrEmpty(text) ? null : text;
for (ContactId c : contacts) { for (ContactId c : contacts) {
try { try {
long time = Math.max(clock.currentTimeMillis(), long time = Math.max(clock.currentTimeMillis(),
conversationManager.getGroupCount(c) conversationManager.getGroupCount(c)
.getLatestMsgTime() + 1); .getLatestMsgTime() + 1);
blogSharingManager.sendInvitation(g, c, msg, time); blogSharingManager.sendInvitation(g, c, txt, time);
} catch (NoSuchContactException | NoSuchGroupException e) { } catch (NoSuchContactException | NoSuchGroupException e) {
logException(LOG, WARNING, e); logException(LOG, WARNING, e);
} }

View File

@@ -17,7 +17,7 @@ import javax.annotation.Nullable;
import javax.inject.Inject; import javax.inject.Inject;
import static android.widget.Toast.LENGTH_SHORT; import static android.widget.Toast.LENGTH_SHORT;
import static org.briarproject.bramble.api.sync.SyncConstants.MAX_MESSAGE_BODY_LENGTH; import static org.briarproject.briar.api.sharing.SharingConstants.MAX_INVITATION_TEXT_LENGTH;
@MethodsNotNullByDefault @MethodsNotNullByDefault
@ParametersNotNullByDefault @ParametersNotNullByDefault
@@ -46,13 +46,13 @@ public class ShareForumActivity extends ShareActivity {
} }
@Override @Override
public int getMaximumMessageLength() { public int getMaximumTextLength() {
return MAX_MESSAGE_BODY_LENGTH; return MAX_INVITATION_TEXT_LENGTH;
} }
@Override @Override
void share(Collection<ContactId> contacts, String msg) { void share(Collection<ContactId> contacts, String text) {
controller.share(groupId, contacts, msg, controller.share(groupId, contacts, text,
new UiExceptionHandler<DbException>(this) { new UiExceptionHandler<DbException>(this) {
@Override @Override
public void onExceptionUi(DbException exception) { public void onExceptionUi(DbException exception) {

View File

@@ -12,7 +12,7 @@ import java.util.Collection;
public interface ShareForumController public interface ShareForumController
extends ContactSelectorController<SelectableContactItem> { extends ContactSelectorController<SelectableContactItem> {
void share(GroupId g, Collection<ContactId> contacts, String msg, void share(GroupId g, Collection<ContactId> contacts, String text,
ExceptionHandler<DbException> handler); ExceptionHandler<DbException> handler);
} }

View File

@@ -57,16 +57,16 @@ class ShareForumControllerImpl extends ContactSelectorControllerImpl
@Override @Override
public void share(GroupId g, Collection<ContactId> contacts, public void share(GroupId g, Collection<ContactId> contacts,
String message, ExceptionHandler<DbException> handler) { String text, ExceptionHandler<DbException> handler) {
runOnDbThread(() -> { runOnDbThread(() -> {
try { try {
String msg = isNullOrEmpty(message) ? null : message; String txt = isNullOrEmpty(text) ? null : text;
for (ContactId c : contacts) { for (ContactId c : contacts) {
try { try {
long time = Math.max(clock.currentTimeMillis(), long time = Math.max(clock.currentTimeMillis(),
conversationManager.getGroupCount(c) conversationManager.getGroupCount(c)
.getLatestMsgTime() + 1); .getLatestMsgTime() + 1);
forumSharingManager.sendInvitation(g, c, msg, time); forumSharingManager.sendInvitation(g, c, txt, time);
} catch (NoSuchContactException | NoSuchGroupException e) { } catch (NoSuchContactException | NoSuchGroupException e) {
logException(LOG, WARNING, e); logException(LOG, WARNING, e);
} }

View File

@@ -17,7 +17,6 @@ import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault; import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
import org.briarproject.bramble.api.sync.GroupId; import org.briarproject.bramble.api.sync.GroupId;
import org.briarproject.bramble.api.sync.MessageId; import org.briarproject.bramble.api.sync.MessageId;
import org.briarproject.bramble.util.StringUtils;
import org.briarproject.briar.R; import org.briarproject.briar.R;
import org.briarproject.briar.android.activity.BriarActivity; import org.briarproject.briar.android.activity.BriarActivity;
import org.briarproject.briar.android.controller.SharingController; import org.briarproject.briar.android.controller.SharingController;
@@ -43,6 +42,7 @@ import static android.support.design.widget.Snackbar.make;
import static android.support.v7.widget.RecyclerView.NO_POSITION; import static android.support.v7.widget.RecyclerView.NO_POSITION;
import static android.support.v7.widget.RecyclerView.SCROLL_STATE_IDLE; import static android.support.v7.widget.RecyclerView.SCROLL_STATE_IDLE;
import static java.util.logging.Level.INFO; import static java.util.logging.Level.INFO;
import static org.briarproject.bramble.util.StringUtils.utf8IsTooLong;
import static org.briarproject.briar.android.threaded.ThreadItemAdapter.UnreadCount; import static org.briarproject.briar.android.threaded.ThreadItemAdapter.UnreadCount;
@MethodsNotNullByDefault @MethodsNotNullByDefault
@@ -351,7 +351,7 @@ public abstract class ThreadListActivity<G extends NamedGroup, I extends ThreadI
public void onSendClick(String text) { public void onSendClick(String text) {
if (text.trim().length() == 0) if (text.trim().length() == 0)
return; return;
if (StringUtils.utf8IsTooLong(text, getMaxBodyLength())) { if (utf8IsTooLong(text, getMaxTextLength())) {
displaySnackbar(R.string.text_too_long); displaySnackbar(R.string.text_too_long);
return; return;
} }
@@ -375,7 +375,7 @@ public abstract class ThreadListActivity<G extends NamedGroup, I extends ThreadI
updateTextInput(); updateTextInput();
} }
protected abstract int getMaxBodyLength(); protected abstract int getMaxTextLength();
@Override @Override
public void onItemReceived(I item) { public void onItemReceived(I item) {

View File

@@ -35,7 +35,7 @@ public interface ThreadListController<G extends NamedGroup, I extends ThreadItem
void markItemsRead(Collection<I> items); void markItemsRead(Collection<I> items);
void createAndStoreMessage(String body, @Nullable I parentItem, void createAndStoreMessage(String text, @Nullable I parentItem,
ResultExceptionHandler<I, DbException> handler); ResultExceptionHandler<I, DbException> handler);
void deleteNamedGroup(ExceptionHandler<DbException> handler); void deleteNamedGroup(ExceptionHandler<DbException> handler);

View File

@@ -50,7 +50,7 @@ public abstract class ThreadListControllerImpl<G extends NamedGroup, I extends T
Logger.getLogger(ThreadListControllerImpl.class.getName()); Logger.getLogger(ThreadListControllerImpl.class.getName());
private final EventBus eventBus; private final EventBus eventBus;
private final Map<MessageId, String> bodyCache = new ConcurrentHashMap<>(); private final Map<MessageId, String> textCache = new ConcurrentHashMap<>();
private volatile GroupId groupId; private volatile GroupId groupId;
protected final IdentityManager identityManager; protected final IdentityManager identityManager;
@@ -161,9 +161,9 @@ public abstract class ThreadListControllerImpl<G extends NamedGroup, I extends T
// Load bodies into cache // Load bodies into cache
start = now(); start = now();
for (H header : headers) { for (H header : headers) {
if (!bodyCache.containsKey(header.getId())) { if (!textCache.containsKey(header.getId())) {
bodyCache.put(header.getId(), textCache.put(header.getId(),
loadMessageBody(header)); loadMessageText(header));
} }
} }
logDuration(LOG, "Loading bodies", start); logDuration(LOG, "Loading bodies", start);
@@ -181,7 +181,7 @@ public abstract class ThreadListControllerImpl<G extends NamedGroup, I extends T
protected abstract Collection<H> loadHeaders() throws DbException; protected abstract Collection<H> loadHeaders() throws DbException;
@DatabaseExecutor @DatabaseExecutor
protected abstract String loadMessageBody(H header) throws DbException; protected abstract String loadMessageText(H header) throws DbException;
@Override @Override
public void markItemRead(I item) { public void markItemRead(I item) {
@@ -206,15 +206,15 @@ public abstract class ThreadListControllerImpl<G extends NamedGroup, I extends T
@DatabaseExecutor @DatabaseExecutor
protected abstract void markRead(MessageId id) throws DbException; protected abstract void markRead(MessageId id) throws DbException;
protected void storePost(M msg, String body, protected void storePost(M msg, String text,
ResultExceptionHandler<I, DbException> resultHandler) { ResultExceptionHandler<I, DbException> resultHandler) {
runOnDbThread(() -> { runOnDbThread(() -> {
try { try {
long start = now(); long start = now();
H header = addLocalMessage(msg); H header = addLocalMessage(msg);
bodyCache.put(msg.getMessage().getId(), body); textCache.put(msg.getMessage().getId(), text);
logDuration(LOG, "Storing message", start); logDuration(LOG, "Storing message", start);
resultHandler.onResult(buildItem(header, body)); resultHandler.onResult(buildItem(header, text));
} catch (DbException e) { } catch (DbException e) {
logException(LOG, WARNING, e); logException(LOG, WARNING, e);
resultHandler.onException(e); resultHandler.onException(e);
@@ -247,7 +247,7 @@ public abstract class ThreadListControllerImpl<G extends NamedGroup, I extends T
throws DbException { throws DbException {
ThreadItemList<I> items = new ThreadItemListImpl<>(); ThreadItemList<I> items = new ThreadItemListImpl<>();
for (H h : headers) { for (H h : headers) {
items.add(buildItem(h, bodyCache.get(h.getId()))); items.add(buildItem(h, textCache.get(h.getId())));
} }
MessageId msgId = messageTracker.loadStoredMessageId(groupId); MessageId msgId = messageTracker.loadStoredMessageId(groupId);
if (LOG.isLoggable(INFO)) if (LOG.isLoggable(INFO))
@@ -256,7 +256,7 @@ public abstract class ThreadListControllerImpl<G extends NamedGroup, I extends T
return items; return items;
} }
protected abstract I buildItem(H header, String body); protected abstract I buildItem(H header, String text);
protected GroupId getGroupId() { protected GroupId getGroupId() {
checkGroupId(); checkGroupId();

View File

@@ -106,13 +106,13 @@ public class UiUtils {
return (int) daysBeforeExpiry; return (int) daysBeforeExpiry;
} }
public static SpannableStringBuilder getTeaser(Context ctx, Spanned body) { public static SpannableStringBuilder getTeaser(Context ctx, Spanned text) {
if (body.length() < TEASER_LENGTH) if (text.length() < TEASER_LENGTH)
throw new IllegalArgumentException( throw new IllegalArgumentException(
"String is shorter than TEASER_LENGTH"); "String is shorter than TEASER_LENGTH");
SpannableStringBuilder builder = SpannableStringBuilder builder =
new SpannableStringBuilder(body.subSequence(0, TEASER_LENGTH)); new SpannableStringBuilder(text.subSequence(0, TEASER_LENGTH));
String ellipsis = ctx.getString(R.string.ellipsis); String ellipsis = ctx.getString(R.string.ellipsis);
builder.append(ellipsis).append(" "); builder.append(ellipsis).append(" ");

View File

@@ -8,7 +8,7 @@
tools:context=".android.blog.WriteBlogPostActivity"> tools:context=".android.blog.WriteBlogPostActivity">
<org.briarproject.briar.android.view.LargeTextInputView <org.briarproject.briar.android.view.LargeTextInputView
android:id="@+id/bodyInput" android:id="@+id/textInput"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:gravity="bottom" android:gravity="bottom"

View File

@@ -24,7 +24,7 @@
app:persona="commenter"/> app:persona="commenter"/>
<com.vanniktech.emoji.EmojiTextView <com.vanniktech.emoji.EmojiTextView
android:id="@+id/bodyView" android:id="@+id/textView"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:paddingBottom="@dimen/listitem_vertical_margin" android:paddingBottom="@dimen/listitem_vertical_margin"

View File

@@ -54,7 +54,7 @@
app:tint="?attr/colorControlNormal"/> app:tint="?attr/colorControlNormal"/>
<com.vanniktech.emoji.EmojiTextView <com.vanniktech.emoji.EmojiTextView
android:id="@+id/bodyView" android:id="@+id/textView"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_margin="@dimen/listitem_vertical_margin" android:layout_margin="@dimen/listitem_vertical_margin"
@@ -72,7 +72,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="@dimen/listitem_vertical_margin" android:layout_marginTop="@dimen/listitem_vertical_margin"
android:orientation="vertical" android:orientation="vertical"
app:layout_constraintTop_toBottomOf="@+id/bodyView"> app:layout_constraintTop_toBottomOf="@+id/textView">
<include <include
layout="@layout/list_item_blog_comment" layout="@layout/list_item_blog_comment"

View File

@@ -30,7 +30,7 @@ import static org.briarproject.bramble.api.identity.Author.Status.UNKNOWN;
import static org.briarproject.bramble.test.TestUtils.getAuthor; import static org.briarproject.bramble.test.TestUtils.getAuthor;
import static org.briarproject.bramble.test.TestUtils.getRandomId; import static org.briarproject.bramble.test.TestUtils.getRandomId;
import static org.briarproject.bramble.util.StringUtils.getRandomString; import static org.briarproject.bramble.util.StringUtils.getRandomString;
import static org.briarproject.briar.api.forum.ForumConstants.MAX_FORUM_POST_BODY_LENGTH; import static org.briarproject.briar.api.forum.ForumConstants.MAX_FORUM_POST_TEXT_LENGTH;
import static org.mockito.Mockito.times; import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
@@ -85,9 +85,9 @@ public class ForumActivityTest {
ForumItem[] forumItems = new ForumItem[6]; ForumItem[] forumItems = new ForumItem[6];
for (int i = 0; i < forumItems.length; i++) { for (int i = 0; i < forumItems.length; i++) {
Author author = getAuthor(); Author author = getAuthor();
String content = getRandomString(MAX_FORUM_POST_BODY_LENGTH); String text = getRandomString(MAX_FORUM_POST_TEXT_LENGTH);
forumItems[i] = new ForumItem(MESSAGE_IDS[i], PARENT_IDS[i], forumItems[i] = new ForumItem(MESSAGE_IDS[i], PARENT_IDS[i],
content, System.currentTimeMillis(), author, UNKNOWN); text, System.currentTimeMillis(), author, UNKNOWN);
forumItems[i].setLevel(LEVELS[i]); forumItems[i].setLevel(LEVELS[i]);
} }
ThreadItemList<ForumItem> list = new ThreadItemListImpl<>(); ThreadItemList<ForumItem> list = new ThreadItemListImpl<>();

View File

@@ -5,14 +5,14 @@ import static org.briarproject.bramble.api.sync.SyncConstants.MAX_MESSAGE_BODY_L
public interface BlogConstants { public interface BlogConstants {
/** /**
* The maximum length of a blog post's body in bytes. * The maximum length of a blog post's text in UTF-8 bytes.
*/ */
int MAX_BLOG_POST_BODY_LENGTH = MAX_MESSAGE_BODY_LENGTH - 1024; int MAX_BLOG_POST_TEXT_LENGTH = MAX_MESSAGE_BODY_LENGTH - 1024;
/** /**
* The maximum length of a blog comment in bytes. * The maximum length of a blog comment's text in UTF-8 bytes.
*/ */
int MAX_BLOG_COMMENT_LENGTH = MAX_BLOG_POST_BODY_LENGTH; int MAX_BLOG_COMMENT_TEXT_LENGTH = MAX_BLOG_POST_TEXT_LENGTH;
// Metadata keys // Metadata keys
String KEY_TYPE = "type"; String KEY_TYPE = "type";

View File

@@ -14,10 +14,10 @@ public class BlogInvitationRequest extends InvitationRequest<Blog> {
public BlogInvitationRequest(MessageId id, GroupId groupId, long time, public BlogInvitationRequest(MessageId id, GroupId groupId, long time,
boolean local, boolean sent, boolean seen, boolean read, boolean local, boolean sent, boolean seen, boolean read,
SessionId sessionId, Blog blog, @Nullable String message, SessionId sessionId, Blog blog, @Nullable String text,
boolean available, boolean canBeOpened) { boolean available, boolean canBeOpened) {
super(id, groupId, time, local, sent, seen, read, sessionId, blog, super(id, groupId, time, local, sent, seen, read, sessionId, blog,
message, available, canBeOpened); text, available, canBeOpened);
} }
@Override @Override

View File

@@ -104,9 +104,9 @@ public interface BlogManager {
BlogPostHeader getPostHeader(GroupId g, MessageId m) throws DbException; BlogPostHeader getPostHeader(GroupId g, MessageId m) throws DbException;
/** /**
* Returns the body of the blog post with the given ID. * Returns the text of the blog post with the given ID.
*/ */
String getPostBody(MessageId m) throws DbException; String getPostText(MessageId m) throws DbException;
/** /**
* Returns the headers of all posts in the given blog. * Returns the headers of all posts in the given blog.

View File

@@ -21,7 +21,7 @@ public interface BlogPostFactory {
String SIGNING_LABEL_COMMENT = CLIENT_ID.getString() + "/COMMENT"; String SIGNING_LABEL_COMMENT = CLIENT_ID.getString() + "/COMMENT";
BlogPost createBlogPost(GroupId groupId, long timestamp, BlogPost createBlogPost(GroupId groupId, long timestamp,
@Nullable MessageId parent, LocalAuthor author, String body) @Nullable MessageId parent, LocalAuthor author, String text)
throws FormatException, GeneralSecurityException; throws FormatException, GeneralSecurityException;
Message createBlogComment(GroupId groupId, LocalAuthor author, Message createBlogComment(GroupId groupId, LocalAuthor author,

View File

@@ -15,9 +15,9 @@ public interface ForumConstants {
int FORUM_SALT_LENGTH = 32; int FORUM_SALT_LENGTH = 32;
/** /**
* The maximum length of a forum post's body in bytes. * The maximum length of a forum post's text in UTF-8 bytes.
*/ */
int MAX_FORUM_POST_BODY_LENGTH = MAX_MESSAGE_BODY_LENGTH - 1024; int MAX_FORUM_POST_TEXT_LENGTH = MAX_MESSAGE_BODY_LENGTH - 1024;
// Metadata keys // Metadata keys
String KEY_TIMESTAMP = "timestamp"; String KEY_TIMESTAMP = "timestamp";

View File

@@ -16,10 +16,10 @@ public class ForumInvitationRequest extends InvitationRequest<Forum> {
public ForumInvitationRequest(MessageId id, GroupId groupId, long time, public ForumInvitationRequest(MessageId id, GroupId groupId, long time,
boolean local, boolean sent, boolean seen, boolean read, boolean local, boolean sent, boolean seen, boolean read,
SessionId sessionId, Forum forum, @Nullable String message, SessionId sessionId, Forum forum, @Nullable String text,
boolean available, boolean canBeOpened) { boolean available, boolean canBeOpened) {
super(id, groupId, time, local, sent, seen, read, sessionId, forum, super(id, groupId, time, local, sent, seen, read, sessionId, forum,
message, available, canBeOpened); text, available, canBeOpened);
} }
@Override @Override

View File

@@ -51,7 +51,7 @@ public interface ForumManager {
* Creates a local forum post. * Creates a local forum post.
*/ */
@CryptoExecutor @CryptoExecutor
ForumPost createLocalPost(GroupId groupId, String body, long timestamp, ForumPost createLocalPost(GroupId groupId, String text, long timestamp,
@Nullable MessageId parentId, LocalAuthor author); @Nullable MessageId parentId, LocalAuthor author);
/** /**
@@ -75,9 +75,9 @@ public interface ForumManager {
Collection<Forum> getForums() throws DbException; Collection<Forum> getForums() throws DbException;
/** /**
* Returns the body of the forum post with the given ID. * Returns the text of the forum post with the given ID.
*/ */
String getPostBody(MessageId m) throws DbException; String getPostText(MessageId m) throws DbException;
/** /**
* Returns the headers of all posts in the given forum. * Returns the headers of all posts in the given forum.

View File

@@ -20,7 +20,7 @@ public interface ForumPostFactory {
@CryptoExecutor @CryptoExecutor
ForumPost createPost(GroupId groupId, long timestamp, ForumPost createPost(GroupId groupId, long timestamp,
@Nullable MessageId parent, LocalAuthor author, String body) @Nullable MessageId parent, LocalAuthor author, String text)
throws FormatException, GeneralSecurityException; throws FormatException, GeneralSecurityException;
} }

View File

@@ -16,13 +16,13 @@ public class ForumPostReceivedEvent extends Event {
private final GroupId groupId; private final GroupId groupId;
private final ForumPostHeader header; private final ForumPostHeader header;
private final String body; private final String text;
public ForumPostReceivedEvent(GroupId groupId, ForumPostHeader header, public ForumPostReceivedEvent(GroupId groupId, ForumPostHeader header,
String body) { String text) {
this.groupId = groupId; this.groupId = groupId;
this.header = header; this.header = header;
this.body = body; this.text = text;
} }
public GroupId getGroupId() { public GroupId getGroupId() {
@@ -33,7 +33,7 @@ public class ForumPostReceivedEvent extends Event {
return header; return header;
} }
public String getBody() { public String getText() {
return body; return text;
} }
} }

View File

@@ -8,7 +8,7 @@ public interface IntroductionConstants {
* The maximum length of the introducer's optional message to the * The maximum length of the introducer's optional message to the
* introducees in UTF-8 bytes. * introducees in UTF-8 bytes.
*/ */
int MAX_REQUEST_MESSAGE_LENGTH = MAX_MESSAGE_BODY_LENGTH - 1024; int MAX_INTRODUCTION_TEXT_LENGTH = MAX_MESSAGE_BODY_LENGTH - 1024;
String LABEL_SESSION_ID = "org.briarproject.briar.introduction/SESSION_ID"; String LABEL_SESSION_ID = "org.briarproject.briar.introduction/SESSION_ID";

View File

@@ -36,7 +36,7 @@ public interface IntroductionManager extends ConversationClient {
/** /**
* Sends two initial introduction messages. * Sends two initial introduction messages.
*/ */
void makeIntroduction(Contact c1, Contact c2, @Nullable String msg, void makeIntroduction(Contact c1, Contact c2, @Nullable String text,
long timestamp) throws DbException; long timestamp) throws DbException;
/** /**

View File

@@ -19,10 +19,10 @@ public class IntroductionRequest extends PrivateRequest<Author> {
public IntroductionRequest(MessageId messageId, GroupId groupId, public IntroductionRequest(MessageId messageId, GroupId groupId,
long time, boolean local, boolean sent, boolean seen, boolean read, long time, boolean local, boolean sent, boolean seen, boolean read,
SessionId sessionId, Author author, @Nullable String message, SessionId sessionId, Author author, @Nullable String text,
boolean answered, boolean contact) { boolean answered, boolean contact) {
super(messageId, groupId, time, local, sent, seen, read, sessionId, super(messageId, groupId, time, local, sent, seen, read, sessionId,
author, message, answered); author, text, answered);
this.contact = contact; this.contact = contact;
} }

View File

@@ -25,7 +25,7 @@ public interface ConversationManager {
* Returns the headers of all messages in the given private conversation. * Returns the headers of all messages in the given private conversation.
* *
* Only {@link MessagingManager} returns only headers. * Only {@link MessagingManager} returns only headers.
* The others also return the message body. * The others also return the message text.
*/ */
Collection<PrivateMessageHeader> getMessageHeaders(ContactId c) Collection<PrivateMessageHeader> getMessageHeaders(ContactId c)
throws DbException; throws DbException;

View File

@@ -5,7 +5,7 @@ import static org.briarproject.bramble.api.sync.SyncConstants.MAX_MESSAGE_BODY_L
public interface MessagingConstants { public interface MessagingConstants {
/** /**
* The maximum length of a private message's body in bytes. * The maximum length of a private message's text in UTF-8 bytes.
*/ */
int MAX_PRIVATE_MESSAGE_BODY_LENGTH = MAX_MESSAGE_BODY_LENGTH - 1024; int MAX_PRIVATE_MESSAGE_TEXT_LENGTH = MAX_MESSAGE_BODY_LENGTH - 1024;
} }

View File

@@ -42,8 +42,8 @@ public interface MessagingManager extends ConversationClient {
GroupId getConversationId(ContactId c) throws DbException; GroupId getConversationId(ContactId c) throws DbException;
/** /**
* Returns the body of the private message with the given ID. * Returns the text of the private message with the given ID.
*/ */
String getMessageBody(MessageId m) throws DbException; String getMessageText(MessageId m) throws DbException;
} }

View File

@@ -8,6 +8,6 @@ import org.briarproject.bramble.api.sync.GroupId;
public interface PrivateMessageFactory { public interface PrivateMessageFactory {
PrivateMessage createPrivateMessage(GroupId groupId, long timestamp, PrivateMessage createPrivateMessage(GroupId groupId, long timestamp,
String body) throws FormatException; String text) throws FormatException;
} }

View File

@@ -16,17 +16,17 @@ public class PrivateRequest<N extends Nameable> extends PrivateMessageHeader {
private final SessionId sessionId; private final SessionId sessionId;
private final N nameable; private final N nameable;
@Nullable @Nullable
private final String message; private final String text;
private final boolean answered; private final boolean answered;
public PrivateRequest(MessageId messageId, GroupId groupId, long time, public PrivateRequest(MessageId messageId, GroupId groupId, long time,
boolean local, boolean sent, boolean seen, boolean read, boolean local, boolean sent, boolean seen, boolean read,
SessionId sessionId, N nameable, @Nullable String message, SessionId sessionId, N nameable, @Nullable String text,
boolean answered) { boolean answered) {
super(messageId, groupId, time, local, sent, seen, read); super(messageId, groupId, time, local, sent, seen, read);
this.sessionId = sessionId; this.sessionId = sessionId;
this.nameable = nameable; this.nameable = nameable;
this.message = message; this.text = text;
this.answered = answered; this.answered = answered;
} }
@@ -43,8 +43,8 @@ public class PrivateRequest<N extends Nameable> extends PrivateMessageHeader {
} }
@Nullable @Nullable
public String getMessage() { public String getText() {
return message; return text;
} }
public boolean wasAnswered() { public boolean wasAnswered() {

View File

@@ -51,13 +51,13 @@ public interface GroupMessageFactory {
* @param parentId The ID of the parent post, or null if the post has no * @param parentId The ID of the parent post, or null if the post has no
* parent * parent
* @param author The author of the post * @param author The author of the post
* @param body The content of the post * @param text The text of the post
* @param previousMsgId The ID of the author's previous message * @param previousMsgId The ID of the author's previous message
* in this group * in this group
*/ */
@CryptoExecutor @CryptoExecutor
GroupMessage createGroupMessage(GroupId groupId, long timestamp, GroupMessage createGroupMessage(GroupId groupId, long timestamp,
@Nullable MessageId parentId, LocalAuthor author, String body, @Nullable MessageId parentId, LocalAuthor author, String text,
MessageId previousMsgId); MessageId previousMsgId);
} }

View File

@@ -15,13 +15,13 @@ public interface PrivateGroupConstants {
int GROUP_SALT_LENGTH = 32; int GROUP_SALT_LENGTH = 32;
/** /**
* The maximum length of a group post's body in bytes. * The maximum length of a group post's text in UTF-8 bytes.
*/ */
int MAX_GROUP_POST_BODY_LENGTH = MAX_MESSAGE_BODY_LENGTH - 1024; int MAX_GROUP_POST_TEXT_LENGTH = MAX_MESSAGE_BODY_LENGTH - 1024;
/** /**
* The maximum length of a group invitation message in bytes. * The maximum length of a group invitation's optional text in UTF-8 bytes.
*/ */
int MAX_GROUP_INVITATION_MSG_LENGTH = MAX_MESSAGE_BODY_LENGTH - 1024; int MAX_GROUP_INVITATION_TEXT_LENGTH = MAX_MESSAGE_BODY_LENGTH - 1024;
} }

View File

@@ -92,9 +92,9 @@ public interface PrivateGroupManager {
Collection<PrivateGroup> getPrivateGroups() throws DbException; Collection<PrivateGroup> getPrivateGroups() throws DbException;
/** /**
* Returns the body of the private group message with the given ID. * Returns the text of the private group message with the given ID.
*/ */
String getMessageBody(MessageId m) throws DbException; String getMessageText(MessageId m) throws DbException;
/** /**
* Returns the headers of all messages in the given private group. * Returns the headers of all messages in the given private group.

View File

@@ -17,14 +17,14 @@ public class GroupMessageAddedEvent extends Event {
private final GroupId groupId; private final GroupId groupId;
private final GroupMessageHeader header; private final GroupMessageHeader header;
private final String body; private final String text;
private final boolean local; private final boolean local;
public GroupMessageAddedEvent(GroupId groupId, GroupMessageHeader header, public GroupMessageAddedEvent(GroupId groupId, GroupMessageHeader header,
String body, boolean local) { String text, boolean local) {
this.groupId = groupId; this.groupId = groupId;
this.header = header; this.header = header;
this.body = body; this.text = text;
this.local = local; this.local = local;
} }
@@ -36,8 +36,8 @@ public class GroupMessageAddedEvent extends Event {
return header; return header;
} }
public String getBody() { public String getText() {
return body; return text;
} }
public boolean isLocal() { public boolean isLocal() {

View File

@@ -42,7 +42,7 @@ public interface GroupInvitationManager extends ConversationClient {
* shared with the contact, for example because an invitation is already * shared with the contact, for example because an invitation is already
* pending. * pending.
*/ */
void sendInvitation(GroupId g, ContactId c, @Nullable String message, void sendInvitation(GroupId g, ContactId c, @Nullable String text,
long timestamp, byte[] signature) throws DbException; long timestamp, byte[] signature) throws DbException;
/** /**

View File

@@ -18,9 +18,9 @@ public class GroupInvitationRequest extends InvitationRequest<PrivateGroup> {
public GroupInvitationRequest(MessageId id, GroupId groupId, long time, public GroupInvitationRequest(MessageId id, GroupId groupId, long time,
boolean local, boolean sent, boolean seen, boolean read, boolean local, boolean sent, boolean seen, boolean read,
SessionId sessionId, PrivateGroup shareable, SessionId sessionId, PrivateGroup shareable,
@Nullable String message, boolean available, boolean canBeOpened) { @Nullable String text, boolean available, boolean canBeOpened) {
super(id, groupId, time, local, sent, seen, read, sessionId, shareable, super(id, groupId, time, local, sent, seen, read, sessionId, shareable,
message, available, canBeOpened); text, available, canBeOpened);
} }
@Override @Override

View File

@@ -14,10 +14,10 @@ public abstract class InvitationRequest<S extends Shareable> extends
public InvitationRequest(MessageId messageId, GroupId groupId, long time, public InvitationRequest(MessageId messageId, GroupId groupId, long time,
boolean local, boolean sent, boolean seen, boolean read, boolean local, boolean sent, boolean seen, boolean read,
SessionId sessionId, S object, @Nullable String message, SessionId sessionId, S object, @Nullable String text,
boolean available, boolean canBeOpened) { boolean available, boolean canBeOpened) {
super(messageId, groupId, time, local, sent, seen, read, sessionId, super(messageId, groupId, time, local, sent, seen, read, sessionId,
object, message, !available); object, text, !available);
this.canBeOpened = canBeOpened; this.canBeOpened = canBeOpened;
} }

View File

@@ -5,9 +5,8 @@ import static org.briarproject.bramble.api.sync.SyncConstants.MAX_MESSAGE_BODY_L
public interface SharingConstants { public interface SharingConstants {
/** /**
* The maximum length of the optional message from the inviter to the * The maximum length of an invitation's optional text in UTF-8 bytes.
* invitee in UTF-8 bytes.
*/ */
int MAX_INVITATION_MESSAGE_LENGTH = MAX_MESSAGE_BODY_LENGTH - 1024; int MAX_INVITATION_TEXT_LENGTH = MAX_MESSAGE_BODY_LENGTH - 1024;
} }

View File

@@ -17,11 +17,11 @@ public interface SharingManager<S extends Shareable>
extends ConversationClient { extends ConversationClient {
/** /**
* Sends an invitation to share the given group with the given contact * Sends an invitation to share the given group with the given contact,
* and sends an optional message along with it. * including optional text.
*/ */
void sendInvitation(GroupId shareableId, ContactId contactId, void sendInvitation(GroupId shareableId, ContactId contactId,
@Nullable String message, long timestamp) throws DbException; @Nullable String text, long timestamp) throws DbException;
/** /**
* Responds to a pending group invitation * Responds to a pending group invitation

View File

@@ -26,7 +26,7 @@ public interface TestDataCreator {
Contact addContact(String name) throws DbException; Contact addContact(String name) throws DbException;
@IoExecutor @IoExecutor
void addPrivateMessage(Contact contact, String body, long time, void addPrivateMessage(Contact contact, String text, long time,
boolean local) throws DbException, FormatException; boolean local) throws DbException, FormatException;
} }

View File

@@ -456,21 +456,22 @@ class BlogManagerImpl extends BdfIncomingMessageHook implements BlogManager,
} }
@Override @Override
public String getPostBody(MessageId m) throws DbException { public String getPostText(MessageId m) throws DbException {
try { try {
return getPostBody(clientHelper.getMessageAsList(m)); return getPostText(clientHelper.getMessageAsList(m));
} catch (FormatException e) { } catch (FormatException e) {
throw new DbException(e); throw new DbException(e);
} }
} }
private String getPostBody(BdfList message) throws FormatException { private String getPostText(BdfList message) throws FormatException {
MessageType type = MessageType.valueOf(message.getLong(0).intValue()); MessageType type = MessageType.valueOf(message.getLong(0).intValue());
if (type == POST) { if (type == POST) {
// type, body, signature // Type, text, signature
return message.getString(1); return message.getString(1);
} else if (type == WRAPPED_POST) { } else if (type == WRAPPED_POST) {
// type, p_group descriptor, p_timestamp, p_content, p_signature // Type, copied group descriptor, copied timestamp, copied text,
// copied signature
return message.getString(3); return message.getString(3);
} else { } else {
throw new FormatException(); throw new FormatException();

View File

@@ -20,8 +20,8 @@ import javax.annotation.Nullable;
import javax.annotation.concurrent.Immutable; import javax.annotation.concurrent.Immutable;
import javax.inject.Inject; import javax.inject.Inject;
import static org.briarproject.briar.api.blog.BlogConstants.MAX_BLOG_COMMENT_LENGTH; import static org.briarproject.briar.api.blog.BlogConstants.MAX_BLOG_COMMENT_TEXT_LENGTH;
import static org.briarproject.briar.api.blog.BlogConstants.MAX_BLOG_POST_BODY_LENGTH; import static org.briarproject.briar.api.blog.BlogConstants.MAX_BLOG_POST_TEXT_LENGTH;
import static org.briarproject.briar.api.blog.MessageType.COMMENT; import static org.briarproject.briar.api.blog.MessageType.COMMENT;
import static org.briarproject.briar.api.blog.MessageType.POST; import static org.briarproject.briar.api.blog.MessageType.POST;
import static org.briarproject.briar.api.blog.MessageType.WRAPPED_COMMENT; import static org.briarproject.briar.api.blog.MessageType.WRAPPED_COMMENT;
@@ -42,23 +42,23 @@ class BlogPostFactoryImpl implements BlogPostFactory {
@Override @Override
public BlogPost createBlogPost(GroupId groupId, long timestamp, public BlogPost createBlogPost(GroupId groupId, long timestamp,
@Nullable MessageId parent, LocalAuthor author, String body) @Nullable MessageId parent, LocalAuthor author, String text)
throws FormatException, GeneralSecurityException { throws FormatException, GeneralSecurityException {
// Validate the arguments // Validate the arguments
int bodyLength = StringUtils.toUtf8(body).length; int textLength = StringUtils.toUtf8(text).length;
if (bodyLength > MAX_BLOG_POST_BODY_LENGTH) if (textLength > MAX_BLOG_POST_TEXT_LENGTH)
throw new IllegalArgumentException(); throw new IllegalArgumentException();
// Serialise the data to be signed // Serialise the data to be signed
BdfList signed = BdfList.of(groupId, timestamp, body); BdfList signed = BdfList.of(groupId, timestamp, text);
// Generate the signature // Generate the signature
byte[] sig = clientHelper byte[] sig = clientHelper
.sign(SIGNING_LABEL_POST, signed, author.getPrivateKey()); .sign(SIGNING_LABEL_POST, signed, author.getPrivateKey());
// Serialise the signed message // Serialise the signed message
BdfList message = BdfList.of(POST.getInt(), body, sig); BdfList message = BdfList.of(POST.getInt(), text, sig);
Message m = clientHelper.createMessage(groupId, timestamp, message); Message m = clientHelper.createMessage(groupId, timestamp, message);
return new BlogPost(m, parent, author); return new BlogPost(m, parent, author);
} }
@@ -72,7 +72,7 @@ class BlogPostFactoryImpl implements BlogPostFactory {
if (comment != null) { if (comment != null) {
int commentLength = StringUtils.toUtf8(comment).length; int commentLength = StringUtils.toUtf8(comment).length;
if (commentLength == 0) throw new IllegalArgumentException(); if (commentLength == 0) throw new IllegalArgumentException();
if (commentLength > MAX_BLOG_COMMENT_LENGTH) if (commentLength > MAX_BLOG_COMMENT_TEXT_LENGTH)
throw new IllegalArgumentException(); throw new IllegalArgumentException();
} }
@@ -98,10 +98,10 @@ class BlogPostFactoryImpl implements BlogPostFactory {
throw new IllegalArgumentException("Needs to wrap a POST"); throw new IllegalArgumentException("Needs to wrap a POST");
// Serialise the message // Serialise the message
String content = body.getString(1); String text = body.getString(1);
byte[] signature = body.getRaw(2); byte[] signature = body.getRaw(2);
BdfList message = BdfList.of(WRAPPED_POST.getInt(), descriptor, BdfList message = BdfList.of(WRAPPED_POST.getInt(), descriptor,
timestamp, content, signature); timestamp, text, signature);
return clientHelper return clientHelper
.createMessage(groupId, clock.currentTimeMillis(), message); .createMessage(groupId, clock.currentTimeMillis(), message);
} }
@@ -116,10 +116,10 @@ class BlogPostFactoryImpl implements BlogPostFactory {
// Serialise the message // Serialise the message
byte[] descriptor = body.getRaw(1); byte[] descriptor = body.getRaw(1);
long timestamp = body.getLong(2); long timestamp = body.getLong(2);
String content = body.getString(3); String text = body.getString(3);
byte[] signature = body.getRaw(4); byte[] signature = body.getRaw(4);
BdfList message = BdfList.of(WRAPPED_POST.getInt(), descriptor, BdfList message = BdfList.of(WRAPPED_POST.getInt(), descriptor,
timestamp, content, signature); timestamp, text, signature);
return clientHelper return clientHelper
.createMessage(groupId, clock.currentTimeMillis(), message); .createMessage(groupId, clock.currentTimeMillis(), message);
} }

View File

@@ -22,10 +22,10 @@ import org.briarproject.briar.api.blog.MessageType;
import java.security.GeneralSecurityException; import java.security.GeneralSecurityException;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
import javax.annotation.concurrent.Immutable; import javax.annotation.concurrent.Immutable;
import static java.util.Collections.singletonList;
import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_SIGNATURE_LENGTH; import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_SIGNATURE_LENGTH;
import static org.briarproject.bramble.util.ValidationUtils.checkLength; import static org.briarproject.bramble.util.ValidationUtils.checkLength;
import static org.briarproject.bramble.util.ValidationUtils.checkSize; import static org.briarproject.bramble.util.ValidationUtils.checkSize;
@@ -39,8 +39,8 @@ import static org.briarproject.briar.api.blog.BlogConstants.KEY_RSS_FEED;
import static org.briarproject.briar.api.blog.BlogConstants.KEY_TIMESTAMP; import static org.briarproject.briar.api.blog.BlogConstants.KEY_TIMESTAMP;
import static org.briarproject.briar.api.blog.BlogConstants.KEY_TIME_RECEIVED; import static org.briarproject.briar.api.blog.BlogConstants.KEY_TIME_RECEIVED;
import static org.briarproject.briar.api.blog.BlogConstants.KEY_TYPE; import static org.briarproject.briar.api.blog.BlogConstants.KEY_TYPE;
import static org.briarproject.briar.api.blog.BlogConstants.MAX_BLOG_COMMENT_LENGTH; import static org.briarproject.briar.api.blog.BlogConstants.MAX_BLOG_COMMENT_TEXT_LENGTH;
import static org.briarproject.briar.api.blog.BlogConstants.MAX_BLOG_POST_BODY_LENGTH; import static org.briarproject.briar.api.blog.BlogConstants.MAX_BLOG_POST_TEXT_LENGTH;
import static org.briarproject.briar.api.blog.BlogManager.CLIENT_ID; import static org.briarproject.briar.api.blog.BlogManager.CLIENT_ID;
import static org.briarproject.briar.api.blog.BlogManager.MAJOR_VERSION; import static org.briarproject.briar.api.blog.BlogManager.MAJOR_VERSION;
import static org.briarproject.briar.api.blog.BlogPostFactory.SIGNING_LABEL_COMMENT; import static org.briarproject.briar.api.blog.BlogPostFactory.SIGNING_LABEL_COMMENT;
@@ -99,15 +99,15 @@ class BlogPostValidator extends BdfMessageValidator {
private BdfMessageContext validatePost(Message m, Group g, BdfList body) private BdfMessageContext validatePost(Message m, Group g, BdfList body)
throws InvalidMessageException, FormatException { throws InvalidMessageException, FormatException {
// Content, Signature // Text, signature
checkSize(body, 2); checkSize(body, 2);
String postBody = body.getString(0); String text = body.getString(0);
checkLength(postBody, 0, MAX_BLOG_POST_BODY_LENGTH); checkLength(text, 0, MAX_BLOG_POST_TEXT_LENGTH);
// Verify Signature // Verify signature
byte[] sig = body.getRaw(1); byte[] sig = body.getRaw(1);
checkLength(sig, 1, MAX_SIGNATURE_LENGTH); checkLength(sig, 1, MAX_SIGNATURE_LENGTH);
BdfList signed = BdfList.of(g.getId(), m.getTimestamp(), postBody); BdfList signed = BdfList.of(g.getId(), m.getTimestamp(), text);
Blog b = blogFactory.parseBlog(g); Blog b = blogFactory.parseBlog(g);
Author a = b.getAuthor(); Author a = b.getAuthor();
try { try {
@@ -128,23 +128,23 @@ class BlogPostValidator extends BdfMessageValidator {
private BdfMessageContext validateComment(Message m, Group g, BdfList body) private BdfMessageContext validateComment(Message m, Group g, BdfList body)
throws InvalidMessageException, FormatException { throws InvalidMessageException, FormatException {
// comment, parent_original_id, parent_id, signature // Comment, parent original ID, parent ID, signature
checkSize(body, 4); checkSize(body, 4);
// Comment // Comment
String comment = body.getOptionalString(0); String comment = body.getOptionalString(0);
checkLength(comment, 1, MAX_BLOG_COMMENT_LENGTH); checkLength(comment, 1, MAX_BLOG_COMMENT_TEXT_LENGTH);
// parent_original_id // Parent original ID
// The ID of a post or comment in this group or another group // The ID of a post or comment in this blog or another blog
byte[] pOriginalIdBytes = body.getRaw(1); byte[] pOriginalIdBytes = body.getRaw(1);
checkLength(pOriginalIdBytes, MessageId.LENGTH); checkLength(pOriginalIdBytes, MessageId.LENGTH);
MessageId pOriginalId = new MessageId(pOriginalIdBytes); MessageId pOriginalId = new MessageId(pOriginalIdBytes);
// parent_id // Parent ID
// The ID of a post, comment, wrapped post or wrapped comment in this // The ID of the comment's parent, which is a post, comment, wrapped
// group, which had the ID parent_original_id in the group // post or wrapped comment in this blog, which had the ID
// where it was originally posted // parentOriginalId in the blog where it was originally posted
byte[] currentIdBytes = body.getRaw(2); byte[] currentIdBytes = body.getRaw(2);
checkLength(currentIdBytes, MessageId.LENGTH); checkLength(currentIdBytes, MessageId.LENGTH);
MessageId currentId = new MessageId(currentIdBytes); MessageId currentId = new MessageId(currentIdBytes);
@@ -170,35 +170,37 @@ class BlogPostValidator extends BdfMessageValidator {
meta.put(KEY_ORIGINAL_PARENT_MSG_ID, pOriginalId); meta.put(KEY_ORIGINAL_PARENT_MSG_ID, pOriginalId);
meta.put(KEY_PARENT_MSG_ID, currentId); meta.put(KEY_PARENT_MSG_ID, currentId);
meta.put(KEY_AUTHOR, clientHelper.toList(a)); meta.put(KEY_AUTHOR, clientHelper.toList(a));
Collection<MessageId> dependencies = Collections.singleton(currentId); Collection<MessageId> dependencies = singletonList(currentId);
return new BdfMessageContext(meta, dependencies); return new BdfMessageContext(meta, dependencies);
} }
private BdfMessageContext validateWrappedPost(BdfList body) private BdfMessageContext validateWrappedPost(BdfList body)
throws InvalidMessageException, FormatException { throws InvalidMessageException, FormatException {
// p_group descriptor, p_timestamp, p_content, p_signature // Copied group descriptor, copied timestamp, copied text, copied
// signature
checkSize(body, 4); checkSize(body, 4);
// Group Descriptor // Copied group descriptor of original post
byte[] descriptor = body.getRaw(0); byte[] descriptor = body.getRaw(0);
// Timestamp of Wrapped Post // Copied timestamp of original post
long wTimestamp = body.getLong(1); long wTimestamp = body.getLong(1);
if (wTimestamp < 0) throw new FormatException(); if (wTimestamp < 0) throw new FormatException();
// Content of Wrapped Post // Copied text of original post
String content = body.getString(2); String text = body.getString(2);
checkLength(text, 0, MAX_BLOG_POST_TEXT_LENGTH);
// Signature of Wrapped Post // Copied signature of original post
byte[] signature = body.getRaw(3); byte[] signature = body.getRaw(3);
checkLength(signature, 1, MAX_SIGNATURE_LENGTH); checkLength(signature, 1, MAX_SIGNATURE_LENGTH);
// Get and Validate the Wrapped Message // Reconstruct and validate the original post
Group wGroup = groupFactory.createGroup(CLIENT_ID, MAJOR_VERSION, Group wGroup = groupFactory.createGroup(CLIENT_ID, MAJOR_VERSION,
descriptor); descriptor);
Blog wBlog = blogFactory.parseBlog(wGroup); Blog wBlog = blogFactory.parseBlog(wGroup);
BdfList wBodyList = BdfList.of(POST.getInt(), content, signature); BdfList wBodyList = BdfList.of(POST.getInt(), text, signature);
byte[] wBody = clientHelper.toByteArray(wBodyList); byte[] wBody = clientHelper.toByteArray(wBodyList);
Message wMessage = Message wMessage =
messageFactory.createMessage(wGroup.getId(), wTimestamp, wBody); messageFactory.createMessage(wGroup.getId(), wTimestamp, wBody);
@@ -217,47 +219,46 @@ class BlogPostValidator extends BdfMessageValidator {
private BdfMessageContext validateWrappedComment(BdfList body) private BdfMessageContext validateWrappedComment(BdfList body)
throws InvalidMessageException, FormatException { throws InvalidMessageException, FormatException {
// c_group descriptor, c_timestamp, c_comment, c_parent_original_id, // Copied group descriptor, copied timestamp, copied text, copied
// c_parent_id, c_signature, parent_id // parent original ID, copied parent ID, copied signature, parent ID
checkSize(body, 7); checkSize(body, 7);
// Group Descriptor // Copied group descriptor of original comment
byte[] descriptor = body.getRaw(0); byte[] descriptor = body.getRaw(0);
// Timestamp of Wrapped Comment // Copied timestamp of original comment
long wTimestamp = body.getLong(1); long wTimestamp = body.getLong(1);
if (wTimestamp < 0) throw new FormatException(); if (wTimestamp < 0) throw new FormatException();
// Body of Wrapped Comment // Copied text of original comment
String comment = body.getOptionalString(2); String comment = body.getOptionalString(2);
checkLength(comment, 1, MAX_BLOG_COMMENT_LENGTH); checkLength(comment, 1, MAX_BLOG_COMMENT_TEXT_LENGTH);
// c_parent_original_id // Copied parent original ID of original comment
// Taken from the original comment
byte[] pOriginalIdBytes = body.getRaw(3); byte[] pOriginalIdBytes = body.getRaw(3);
checkLength(pOriginalIdBytes, MessageId.LENGTH); checkLength(pOriginalIdBytes, MessageId.LENGTH);
MessageId pOriginalId = new MessageId(pOriginalIdBytes); MessageId pOriginalId = new MessageId(pOriginalIdBytes);
// c_parent_id // Copied parent ID of original comment
// Taken from the original comment
byte[] oldIdBytes = body.getRaw(4); byte[] oldIdBytes = body.getRaw(4);
checkLength(oldIdBytes, MessageId.LENGTH); checkLength(oldIdBytes, MessageId.LENGTH);
MessageId oldId = new MessageId(oldIdBytes); MessageId oldId = new MessageId(oldIdBytes);
// c_signature // Copied signature of original comment
// Taken from the original comment
byte[] signature = body.getRaw(5); byte[] signature = body.getRaw(5);
checkLength(signature, 1, MAX_SIGNATURE_LENGTH); checkLength(signature, 1, MAX_SIGNATURE_LENGTH);
// parent_id // Parent ID
// The ID of a post, comment, wrapped post or wrapped comment in this // The ID of this comment's parent, which is a post, comment, wrapped
// group, which had the ID c_parent_original_id in the group // post or wrapped comment in this blog, which had the ID
// where it was originally posted // copiedParentOriginalId in the blog where the parent was originally
// posted, and the ID copiedParentId in the blog where this comment was
// originally posted
byte[] parentIdBytes = body.getRaw(6); byte[] parentIdBytes = body.getRaw(6);
checkLength(parentIdBytes, MessageId.LENGTH); checkLength(parentIdBytes, MessageId.LENGTH);
MessageId parentId = new MessageId(parentIdBytes); MessageId parentId = new MessageId(parentIdBytes);
// Get and Validate the Wrapped Comment // Reconstruct and validate the original comment
Group wGroup = groupFactory.createGroup(CLIENT_ID, MAJOR_VERSION, Group wGroup = groupFactory.createGroup(CLIENT_ID, MAJOR_VERSION,
descriptor); descriptor);
BdfList wBodyList = BdfList.of(COMMENT.getInt(), comment, pOriginalId, BdfList wBodyList = BdfList.of(COMMENT.getInt(), comment, pOriginalId,
@@ -269,7 +270,7 @@ class BlogPostValidator extends BdfMessageValidator {
BdfMessageContext c = validateComment(wMessage, wGroup, wBodyList); BdfMessageContext c = validateComment(wMessage, wGroup, wBodyList);
// Return the metadata and dependencies // Return the metadata and dependencies
Collection<MessageId> dependencies = Collections.singleton(parentId); Collection<MessageId> dependencies = singletonList(parentId);
BdfDictionary meta = new BdfDictionary(); BdfDictionary meta = new BdfDictionary();
meta.put(KEY_ORIGINAL_MSG_ID, wMessage.getId()); meta.put(KEY_ORIGINAL_MSG_ID, wMessage.getId());
meta.put(KEY_ORIGINAL_PARENT_MSG_ID, pOriginalId); meta.put(KEY_ORIGINAL_PARENT_MSG_ID, pOriginalId);

View File

@@ -64,7 +64,7 @@ import okhttp3.ResponseBody;
import static java.util.concurrent.TimeUnit.MILLISECONDS; import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static java.util.logging.Level.WARNING; import static java.util.logging.Level.WARNING;
import static org.briarproject.bramble.util.LogUtils.logException; import static org.briarproject.bramble.util.LogUtils.logException;
import static org.briarproject.briar.api.blog.BlogConstants.MAX_BLOG_POST_BODY_LENGTH; import static org.briarproject.briar.api.blog.BlogConstants.MAX_BLOG_POST_TEXT_LENGTH;
import static org.briarproject.briar.api.feed.FeedConstants.FETCH_DELAY_INITIAL; import static org.briarproject.briar.api.feed.FeedConstants.FETCH_DELAY_INITIAL;
import static org.briarproject.briar.api.feed.FeedConstants.FETCH_INTERVAL; import static org.briarproject.briar.api.feed.FeedConstants.FETCH_INTERVAL;
import static org.briarproject.briar.api.feed.FeedConstants.FETCH_UNIT; import static org.briarproject.briar.api.feed.FeedConstants.FETCH_UNIT;
@@ -410,11 +410,10 @@ class FeedManagerImpl implements FeedManager, Client, EventListener,
return lastEntryTime; return lastEntryTime;
} }
private void postEntry(Transaction txn, Feed feed, SyndEntry entry) private void postEntry(Transaction txn, Feed feed, SyndEntry entry) {
throws DbException {
LOG.info("Adding new entry..."); LOG.info("Adding new entry...");
// build post body // build post text
StringBuilder b = new StringBuilder(); StringBuilder b = new StringBuilder();
if (!StringUtils.isNullOrEmpty(entry.getTitle())) { if (!StringUtils.isNullOrEmpty(entry.getTitle())) {
@@ -454,12 +453,12 @@ class FeedManagerImpl implements FeedManager, Client, EventListener,
if (date == null) date = entry.getPublishedDate(); if (date == null) date = entry.getPublishedDate();
if (date == null) time = now; if (date == null) time = now;
else time = Math.max(0, Math.min(date.getTime(), now)); else time = Math.max(0, Math.min(date.getTime(), now));
String body = getPostBody(b.toString()); String text = getPostText(b.toString());
try { try {
// create and store post // create and store post
LocalAuthor localAuthor = feed.getLocalAuthor(); LocalAuthor localAuthor = feed.getLocalAuthor();
BlogPost post = blogPostFactory BlogPost post = blogPostFactory
.createBlogPost(groupId, time, null, localAuthor, body); .createBlogPost(groupId, time, null, localAuthor, text);
blogManager.addLocalPost(txn, post); blogManager.addLocalPost(txn, post);
} catch (DbException | GeneralSecurityException | FormatException e) { } catch (DbException | GeneralSecurityException | FormatException e) {
logException(LOG, WARNING, e); logException(LOG, WARNING, e);
@@ -470,9 +469,9 @@ class FeedManagerImpl implements FeedManager, Client, EventListener,
} }
} }
private String getPostBody(String text) { private String getPostText(String text) {
text = clean(text, ARTICLE); text = clean(text, ARTICLE);
return StringUtils.truncateUtf8(text, MAX_BLOG_POST_BODY_LENGTH); return StringUtils.truncateUtf8(text, MAX_BLOG_POST_TEXT_LENGTH);
} }
private Comparator<SyndEntry> getEntryComparator() { private Comparator<SyndEntry> getEntryComparator() {

View File

@@ -82,9 +82,9 @@ class ForumManagerImpl extends BdfIncomingMessageHook implements ForumManager {
messageTracker.trackIncomingMessage(txn, m); messageTracker.trackIncomingMessage(txn, m);
ForumPostHeader header = getForumPostHeader(txn, m.getId(), meta); ForumPostHeader header = getForumPostHeader(txn, m.getId(), meta);
String postBody = getPostBody(body); String text = getPostText(body);
ForumPostReceivedEvent event = ForumPostReceivedEvent event =
new ForumPostReceivedEvent(m.getGroupId(), header, postBody); new ForumPostReceivedEvent(m.getGroupId(), header, text);
txn.attach(event); txn.attach(event);
// share message // share message
@@ -113,12 +113,12 @@ class ForumManagerImpl extends BdfIncomingMessageHook implements ForumManager {
} }
@Override @Override
public ForumPost createLocalPost(GroupId groupId, String body, public ForumPost createLocalPost(GroupId groupId, String text,
long timestamp, @Nullable MessageId parentId, LocalAuthor author) { long timestamp, @Nullable MessageId parentId, LocalAuthor author) {
ForumPost p; ForumPost p;
try { try {
p = forumPostFactory.createPost(groupId, timestamp, parentId, p = forumPostFactory.createPost(groupId, timestamp, parentId,
author, body); author, text);
} catch (GeneralSecurityException | FormatException e) { } catch (GeneralSecurityException | FormatException e) {
throw new AssertionError(e); throw new AssertionError(e);
} }
@@ -175,16 +175,16 @@ class ForumManagerImpl extends BdfIncomingMessageHook implements ForumManager {
} }
@Override @Override
public String getPostBody(MessageId m) throws DbException { public String getPostText(MessageId m) throws DbException {
try { try {
return getPostBody(clientHelper.getMessageAsList(m)); return getPostText(clientHelper.getMessageAsList(m));
} catch (FormatException e) { } catch (FormatException e) {
throw new DbException(e); throw new DbException(e);
} }
} }
private String getPostBody(BdfList body) throws FormatException { private String getPostText(BdfList body) throws FormatException {
// Parent ID, author, forum post body, signature // Parent ID, author, text, signature
return body.getString(2); return body.getString(2);
} }

View File

@@ -8,7 +8,6 @@ import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import org.briarproject.bramble.api.sync.GroupId; import org.briarproject.bramble.api.sync.GroupId;
import org.briarproject.bramble.api.sync.Message; import org.briarproject.bramble.api.sync.Message;
import org.briarproject.bramble.api.sync.MessageId; import org.briarproject.bramble.api.sync.MessageId;
import org.briarproject.bramble.util.StringUtils;
import org.briarproject.briar.api.forum.ForumPost; import org.briarproject.briar.api.forum.ForumPost;
import org.briarproject.briar.api.forum.ForumPostFactory; import org.briarproject.briar.api.forum.ForumPostFactory;
@@ -18,7 +17,8 @@ import javax.annotation.Nullable;
import javax.annotation.concurrent.Immutable; import javax.annotation.concurrent.Immutable;
import javax.inject.Inject; import javax.inject.Inject;
import static org.briarproject.briar.api.forum.ForumConstants.MAX_FORUM_POST_BODY_LENGTH; import static org.briarproject.bramble.util.StringUtils.utf8IsTooLong;
import static org.briarproject.briar.api.forum.ForumConstants.MAX_FORUM_POST_TEXT_LENGTH;
@Immutable @Immutable
@NotNullByDefault @NotNullByDefault
@@ -33,20 +33,20 @@ class ForumPostFactoryImpl implements ForumPostFactory {
@Override @Override
public ForumPost createPost(GroupId groupId, long timestamp, public ForumPost createPost(GroupId groupId, long timestamp,
@Nullable MessageId parent, LocalAuthor author, String body) @Nullable MessageId parent, LocalAuthor author, String text)
throws FormatException, GeneralSecurityException { throws FormatException, GeneralSecurityException {
// Validate the arguments // Validate the arguments
if (StringUtils.utf8IsTooLong(body, MAX_FORUM_POST_BODY_LENGTH)) if (utf8IsTooLong(text, MAX_FORUM_POST_TEXT_LENGTH))
throw new IllegalArgumentException(); throw new IllegalArgumentException();
// Serialise the data to be signed // Serialise the data to be signed
BdfList authorList = clientHelper.toList(author); BdfList authorList = clientHelper.toList(author);
BdfList signed = BdfList.of(groupId, timestamp, parent, authorList, BdfList signed = BdfList.of(groupId, timestamp, parent, authorList,
body); text);
// Sign the data // Sign the data
byte[] sig = clientHelper.sign(SIGNING_LABEL_POST, signed, byte[] sig = clientHelper.sign(SIGNING_LABEL_POST, signed,
author.getPrivateKey()); author.getPrivateKey());
// Serialise the signed message // Serialise the signed message
BdfList message = BdfList.of(parent, authorList, body, sig); BdfList message = BdfList.of(parent, authorList, text, sig);
Message m = clientHelper.createMessage(groupId, timestamp, message); Message m = clientHelper.createMessage(groupId, timestamp, message);
return new ForumPost(m, parent, author); return new ForumPost(m, parent, author);
} }

View File

@@ -18,10 +18,11 @@ import org.briarproject.bramble.api.system.Clock;
import java.security.GeneralSecurityException; import java.security.GeneralSecurityException;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
import javax.annotation.concurrent.Immutable; import javax.annotation.concurrent.Immutable;
import static java.util.Collections.emptyList;
import static java.util.Collections.singletonList;
import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_SIGNATURE_LENGTH; import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_SIGNATURE_LENGTH;
import static org.briarproject.bramble.util.ValidationUtils.checkLength; import static org.briarproject.bramble.util.ValidationUtils.checkLength;
import static org.briarproject.bramble.util.ValidationUtils.checkSize; import static org.briarproject.bramble.util.ValidationUtils.checkSize;
@@ -29,7 +30,7 @@ import static org.briarproject.briar.api.forum.ForumConstants.KEY_AUTHOR;
import static org.briarproject.briar.api.forum.ForumConstants.KEY_PARENT; import static org.briarproject.briar.api.forum.ForumConstants.KEY_PARENT;
import static org.briarproject.briar.api.forum.ForumConstants.KEY_READ; import static org.briarproject.briar.api.forum.ForumConstants.KEY_READ;
import static org.briarproject.briar.api.forum.ForumConstants.KEY_TIMESTAMP; import static org.briarproject.briar.api.forum.ForumConstants.KEY_TIMESTAMP;
import static org.briarproject.briar.api.forum.ForumConstants.MAX_FORUM_POST_BODY_LENGTH; import static org.briarproject.briar.api.forum.ForumConstants.MAX_FORUM_POST_TEXT_LENGTH;
import static org.briarproject.briar.api.forum.ForumPostFactory.SIGNING_LABEL_POST; import static org.briarproject.briar.api.forum.ForumPostFactory.SIGNING_LABEL_POST;
@Immutable @Immutable
@@ -44,7 +45,7 @@ class ForumPostValidator extends BdfMessageValidator {
@Override @Override
protected BdfMessageContext validateMessage(Message m, Group g, protected BdfMessageContext validateMessage(Message m, Group g,
BdfList body) throws InvalidMessageException, FormatException { BdfList body) throws InvalidMessageException, FormatException {
// Parent ID, author, content type, forum post body, signature // Parent ID, author, text, signature
checkSize(body, 4); checkSize(body, 4);
// Parent ID is optional // Parent ID is optional
@@ -55,16 +56,17 @@ class ForumPostValidator extends BdfMessageValidator {
BdfList authorList = body.getList(1); BdfList authorList = body.getList(1);
Author author = clientHelper.parseAndValidateAuthor(authorList); Author author = clientHelper.parseAndValidateAuthor(authorList);
// Forum post body // Text
String content = body.getString(2); String text = body.getString(2);
checkLength(content, 0, MAX_FORUM_POST_BODY_LENGTH); checkLength(text, 0, MAX_FORUM_POST_TEXT_LENGTH);
// Signature // Signature
byte[] sig = body.getRaw(3); byte[] sig = body.getRaw(3);
checkLength(sig, 1, MAX_SIGNATURE_LENGTH); checkLength(sig, 1, MAX_SIGNATURE_LENGTH);
// Verify the signature // Verify the signature
BdfList signed = BdfList.of(g.getId(), m.getTimestamp(), parent, BdfList signed = BdfList.of(g.getId(), m.getTimestamp(), parent,
authorList, content); authorList, text);
try { try {
clientHelper.verifySignature(sig, SIGNING_LABEL_POST, clientHelper.verifySignature(sig, SIGNING_LABEL_POST,
signed, author.getPublicKey()); signed, author.getPublicKey());
@@ -74,11 +76,11 @@ class ForumPostValidator extends BdfMessageValidator {
// Return the metadata and dependencies // Return the metadata and dependencies
BdfDictionary meta = new BdfDictionary(); BdfDictionary meta = new BdfDictionary();
Collection<MessageId> dependencies = Collections.emptyList(); Collection<MessageId> dependencies = emptyList();
meta.put(KEY_TIMESTAMP, m.getTimestamp()); meta.put(KEY_TIMESTAMP, m.getTimestamp());
if (parent != null) { if (parent != null) {
meta.put(KEY_PARENT, parent); meta.put(KEY_PARENT, parent);
dependencies = Collections.singletonList(new MessageId(parent)); dependencies = singletonList(new MessageId(parent));
} }
meta.put(KEY_AUTHOR, authorList); meta.put(KEY_AUTHOR, authorList);
meta.put(KEY_READ, false); meta.put(KEY_READ, false);

View File

@@ -72,11 +72,11 @@ abstract class AbstractProtocolEngine<S extends Session>
} }
Message sendRequestMessage(Transaction txn, PeerSession s, Message sendRequestMessage(Transaction txn, PeerSession s,
long timestamp, Author author, @Nullable String message) long timestamp, Author author, @Nullable String text)
throws DbException { throws DbException {
Message m = messageEncoder Message m = messageEncoder
.encodeRequestMessage(s.getContactGroupId(), timestamp, .encodeRequestMessage(s.getContactGroupId(), timestamp,
s.getLastLocalMessageId(), author, message); s.getLastLocalMessageId(), author, text);
sendMessage(txn, REQUEST, s.getSessionId(), m, true); sendMessage(txn, REQUEST, s.getSessionId(), m, true);
return m; return m;
} }

View File

@@ -85,8 +85,7 @@ class IntroduceeProtocolEngine
@Override @Override
public IntroduceeSession onRequestAction(Transaction txn, public IntroduceeSession onRequestAction(Transaction txn,
IntroduceeSession session, @Nullable String message, IntroduceeSession session, @Nullable String text, long timestamp) {
long timestamp) {
throw new UnsupportedOperationException(); // Invalid in this role throw new UnsupportedOperationException(); // Invalid in this role
} }
@@ -256,7 +255,7 @@ class IntroduceeProtocolEngine
.contactExists(txn, m.getAuthor().getId(), localAuthor.getId()); .contactExists(txn, m.getAuthor().getId(), localAuthor.getId());
IntroductionRequest request = new IntroductionRequest(m.getMessageId(), IntroductionRequest request = new IntroductionRequest(m.getMessageId(),
m.getGroupId(), m.getTimestamp(), false, false, false, false, m.getGroupId(), m.getTimestamp(), false, false, false, false,
s.getSessionId(), m.getAuthor(), m.getMessage(), false, s.getSessionId(), m.getAuthor(), m.getText(), false,
contactExists); contactExists);
IntroductionRequestReceivedEvent e = IntroductionRequestReceivedEvent e =
new IntroductionRequestReceivedEvent(request, c.getId()); new IntroductionRequestReceivedEvent(request, c.getId());

View File

@@ -58,11 +58,11 @@ class IntroducerProtocolEngine
@Override @Override
public IntroducerSession onRequestAction(Transaction txn, public IntroducerSession onRequestAction(Transaction txn,
IntroducerSession s, @Nullable String message, long timestamp) IntroducerSession s, @Nullable String text, long timestamp)
throws DbException { throws DbException {
switch (s.getState()) { switch (s.getState()) {
case START: case START:
return onLocalRequest(txn, s, message, timestamp); return onLocalRequest(txn, s, text, timestamp);
case AWAIT_RESPONSES: case AWAIT_RESPONSES:
case AWAIT_RESPONSE_A: case AWAIT_RESPONSE_A:
case AWAIT_RESPONSE_B: case AWAIT_RESPONSE_B:
@@ -222,7 +222,7 @@ class IntroducerProtocolEngine
} }
private IntroducerSession onLocalRequest(Transaction txn, private IntroducerSession onLocalRequest(Transaction txn,
IntroducerSession s, @Nullable String message, long timestamp) IntroducerSession s, @Nullable String text, long timestamp)
throws DbException { throws DbException {
// Send REQUEST messages // Send REQUEST messages
long maxIntroduceeTimestamp = long maxIntroduceeTimestamp =
@@ -230,11 +230,9 @@ class IntroducerProtocolEngine
getLocalTimestamp(s, s.getIntroduceeB())); getLocalTimestamp(s, s.getIntroduceeB()));
long localTimestamp = Math.max(timestamp, maxIntroduceeTimestamp); long localTimestamp = Math.max(timestamp, maxIntroduceeTimestamp);
Message sentA = sendRequestMessage(txn, s.getIntroduceeA(), Message sentA = sendRequestMessage(txn, s.getIntroduceeA(),
localTimestamp, s.getIntroduceeB().author, message localTimestamp, s.getIntroduceeB().author, text);
);
Message sentB = sendRequestMessage(txn, s.getIntroduceeB(), Message sentB = sendRequestMessage(txn, s.getIntroduceeB(),
localTimestamp, s.getIntroduceeA().author, message localTimestamp, s.getIntroduceeA().author, text);
);
// Track the messages // Track the messages
messageTracker.trackOutgoingMessage(txn, sentA); messageTracker.trackOutgoingMessage(txn, sentA);
messageTracker.trackOutgoingMessage(txn, sentB); messageTracker.trackOutgoingMessage(txn, sentB);

View File

@@ -316,7 +316,7 @@ class IntroductionManagerImpl extends ConversationClientImpl
} }
@Override @Override
public void makeIntroduction(Contact c1, Contact c2, @Nullable String msg, public void makeIntroduction(Contact c1, Contact c2, @Nullable String text,
long timestamp) throws DbException { long timestamp) throws DbException {
Transaction txn = db.startTransaction(false); Transaction txn = db.startTransaction(false);
try { try {
@@ -350,7 +350,7 @@ class IntroductionManagerImpl extends ConversationClientImpl
} }
// Handle the request action // Handle the request action
session = introducerEngine session = introducerEngine
.onRequestAction(txn, session, msg, timestamp); .onRequestAction(txn, session, text, timestamp);
// Store the updated session // Store the updated session
storeSession(txn, storageId, session); storeSession(txn, storageId, session);
db.commitTransaction(txn); db.commitTransaction(txn);
@@ -461,14 +461,14 @@ class IntroductionManagerImpl extends ConversationClientImpl
Message msg = clientHelper.getMessage(txn, m); Message msg = clientHelper.getMessage(txn, m);
BdfList body = clientHelper.toList(msg); BdfList body = clientHelper.toList(msg);
RequestMessage rm = messageParser.parseRequestMessage(msg, body); RequestMessage rm = messageParser.parseRequestMessage(msg, body);
String message = rm.getMessage(); String text = rm.getText();
LocalAuthor localAuthor = identityManager.getLocalAuthor(txn); LocalAuthor localAuthor = identityManager.getLocalAuthor(txn);
boolean contactExists = contactManager boolean contactExists = contactManager
.contactExists(txn, rm.getAuthor().getId(), .contactExists(txn, rm.getAuthor().getId(),
localAuthor.getId()); localAuthor.getId());
return new IntroductionRequest(m, contactGroupId, meta.getTimestamp(), return new IntroductionRequest(m, contactGroupId, meta.getTimestamp(),
meta.isLocal(), status.isSent(), status.isSeen(), meta.isRead(), meta.isLocal(), status.isSent(), status.isSeen(), meta.isRead(),
sessionId, author, message, !meta.isAvailableToAnswer(), sessionId, author, text, !meta.isAvailableToAnswer(),
contactExists); contactExists);
} }

View File

@@ -24,7 +24,7 @@ import static org.briarproject.bramble.api.crypto.CryptoConstants.MAX_SIGNATURE_
import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_PUBLIC_KEY_LENGTH; import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_PUBLIC_KEY_LENGTH;
import static org.briarproject.bramble.util.ValidationUtils.checkLength; import static org.briarproject.bramble.util.ValidationUtils.checkLength;
import static org.briarproject.bramble.util.ValidationUtils.checkSize; import static org.briarproject.bramble.util.ValidationUtils.checkSize;
import static org.briarproject.briar.api.introduction.IntroductionConstants.MAX_REQUEST_MESSAGE_LENGTH; import static org.briarproject.briar.api.introduction.IntroductionConstants.MAX_INTRODUCTION_TEXT_LENGTH;
import static org.briarproject.briar.introduction.MessageType.ACCEPT; import static org.briarproject.briar.introduction.MessageType.ACCEPT;
import static org.briarproject.briar.introduction.MessageType.ACTIVATE; import static org.briarproject.briar.introduction.MessageType.ACTIVATE;
import static org.briarproject.briar.introduction.MessageType.AUTH; import static org.briarproject.briar.introduction.MessageType.AUTH;
@@ -75,8 +75,8 @@ class IntroductionValidator extends BdfMessageValidator {
BdfList authorList = body.getList(2); BdfList authorList = body.getList(2);
clientHelper.parseAndValidateAuthor(authorList); clientHelper.parseAndValidateAuthor(authorList);
String msg = body.getOptionalString(3); String text = body.getOptionalString(3);
checkLength(msg, 1, MAX_REQUEST_MESSAGE_LENGTH); checkLength(text, 1, MAX_INTRODUCTION_TEXT_LENGTH);
BdfDictionary meta = BdfDictionary meta =
messageEncoder.encodeRequestMetadata(m.getTimestamp()); messageEncoder.encodeRequestMetadata(m.getTimestamp());

View File

@@ -31,7 +31,7 @@ interface MessageEncoder {
Message encodeRequestMessage(GroupId contactGroupId, long timestamp, Message encodeRequestMessage(GroupId contactGroupId, long timestamp,
@Nullable MessageId previousMessageId, Author author, @Nullable MessageId previousMessageId, Author author,
@Nullable String message); @Nullable String text);
Message encodeAcceptMessage(GroupId contactGroupId, long timestamp, Message encodeAcceptMessage(GroupId contactGroupId, long timestamp,
@Nullable MessageId previousMessageId, SessionId sessionId, @Nullable MessageId previousMessageId, SessionId sessionId,

View File

@@ -89,15 +89,15 @@ class MessageEncoderImpl implements MessageEncoder {
@Override @Override
public Message encodeRequestMessage(GroupId contactGroupId, long timestamp, public Message encodeRequestMessage(GroupId contactGroupId, long timestamp,
@Nullable MessageId previousMessageId, Author author, @Nullable MessageId previousMessageId, Author author,
@Nullable String message) { @Nullable String text) {
if (message != null && message.equals("")) { if (text != null && text.isEmpty()) {
throw new IllegalArgumentException(); throw new IllegalArgumentException();
} }
BdfList body = BdfList.of( BdfList body = BdfList.of(
REQUEST.getValue(), REQUEST.getValue(),
previousMessageId, previousMessageId,
clientHelper.toList(author), clientHelper.toList(author),
message text
); );
return createMessage(contactGroupId, timestamp, body); return createMessage(contactGroupId, timestamp, body);
} }

View File

@@ -74,9 +74,9 @@ class MessageParserImpl implements MessageParser {
MessageId previousMessageId = (previousMsgBytes == null ? null : MessageId previousMessageId = (previousMsgBytes == null ? null :
new MessageId(previousMsgBytes)); new MessageId(previousMsgBytes));
Author author = clientHelper.parseAndValidateAuthor(body.getList(2)); Author author = clientHelper.parseAndValidateAuthor(body.getList(2));
String message = body.getOptionalString(3); String text = body.getOptionalString(3);
return new RequestMessage(m.getId(), m.getGroupId(), return new RequestMessage(m.getId(), m.getGroupId(),
m.getTimestamp(), previousMessageId, author, message); m.getTimestamp(), previousMessageId, author, text);
} }
@Override @Override

View File

@@ -10,7 +10,7 @@ import javax.annotation.Nullable;
@NotNullByDefault @NotNullByDefault
interface ProtocolEngine<S extends Session> { interface ProtocolEngine<S extends Session> {
S onRequestAction(Transaction txn, S session, @Nullable String message, S onRequestAction(Transaction txn, S session, @Nullable String text,
long timestamp) throws DbException; long timestamp) throws DbException;
S onAcceptAction(Transaction txn, S session, long timestamp) S onAcceptAction(Transaction txn, S session, long timestamp)

View File

@@ -14,14 +14,14 @@ class RequestMessage extends AbstractIntroductionMessage {
private final Author author; private final Author author;
@Nullable @Nullable
private final String message; private final String text;
protected RequestMessage(MessageId messageId, GroupId groupId, RequestMessage(MessageId messageId, GroupId groupId, long timestamp,
long timestamp, @Nullable MessageId previousMessageId, @Nullable MessageId previousMessageId, Author author,
Author author, @Nullable String message) { @Nullable String text) {
super(messageId, groupId, timestamp, previousMessageId); super(messageId, groupId, timestamp, previousMessageId);
this.author = author; this.author = author;
this.message = message; this.text = text;
} }
public Author getAuthor() { public Author getAuthor() {
@@ -29,8 +29,8 @@ class RequestMessage extends AbstractIntroductionMessage {
} }
@Nullable @Nullable
public String getMessage() { public String getText() {
return message; return text;
} }
} }

View File

@@ -209,9 +209,9 @@ class MessagingManagerImpl extends ConversationClientImpl
} }
@Override @Override
public String getMessageBody(MessageId m) throws DbException { public String getMessageText(MessageId m) throws DbException {
try { try {
// 0: private message body // 0: private message text
return clientHelper.getMessageAsList(m).getString(0); return clientHelper.getMessageAsList(m).getString(0);
} catch (FormatException e) { } catch (FormatException e) {
throw new DbException(e); throw new DbException(e);

View File

@@ -13,7 +13,7 @@ import javax.annotation.concurrent.Immutable;
import javax.inject.Inject; import javax.inject.Inject;
import static org.briarproject.bramble.util.StringUtils.utf8IsTooLong; import static org.briarproject.bramble.util.StringUtils.utf8IsTooLong;
import static org.briarproject.briar.api.messaging.MessagingConstants.MAX_PRIVATE_MESSAGE_BODY_LENGTH; import static org.briarproject.briar.api.messaging.MessagingConstants.MAX_PRIVATE_MESSAGE_TEXT_LENGTH;
@Immutable @Immutable
@NotNullByDefault @NotNullByDefault
@@ -28,12 +28,12 @@ class PrivateMessageFactoryImpl implements PrivateMessageFactory {
@Override @Override
public PrivateMessage createPrivateMessage(GroupId groupId, long timestamp, public PrivateMessage createPrivateMessage(GroupId groupId, long timestamp,
String body) throws FormatException { String text) throws FormatException {
// Validate the arguments // Validate the arguments
if (utf8IsTooLong(body, MAX_PRIVATE_MESSAGE_BODY_LENGTH)) if (utf8IsTooLong(text, MAX_PRIVATE_MESSAGE_TEXT_LENGTH))
throw new IllegalArgumentException(); throw new IllegalArgumentException();
// Serialise the message // Serialise the message
BdfList message = BdfList.of(body); BdfList message = BdfList.of(text);
Message m = clientHelper.createMessage(groupId, timestamp, message); Message m = clientHelper.createMessage(groupId, timestamp, message);
return new PrivateMessage(m); return new PrivateMessage(m);
} }

View File

@@ -16,7 +16,7 @@ import javax.annotation.concurrent.Immutable;
import static org.briarproject.bramble.util.ValidationUtils.checkLength; import static org.briarproject.bramble.util.ValidationUtils.checkLength;
import static org.briarproject.bramble.util.ValidationUtils.checkSize; import static org.briarproject.bramble.util.ValidationUtils.checkSize;
import static org.briarproject.briar.api.messaging.MessagingConstants.MAX_PRIVATE_MESSAGE_BODY_LENGTH; import static org.briarproject.briar.api.messaging.MessagingConstants.MAX_PRIVATE_MESSAGE_TEXT_LENGTH;
import static org.briarproject.briar.client.MessageTrackerConstants.MSG_KEY_READ; import static org.briarproject.briar.client.MessageTrackerConstants.MSG_KEY_READ;
@Immutable @Immutable
@@ -31,11 +31,10 @@ class PrivateMessageValidator extends BdfMessageValidator {
@Override @Override
protected BdfMessageContext validateMessage(Message m, Group g, protected BdfMessageContext validateMessage(Message m, Group g,
BdfList body) throws FormatException { BdfList body) throws FormatException {
// private message body // Private message text
checkSize(body, 1); checkSize(body, 1);
// Private message body String text = body.getString(0);
String privateMessageBody = body.getString(0); checkLength(text, 0, MAX_PRIVATE_MESSAGE_TEXT_LENGTH);
checkLength(privateMessageBody, 0, MAX_PRIVATE_MESSAGE_BODY_LENGTH);
// Return the metadata // Return the metadata
BdfDictionary meta = new BdfDictionary(); BdfDictionary meta = new BdfDictionary();
meta.put("timestamp", m.getTimestamp()); meta.put("timestamp", m.getTimestamp());

View File

@@ -78,7 +78,7 @@ class GroupMessageFactoryImpl implements GroupMessageFactory {
@Override @Override
public GroupMessage createGroupMessage(GroupId groupId, long timestamp, public GroupMessage createGroupMessage(GroupId groupId, long timestamp,
@Nullable MessageId parentId, LocalAuthor member, String content, @Nullable MessageId parentId, LocalAuthor member, String text,
MessageId previousMsgId) { MessageId previousMsgId) {
try { try {
// Generate the signature // Generate the signature
@@ -89,7 +89,7 @@ class GroupMessageFactoryImpl implements GroupMessageFactory {
memberList, memberList,
parentId, parentId,
previousMsgId, previousMsgId,
content text
); );
byte[] signature = clientHelper.sign(SIGNING_LABEL_POST, toSign, byte[] signature = clientHelper.sign(SIGNING_LABEL_POST, toSign,
member.getPrivateKey()); member.getPrivateKey());
@@ -100,7 +100,7 @@ class GroupMessageFactoryImpl implements GroupMessageFactory {
memberList, memberList,
parentId, parentId,
previousMsgId, previousMsgId,
content, text,
signature signature
); );
Message m = clientHelper.createMessage(groupId, timestamp, body); Message m = clientHelper.createMessage(groupId, timestamp, body);

View File

@@ -31,7 +31,7 @@ import static org.briarproject.briar.api.privategroup.GroupMessageFactory.SIGNIN
import static org.briarproject.briar.api.privategroup.GroupMessageFactory.SIGNING_LABEL_POST; import static org.briarproject.briar.api.privategroup.GroupMessageFactory.SIGNING_LABEL_POST;
import static org.briarproject.briar.api.privategroup.MessageType.JOIN; import static org.briarproject.briar.api.privategroup.MessageType.JOIN;
import static org.briarproject.briar.api.privategroup.MessageType.POST; import static org.briarproject.briar.api.privategroup.MessageType.POST;
import static org.briarproject.briar.api.privategroup.PrivateGroupConstants.MAX_GROUP_POST_BODY_LENGTH; import static org.briarproject.briar.api.privategroup.PrivateGroupConstants.MAX_GROUP_POST_TEXT_LENGTH;
import static org.briarproject.briar.api.privategroup.invitation.GroupInvitationFactory.SIGNING_LABEL_INVITE; import static org.briarproject.briar.api.privategroup.invitation.GroupInvitationFactory.SIGNING_LABEL_INVITE;
import static org.briarproject.briar.privategroup.GroupConstants.KEY_INITIAL_JOIN_MSG; import static org.briarproject.briar.privategroup.GroupConstants.KEY_INITIAL_JOIN_MSG;
import static org.briarproject.briar.privategroup.GroupConstants.KEY_MEMBER; import static org.briarproject.briar.privategroup.GroupConstants.KEY_MEMBER;
@@ -65,7 +65,7 @@ class GroupMessageValidator extends BdfMessageValidator {
// Message type (int) // Message type (int)
int type = body.getLong(0).intValue(); int type = body.getLong(0).intValue();
// Member (list of int, string, raw) // Member (author)
BdfList memberList = body.getList(1); BdfList memberList = body.getList(1);
Author member = clientHelper.parseAndValidateAuthor(memberList); Author member = clientHelper.parseAndValidateAuthor(memberList);
@@ -144,14 +144,14 @@ class GroupMessageValidator extends BdfMessageValidator {
private BdfMessageContext validatePost(Message m, Group g, BdfList body, private BdfMessageContext validatePost(Message m, Group g, BdfList body,
Author member) throws FormatException { Author member) throws FormatException {
// Message type, member, optional parent ID, previous message ID, // Message type, member, optional parent ID, previous message ID,
// content, signature // text, signature
checkSize(body, 6); checkSize(body, 6);
byte[] parentId = body.getOptionalRaw(2); byte[] parentId = body.getOptionalRaw(2);
checkLength(parentId, MessageId.LENGTH); checkLength(parentId, MessageId.LENGTH);
byte[] previousMessageId = body.getRaw(3); byte[] previousMessageId = body.getRaw(3);
checkLength(previousMessageId, MessageId.LENGTH); checkLength(previousMessageId, MessageId.LENGTH);
String content = body.getString(4); String text = body.getString(4);
checkLength(content, 1, MAX_GROUP_POST_BODY_LENGTH); checkLength(text, 1, MAX_GROUP_POST_TEXT_LENGTH);
byte[] signature = body.getRaw(5); byte[] signature = body.getRaw(5);
checkLength(signature, 1, MAX_SIGNATURE_LENGTH); checkLength(signature, 1, MAX_SIGNATURE_LENGTH);
@@ -163,7 +163,7 @@ class GroupMessageValidator extends BdfMessageValidator {
memberList, memberList,
parentId, parentId,
previousMessageId, previousMessageId,
content text
); );
try { try {
clientHelper.verifySignature(signature, SIGNING_LABEL_POST, clientHelper.verifySignature(signature, SIGNING_LABEL_POST,

View File

@@ -299,17 +299,17 @@ class PrivateGroupManagerImpl extends BdfIncomingMessageHook
} }
@Override @Override
public String getMessageBody(MessageId m) throws DbException { public String getMessageText(MessageId m) throws DbException {
try { try {
return getMessageBody(clientHelper.getMessageAsList(m)); return getMessageText(clientHelper.getMessageAsList(m));
} catch (FormatException e) { } catch (FormatException e) {
throw new DbException(e); throw new DbException(e);
} }
} }
private String getMessageBody(BdfList body) throws FormatException { private String getMessageText(BdfList body) throws FormatException {
// Message type (0), member (1), parent ID (2), previous message ID (3), // Message type (0), member (1), parent ID (2), previous message ID (3),
// content (4), signature (5) // text (4), signature (5)
return body.getString(4); return body.getString(4);
} }
@@ -570,8 +570,8 @@ class PrivateGroupManagerImpl extends BdfIncomingMessageHook
throws DbException, FormatException { throws DbException, FormatException {
GroupMessageHeader header = getGroupMessageHeader(txn, m.getGroupId(), GroupMessageHeader header = getGroupMessageHeader(txn, m.getGroupId(),
m.getId(), meta, Collections.emptyMap()); m.getId(), meta, Collections.emptyMap());
String body = getMessageBody(clientHelper.toList(m)); String text = getMessageText(clientHelper.toList(m));
txn.attach(new GroupMessageAddedEvent(m.getGroupId(), header, body, txn.attach(new GroupMessageAddedEvent(m.getGroupId(), header, text,
local)); local));
} }

View File

@@ -107,7 +107,7 @@ abstract class AbstractProtocolEngine<S extends Session>
} }
Message sendInviteMessage(Transaction txn, S session, Message sendInviteMessage(Transaction txn, S session,
@Nullable String message, long timestamp, byte[] signature) @Nullable String text, long timestamp, byte[] signature)
throws DbException { throws DbException {
Group g = db.getGroup(txn, session.getPrivateGroupId()); Group g = db.getGroup(txn, session.getPrivateGroupId());
PrivateGroup privateGroup; PrivateGroup privateGroup;
@@ -119,7 +119,7 @@ abstract class AbstractProtocolEngine<S extends Session>
Message m = messageEncoder.encodeInviteMessage( Message m = messageEncoder.encodeInviteMessage(
session.getContactGroupId(), privateGroup.getId(), session.getContactGroupId(), privateGroup.getId(),
timestamp, privateGroup.getName(), privateGroup.getCreator(), timestamp, privateGroup.getName(), privateGroup.getCreator(),
privateGroup.getSalt(), message, signature); privateGroup.getSalt(), text, signature);
sendMessage(txn, m, INVITE, privateGroup.getId(), true); sendMessage(txn, m, INVITE, privateGroup.getId(), true);
return m; return m;
} }

View File

@@ -51,11 +51,11 @@ class CreatorProtocolEngine extends AbstractProtocolEngine<CreatorSession> {
@Override @Override
public CreatorSession onInviteAction(Transaction txn, CreatorSession s, public CreatorSession onInviteAction(Transaction txn, CreatorSession s,
@Nullable String message, long timestamp, byte[] signature) @Nullable String text, long timestamp, byte[] signature)
throws DbException { throws DbException {
switch (s.getState()) { switch (s.getState()) {
case START: case START:
return onLocalInvite(txn, s, message, timestamp, signature); return onLocalInvite(txn, s, text, timestamp, signature);
case INVITED: case INVITED:
case JOINED: case JOINED:
case LEFT: case LEFT:
@@ -145,10 +145,10 @@ class CreatorProtocolEngine extends AbstractProtocolEngine<CreatorSession> {
} }
private CreatorSession onLocalInvite(Transaction txn, CreatorSession s, private CreatorSession onLocalInvite(Transaction txn, CreatorSession s,
@Nullable String message, long timestamp, byte[] signature) @Nullable String text, long timestamp, byte[] signature)
throws DbException { throws DbException {
// Send an INVITE message // Send an INVITE message
Message sent = sendInviteMessage(txn, s, message, timestamp, signature); Message sent = sendInviteMessage(txn, s, text, timestamp, signature);
// Track the message // Track the message
messageTracker.trackOutgoingMessage(txn, sent); messageTracker.trackOutgoingMessage(txn, sent);
// Move to the INVITED state // Move to the INVITED state

View File

@@ -260,7 +260,7 @@ class GroupInvitationManagerImpl extends ConversationClientImpl
@Override @Override
public void sendInvitation(GroupId privateGroupId, ContactId c, public void sendInvitation(GroupId privateGroupId, ContactId c,
@Nullable String message, long timestamp, byte[] signature) @Nullable String text, long timestamp, byte[] signature)
throws DbException { throws DbException {
SessionId sessionId = getSessionId(privateGroupId); SessionId sessionId = getSessionId(privateGroupId);
Transaction txn = db.startTransaction(false); Transaction txn = db.startTransaction(false);
@@ -283,7 +283,7 @@ class GroupInvitationManagerImpl extends ConversationClientImpl
storageId = ss.storageId; storageId = ss.storageId;
} }
// Handle the invite action // Handle the invite action
session = creatorEngine.onInviteAction(txn, session, message, session = creatorEngine.onInviteAction(txn, session, text,
timestamp, signature); timestamp, signature);
// Store the updated session // Store the updated session
storeSession(txn, storageId, session); storeSession(txn, storageId, session);
@@ -416,7 +416,7 @@ class GroupInvitationManagerImpl extends ConversationClientImpl
return new GroupInvitationRequest(m, contactGroupId, return new GroupInvitationRequest(m, contactGroupId,
meta.getTimestamp(), meta.isLocal(), status.isSent(), meta.getTimestamp(), meta.isLocal(), status.isSent(),
status.isSeen(), meta.isRead(), sessionId, pg, status.isSeen(), meta.isRead(), sessionId, pg,
invite.getMessage(), meta.isAvailableToAnswer(), canBeOpened); invite.getText(), meta.isAvailableToAnswer(), canBeOpened);
} }
private GroupInvitationResponse parseInvitationResponse( private GroupInvitationResponse parseInvitationResponse(

View File

@@ -27,7 +27,7 @@ import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_SIGNATUR
import static org.briarproject.bramble.util.ValidationUtils.checkLength; import static org.briarproject.bramble.util.ValidationUtils.checkLength;
import static org.briarproject.bramble.util.ValidationUtils.checkSize; import static org.briarproject.bramble.util.ValidationUtils.checkSize;
import static org.briarproject.briar.api.privategroup.PrivateGroupConstants.GROUP_SALT_LENGTH; import static org.briarproject.briar.api.privategroup.PrivateGroupConstants.GROUP_SALT_LENGTH;
import static org.briarproject.briar.api.privategroup.PrivateGroupConstants.MAX_GROUP_INVITATION_MSG_LENGTH; import static org.briarproject.briar.api.privategroup.PrivateGroupConstants.MAX_GROUP_INVITATION_TEXT_LENGTH;
import static org.briarproject.briar.api.privategroup.PrivateGroupConstants.MAX_GROUP_NAME_LENGTH; import static org.briarproject.briar.api.privategroup.PrivateGroupConstants.MAX_GROUP_NAME_LENGTH;
import static org.briarproject.briar.api.privategroup.invitation.GroupInvitationFactory.SIGNING_LABEL_INVITE; import static org.briarproject.briar.api.privategroup.invitation.GroupInvitationFactory.SIGNING_LABEL_INVITE;
import static org.briarproject.briar.privategroup.invitation.MessageType.ABORT; import static org.briarproject.briar.privategroup.invitation.MessageType.ABORT;
@@ -71,15 +71,15 @@ class GroupInvitationValidator extends BdfMessageValidator {
private BdfMessageContext validateInviteMessage(Message m, BdfList body) private BdfMessageContext validateInviteMessage(Message m, BdfList body)
throws FormatException { throws FormatException {
// Message type, creator, group name, salt, optional message, signature // Message type, creator, group name, salt, optional text, signature
checkSize(body, 6); checkSize(body, 6);
BdfList creatorList = body.getList(1); BdfList creatorList = body.getList(1);
String groupName = body.getString(2); String groupName = body.getString(2);
checkLength(groupName, 1, MAX_GROUP_NAME_LENGTH); checkLength(groupName, 1, MAX_GROUP_NAME_LENGTH);
byte[] salt = body.getRaw(3); byte[] salt = body.getRaw(3);
checkLength(salt, GROUP_SALT_LENGTH); checkLength(salt, GROUP_SALT_LENGTH);
String message = body.getOptionalString(4); String text = body.getOptionalString(4);
checkLength(message, 1, MAX_GROUP_INVITATION_MSG_LENGTH); checkLength(text, 1, MAX_GROUP_INVITATION_TEXT_LENGTH);
byte[] signature = body.getRaw(5); byte[] signature = body.getRaw(5);
checkLength(signature, 1, MAX_SIGNATURE_LENGTH); checkLength(signature, 1, MAX_SIGNATURE_LENGTH);

View File

@@ -16,16 +16,16 @@ class InviteMessage extends GroupInvitationMessage {
private final Author creator; private final Author creator;
private final byte[] salt, signature; private final byte[] salt, signature;
@Nullable @Nullable
private final String message; private final String text;
InviteMessage(MessageId id, GroupId contactGroupId, GroupId privateGroupId, InviteMessage(MessageId id, GroupId contactGroupId, GroupId privateGroupId,
long timestamp, String groupName, Author creator, byte[] salt, long timestamp, String groupName, Author creator, byte[] salt,
@Nullable String message, byte[] signature) { @Nullable String text, byte[] signature) {
super(id, contactGroupId, privateGroupId, timestamp); super(id, contactGroupId, privateGroupId, timestamp);
this.groupName = groupName; this.groupName = groupName;
this.creator = creator; this.creator = creator;
this.salt = salt; this.salt = salt;
this.message = message; this.text = text;
this.signature = signature; this.signature = signature;
} }
@@ -42,8 +42,8 @@ class InviteMessage extends GroupInvitationMessage {
} }
@Nullable @Nullable
String getMessage() { String getText() {
return message; return text;
} }
byte[] getSignature() { byte[] getSignature() {

View File

@@ -56,7 +56,7 @@ class InviteeProtocolEngine extends AbstractProtocolEngine<InviteeSession> {
@Override @Override
public InviteeSession onInviteAction(Transaction txn, InviteeSession s, public InviteeSession onInviteAction(Transaction txn, InviteeSession s,
@Nullable String message, long timestamp, byte[] signature) { @Nullable String text, long timestamp, byte[] signature) {
throw new UnsupportedOperationException(); // Invalid in this role throw new UnsupportedOperationException(); // Invalid in this role
} }
@@ -330,7 +330,7 @@ class InviteeProtocolEngine extends AbstractProtocolEngine<InviteeSession> {
SessionId sessionId = new SessionId(m.getPrivateGroupId().getBytes()); SessionId sessionId = new SessionId(m.getPrivateGroupId().getBytes());
return new GroupInvitationRequest(m.getId(), m.getContactGroupId(), return new GroupInvitationRequest(m.getId(), m.getContactGroupId(),
m.getTimestamp(), false, false, true, false, sessionId, pg, m.getTimestamp(), false, false, true, false, sessionId, pg,
m.getMessage(), true, false); m.getText(), true, false);
} }
} }

View File

@@ -24,7 +24,7 @@ interface MessageEncoder {
Message encodeInviteMessage(GroupId contactGroupId, GroupId privateGroupId, Message encodeInviteMessage(GroupId contactGroupId, GroupId privateGroupId,
long timestamp, String groupName, Author creator, byte[] salt, long timestamp, String groupName, Author creator, byte[] salt,
@Nullable String message, byte[] signature); @Nullable String text, byte[] signature);
Message encodeJoinMessage(GroupId contactGroupId, GroupId privateGroupId, Message encodeJoinMessage(GroupId contactGroupId, GroupId privateGroupId,
long timestamp, @Nullable MessageId previousMessageId); long timestamp, @Nullable MessageId previousMessageId);

View File

@@ -76,7 +76,7 @@ class MessageEncoderImpl implements MessageEncoder {
@Override @Override
public Message encodeInviteMessage(GroupId contactGroupId, public Message encodeInviteMessage(GroupId contactGroupId,
GroupId privateGroupId, long timestamp, String groupName, GroupId privateGroupId, long timestamp, String groupName,
Author creator, byte[] salt, @Nullable String message, Author creator, byte[] salt, @Nullable String text,
byte[] signature) { byte[] signature) {
BdfList creatorList = clientHelper.toList(creator); BdfList creatorList = clientHelper.toList(creator);
BdfList body = BdfList.of( BdfList body = BdfList.of(
@@ -84,7 +84,7 @@ class MessageEncoderImpl implements MessageEncoder {
creatorList, creatorList,
groupName, groupName,
salt, salt,
message, text,
signature signature
); );
try { try {

View File

@@ -98,11 +98,11 @@ class MessageParserImpl implements MessageParser {
@Override @Override
public InviteMessage parseInviteMessage(Message m, BdfList body) public InviteMessage parseInviteMessage(Message m, BdfList body)
throws FormatException { throws FormatException {
// Message type, creator, group name, salt, optional message, signature // Message type, creator, group name, salt, optional text, signature
BdfList creatorList = body.getList(1); BdfList creatorList = body.getList(1);
String groupName = body.getString(2); String groupName = body.getString(2);
byte[] salt = body.getRaw(3); byte[] salt = body.getRaw(3);
String message = body.getOptionalString(4); String text = body.getOptionalString(4);
byte[] signature = body.getRaw(5); byte[] signature = body.getRaw(5);
// Format version, name, public key // Format version, name, public key
@@ -117,7 +117,7 @@ class MessageParserImpl implements MessageParser {
groupName, creator, salt); groupName, creator, salt);
return new InviteMessage(m.getId(), m.getGroupId(), return new InviteMessage(m.getId(), m.getGroupId(),
privateGroup.getId(), m.getTimestamp(), groupName, creator, privateGroup.getId(), m.getTimestamp(), groupName, creator,
salt, message, signature); salt, text, signature);
} }
@Override @Override

View File

@@ -51,8 +51,7 @@ class PeerProtocolEngine extends AbstractProtocolEngine<PeerSession> {
@Override @Override
public PeerSession onInviteAction(Transaction txn, PeerSession s, public PeerSession onInviteAction(Transaction txn, PeerSession s,
@Nullable String message, long timestamp, byte[] signature) @Nullable String text, long timestamp, byte[] signature) {
throws DbException {
throw new UnsupportedOperationException(); // Invalid in this role throw new UnsupportedOperationException(); // Invalid in this role
} }

View File

@@ -10,7 +10,7 @@ import javax.annotation.Nullable;
@NotNullByDefault @NotNullByDefault
interface ProtocolEngine<S extends Session> { interface ProtocolEngine<S extends Session> {
S onInviteAction(Transaction txn, S session, @Nullable String message, S onInviteAction(Transaction txn, S session, @Nullable String text,
long timestamp, byte[] signature) throws DbException; long timestamp, byte[] signature) throws DbException;
S onJoinAction(Transaction txn, S session) throws DbException; S onJoinAction(Transaction txn, S session) throws DbException;

View File

@@ -24,7 +24,7 @@ public class BlogInvitationFactoryImpl
SessionId sessionId = new SessionId(m.getShareableId().getBytes()); SessionId sessionId = new SessionId(m.getShareableId().getBytes());
return new BlogInvitationRequest(m.getId(), m.getContactGroupId(), return new BlogInvitationRequest(m.getId(), m.getContactGroupId(),
m.getTimestamp(), local, sent, seen, read, sessionId, m.getTimestamp(), local, sent, seen, read, sessionId,
m.getShareable(), m.getMessage(), available, canBeOpened); m.getShareable(), m.getText(), available, canBeOpened);
} }
@Override @Override

Some files were not shown because too many files have changed in this diff Show More