mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 18:59:06 +01:00
Merge branch 'message-terminology' into 'master'
Use "text" to refer to message text See merge request briar/briar!948
This commit is contained in:
@@ -51,7 +51,7 @@ abstract class BaseControllerImpl extends DbControllerImpl
|
||||
protected final IdentityManager identityManager;
|
||||
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 =
|
||||
new ConcurrentHashMap<>();
|
||||
|
||||
@@ -129,17 +129,17 @@ abstract class BaseControllerImpl extends DbControllerImpl
|
||||
public void loadBlogPost(BlogPostHeader header,
|
||||
ResultExceptionHandler<BlogPostItem, DbException> handler) {
|
||||
|
||||
String body = bodyCache.get(header.getId());
|
||||
if (body != null) {
|
||||
LOG.info("Loaded body from cache");
|
||||
handler.onResult(new BlogPostItem(header, body));
|
||||
String text = textCache.get(header.getId());
|
||||
if (text != null) {
|
||||
LOG.info("Loaded text from cache");
|
||||
handler.onResult(new BlogPostItem(header, text));
|
||||
return;
|
||||
}
|
||||
runOnDbThread(() -> {
|
||||
try {
|
||||
long start = now();
|
||||
BlogPostItem item = getItem(header);
|
||||
logDuration(LOG, "Loading body", start);
|
||||
logDuration(LOG, "Loading text", start);
|
||||
handler.onResult(item);
|
||||
} catch (DbException e) {
|
||||
logException(LOG, WARNING, e);
|
||||
@@ -200,28 +200,28 @@ abstract class BaseControllerImpl extends DbControllerImpl
|
||||
|
||||
@DatabaseExecutor
|
||||
private BlogPostItem getItem(BlogPostHeader h) throws DbException {
|
||||
String body;
|
||||
String text;
|
||||
if (h instanceof BlogCommentHeader) {
|
||||
BlogCommentHeader c = (BlogCommentHeader) h;
|
||||
BlogCommentItem item = new BlogCommentItem(c);
|
||||
body = getPostBody(item.getPostHeader().getId());
|
||||
item.setBody(body);
|
||||
text = getPostText(item.getPostHeader().getId());
|
||||
item.setText(text);
|
||||
return item;
|
||||
} else {
|
||||
body = getPostBody(h.getId());
|
||||
return new BlogPostItem(h, body);
|
||||
text = getPostText(h.getId());
|
||||
return new BlogPostItem(h, text);
|
||||
}
|
||||
}
|
||||
|
||||
@DatabaseExecutor
|
||||
private String getPostBody(MessageId m) throws DbException {
|
||||
String body = bodyCache.get(m);
|
||||
if (body == null) {
|
||||
body = HtmlUtils.clean(blogManager.getPostBody(m), ARTICLE);
|
||||
bodyCache.put(m, body);
|
||||
private String getPostText(MessageId m) throws DbException {
|
||||
String text = textCache.get(m);
|
||||
if (text == null) {
|
||||
text = HtmlUtils.clean(blogManager.getPostText(m), ARTICLE);
|
||||
textCache.put(m, text);
|
||||
}
|
||||
//noinspection ConstantConditions
|
||||
return body;
|
||||
return text;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -34,8 +34,8 @@ class BlogCommentItem extends BlogPostItem {
|
||||
}
|
||||
}
|
||||
|
||||
public void setBody(String body) {
|
||||
this.body = body;
|
||||
public void setText(String text) {
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -15,12 +15,12 @@ import javax.annotation.concurrent.NotThreadSafe;
|
||||
public class BlogPostItem implements Comparable<BlogPostItem> {
|
||||
|
||||
private final BlogPostHeader header;
|
||||
protected String body;
|
||||
protected String text;
|
||||
private boolean read;
|
||||
|
||||
BlogPostItem(BlogPostHeader header, @Nullable String body) {
|
||||
BlogPostItem(BlogPostHeader header, @Nullable String text) {
|
||||
this.header = header;
|
||||
this.body = body;
|
||||
this.text = text;
|
||||
this.read = header.isRead();
|
||||
}
|
||||
|
||||
@@ -44,8 +44,8 @@ public class BlogPostItem implements Comparable<BlogPostItem> {
|
||||
return header.getAuthorStatus();
|
||||
}
|
||||
|
||||
public String getBody() {
|
||||
return body;
|
||||
public String getText() {
|
||||
return text;
|
||||
}
|
||||
|
||||
public boolean isRssFeed() {
|
||||
|
||||
@@ -41,7 +41,7 @@ class BlogPostViewHolder extends RecyclerView.ViewHolder {
|
||||
private final AuthorView reblogger;
|
||||
private final AuthorView author;
|
||||
private final ImageButton reblogButton;
|
||||
private final TextView body;
|
||||
private final TextView text;
|
||||
private final ViewGroup commentContainer;
|
||||
private final boolean fullText;
|
||||
|
||||
@@ -63,7 +63,7 @@ class BlogPostViewHolder extends RecyclerView.ViewHolder {
|
||||
reblogger = v.findViewById(R.id.rebloggerView);
|
||||
author = v.findViewById(R.id.authorView);
|
||||
reblogButton = v.findViewById(R.id.commentView);
|
||||
body = v.findViewById(R.id.bodyView);
|
||||
text = v.findViewById(R.id.textView);
|
||||
commentContainer = v.findViewById(R.id.commentContainer);
|
||||
}
|
||||
|
||||
@@ -111,17 +111,17 @@ class BlogPostViewHolder extends RecyclerView.ViewHolder {
|
||||
author.setAuthorNotClickable();
|
||||
}
|
||||
|
||||
// post body
|
||||
Spanned bodyText = getSpanned(item.getBody());
|
||||
// post text
|
||||
Spanned postText = getSpanned(item.getText());
|
||||
if (fullText) {
|
||||
body.setText(bodyText);
|
||||
body.setTextIsSelectable(true);
|
||||
makeLinksClickable(body, fragmentManager);
|
||||
text.setText(postText);
|
||||
text.setTextIsSelectable(true);
|
||||
makeLinksClickable(text, fragmentManager);
|
||||
} else {
|
||||
body.setTextIsSelectable(false);
|
||||
if (bodyText.length() > TEASER_LENGTH)
|
||||
bodyText = getTeaser(ctx, bodyText);
|
||||
body.setText(bodyText);
|
||||
text.setTextIsSelectable(false);
|
||||
if (postText.length() > TEASER_LENGTH)
|
||||
postText = getTeaser(ctx, postText);
|
||||
text.setText(postText);
|
||||
}
|
||||
|
||||
// reblog button
|
||||
@@ -163,15 +163,15 @@ class BlogPostViewHolder extends RecyclerView.ViewHolder {
|
||||
commentContainer, false);
|
||||
|
||||
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.setAuthorStatus(c.getAuthorStatus());
|
||||
author.setDate(c.getTimestamp());
|
||||
// TODO make author clickable #624
|
||||
|
||||
body.setText(c.getComment());
|
||||
if (fullText) body.setTextIsSelectable(true);
|
||||
text.setText(c.getComment());
|
||||
if (fullText) text.setTextIsSelectable(true);
|
||||
|
||||
commentContainer.addView(v);
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ import static android.view.View.GONE;
|
||||
import static android.view.View.VISIBLE;
|
||||
import static java.util.logging.Level.WARNING;
|
||||
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
|
||||
implements OnEditorActionListener, TextInputListener {
|
||||
@@ -70,7 +70,7 @@ public class WriteBlogPostActivity extends BriarActivity
|
||||
|
||||
setContentView(R.layout.activity_write_blog_post);
|
||||
|
||||
input = findViewById(R.id.bodyInput);
|
||||
input = findViewById(R.id.textInput);
|
||||
input.setSendButtonEnabled(false);
|
||||
input.addTextChangedListener(new TextWatcher() {
|
||||
@Override
|
||||
@@ -132,23 +132,23 @@ public class WriteBlogPostActivity extends BriarActivity
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSendClick(String body) {
|
||||
public void onSendClick(String text) {
|
||||
// hide publish button, show progress bar
|
||||
input.hideSoftKeyboard();
|
||||
input.setVisibility(GONE);
|
||||
progressBar.setVisibility(VISIBLE);
|
||||
|
||||
body = StringUtils.truncateUtf8(body, MAX_BLOG_POST_BODY_LENGTH);
|
||||
storePost(body);
|
||||
text = StringUtils.truncateUtf8(text, MAX_BLOG_POST_TEXT_LENGTH);
|
||||
storePost(text);
|
||||
}
|
||||
|
||||
private void storePost(String body) {
|
||||
private void storePost(String text) {
|
||||
runOnDbThread(() -> {
|
||||
long timestamp = System.currentTimeMillis();
|
||||
try {
|
||||
LocalAuthor author = identityManager.getLocalAuthor();
|
||||
BlogPost p = blogPostFactory
|
||||
.createBlogPost(groupId, timestamp, null, author, body);
|
||||
.createBlogPost(groupId, timestamp, null, author, text);
|
||||
blogManager.addLocalPost(p);
|
||||
postPublished();
|
||||
} catch (DbException | GeneralSecurityException
|
||||
|
||||
@@ -53,7 +53,7 @@ import org.briarproject.briar.android.activity.ActivityComponent;
|
||||
import org.briarproject.briar.android.activity.BriarActivity;
|
||||
import org.briarproject.briar.android.blog.BlogActivity;
|
||||
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.introduction.IntroductionActivity;
|
||||
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.util.UiUtils.getAvatarTransitionName;
|
||||
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_FINISHED;
|
||||
|
||||
@@ -113,7 +113,7 @@ import static uk.co.samuelwall.materialtaptargetprompt.MaterialTapTargetPrompt.S
|
||||
@ParametersNotNullByDefault
|
||||
public class ConversationActivity extends BriarActivity
|
||||
implements EventListener, ConversationListener, TextInputListener,
|
||||
BodyCache {
|
||||
TextCache {
|
||||
|
||||
public static final String CONTACT_ID = "briar.CONTACT_ID";
|
||||
|
||||
@@ -130,7 +130,7 @@ public class ConversationActivity extends BriarActivity
|
||||
@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 ConversationVisitor visitor;
|
||||
@@ -370,28 +370,28 @@ public class ConversationActivity extends BriarActivity
|
||||
return items;
|
||||
}
|
||||
|
||||
private void loadMessageBody(MessageId m) {
|
||||
private void loadMessageText(MessageId m) {
|
||||
runOnDbThread(() -> {
|
||||
try {
|
||||
long start = now();
|
||||
String body = messagingManager.getMessageBody(m);
|
||||
logDuration(LOG, "Loading body", start);
|
||||
displayMessageBody(m, body);
|
||||
String text = messagingManager.getMessageText(m);
|
||||
logDuration(LOG, "Loading text", start);
|
||||
displayMessageText(m, text);
|
||||
} catch (DbException e) {
|
||||
logException(LOG, WARNING, e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void displayMessageBody(MessageId m, String body) {
|
||||
private void displayMessageText(MessageId m, String text) {
|
||||
runOnUiThreadUnlessDestroyed(() -> {
|
||||
bodyCache.put(m, body);
|
||||
textCache.put(m, text);
|
||||
SparseArray<ConversationItem> messages =
|
||||
adapter.getPrivateMessages();
|
||||
for (int i = 0; i < messages.size(); i++) {
|
||||
ConversationItem item = messages.valueAt(i);
|
||||
if (item.getId().equals(m)) {
|
||||
item.setBody(body);
|
||||
item.setText(text);
|
||||
adapter.notifyItemChanged(messages.keyAt(i));
|
||||
list.scrollToPosition(adapter.getItemCount() - 1);
|
||||
return;
|
||||
@@ -470,7 +470,7 @@ public class ConversationActivity extends BriarActivity
|
||||
}
|
||||
} else {
|
||||
addConversationItem(h.accept(visitor));
|
||||
loadMessageBody(h.getId());
|
||||
loadMessageText(h.getId());
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -495,8 +495,8 @@ public class ConversationActivity extends BriarActivity
|
||||
|
||||
@Override
|
||||
public void onSendClick(String text) {
|
||||
if (text.equals("")) return;
|
||||
text = StringUtils.truncateUtf8(text, MAX_PRIVATE_MESSAGE_BODY_LENGTH);
|
||||
if (text.isEmpty()) return;
|
||||
text = StringUtils.truncateUtf8(text, MAX_PRIVATE_MESSAGE_TEXT_LENGTH);
|
||||
long timestamp = System.currentTimeMillis();
|
||||
timestamp = Math.max(timestamp, getMinTimestampForNewMessage());
|
||||
if (messagingGroupId == null) loadGroupId(text, timestamp);
|
||||
@@ -510,12 +510,12 @@ public class ConversationActivity extends BriarActivity
|
||||
return item == null ? 0 : item.getTime() + 1;
|
||||
}
|
||||
|
||||
private void loadGroupId(String body, long timestamp) {
|
||||
private void loadGroupId(String text, long timestamp) {
|
||||
runOnDbThread(() -> {
|
||||
try {
|
||||
messagingGroupId =
|
||||
messagingManager.getConversationId(contactId);
|
||||
createMessage(body, timestamp);
|
||||
createMessage(text, timestamp);
|
||||
} catch (DbException 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(() -> {
|
||||
try {
|
||||
//noinspection ConstantConditions init in loadGroupId()
|
||||
storeMessage(privateMessageFactory.createPrivateMessage(
|
||||
messagingGroupId, timestamp, body), body);
|
||||
messagingGroupId, timestamp, text), text);
|
||||
} catch (FormatException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void storeMessage(PrivateMessage m, String body) {
|
||||
private void storeMessage(PrivateMessage m, String text) {
|
||||
runOnDbThread(() -> {
|
||||
try {
|
||||
long start = now();
|
||||
@@ -545,7 +545,7 @@ public class ConversationActivity extends BriarActivity
|
||||
PrivateMessageHeader h = new PrivateMessageHeader(
|
||||
message.getId(), message.getGroupId(),
|
||||
message.getTimestamp(), true, false, false, false);
|
||||
bodyCache.put(message.getId(), body);
|
||||
textCache.put(message.getId(), text);
|
||||
addConversationItem(h.accept(visitor));
|
||||
} catch (DbException e) {
|
||||
logException(LOG, WARNING, e);
|
||||
@@ -761,9 +761,9 @@ public class ConversationActivity extends BriarActivity
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getBody(MessageId m) {
|
||||
String body = bodyCache.get(m);
|
||||
if (body == null) loadMessageBody(m);
|
||||
return body;
|
||||
public String getText(MessageId m) {
|
||||
String text = textCache.get(m);
|
||||
if (text == null) loadMessageText(m);
|
||||
return text;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,17 +14,17 @@ import javax.annotation.concurrent.NotThreadSafe;
|
||||
abstract class ConversationItem {
|
||||
|
||||
@Nullable
|
||||
protected String body;
|
||||
protected String text;
|
||||
private final MessageId id;
|
||||
private final GroupId groupId;
|
||||
private final long time;
|
||||
private boolean read;
|
||||
|
||||
ConversationItem(MessageId id, GroupId groupId, @Nullable String body,
|
||||
ConversationItem(MessageId id, GroupId groupId, @Nullable String text,
|
||||
long time, boolean read) {
|
||||
this.id = id;
|
||||
this.groupId = groupId;
|
||||
this.body = body;
|
||||
this.text = text;
|
||||
this.time = time;
|
||||
this.read = read;
|
||||
}
|
||||
@@ -37,13 +37,13 @@ abstract class ConversationItem {
|
||||
return groupId;
|
||||
}
|
||||
|
||||
void setBody(String body) {
|
||||
this.body = body;
|
||||
void setText(String text) {
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getBody() {
|
||||
return body;
|
||||
public String getText() {
|
||||
return text;
|
||||
}
|
||||
|
||||
long getTime() {
|
||||
|
||||
@@ -29,10 +29,10 @@ class ConversationItemViewHolder extends ViewHolder {
|
||||
|
||||
@CallSuper
|
||||
void bind(ConversationItem item) {
|
||||
if (item.getBody() == null) {
|
||||
if (item.getText() == null) {
|
||||
text.setText("\u2026");
|
||||
} else {
|
||||
text.setText(StringUtils.trim(item.getBody()));
|
||||
text.setText(StringUtils.trim(item.getText()));
|
||||
}
|
||||
|
||||
long timestamp = item.getTime();
|
||||
|
||||
@@ -29,13 +29,13 @@ class ConversationNoticeInViewHolder extends ConversationItemViewHolder {
|
||||
ConversationNoticeInItem item =
|
||||
(ConversationNoticeInItem) conversationItem;
|
||||
|
||||
String message = item.getMsgText();
|
||||
if (StringUtils.isNullOrEmpty(message)) {
|
||||
String text = item.getMsgText();
|
||||
if (StringUtils.isNullOrEmpty(text)) {
|
||||
msgText.setVisibility(GONE);
|
||||
layout.setBackgroundResource(R.drawable.notice_in);
|
||||
} else {
|
||||
msgText.setVisibility(VISIBLE);
|
||||
msgText.setText(StringUtils.trim(message));
|
||||
msgText.setText(StringUtils.trim(text));
|
||||
layout.setBackgroundResource(R.drawable.notice_in_bottom);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ class ConversationNoticeOutItem extends ConversationOutItem {
|
||||
ConversationNoticeOutItem(String text, PrivateRequest r) {
|
||||
super(r.getId(), r.getGroupId(), text, r.getTimestamp(), r.isSent(),
|
||||
r.isSeen());
|
||||
this.msgText = r.getMessage();
|
||||
this.msgText = r.getText();
|
||||
}
|
||||
|
||||
ConversationNoticeOutItem(String text, PrivateResponse r) {
|
||||
|
||||
@@ -29,13 +29,13 @@ class ConversationNoticeOutViewHolder extends ConversationOutItemViewHolder {
|
||||
ConversationNoticeOutItem item =
|
||||
(ConversationNoticeOutItem) conversationItem;
|
||||
|
||||
String message = item.getMsgText();
|
||||
if (StringUtils.isNullOrEmpty(message)) {
|
||||
String text = item.getMsgText();
|
||||
if (StringUtils.isNullOrEmpty(text)) {
|
||||
msgText.setVisibility(GONE);
|
||||
layout.setBackgroundResource(R.drawable.notice_out);
|
||||
} else {
|
||||
msgText.setVisibility(VISIBLE);
|
||||
msgText.setText(StringUtils.trim(message));
|
||||
msgText.setText(StringUtils.trim(text));
|
||||
layout.setBackgroundResource(R.drawable.notice_out_bottom);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ class ConversationRequestItem extends ConversationNoticeInItem {
|
||||
private boolean answered;
|
||||
|
||||
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());
|
||||
this.requestType = type;
|
||||
this.sessionId = r.getSessionId();
|
||||
|
||||
@@ -30,13 +30,13 @@ import static org.briarproject.briar.android.contact.ConversationRequestItem.Req
|
||||
class ConversationVisitor implements PrivateMessageVisitor<ConversationItem> {
|
||||
|
||||
private final Context ctx;
|
||||
private final BodyCache bodyCache;
|
||||
private final TextCache textCache;
|
||||
private final LiveData<String> contactName;
|
||||
|
||||
ConversationVisitor(Context ctx, BodyCache bodyCache,
|
||||
ConversationVisitor(Context ctx, TextCache textCache,
|
||||
LiveData<String> contactName) {
|
||||
this.ctx = ctx;
|
||||
this.bodyCache = bodyCache;
|
||||
this.textCache = textCache;
|
||||
this.contactName = contactName;
|
||||
}
|
||||
|
||||
@@ -45,8 +45,8 @@ class ConversationVisitor implements PrivateMessageVisitor<ConversationItem> {
|
||||
ConversationItem item;
|
||||
if (h.isLocal()) item = new ConversationMessageOutItem(h);
|
||||
else item = new ConversationMessageInItem(h);
|
||||
String body = bodyCache.getBody(h.getId());
|
||||
if (body != null) item.setBody(body);
|
||||
String text = textCache.getText(h.getId());
|
||||
if (text != null) item.setText(text);
|
||||
return item;
|
||||
}
|
||||
|
||||
@@ -239,8 +239,8 @@ class ConversationVisitor implements PrivateMessageVisitor<ConversationItem> {
|
||||
}
|
||||
}
|
||||
|
||||
interface BodyCache {
|
||||
interface TextCache {
|
||||
@Nullable
|
||||
String getBody(MessageId m);
|
||||
String getText(MessageId m);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ import javax.inject.Inject;
|
||||
import static android.content.Intent.FLAG_ACTIVITY_CLEAR_TOP;
|
||||
import static android.widget.Toast.LENGTH_SHORT;
|
||||
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
|
||||
@ParametersNotNullByDefault
|
||||
@@ -130,8 +130,8 @@ public class ForumActivity extends
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getMaxBodyLength() {
|
||||
return MAX_FORUM_POST_BODY_LENGTH;
|
||||
protected int getMaxTextLength() {
|
||||
return MAX_FORUM_POST_TEXT_LENGTH;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -79,7 +79,7 @@ class ForumControllerImpl extends
|
||||
ForumPostReceivedEvent f = (ForumPostReceivedEvent) e;
|
||||
if (f.getGroupId().equals(getGroupId())) {
|
||||
LOG.info("Forum post received, adding...");
|
||||
onForumPostReceived(f.getHeader(), f.getBody());
|
||||
onForumPostReceived(f.getHeader(), f.getText());
|
||||
}
|
||||
} else if (e instanceof ForumInvitationResponseReceivedEvent) {
|
||||
ForumInvitationResponseReceivedEvent f =
|
||||
@@ -109,8 +109,8 @@ class ForumControllerImpl extends
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String loadMessageBody(ForumPostHeader h) throws DbException {
|
||||
return forumManager.getPostBody(h.getId());
|
||||
protected String loadMessageText(ForumPostHeader h) throws DbException {
|
||||
return forumManager.getPostText(h.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -137,7 +137,7 @@ class ForumControllerImpl extends
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createAndStoreMessage(String body,
|
||||
public void createAndStoreMessage(String text,
|
||||
@Nullable ForumItem parentItem,
|
||||
ResultExceptionHandler<ForumItem, DbException> handler) {
|
||||
runOnDbThread(() -> {
|
||||
@@ -148,7 +148,7 @@ class ForumControllerImpl extends
|
||||
clock.currentTimeMillis());
|
||||
MessageId parentId = parentItem != null ?
|
||||
parentItem.getId() : null;
|
||||
createMessage(body, timestamp, parentId, author, handler);
|
||||
createMessage(text, timestamp, parentId, author, handler);
|
||||
} catch (DbException e) {
|
||||
logException(LOG, WARNING, 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,
|
||||
ResultExceptionHandler<ForumItem, DbException> handler) {
|
||||
cryptoExecutor.execute(() -> {
|
||||
LOG.info("Creating forum post...");
|
||||
ForumPost msg = forumManager.createLocalPost(getGroupId(), body,
|
||||
ForumPost msg = forumManager.createLocalPost(getGroupId(), text,
|
||||
timestamp, parentId, author);
|
||||
storePost(msg, body, handler);
|
||||
storePost(msg, text, handler);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -179,12 +179,12 @@ class ForumControllerImpl extends
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ForumItem buildItem(ForumPostHeader header, String body) {
|
||||
return new ForumItem(header, body);
|
||||
protected ForumItem buildItem(ForumPostHeader header, String text) {
|
||||
return new ForumItem(header, text);
|
||||
}
|
||||
|
||||
private void onForumPostReceived(ForumPostHeader h, String body) {
|
||||
ForumItem item = buildItem(h, body);
|
||||
private void onForumPostReceived(ForumPostHeader h, String text) {
|
||||
ForumItem item = buildItem(h, text);
|
||||
listener.runOnUiThreadUnlessDestroyed(
|
||||
() -> listener.onItemReceived(item));
|
||||
}
|
||||
|
||||
@@ -12,8 +12,8 @@ import javax.annotation.concurrent.NotThreadSafe;
|
||||
@NotThreadSafe
|
||||
class ForumItem extends ThreadItem {
|
||||
|
||||
ForumItem(ForumPostHeader h, String body) {
|
||||
super(h.getId(), h.getParentId(), body, h.getTimestamp(), h.getAuthor(),
|
||||
ForumItem(ForumPostHeader h, String text) {
|
||||
super(h.getId(), h.getParentId(), text, h.getTimestamp(), h.getAuthor(),
|
||||
h.getAuthorStatus(), h.isRead());
|
||||
}
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ import static android.view.View.VISIBLE;
|
||||
import static android.widget.Toast.LENGTH_SHORT;
|
||||
import static java.util.logging.Level.WARNING;
|
||||
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
|
||||
implements TextInputListener {
|
||||
@@ -187,10 +187,10 @@ public class IntroductionMessageFragment extends BaseFragment
|
||||
// disable button to prevent accidental double invitations
|
||||
ui.message.setSendButtonEnabled(false);
|
||||
|
||||
String msg = ui.message.getText().toString();
|
||||
if (msg.equals("")) msg = null;
|
||||
else msg = StringUtils.truncateUtf8(msg, MAX_REQUEST_MESSAGE_LENGTH);
|
||||
makeIntroduction(contact1, contact2, msg);
|
||||
String txt = ui.message.getText().toString();
|
||||
if (txt.isEmpty()) txt = null;
|
||||
else txt = StringUtils.truncateUtf8(txt, MAX_INTRODUCTION_TEXT_LENGTH);
|
||||
makeIntroduction(contact1, contact2, txt);
|
||||
|
||||
// don't wait for the introduction to be made before finishing activity
|
||||
introductionActivity.hideSoftKeyboard(ui.message);
|
||||
@@ -199,12 +199,12 @@ public class IntroductionMessageFragment extends BaseFragment
|
||||
}
|
||||
|
||||
private void makeIntroduction(Contact c1, Contact c2,
|
||||
@Nullable String msg) {
|
||||
@Nullable String text) {
|
||||
introductionActivity.runOnDbThread(() -> {
|
||||
// actually make the introduction
|
||||
try {
|
||||
long timestamp = System.currentTimeMillis();
|
||||
introductionManager.makeIntroduction(c1, c2, msg, timestamp);
|
||||
introductionManager.makeIntroduction(c1, c2, text, timestamp);
|
||||
} catch (DbException e) {
|
||||
logException(LOG, WARNING, e);
|
||||
introductionError();
|
||||
|
||||
@@ -37,7 +37,7 @@ import javax.inject.Inject;
|
||||
import static android.view.View.GONE;
|
||||
import static android.view.View.VISIBLE;
|
||||
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
|
||||
@ParametersNotNullByDefault
|
||||
@@ -179,8 +179,8 @@ public class GroupActivity extends
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getMaxBodyLength() {
|
||||
return MAX_GROUP_POST_BODY_LENGTH;
|
||||
protected int getMaxTextLength() {
|
||||
return MAX_GROUP_POST_TEXT_LENGTH;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -84,7 +84,7 @@ class GroupControllerImpl extends
|
||||
GroupMessageAddedEvent g = (GroupMessageAddedEvent) e;
|
||||
if (!g.isLocal() && g.getGroupId().equals(getGroupId())) {
|
||||
LOG.info("Group message received, adding...");
|
||||
GroupMessageItem item = buildItem(g.getHeader(), g.getBody());
|
||||
GroupMessageItem item = buildItem(g.getHeader(), g.getText());
|
||||
listener.runOnUiThreadUnlessDestroyed(
|
||||
() -> listener.onItemReceived(item));
|
||||
}
|
||||
@@ -124,13 +124,13 @@ class GroupControllerImpl extends
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String loadMessageBody(GroupMessageHeader header)
|
||||
protected String loadMessageText(GroupMessageHeader header)
|
||||
throws DbException {
|
||||
if (header instanceof JoinMessageHeader) {
|
||||
// will be looked up later
|
||||
return "";
|
||||
}
|
||||
return privateGroupManager.getMessageBody(header.getId());
|
||||
return privateGroupManager.getMessageText(header.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -159,7 +159,7 @@ class GroupControllerImpl extends
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createAndStoreMessage(String body,
|
||||
public void createAndStoreMessage(String text,
|
||||
@Nullable GroupMessageItem parentItem,
|
||||
ResultExceptionHandler<GroupMessageItem, DbException> handler) {
|
||||
runOnDbThread(() -> {
|
||||
@@ -173,7 +173,7 @@ class GroupControllerImpl extends
|
||||
long timestamp = count.getLatestMsgTime();
|
||||
if (parentItem != null) parentId = parentItem.getId();
|
||||
timestamp = max(clock.currentTimeMillis(), timestamp + 1);
|
||||
createMessage(body, timestamp, parentId, author, previousMsgId,
|
||||
createMessage(text, timestamp, parentId, author, previousMsgId,
|
||||
handler);
|
||||
} catch (DbException 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,
|
||||
MessageId previousMsgId,
|
||||
ResultExceptionHandler<GroupMessageItem, DbException> handler) {
|
||||
@@ -190,8 +190,8 @@ class GroupControllerImpl extends
|
||||
LOG.info("Creating group message...");
|
||||
GroupMessage msg = groupMessageFactory
|
||||
.createGroupMessage(getGroupId(), timestamp,
|
||||
parentId, author, body, previousMsgId);
|
||||
storePost(msg, body, handler);
|
||||
parentId, author, text, previousMsgId);
|
||||
storePost(msg, text, handler);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -208,11 +208,11 @@ class GroupControllerImpl extends
|
||||
|
||||
@Override
|
||||
protected GroupMessageItem buildItem(GroupMessageHeader header,
|
||||
String body) {
|
||||
String text) {
|
||||
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
|
||||
|
||||
@@ -18,6 +18,6 @@ public interface CreateGroupController
|
||||
ResultExceptionHandler<GroupId, DbException> result);
|
||||
|
||||
void sendInvitation(GroupId g, Collection<ContactId> contacts,
|
||||
String message, ResultExceptionHandler<Void, DbException> result);
|
||||
String text, ResultExceptionHandler<Void, DbException> result);
|
||||
|
||||
}
|
||||
|
||||
@@ -123,7 +123,7 @@ class CreateGroupControllerImpl extends ContactSelectorControllerImpl
|
||||
|
||||
@Override
|
||||
public void sendInvitation(GroupId g, Collection<ContactId> contactIds,
|
||||
String message, ResultExceptionHandler<Void, DbException> handler) {
|
||||
String text, ResultExceptionHandler<Void, DbException> handler) {
|
||||
runOnDbThread(() -> {
|
||||
try {
|
||||
LocalAuthor localAuthor = identityManager.getLocalAuthor();
|
||||
@@ -135,7 +135,7 @@ class CreateGroupControllerImpl extends ContactSelectorControllerImpl
|
||||
// Continue
|
||||
}
|
||||
}
|
||||
signInvitations(g, localAuthor, contacts, message, handler);
|
||||
signInvitations(g, localAuthor, contacts, text, handler);
|
||||
} catch (DbException e) {
|
||||
logException(LOG, WARNING, e);
|
||||
handler.onException(e);
|
||||
@@ -144,7 +144,7 @@ class CreateGroupControllerImpl extends ContactSelectorControllerImpl
|
||||
}
|
||||
|
||||
private void signInvitations(GroupId g, LocalAuthor localAuthor,
|
||||
Collection<Contact> contacts, String message,
|
||||
Collection<Contact> contacts, String text,
|
||||
ResultExceptionHandler<Void, DbException> handler) {
|
||||
cryptoExecutor.execute(() -> {
|
||||
long timestamp = clock.currentTimeMillis();
|
||||
@@ -155,20 +155,20 @@ class CreateGroupControllerImpl extends ContactSelectorControllerImpl
|
||||
contexts.add(new InvitationContext(c.getId(), timestamp,
|
||||
signature));
|
||||
}
|
||||
sendInvitations(g, contexts, message, handler);
|
||||
sendInvitations(g, contexts, text, handler);
|
||||
});
|
||||
}
|
||||
|
||||
private void sendInvitations(GroupId g,
|
||||
Collection<InvitationContext> contexts, String message,
|
||||
Collection<InvitationContext> contexts, String text,
|
||||
ResultExceptionHandler<Void, DbException> handler) {
|
||||
runOnDbThread(() -> {
|
||||
try {
|
||||
String msg = message.isEmpty() ? null : message;
|
||||
String txt = text.isEmpty() ? null : text;
|
||||
for (InvitationContext context : contexts) {
|
||||
try {
|
||||
groupInvitationManager.sendInvitation(g,
|
||||
context.contactId, msg, context.timestamp,
|
||||
context.contactId, txt, context.timestamp,
|
||||
context.signature);
|
||||
} catch (NoSuchContactException e) {
|
||||
// Continue
|
||||
|
||||
@@ -18,7 +18,7 @@ import java.util.Collection;
|
||||
import javax.annotation.Nullable;
|
||||
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
|
||||
@ParametersNotNullByDefault
|
||||
@@ -55,10 +55,10 @@ public class GroupInviteActivity extends ContactSelectorActivity
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onButtonClick(String message) {
|
||||
public boolean onButtonClick(String text) {
|
||||
if (groupId == null)
|
||||
throw new IllegalStateException("GroupId was not initialized");
|
||||
controller.sendInvitation(groupId, contacts, message,
|
||||
controller.sendInvitation(groupId, contacts, text,
|
||||
new UiResultExceptionHandler<Void, DbException>(this) {
|
||||
@Override
|
||||
public void onResultUi(Void result) {
|
||||
@@ -76,7 +76,7 @@ public class GroupInviteActivity extends ContactSelectorActivity
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaximumMessageLength() {
|
||||
return MAX_GROUP_INVITATION_MSG_LENGTH;
|
||||
public int getMaximumTextLength() {
|
||||
return MAX_GROUP_INVITATION_TEXT_LENGTH;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,6 @@ import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.util.StringUtils;
|
||||
import org.briarproject.briar.R;
|
||||
import org.briarproject.briar.android.fragment.BaseFragment;
|
||||
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 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
|
||||
implements TextInputListener {
|
||||
@@ -76,8 +76,8 @@ public abstract class BaseMessageFragment extends BaseFragment
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSendClick(String msg) {
|
||||
if (StringUtils.utf8IsTooLong(msg, listener.getMaximumMessageLength())) {
|
||||
public void onSendClick(String text) {
|
||||
if (utf8IsTooLong(text, listener.getMaximumTextLength())) {
|
||||
Snackbar.make(message, R.string.text_too_long, LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
@@ -86,8 +86,8 @@ public abstract class BaseMessageFragment extends BaseFragment
|
||||
message.setSendButtonEnabled(false);
|
||||
message.hideSoftKeyboard();
|
||||
|
||||
msg = truncateUtf8(msg, MAX_INVITATION_MESSAGE_LENGTH);
|
||||
if(!listener.onButtonClick(msg)) {
|
||||
text = truncateUtf8(text, MAX_INVITATION_TEXT_LENGTH);
|
||||
if(!listener.onButtonClick(text)) {
|
||||
message.setSendButtonEnabled(true);
|
||||
message.showSoftKeyboard();
|
||||
}
|
||||
@@ -102,9 +102,9 @@ public abstract class BaseMessageFragment extends BaseFragment
|
||||
void setTitle(@StringRes int titleRes);
|
||||
|
||||
/** Returns true when the button click has been consumed. */
|
||||
boolean onButtonClick(String message);
|
||||
boolean onButtonClick(String text);
|
||||
|
||||
int getMaximumMessageLength();
|
||||
int getMaximumTextLength();
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -41,13 +41,13 @@ public abstract class ShareActivity extends ContactSelectorActivity
|
||||
|
||||
@UiThread
|
||||
@Override
|
||||
public boolean onButtonClick(String message) {
|
||||
share(contacts, message);
|
||||
public boolean onButtonClick(String text) {
|
||||
share(contacts, text);
|
||||
setResult(RESULT_OK);
|
||||
supportFinishAfterTransition();
|
||||
return true;
|
||||
}
|
||||
|
||||
abstract void share(Collection<ContactId> contacts, String msg);
|
||||
abstract void share(Collection<ContactId> contacts, String text);
|
||||
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ import javax.annotation.Nullable;
|
||||
import javax.inject.Inject;
|
||||
|
||||
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
|
||||
@ParametersNotNullByDefault
|
||||
@@ -46,13 +46,13 @@ public class ShareBlogActivity extends ShareActivity {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaximumMessageLength() {
|
||||
return MAX_MESSAGE_BODY_LENGTH;
|
||||
public int getMaximumTextLength() {
|
||||
return MAX_INVITATION_TEXT_LENGTH;
|
||||
}
|
||||
|
||||
@Override
|
||||
void share(Collection<ContactId> contacts, String msg) {
|
||||
controller.share(groupId, contacts, msg,
|
||||
void share(Collection<ContactId> contacts, String text) {
|
||||
controller.share(groupId, contacts, text,
|
||||
new UiExceptionHandler<DbException>(this) {
|
||||
@Override
|
||||
public void onExceptionUi(DbException exception) {
|
||||
|
||||
@@ -12,7 +12,7 @@ import java.util.Collection;
|
||||
public interface ShareBlogController
|
||||
extends ContactSelectorController<SelectableContactItem> {
|
||||
|
||||
void share(GroupId g, Collection<ContactId> contacts, String msg,
|
||||
void share(GroupId g, Collection<ContactId> contacts, String text,
|
||||
ExceptionHandler<DbException> handler);
|
||||
|
||||
}
|
||||
|
||||
@@ -56,17 +56,17 @@ class ShareBlogControllerImpl extends ContactSelectorControllerImpl
|
||||
}
|
||||
|
||||
@Override
|
||||
public void share(GroupId g, Collection<ContactId> contacts, String message,
|
||||
public void share(GroupId g, Collection<ContactId> contacts, String text,
|
||||
ExceptionHandler<DbException> handler) {
|
||||
runOnDbThread(() -> {
|
||||
try {
|
||||
String msg = isNullOrEmpty(message) ? null : message;
|
||||
String txt = isNullOrEmpty(text) ? null : text;
|
||||
for (ContactId c : contacts) {
|
||||
try {
|
||||
long time = Math.max(clock.currentTimeMillis(),
|
||||
conversationManager.getGroupCount(c)
|
||||
.getLatestMsgTime() + 1);
|
||||
blogSharingManager.sendInvitation(g, c, msg, time);
|
||||
blogSharingManager.sendInvitation(g, c, txt, time);
|
||||
} catch (NoSuchContactException | NoSuchGroupException e) {
|
||||
logException(LOG, WARNING, e);
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ import javax.annotation.Nullable;
|
||||
import javax.inject.Inject;
|
||||
|
||||
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
|
||||
@ParametersNotNullByDefault
|
||||
@@ -46,13 +46,13 @@ public class ShareForumActivity extends ShareActivity {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaximumMessageLength() {
|
||||
return MAX_MESSAGE_BODY_LENGTH;
|
||||
public int getMaximumTextLength() {
|
||||
return MAX_INVITATION_TEXT_LENGTH;
|
||||
}
|
||||
|
||||
@Override
|
||||
void share(Collection<ContactId> contacts, String msg) {
|
||||
controller.share(groupId, contacts, msg,
|
||||
void share(Collection<ContactId> contacts, String text) {
|
||||
controller.share(groupId, contacts, text,
|
||||
new UiExceptionHandler<DbException>(this) {
|
||||
@Override
|
||||
public void onExceptionUi(DbException exception) {
|
||||
|
||||
@@ -12,7 +12,7 @@ import java.util.Collection;
|
||||
public interface ShareForumController
|
||||
extends ContactSelectorController<SelectableContactItem> {
|
||||
|
||||
void share(GroupId g, Collection<ContactId> contacts, String msg,
|
||||
void share(GroupId g, Collection<ContactId> contacts, String text,
|
||||
ExceptionHandler<DbException> handler);
|
||||
|
||||
}
|
||||
|
||||
@@ -57,16 +57,16 @@ class ShareForumControllerImpl extends ContactSelectorControllerImpl
|
||||
|
||||
@Override
|
||||
public void share(GroupId g, Collection<ContactId> contacts,
|
||||
String message, ExceptionHandler<DbException> handler) {
|
||||
String text, ExceptionHandler<DbException> handler) {
|
||||
runOnDbThread(() -> {
|
||||
try {
|
||||
String msg = isNullOrEmpty(message) ? null : message;
|
||||
String txt = isNullOrEmpty(text) ? null : text;
|
||||
for (ContactId c : contacts) {
|
||||
try {
|
||||
long time = Math.max(clock.currentTimeMillis(),
|
||||
conversationManager.getGroupCount(c)
|
||||
.getLatestMsgTime() + 1);
|
||||
forumSharingManager.sendInvitation(g, c, msg, time);
|
||||
forumSharingManager.sendInvitation(g, c, txt, time);
|
||||
} catch (NoSuchContactException | NoSuchGroupException e) {
|
||||
logException(LOG, WARNING, e);
|
||||
}
|
||||
|
||||
@@ -17,7 +17,6 @@ import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
||||
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
||||
import org.briarproject.bramble.api.sync.GroupId;
|
||||
import org.briarproject.bramble.api.sync.MessageId;
|
||||
import org.briarproject.bramble.util.StringUtils;
|
||||
import org.briarproject.briar.R;
|
||||
import org.briarproject.briar.android.activity.BriarActivity;
|
||||
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.SCROLL_STATE_IDLE;
|
||||
import static java.util.logging.Level.INFO;
|
||||
import static org.briarproject.bramble.util.StringUtils.utf8IsTooLong;
|
||||
import static org.briarproject.briar.android.threaded.ThreadItemAdapter.UnreadCount;
|
||||
|
||||
@MethodsNotNullByDefault
|
||||
@@ -351,7 +351,7 @@ public abstract class ThreadListActivity<G extends NamedGroup, I extends ThreadI
|
||||
public void onSendClick(String text) {
|
||||
if (text.trim().length() == 0)
|
||||
return;
|
||||
if (StringUtils.utf8IsTooLong(text, getMaxBodyLength())) {
|
||||
if (utf8IsTooLong(text, getMaxTextLength())) {
|
||||
displaySnackbar(R.string.text_too_long);
|
||||
return;
|
||||
}
|
||||
@@ -375,7 +375,7 @@ public abstract class ThreadListActivity<G extends NamedGroup, I extends ThreadI
|
||||
updateTextInput();
|
||||
}
|
||||
|
||||
protected abstract int getMaxBodyLength();
|
||||
protected abstract int getMaxTextLength();
|
||||
|
||||
@Override
|
||||
public void onItemReceived(I item) {
|
||||
|
||||
@@ -35,7 +35,7 @@ public interface ThreadListController<G extends NamedGroup, I extends ThreadItem
|
||||
|
||||
void markItemsRead(Collection<I> items);
|
||||
|
||||
void createAndStoreMessage(String body, @Nullable I parentItem,
|
||||
void createAndStoreMessage(String text, @Nullable I parentItem,
|
||||
ResultExceptionHandler<I, DbException> handler);
|
||||
|
||||
void deleteNamedGroup(ExceptionHandler<DbException> handler);
|
||||
|
||||
@@ -50,7 +50,7 @@ public abstract class ThreadListControllerImpl<G extends NamedGroup, I extends T
|
||||
Logger.getLogger(ThreadListControllerImpl.class.getName());
|
||||
|
||||
private final EventBus eventBus;
|
||||
private final Map<MessageId, String> bodyCache = new ConcurrentHashMap<>();
|
||||
private final Map<MessageId, String> textCache = new ConcurrentHashMap<>();
|
||||
private volatile GroupId groupId;
|
||||
|
||||
protected final IdentityManager identityManager;
|
||||
@@ -161,9 +161,9 @@ public abstract class ThreadListControllerImpl<G extends NamedGroup, I extends T
|
||||
// Load bodies into cache
|
||||
start = now();
|
||||
for (H header : headers) {
|
||||
if (!bodyCache.containsKey(header.getId())) {
|
||||
bodyCache.put(header.getId(),
|
||||
loadMessageBody(header));
|
||||
if (!textCache.containsKey(header.getId())) {
|
||||
textCache.put(header.getId(),
|
||||
loadMessageText(header));
|
||||
}
|
||||
}
|
||||
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;
|
||||
|
||||
@DatabaseExecutor
|
||||
protected abstract String loadMessageBody(H header) throws DbException;
|
||||
protected abstract String loadMessageText(H header) throws DbException;
|
||||
|
||||
@Override
|
||||
public void markItemRead(I item) {
|
||||
@@ -206,15 +206,15 @@ public abstract class ThreadListControllerImpl<G extends NamedGroup, I extends T
|
||||
@DatabaseExecutor
|
||||
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) {
|
||||
runOnDbThread(() -> {
|
||||
try {
|
||||
long start = now();
|
||||
H header = addLocalMessage(msg);
|
||||
bodyCache.put(msg.getMessage().getId(), body);
|
||||
textCache.put(msg.getMessage().getId(), text);
|
||||
logDuration(LOG, "Storing message", start);
|
||||
resultHandler.onResult(buildItem(header, body));
|
||||
resultHandler.onResult(buildItem(header, text));
|
||||
} catch (DbException e) {
|
||||
logException(LOG, WARNING, e);
|
||||
resultHandler.onException(e);
|
||||
@@ -247,7 +247,7 @@ public abstract class ThreadListControllerImpl<G extends NamedGroup, I extends T
|
||||
throws DbException {
|
||||
ThreadItemList<I> items = new ThreadItemListImpl<>();
|
||||
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);
|
||||
if (LOG.isLoggable(INFO))
|
||||
@@ -256,7 +256,7 @@ public abstract class ThreadListControllerImpl<G extends NamedGroup, I extends T
|
||||
return items;
|
||||
}
|
||||
|
||||
protected abstract I buildItem(H header, String body);
|
||||
protected abstract I buildItem(H header, String text);
|
||||
|
||||
protected GroupId getGroupId() {
|
||||
checkGroupId();
|
||||
|
||||
@@ -106,13 +106,13 @@ public class UiUtils {
|
||||
return (int) daysBeforeExpiry;
|
||||
}
|
||||
|
||||
public static SpannableStringBuilder getTeaser(Context ctx, Spanned body) {
|
||||
if (body.length() < TEASER_LENGTH)
|
||||
public static SpannableStringBuilder getTeaser(Context ctx, Spanned text) {
|
||||
if (text.length() < TEASER_LENGTH)
|
||||
throw new IllegalArgumentException(
|
||||
"String is shorter than TEASER_LENGTH");
|
||||
|
||||
SpannableStringBuilder builder =
|
||||
new SpannableStringBuilder(body.subSequence(0, TEASER_LENGTH));
|
||||
new SpannableStringBuilder(text.subSequence(0, TEASER_LENGTH));
|
||||
String ellipsis = ctx.getString(R.string.ellipsis);
|
||||
builder.append(ellipsis).append(" ");
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
tools:context=".android.blog.WriteBlogPostActivity">
|
||||
|
||||
<org.briarproject.briar.android.view.LargeTextInputView
|
||||
android:id="@+id/bodyInput"
|
||||
android:id="@+id/textInput"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="bottom"
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
app:persona="commenter"/>
|
||||
|
||||
<com.vanniktech.emoji.EmojiTextView
|
||||
android:id="@+id/bodyView"
|
||||
android:id="@+id/textView"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingBottom="@dimen/listitem_vertical_margin"
|
||||
|
||||
@@ -54,7 +54,7 @@
|
||||
app:tint="?attr/colorControlNormal"/>
|
||||
|
||||
<com.vanniktech.emoji.EmojiTextView
|
||||
android:id="@+id/bodyView"
|
||||
android:id="@+id/textView"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="@dimen/listitem_vertical_margin"
|
||||
@@ -72,7 +72,7 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/listitem_vertical_margin"
|
||||
android:orientation="vertical"
|
||||
app:layout_constraintTop_toBottomOf="@+id/bodyView">
|
||||
app:layout_constraintTop_toBottomOf="@+id/textView">
|
||||
|
||||
<include
|
||||
layout="@layout/list_item_blog_comment"
|
||||
|
||||
@@ -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.getRandomId;
|
||||
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.verify;
|
||||
|
||||
@@ -85,9 +85,9 @@ public class ForumActivityTest {
|
||||
ForumItem[] forumItems = new ForumItem[6];
|
||||
for (int i = 0; i < forumItems.length; i++) {
|
||||
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],
|
||||
content, System.currentTimeMillis(), author, UNKNOWN);
|
||||
text, System.currentTimeMillis(), author, UNKNOWN);
|
||||
forumItems[i].setLevel(LEVELS[i]);
|
||||
}
|
||||
ThreadItemList<ForumItem> list = new ThreadItemListImpl<>();
|
||||
|
||||
@@ -5,14 +5,14 @@ import static org.briarproject.bramble.api.sync.SyncConstants.MAX_MESSAGE_BODY_L
|
||||
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
|
||||
String KEY_TYPE = "type";
|
||||
|
||||
@@ -14,10 +14,10 @@ public class BlogInvitationRequest extends InvitationRequest<Blog> {
|
||||
|
||||
public BlogInvitationRequest(MessageId id, GroupId groupId, long time,
|
||||
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) {
|
||||
super(id, groupId, time, local, sent, seen, read, sessionId, blog,
|
||||
message, available, canBeOpened);
|
||||
text, available, canBeOpened);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -104,9 +104,9 @@ public interface BlogManager {
|
||||
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.
|
||||
|
||||
@@ -21,7 +21,7 @@ public interface BlogPostFactory {
|
||||
String SIGNING_LABEL_COMMENT = CLIENT_ID.getString() + "/COMMENT";
|
||||
|
||||
BlogPost createBlogPost(GroupId groupId, long timestamp,
|
||||
@Nullable MessageId parent, LocalAuthor author, String body)
|
||||
@Nullable MessageId parent, LocalAuthor author, String text)
|
||||
throws FormatException, GeneralSecurityException;
|
||||
|
||||
Message createBlogComment(GroupId groupId, LocalAuthor author,
|
||||
|
||||
@@ -15,9 +15,9 @@ public interface ForumConstants {
|
||||
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
|
||||
String KEY_TIMESTAMP = "timestamp";
|
||||
|
||||
@@ -16,10 +16,10 @@ public class ForumInvitationRequest extends InvitationRequest<Forum> {
|
||||
|
||||
public ForumInvitationRequest(MessageId id, GroupId groupId, long time,
|
||||
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) {
|
||||
super(id, groupId, time, local, sent, seen, read, sessionId, forum,
|
||||
message, available, canBeOpened);
|
||||
text, available, canBeOpened);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -51,7 +51,7 @@ public interface ForumManager {
|
||||
* Creates a local forum post.
|
||||
*/
|
||||
@CryptoExecutor
|
||||
ForumPost createLocalPost(GroupId groupId, String body, long timestamp,
|
||||
ForumPost createLocalPost(GroupId groupId, String text, long timestamp,
|
||||
@Nullable MessageId parentId, LocalAuthor author);
|
||||
|
||||
/**
|
||||
@@ -75,9 +75,9 @@ public interface ForumManager {
|
||||
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.
|
||||
|
||||
@@ -20,7 +20,7 @@ public interface ForumPostFactory {
|
||||
|
||||
@CryptoExecutor
|
||||
ForumPost createPost(GroupId groupId, long timestamp,
|
||||
@Nullable MessageId parent, LocalAuthor author, String body)
|
||||
@Nullable MessageId parent, LocalAuthor author, String text)
|
||||
throws FormatException, GeneralSecurityException;
|
||||
|
||||
}
|
||||
|
||||
@@ -16,13 +16,13 @@ public class ForumPostReceivedEvent extends Event {
|
||||
|
||||
private final GroupId groupId;
|
||||
private final ForumPostHeader header;
|
||||
private final String body;
|
||||
private final String text;
|
||||
|
||||
public ForumPostReceivedEvent(GroupId groupId, ForumPostHeader header,
|
||||
String body) {
|
||||
String text) {
|
||||
this.groupId = groupId;
|
||||
this.header = header;
|
||||
this.body = body;
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
public GroupId getGroupId() {
|
||||
@@ -33,7 +33,7 @@ public class ForumPostReceivedEvent extends Event {
|
||||
return header;
|
||||
}
|
||||
|
||||
public String getBody() {
|
||||
return body;
|
||||
public String getText() {
|
||||
return text;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ public interface IntroductionConstants {
|
||||
* The maximum length of the introducer's optional message to the
|
||||
* 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";
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ public interface IntroductionManager extends ConversationClient {
|
||||
/**
|
||||
* 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;
|
||||
|
||||
/**
|
||||
|
||||
@@ -19,10 +19,10 @@ public class IntroductionRequest extends PrivateRequest<Author> {
|
||||
|
||||
public IntroductionRequest(MessageId messageId, GroupId groupId,
|
||||
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) {
|
||||
super(messageId, groupId, time, local, sent, seen, read, sessionId,
|
||||
author, message, answered);
|
||||
author, text, answered);
|
||||
this.contact = contact;
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ public interface ConversationManager {
|
||||
* Returns the headers of all messages in the given private conversation.
|
||||
*
|
||||
* 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)
|
||||
throws DbException;
|
||||
|
||||
@@ -5,7 +5,7 @@ import static org.briarproject.bramble.api.sync.SyncConstants.MAX_MESSAGE_BODY_L
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -42,8 +42,8 @@ public interface MessagingManager extends ConversationClient {
|
||||
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;
|
||||
|
||||
}
|
||||
|
||||
@@ -8,6 +8,6 @@ import org.briarproject.bramble.api.sync.GroupId;
|
||||
public interface PrivateMessageFactory {
|
||||
|
||||
PrivateMessage createPrivateMessage(GroupId groupId, long timestamp,
|
||||
String body) throws FormatException;
|
||||
String text) throws FormatException;
|
||||
|
||||
}
|
||||
|
||||
@@ -16,17 +16,17 @@ public class PrivateRequest<N extends Nameable> extends PrivateMessageHeader {
|
||||
private final SessionId sessionId;
|
||||
private final N nameable;
|
||||
@Nullable
|
||||
private final String message;
|
||||
private final String text;
|
||||
private final boolean answered;
|
||||
|
||||
public PrivateRequest(MessageId messageId, GroupId groupId, long time,
|
||||
boolean local, boolean sent, boolean seen, boolean read,
|
||||
SessionId sessionId, N nameable, @Nullable String message,
|
||||
SessionId sessionId, N nameable, @Nullable String text,
|
||||
boolean answered) {
|
||||
super(messageId, groupId, time, local, sent, seen, read);
|
||||
this.sessionId = sessionId;
|
||||
this.nameable = nameable;
|
||||
this.message = message;
|
||||
this.text = text;
|
||||
this.answered = answered;
|
||||
}
|
||||
|
||||
@@ -43,8 +43,8 @@ public class PrivateRequest<N extends Nameable> extends PrivateMessageHeader {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getMessage() {
|
||||
return message;
|
||||
public String getText() {
|
||||
return text;
|
||||
}
|
||||
|
||||
public boolean wasAnswered() {
|
||||
|
||||
@@ -51,13 +51,13 @@ public interface GroupMessageFactory {
|
||||
* @param parentId The ID of the parent post, or null if the post has no
|
||||
* parent
|
||||
* @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
|
||||
* in this group
|
||||
*/
|
||||
@CryptoExecutor
|
||||
GroupMessage createGroupMessage(GroupId groupId, long timestamp,
|
||||
@Nullable MessageId parentId, LocalAuthor author, String body,
|
||||
@Nullable MessageId parentId, LocalAuthor author, String text,
|
||||
MessageId previousMsgId);
|
||||
|
||||
}
|
||||
|
||||
@@ -15,13 +15,13 @@ public interface PrivateGroupConstants {
|
||||
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;
|
||||
|
||||
}
|
||||
|
||||
@@ -92,9 +92,9 @@ public interface PrivateGroupManager {
|
||||
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.
|
||||
|
||||
@@ -17,14 +17,14 @@ public class GroupMessageAddedEvent extends Event {
|
||||
|
||||
private final GroupId groupId;
|
||||
private final GroupMessageHeader header;
|
||||
private final String body;
|
||||
private final String text;
|
||||
private final boolean local;
|
||||
|
||||
public GroupMessageAddedEvent(GroupId groupId, GroupMessageHeader header,
|
||||
String body, boolean local) {
|
||||
String text, boolean local) {
|
||||
this.groupId = groupId;
|
||||
this.header = header;
|
||||
this.body = body;
|
||||
this.text = text;
|
||||
this.local = local;
|
||||
}
|
||||
|
||||
@@ -36,8 +36,8 @@ public class GroupMessageAddedEvent extends Event {
|
||||
return header;
|
||||
}
|
||||
|
||||
public String getBody() {
|
||||
return body;
|
||||
public String getText() {
|
||||
return text;
|
||||
}
|
||||
|
||||
public boolean isLocal() {
|
||||
|
||||
@@ -42,7 +42,7 @@ public interface GroupInvitationManager extends ConversationClient {
|
||||
* shared with the contact, for example because an invitation is already
|
||||
* 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;
|
||||
|
||||
/**
|
||||
|
||||
@@ -18,9 +18,9 @@ public class GroupInvitationRequest extends InvitationRequest<PrivateGroup> {
|
||||
public GroupInvitationRequest(MessageId id, GroupId groupId, long time,
|
||||
boolean local, boolean sent, boolean seen, boolean read,
|
||||
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,
|
||||
message, available, canBeOpened);
|
||||
text, available, canBeOpened);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -14,10 +14,10 @@ public abstract class InvitationRequest<S extends Shareable> extends
|
||||
|
||||
public InvitationRequest(MessageId messageId, GroupId groupId, long time,
|
||||
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) {
|
||||
super(messageId, groupId, time, local, sent, seen, read, sessionId,
|
||||
object, message, !available);
|
||||
object, text, !available);
|
||||
this.canBeOpened = canBeOpened;
|
||||
}
|
||||
|
||||
|
||||
@@ -5,9 +5,8 @@ import static org.briarproject.bramble.api.sync.SyncConstants.MAX_MESSAGE_BODY_L
|
||||
public interface SharingConstants {
|
||||
|
||||
/**
|
||||
* The maximum length of the optional message from the inviter to the
|
||||
* invitee in UTF-8 bytes.
|
||||
* The maximum length of an invitation's optional text in UTF-8 bytes.
|
||||
*/
|
||||
int MAX_INVITATION_MESSAGE_LENGTH = MAX_MESSAGE_BODY_LENGTH - 1024;
|
||||
int MAX_INVITATION_TEXT_LENGTH = MAX_MESSAGE_BODY_LENGTH - 1024;
|
||||
|
||||
}
|
||||
|
||||
@@ -17,11 +17,11 @@ public interface SharingManager<S extends Shareable>
|
||||
extends ConversationClient {
|
||||
|
||||
/**
|
||||
* Sends an invitation to share the given group with the given contact
|
||||
* and sends an optional message along with it.
|
||||
* Sends an invitation to share the given group with the given contact,
|
||||
* including optional text.
|
||||
*/
|
||||
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
|
||||
|
||||
@@ -26,7 +26,7 @@ public interface TestDataCreator {
|
||||
Contact addContact(String name) throws DbException;
|
||||
|
||||
@IoExecutor
|
||||
void addPrivateMessage(Contact contact, String body, long time,
|
||||
void addPrivateMessage(Contact contact, String text, long time,
|
||||
boolean local) throws DbException, FormatException;
|
||||
|
||||
}
|
||||
|
||||
@@ -456,21 +456,22 @@ class BlogManagerImpl extends BdfIncomingMessageHook implements BlogManager,
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPostBody(MessageId m) throws DbException {
|
||||
public String getPostText(MessageId m) throws DbException {
|
||||
try {
|
||||
return getPostBody(clientHelper.getMessageAsList(m));
|
||||
return getPostText(clientHelper.getMessageAsList(m));
|
||||
} catch (FormatException 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());
|
||||
if (type == POST) {
|
||||
// type, body, signature
|
||||
// Type, text, signature
|
||||
return message.getString(1);
|
||||
} 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);
|
||||
} else {
|
||||
throw new FormatException();
|
||||
|
||||
@@ -20,8 +20,8 @@ import javax.annotation.Nullable;
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
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_POST_BODY_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_TEXT_LENGTH;
|
||||
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.WRAPPED_COMMENT;
|
||||
@@ -42,23 +42,23 @@ class BlogPostFactoryImpl implements BlogPostFactory {
|
||||
|
||||
@Override
|
||||
public BlogPost createBlogPost(GroupId groupId, long timestamp,
|
||||
@Nullable MessageId parent, LocalAuthor author, String body)
|
||||
@Nullable MessageId parent, LocalAuthor author, String text)
|
||||
throws FormatException, GeneralSecurityException {
|
||||
|
||||
// Validate the arguments
|
||||
int bodyLength = StringUtils.toUtf8(body).length;
|
||||
if (bodyLength > MAX_BLOG_POST_BODY_LENGTH)
|
||||
int textLength = StringUtils.toUtf8(text).length;
|
||||
if (textLength > MAX_BLOG_POST_TEXT_LENGTH)
|
||||
throw new IllegalArgumentException();
|
||||
|
||||
// Serialise the data to be signed
|
||||
BdfList signed = BdfList.of(groupId, timestamp, body);
|
||||
BdfList signed = BdfList.of(groupId, timestamp, text);
|
||||
|
||||
// Generate the signature
|
||||
byte[] sig = clientHelper
|
||||
.sign(SIGNING_LABEL_POST, signed, author.getPrivateKey());
|
||||
|
||||
// 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);
|
||||
return new BlogPost(m, parent, author);
|
||||
}
|
||||
@@ -72,7 +72,7 @@ class BlogPostFactoryImpl implements BlogPostFactory {
|
||||
if (comment != null) {
|
||||
int commentLength = StringUtils.toUtf8(comment).length;
|
||||
if (commentLength == 0) throw new IllegalArgumentException();
|
||||
if (commentLength > MAX_BLOG_COMMENT_LENGTH)
|
||||
if (commentLength > MAX_BLOG_COMMENT_TEXT_LENGTH)
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
|
||||
@@ -98,10 +98,10 @@ class BlogPostFactoryImpl implements BlogPostFactory {
|
||||
throw new IllegalArgumentException("Needs to wrap a POST");
|
||||
|
||||
// Serialise the message
|
||||
String content = body.getString(1);
|
||||
String text = body.getString(1);
|
||||
byte[] signature = body.getRaw(2);
|
||||
BdfList message = BdfList.of(WRAPPED_POST.getInt(), descriptor,
|
||||
timestamp, content, signature);
|
||||
timestamp, text, signature);
|
||||
return clientHelper
|
||||
.createMessage(groupId, clock.currentTimeMillis(), message);
|
||||
}
|
||||
@@ -116,10 +116,10 @@ class BlogPostFactoryImpl implements BlogPostFactory {
|
||||
// Serialise the message
|
||||
byte[] descriptor = body.getRaw(1);
|
||||
long timestamp = body.getLong(2);
|
||||
String content = body.getString(3);
|
||||
String text = body.getString(3);
|
||||
byte[] signature = body.getRaw(4);
|
||||
BdfList message = BdfList.of(WRAPPED_POST.getInt(), descriptor,
|
||||
timestamp, content, signature);
|
||||
timestamp, text, signature);
|
||||
return clientHelper
|
||||
.createMessage(groupId, clock.currentTimeMillis(), message);
|
||||
}
|
||||
|
||||
@@ -22,10 +22,10 @@ import org.briarproject.briar.api.blog.MessageType;
|
||||
|
||||
import java.security.GeneralSecurityException;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
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.util.ValidationUtils.checkLength;
|
||||
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_TIME_RECEIVED;
|
||||
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_POST_BODY_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_TEXT_LENGTH;
|
||||
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.BlogPostFactory.SIGNING_LABEL_COMMENT;
|
||||
@@ -99,15 +99,15 @@ class BlogPostValidator extends BdfMessageValidator {
|
||||
private BdfMessageContext validatePost(Message m, Group g, BdfList body)
|
||||
throws InvalidMessageException, FormatException {
|
||||
|
||||
// Content, Signature
|
||||
// Text, signature
|
||||
checkSize(body, 2);
|
||||
String postBody = body.getString(0);
|
||||
checkLength(postBody, 0, MAX_BLOG_POST_BODY_LENGTH);
|
||||
String text = body.getString(0);
|
||||
checkLength(text, 0, MAX_BLOG_POST_TEXT_LENGTH);
|
||||
|
||||
// Verify Signature
|
||||
// Verify signature
|
||||
byte[] sig = body.getRaw(1);
|
||||
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);
|
||||
Author a = b.getAuthor();
|
||||
try {
|
||||
@@ -128,23 +128,23 @@ class BlogPostValidator extends BdfMessageValidator {
|
||||
private BdfMessageContext validateComment(Message m, Group g, BdfList body)
|
||||
throws InvalidMessageException, FormatException {
|
||||
|
||||
// comment, parent_original_id, parent_id, signature
|
||||
// Comment, parent original ID, parent ID, signature
|
||||
checkSize(body, 4);
|
||||
|
||||
// Comment
|
||||
String comment = body.getOptionalString(0);
|
||||
checkLength(comment, 1, MAX_BLOG_COMMENT_LENGTH);
|
||||
checkLength(comment, 1, MAX_BLOG_COMMENT_TEXT_LENGTH);
|
||||
|
||||
// parent_original_id
|
||||
// The ID of a post or comment in this group or another group
|
||||
// Parent original ID
|
||||
// The ID of a post or comment in this blog or another blog
|
||||
byte[] pOriginalIdBytes = body.getRaw(1);
|
||||
checkLength(pOriginalIdBytes, MessageId.LENGTH);
|
||||
MessageId pOriginalId = new MessageId(pOriginalIdBytes);
|
||||
|
||||
// parent_id
|
||||
// The ID of a post, comment, wrapped post or wrapped comment in this
|
||||
// group, which had the ID parent_original_id in the group
|
||||
// where it was originally posted
|
||||
// Parent ID
|
||||
// The ID of the comment's parent, which is a post, comment, wrapped
|
||||
// post or wrapped comment in this blog, which had the ID
|
||||
// parentOriginalId in the blog where it was originally posted
|
||||
byte[] currentIdBytes = body.getRaw(2);
|
||||
checkLength(currentIdBytes, MessageId.LENGTH);
|
||||
MessageId currentId = new MessageId(currentIdBytes);
|
||||
@@ -170,35 +170,37 @@ class BlogPostValidator extends BdfMessageValidator {
|
||||
meta.put(KEY_ORIGINAL_PARENT_MSG_ID, pOriginalId);
|
||||
meta.put(KEY_PARENT_MSG_ID, currentId);
|
||||
meta.put(KEY_AUTHOR, clientHelper.toList(a));
|
||||
Collection<MessageId> dependencies = Collections.singleton(currentId);
|
||||
Collection<MessageId> dependencies = singletonList(currentId);
|
||||
return new BdfMessageContext(meta, dependencies);
|
||||
}
|
||||
|
||||
private BdfMessageContext validateWrappedPost(BdfList body)
|
||||
throws InvalidMessageException, FormatException {
|
||||
|
||||
// p_group descriptor, p_timestamp, p_content, p_signature
|
||||
// Copied group descriptor, copied timestamp, copied text, copied
|
||||
// signature
|
||||
checkSize(body, 4);
|
||||
|
||||
// Group Descriptor
|
||||
// Copied group descriptor of original post
|
||||
byte[] descriptor = body.getRaw(0);
|
||||
|
||||
// Timestamp of Wrapped Post
|
||||
// Copied timestamp of original post
|
||||
long wTimestamp = body.getLong(1);
|
||||
if (wTimestamp < 0) throw new FormatException();
|
||||
|
||||
// Content of Wrapped Post
|
||||
String content = body.getString(2);
|
||||
// Copied text of original post
|
||||
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);
|
||||
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,
|
||||
descriptor);
|
||||
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);
|
||||
Message wMessage =
|
||||
messageFactory.createMessage(wGroup.getId(), wTimestamp, wBody);
|
||||
@@ -217,47 +219,46 @@ class BlogPostValidator extends BdfMessageValidator {
|
||||
private BdfMessageContext validateWrappedComment(BdfList body)
|
||||
throws InvalidMessageException, FormatException {
|
||||
|
||||
// c_group descriptor, c_timestamp, c_comment, c_parent_original_id,
|
||||
// c_parent_id, c_signature, parent_id
|
||||
// Copied group descriptor, copied timestamp, copied text, copied
|
||||
// parent original ID, copied parent ID, copied signature, parent ID
|
||||
checkSize(body, 7);
|
||||
|
||||
// Group Descriptor
|
||||
// Copied group descriptor of original comment
|
||||
byte[] descriptor = body.getRaw(0);
|
||||
|
||||
// Timestamp of Wrapped Comment
|
||||
// Copied timestamp of original comment
|
||||
long wTimestamp = body.getLong(1);
|
||||
if (wTimestamp < 0) throw new FormatException();
|
||||
|
||||
// Body of Wrapped Comment
|
||||
// Copied text of original comment
|
||||
String comment = body.getOptionalString(2);
|
||||
checkLength(comment, 1, MAX_BLOG_COMMENT_LENGTH);
|
||||
checkLength(comment, 1, MAX_BLOG_COMMENT_TEXT_LENGTH);
|
||||
|
||||
// c_parent_original_id
|
||||
// Taken from the original comment
|
||||
// Copied parent original ID of original comment
|
||||
byte[] pOriginalIdBytes = body.getRaw(3);
|
||||
checkLength(pOriginalIdBytes, MessageId.LENGTH);
|
||||
MessageId pOriginalId = new MessageId(pOriginalIdBytes);
|
||||
|
||||
// c_parent_id
|
||||
// Taken from the original comment
|
||||
// Copied parent ID of original comment
|
||||
byte[] oldIdBytes = body.getRaw(4);
|
||||
checkLength(oldIdBytes, MessageId.LENGTH);
|
||||
MessageId oldId = new MessageId(oldIdBytes);
|
||||
|
||||
// c_signature
|
||||
// Taken from the original comment
|
||||
// Copied signature of original comment
|
||||
byte[] signature = body.getRaw(5);
|
||||
checkLength(signature, 1, MAX_SIGNATURE_LENGTH);
|
||||
|
||||
// parent_id
|
||||
// The ID of a post, comment, wrapped post or wrapped comment in this
|
||||
// group, which had the ID c_parent_original_id in the group
|
||||
// where it was originally posted
|
||||
// Parent ID
|
||||
// The ID of this comment's parent, which is a post, comment, wrapped
|
||||
// post or wrapped comment in this blog, which had the ID
|
||||
// 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);
|
||||
checkLength(parentIdBytes, MessageId.LENGTH);
|
||||
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,
|
||||
descriptor);
|
||||
BdfList wBodyList = BdfList.of(COMMENT.getInt(), comment, pOriginalId,
|
||||
@@ -269,7 +270,7 @@ class BlogPostValidator extends BdfMessageValidator {
|
||||
BdfMessageContext c = validateComment(wMessage, wGroup, wBodyList);
|
||||
|
||||
// Return the metadata and dependencies
|
||||
Collection<MessageId> dependencies = Collections.singleton(parentId);
|
||||
Collection<MessageId> dependencies = singletonList(parentId);
|
||||
BdfDictionary meta = new BdfDictionary();
|
||||
meta.put(KEY_ORIGINAL_MSG_ID, wMessage.getId());
|
||||
meta.put(KEY_ORIGINAL_PARENT_MSG_ID, pOriginalId);
|
||||
|
||||
@@ -64,7 +64,7 @@ import okhttp3.ResponseBody;
|
||||
import static java.util.concurrent.TimeUnit.MILLISECONDS;
|
||||
import static java.util.logging.Level.WARNING;
|
||||
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_INTERVAL;
|
||||
import static org.briarproject.briar.api.feed.FeedConstants.FETCH_UNIT;
|
||||
@@ -410,11 +410,10 @@ class FeedManagerImpl implements FeedManager, Client, EventListener,
|
||||
return lastEntryTime;
|
||||
}
|
||||
|
||||
private void postEntry(Transaction txn, Feed feed, SyndEntry entry)
|
||||
throws DbException {
|
||||
private void postEntry(Transaction txn, Feed feed, SyndEntry entry) {
|
||||
LOG.info("Adding new entry...");
|
||||
|
||||
// build post body
|
||||
// build post text
|
||||
StringBuilder b = new StringBuilder();
|
||||
|
||||
if (!StringUtils.isNullOrEmpty(entry.getTitle())) {
|
||||
@@ -454,12 +453,12 @@ class FeedManagerImpl implements FeedManager, Client, EventListener,
|
||||
if (date == null) date = entry.getPublishedDate();
|
||||
if (date == null) time = now;
|
||||
else time = Math.max(0, Math.min(date.getTime(), now));
|
||||
String body = getPostBody(b.toString());
|
||||
String text = getPostText(b.toString());
|
||||
try {
|
||||
// create and store post
|
||||
LocalAuthor localAuthor = feed.getLocalAuthor();
|
||||
BlogPost post = blogPostFactory
|
||||
.createBlogPost(groupId, time, null, localAuthor, body);
|
||||
.createBlogPost(groupId, time, null, localAuthor, text);
|
||||
blogManager.addLocalPost(txn, post);
|
||||
} catch (DbException | GeneralSecurityException | FormatException 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);
|
||||
return StringUtils.truncateUtf8(text, MAX_BLOG_POST_BODY_LENGTH);
|
||||
return StringUtils.truncateUtf8(text, MAX_BLOG_POST_TEXT_LENGTH);
|
||||
}
|
||||
|
||||
private Comparator<SyndEntry> getEntryComparator() {
|
||||
|
||||
@@ -82,9 +82,9 @@ class ForumManagerImpl extends BdfIncomingMessageHook implements ForumManager {
|
||||
messageTracker.trackIncomingMessage(txn, m);
|
||||
|
||||
ForumPostHeader header = getForumPostHeader(txn, m.getId(), meta);
|
||||
String postBody = getPostBody(body);
|
||||
String text = getPostText(body);
|
||||
ForumPostReceivedEvent event =
|
||||
new ForumPostReceivedEvent(m.getGroupId(), header, postBody);
|
||||
new ForumPostReceivedEvent(m.getGroupId(), header, text);
|
||||
txn.attach(event);
|
||||
|
||||
// share message
|
||||
@@ -113,12 +113,12 @@ class ForumManagerImpl extends BdfIncomingMessageHook implements ForumManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ForumPost createLocalPost(GroupId groupId, String body,
|
||||
public ForumPost createLocalPost(GroupId groupId, String text,
|
||||
long timestamp, @Nullable MessageId parentId, LocalAuthor author) {
|
||||
ForumPost p;
|
||||
try {
|
||||
p = forumPostFactory.createPost(groupId, timestamp, parentId,
|
||||
author, body);
|
||||
author, text);
|
||||
} catch (GeneralSecurityException | FormatException e) {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
@@ -175,16 +175,16 @@ class ForumManagerImpl extends BdfIncomingMessageHook implements ForumManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPostBody(MessageId m) throws DbException {
|
||||
public String getPostText(MessageId m) throws DbException {
|
||||
try {
|
||||
return getPostBody(clientHelper.getMessageAsList(m));
|
||||
return getPostText(clientHelper.getMessageAsList(m));
|
||||
} catch (FormatException e) {
|
||||
throw new DbException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private String getPostBody(BdfList body) throws FormatException {
|
||||
// Parent ID, author, forum post body, signature
|
||||
private String getPostText(BdfList body) throws FormatException {
|
||||
// Parent ID, author, text, signature
|
||||
return body.getString(2);
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,6 @@ import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.sync.GroupId;
|
||||
import org.briarproject.bramble.api.sync.Message;
|
||||
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.ForumPostFactory;
|
||||
|
||||
@@ -18,7 +17,8 @@ import javax.annotation.Nullable;
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
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
|
||||
@NotNullByDefault
|
||||
@@ -33,20 +33,20 @@ class ForumPostFactoryImpl implements ForumPostFactory {
|
||||
|
||||
@Override
|
||||
public ForumPost createPost(GroupId groupId, long timestamp,
|
||||
@Nullable MessageId parent, LocalAuthor author, String body)
|
||||
@Nullable MessageId parent, LocalAuthor author, String text)
|
||||
throws FormatException, GeneralSecurityException {
|
||||
// Validate the arguments
|
||||
if (StringUtils.utf8IsTooLong(body, MAX_FORUM_POST_BODY_LENGTH))
|
||||
if (utf8IsTooLong(text, MAX_FORUM_POST_TEXT_LENGTH))
|
||||
throw new IllegalArgumentException();
|
||||
// Serialise the data to be signed
|
||||
BdfList authorList = clientHelper.toList(author);
|
||||
BdfList signed = BdfList.of(groupId, timestamp, parent, authorList,
|
||||
body);
|
||||
text);
|
||||
// Sign the data
|
||||
byte[] sig = clientHelper.sign(SIGNING_LABEL_POST, signed,
|
||||
author.getPrivateKey());
|
||||
// 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);
|
||||
return new ForumPost(m, parent, author);
|
||||
}
|
||||
|
||||
@@ -18,10 +18,11 @@ import org.briarproject.bramble.api.system.Clock;
|
||||
|
||||
import java.security.GeneralSecurityException;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
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.util.ValidationUtils.checkLength;
|
||||
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_READ;
|
||||
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;
|
||||
|
||||
@Immutable
|
||||
@@ -44,7 +45,7 @@ class ForumPostValidator extends BdfMessageValidator {
|
||||
@Override
|
||||
protected BdfMessageContext validateMessage(Message m, Group g,
|
||||
BdfList body) throws InvalidMessageException, FormatException {
|
||||
// Parent ID, author, content type, forum post body, signature
|
||||
// Parent ID, author, text, signature
|
||||
checkSize(body, 4);
|
||||
|
||||
// Parent ID is optional
|
||||
@@ -55,16 +56,17 @@ class ForumPostValidator extends BdfMessageValidator {
|
||||
BdfList authorList = body.getList(1);
|
||||
Author author = clientHelper.parseAndValidateAuthor(authorList);
|
||||
|
||||
// Forum post body
|
||||
String content = body.getString(2);
|
||||
checkLength(content, 0, MAX_FORUM_POST_BODY_LENGTH);
|
||||
// Text
|
||||
String text = body.getString(2);
|
||||
checkLength(text, 0, MAX_FORUM_POST_TEXT_LENGTH);
|
||||
|
||||
// Signature
|
||||
byte[] sig = body.getRaw(3);
|
||||
checkLength(sig, 1, MAX_SIGNATURE_LENGTH);
|
||||
|
||||
// Verify the signature
|
||||
BdfList signed = BdfList.of(g.getId(), m.getTimestamp(), parent,
|
||||
authorList, content);
|
||||
authorList, text);
|
||||
try {
|
||||
clientHelper.verifySignature(sig, SIGNING_LABEL_POST,
|
||||
signed, author.getPublicKey());
|
||||
@@ -74,11 +76,11 @@ class ForumPostValidator extends BdfMessageValidator {
|
||||
|
||||
// Return the metadata and dependencies
|
||||
BdfDictionary meta = new BdfDictionary();
|
||||
Collection<MessageId> dependencies = Collections.emptyList();
|
||||
Collection<MessageId> dependencies = emptyList();
|
||||
meta.put(KEY_TIMESTAMP, m.getTimestamp());
|
||||
if (parent != null) {
|
||||
meta.put(KEY_PARENT, parent);
|
||||
dependencies = Collections.singletonList(new MessageId(parent));
|
||||
dependencies = singletonList(new MessageId(parent));
|
||||
}
|
||||
meta.put(KEY_AUTHOR, authorList);
|
||||
meta.put(KEY_READ, false);
|
||||
|
||||
@@ -72,11 +72,11 @@ abstract class AbstractProtocolEngine<S extends Session>
|
||||
}
|
||||
|
||||
Message sendRequestMessage(Transaction txn, PeerSession s,
|
||||
long timestamp, Author author, @Nullable String message)
|
||||
long timestamp, Author author, @Nullable String text)
|
||||
throws DbException {
|
||||
Message m = messageEncoder
|
||||
.encodeRequestMessage(s.getContactGroupId(), timestamp,
|
||||
s.getLastLocalMessageId(), author, message);
|
||||
s.getLastLocalMessageId(), author, text);
|
||||
sendMessage(txn, REQUEST, s.getSessionId(), m, true);
|
||||
return m;
|
||||
}
|
||||
|
||||
@@ -85,8 +85,7 @@ class IntroduceeProtocolEngine
|
||||
|
||||
@Override
|
||||
public IntroduceeSession onRequestAction(Transaction txn,
|
||||
IntroduceeSession session, @Nullable String message,
|
||||
long timestamp) {
|
||||
IntroduceeSession session, @Nullable String text, long timestamp) {
|
||||
throw new UnsupportedOperationException(); // Invalid in this role
|
||||
}
|
||||
|
||||
@@ -256,7 +255,7 @@ class IntroduceeProtocolEngine
|
||||
.contactExists(txn, m.getAuthor().getId(), localAuthor.getId());
|
||||
IntroductionRequest request = new IntroductionRequest(m.getMessageId(),
|
||||
m.getGroupId(), m.getTimestamp(), false, false, false, false,
|
||||
s.getSessionId(), m.getAuthor(), m.getMessage(), false,
|
||||
s.getSessionId(), m.getAuthor(), m.getText(), false,
|
||||
contactExists);
|
||||
IntroductionRequestReceivedEvent e =
|
||||
new IntroductionRequestReceivedEvent(request, c.getId());
|
||||
|
||||
@@ -58,11 +58,11 @@ class IntroducerProtocolEngine
|
||||
|
||||
@Override
|
||||
public IntroducerSession onRequestAction(Transaction txn,
|
||||
IntroducerSession s, @Nullable String message, long timestamp)
|
||||
IntroducerSession s, @Nullable String text, long timestamp)
|
||||
throws DbException {
|
||||
switch (s.getState()) {
|
||||
case START:
|
||||
return onLocalRequest(txn, s, message, timestamp);
|
||||
return onLocalRequest(txn, s, text, timestamp);
|
||||
case AWAIT_RESPONSES:
|
||||
case AWAIT_RESPONSE_A:
|
||||
case AWAIT_RESPONSE_B:
|
||||
@@ -222,7 +222,7 @@ class IntroducerProtocolEngine
|
||||
}
|
||||
|
||||
private IntroducerSession onLocalRequest(Transaction txn,
|
||||
IntroducerSession s, @Nullable String message, long timestamp)
|
||||
IntroducerSession s, @Nullable String text, long timestamp)
|
||||
throws DbException {
|
||||
// Send REQUEST messages
|
||||
long maxIntroduceeTimestamp =
|
||||
@@ -230,11 +230,9 @@ class IntroducerProtocolEngine
|
||||
getLocalTimestamp(s, s.getIntroduceeB()));
|
||||
long localTimestamp = Math.max(timestamp, maxIntroduceeTimestamp);
|
||||
Message sentA = sendRequestMessage(txn, s.getIntroduceeA(),
|
||||
localTimestamp, s.getIntroduceeB().author, message
|
||||
);
|
||||
localTimestamp, s.getIntroduceeB().author, text);
|
||||
Message sentB = sendRequestMessage(txn, s.getIntroduceeB(),
|
||||
localTimestamp, s.getIntroduceeA().author, message
|
||||
);
|
||||
localTimestamp, s.getIntroduceeA().author, text);
|
||||
// Track the messages
|
||||
messageTracker.trackOutgoingMessage(txn, sentA);
|
||||
messageTracker.trackOutgoingMessage(txn, sentB);
|
||||
|
||||
@@ -316,7 +316,7 @@ class IntroductionManagerImpl extends ConversationClientImpl
|
||||
}
|
||||
|
||||
@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 {
|
||||
Transaction txn = db.startTransaction(false);
|
||||
try {
|
||||
@@ -350,7 +350,7 @@ class IntroductionManagerImpl extends ConversationClientImpl
|
||||
}
|
||||
// Handle the request action
|
||||
session = introducerEngine
|
||||
.onRequestAction(txn, session, msg, timestamp);
|
||||
.onRequestAction(txn, session, text, timestamp);
|
||||
// Store the updated session
|
||||
storeSession(txn, storageId, session);
|
||||
db.commitTransaction(txn);
|
||||
@@ -461,14 +461,14 @@ class IntroductionManagerImpl extends ConversationClientImpl
|
||||
Message msg = clientHelper.getMessage(txn, m);
|
||||
BdfList body = clientHelper.toList(msg);
|
||||
RequestMessage rm = messageParser.parseRequestMessage(msg, body);
|
||||
String message = rm.getMessage();
|
||||
String text = rm.getText();
|
||||
LocalAuthor localAuthor = identityManager.getLocalAuthor(txn);
|
||||
boolean contactExists = contactManager
|
||||
.contactExists(txn, rm.getAuthor().getId(),
|
||||
localAuthor.getId());
|
||||
return new IntroductionRequest(m, contactGroupId, meta.getTimestamp(),
|
||||
meta.isLocal(), status.isSent(), status.isSeen(), meta.isRead(),
|
||||
sessionId, author, message, !meta.isAvailableToAnswer(),
|
||||
sessionId, author, text, !meta.isAvailableToAnswer(),
|
||||
contactExists);
|
||||
}
|
||||
|
||||
|
||||
@@ -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.util.ValidationUtils.checkLength;
|
||||
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.ACTIVATE;
|
||||
import static org.briarproject.briar.introduction.MessageType.AUTH;
|
||||
@@ -75,8 +75,8 @@ class IntroductionValidator extends BdfMessageValidator {
|
||||
BdfList authorList = body.getList(2);
|
||||
clientHelper.parseAndValidateAuthor(authorList);
|
||||
|
||||
String msg = body.getOptionalString(3);
|
||||
checkLength(msg, 1, MAX_REQUEST_MESSAGE_LENGTH);
|
||||
String text = body.getOptionalString(3);
|
||||
checkLength(text, 1, MAX_INTRODUCTION_TEXT_LENGTH);
|
||||
|
||||
BdfDictionary meta =
|
||||
messageEncoder.encodeRequestMetadata(m.getTimestamp());
|
||||
|
||||
@@ -31,7 +31,7 @@ interface MessageEncoder {
|
||||
|
||||
Message encodeRequestMessage(GroupId contactGroupId, long timestamp,
|
||||
@Nullable MessageId previousMessageId, Author author,
|
||||
@Nullable String message);
|
||||
@Nullable String text);
|
||||
|
||||
Message encodeAcceptMessage(GroupId contactGroupId, long timestamp,
|
||||
@Nullable MessageId previousMessageId, SessionId sessionId,
|
||||
|
||||
@@ -89,15 +89,15 @@ class MessageEncoderImpl implements MessageEncoder {
|
||||
@Override
|
||||
public Message encodeRequestMessage(GroupId contactGroupId, long timestamp,
|
||||
@Nullable MessageId previousMessageId, Author author,
|
||||
@Nullable String message) {
|
||||
if (message != null && message.equals("")) {
|
||||
@Nullable String text) {
|
||||
if (text != null && text.isEmpty()) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
BdfList body = BdfList.of(
|
||||
REQUEST.getValue(),
|
||||
previousMessageId,
|
||||
clientHelper.toList(author),
|
||||
message
|
||||
text
|
||||
);
|
||||
return createMessage(contactGroupId, timestamp, body);
|
||||
}
|
||||
|
||||
@@ -74,9 +74,9 @@ class MessageParserImpl implements MessageParser {
|
||||
MessageId previousMessageId = (previousMsgBytes == null ? null :
|
||||
new MessageId(previousMsgBytes));
|
||||
Author author = clientHelper.parseAndValidateAuthor(body.getList(2));
|
||||
String message = body.getOptionalString(3);
|
||||
String text = body.getOptionalString(3);
|
||||
return new RequestMessage(m.getId(), m.getGroupId(),
|
||||
m.getTimestamp(), previousMessageId, author, message);
|
||||
m.getTimestamp(), previousMessageId, author, text);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -10,7 +10,7 @@ import javax.annotation.Nullable;
|
||||
@NotNullByDefault
|
||||
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;
|
||||
|
||||
S onAcceptAction(Transaction txn, S session, long timestamp)
|
||||
|
||||
@@ -14,14 +14,14 @@ class RequestMessage extends AbstractIntroductionMessage {
|
||||
|
||||
private final Author author;
|
||||
@Nullable
|
||||
private final String message;
|
||||
private final String text;
|
||||
|
||||
protected RequestMessage(MessageId messageId, GroupId groupId,
|
||||
long timestamp, @Nullable MessageId previousMessageId,
|
||||
Author author, @Nullable String message) {
|
||||
RequestMessage(MessageId messageId, GroupId groupId, long timestamp,
|
||||
@Nullable MessageId previousMessageId, Author author,
|
||||
@Nullable String text) {
|
||||
super(messageId, groupId, timestamp, previousMessageId);
|
||||
this.author = author;
|
||||
this.message = message;
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
public Author getAuthor() {
|
||||
@@ -29,8 +29,8 @@ class RequestMessage extends AbstractIntroductionMessage {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getMessage() {
|
||||
return message;
|
||||
public String getText() {
|
||||
return text;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -209,9 +209,9 @@ class MessagingManagerImpl extends ConversationClientImpl
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMessageBody(MessageId m) throws DbException {
|
||||
public String getMessageText(MessageId m) throws DbException {
|
||||
try {
|
||||
// 0: private message body
|
||||
// 0: private message text
|
||||
return clientHelper.getMessageAsList(m).getString(0);
|
||||
} catch (FormatException e) {
|
||||
throw new DbException(e);
|
||||
|
||||
@@ -13,7 +13,7 @@ import javax.annotation.concurrent.Immutable;
|
||||
import javax.inject.Inject;
|
||||
|
||||
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
|
||||
@NotNullByDefault
|
||||
@@ -28,12 +28,12 @@ class PrivateMessageFactoryImpl implements PrivateMessageFactory {
|
||||
|
||||
@Override
|
||||
public PrivateMessage createPrivateMessage(GroupId groupId, long timestamp,
|
||||
String body) throws FormatException {
|
||||
String text) throws FormatException {
|
||||
// Validate the arguments
|
||||
if (utf8IsTooLong(body, MAX_PRIVATE_MESSAGE_BODY_LENGTH))
|
||||
if (utf8IsTooLong(text, MAX_PRIVATE_MESSAGE_TEXT_LENGTH))
|
||||
throw new IllegalArgumentException();
|
||||
// Serialise the message
|
||||
BdfList message = BdfList.of(body);
|
||||
BdfList message = BdfList.of(text);
|
||||
Message m = clientHelper.createMessage(groupId, timestamp, message);
|
||||
return new PrivateMessage(m);
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ import javax.annotation.concurrent.Immutable;
|
||||
|
||||
import static org.briarproject.bramble.util.ValidationUtils.checkLength;
|
||||
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;
|
||||
|
||||
@Immutable
|
||||
@@ -31,11 +31,10 @@ class PrivateMessageValidator extends BdfMessageValidator {
|
||||
@Override
|
||||
protected BdfMessageContext validateMessage(Message m, Group g,
|
||||
BdfList body) throws FormatException {
|
||||
// private message body
|
||||
// Private message text
|
||||
checkSize(body, 1);
|
||||
// Private message body
|
||||
String privateMessageBody = body.getString(0);
|
||||
checkLength(privateMessageBody, 0, MAX_PRIVATE_MESSAGE_BODY_LENGTH);
|
||||
String text = body.getString(0);
|
||||
checkLength(text, 0, MAX_PRIVATE_MESSAGE_TEXT_LENGTH);
|
||||
// Return the metadata
|
||||
BdfDictionary meta = new BdfDictionary();
|
||||
meta.put("timestamp", m.getTimestamp());
|
||||
|
||||
@@ -78,7 +78,7 @@ class GroupMessageFactoryImpl implements GroupMessageFactory {
|
||||
|
||||
@Override
|
||||
public GroupMessage createGroupMessage(GroupId groupId, long timestamp,
|
||||
@Nullable MessageId parentId, LocalAuthor member, String content,
|
||||
@Nullable MessageId parentId, LocalAuthor member, String text,
|
||||
MessageId previousMsgId) {
|
||||
try {
|
||||
// Generate the signature
|
||||
@@ -89,7 +89,7 @@ class GroupMessageFactoryImpl implements GroupMessageFactory {
|
||||
memberList,
|
||||
parentId,
|
||||
previousMsgId,
|
||||
content
|
||||
text
|
||||
);
|
||||
byte[] signature = clientHelper.sign(SIGNING_LABEL_POST, toSign,
|
||||
member.getPrivateKey());
|
||||
@@ -100,7 +100,7 @@ class GroupMessageFactoryImpl implements GroupMessageFactory {
|
||||
memberList,
|
||||
parentId,
|
||||
previousMsgId,
|
||||
content,
|
||||
text,
|
||||
signature
|
||||
);
|
||||
Message m = clientHelper.createMessage(groupId, timestamp, body);
|
||||
|
||||
@@ -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.MessageType.JOIN;
|
||||
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.privategroup.GroupConstants.KEY_INITIAL_JOIN_MSG;
|
||||
import static org.briarproject.briar.privategroup.GroupConstants.KEY_MEMBER;
|
||||
@@ -65,7 +65,7 @@ class GroupMessageValidator extends BdfMessageValidator {
|
||||
// Message type (int)
|
||||
int type = body.getLong(0).intValue();
|
||||
|
||||
// Member (list of int, string, raw)
|
||||
// Member (author)
|
||||
BdfList memberList = body.getList(1);
|
||||
Author member = clientHelper.parseAndValidateAuthor(memberList);
|
||||
|
||||
@@ -144,14 +144,14 @@ class GroupMessageValidator extends BdfMessageValidator {
|
||||
private BdfMessageContext validatePost(Message m, Group g, BdfList body,
|
||||
Author member) throws FormatException {
|
||||
// Message type, member, optional parent ID, previous message ID,
|
||||
// content, signature
|
||||
// text, signature
|
||||
checkSize(body, 6);
|
||||
byte[] parentId = body.getOptionalRaw(2);
|
||||
checkLength(parentId, MessageId.LENGTH);
|
||||
byte[] previousMessageId = body.getRaw(3);
|
||||
checkLength(previousMessageId, MessageId.LENGTH);
|
||||
String content = body.getString(4);
|
||||
checkLength(content, 1, MAX_GROUP_POST_BODY_LENGTH);
|
||||
String text = body.getString(4);
|
||||
checkLength(text, 1, MAX_GROUP_POST_TEXT_LENGTH);
|
||||
byte[] signature = body.getRaw(5);
|
||||
checkLength(signature, 1, MAX_SIGNATURE_LENGTH);
|
||||
|
||||
@@ -163,7 +163,7 @@ class GroupMessageValidator extends BdfMessageValidator {
|
||||
memberList,
|
||||
parentId,
|
||||
previousMessageId,
|
||||
content
|
||||
text
|
||||
);
|
||||
try {
|
||||
clientHelper.verifySignature(signature, SIGNING_LABEL_POST,
|
||||
|
||||
@@ -299,17 +299,17 @@ class PrivateGroupManagerImpl extends BdfIncomingMessageHook
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMessageBody(MessageId m) throws DbException {
|
||||
public String getMessageText(MessageId m) throws DbException {
|
||||
try {
|
||||
return getMessageBody(clientHelper.getMessageAsList(m));
|
||||
return getMessageText(clientHelper.getMessageAsList(m));
|
||||
} catch (FormatException 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),
|
||||
// content (4), signature (5)
|
||||
// text (4), signature (5)
|
||||
return body.getString(4);
|
||||
}
|
||||
|
||||
@@ -570,8 +570,8 @@ class PrivateGroupManagerImpl extends BdfIncomingMessageHook
|
||||
throws DbException, FormatException {
|
||||
GroupMessageHeader header = getGroupMessageHeader(txn, m.getGroupId(),
|
||||
m.getId(), meta, Collections.emptyMap());
|
||||
String body = getMessageBody(clientHelper.toList(m));
|
||||
txn.attach(new GroupMessageAddedEvent(m.getGroupId(), header, body,
|
||||
String text = getMessageText(clientHelper.toList(m));
|
||||
txn.attach(new GroupMessageAddedEvent(m.getGroupId(), header, text,
|
||||
local));
|
||||
}
|
||||
|
||||
|
||||
@@ -107,7 +107,7 @@ abstract class AbstractProtocolEngine<S extends Session>
|
||||
}
|
||||
|
||||
Message sendInviteMessage(Transaction txn, S session,
|
||||
@Nullable String message, long timestamp, byte[] signature)
|
||||
@Nullable String text, long timestamp, byte[] signature)
|
||||
throws DbException {
|
||||
Group g = db.getGroup(txn, session.getPrivateGroupId());
|
||||
PrivateGroup privateGroup;
|
||||
@@ -119,7 +119,7 @@ abstract class AbstractProtocolEngine<S extends Session>
|
||||
Message m = messageEncoder.encodeInviteMessage(
|
||||
session.getContactGroupId(), privateGroup.getId(),
|
||||
timestamp, privateGroup.getName(), privateGroup.getCreator(),
|
||||
privateGroup.getSalt(), message, signature);
|
||||
privateGroup.getSalt(), text, signature);
|
||||
sendMessage(txn, m, INVITE, privateGroup.getId(), true);
|
||||
return m;
|
||||
}
|
||||
|
||||
@@ -51,11 +51,11 @@ class CreatorProtocolEngine extends AbstractProtocolEngine<CreatorSession> {
|
||||
|
||||
@Override
|
||||
public CreatorSession onInviteAction(Transaction txn, CreatorSession s,
|
||||
@Nullable String message, long timestamp, byte[] signature)
|
||||
@Nullable String text, long timestamp, byte[] signature)
|
||||
throws DbException {
|
||||
switch (s.getState()) {
|
||||
case START:
|
||||
return onLocalInvite(txn, s, message, timestamp, signature);
|
||||
return onLocalInvite(txn, s, text, timestamp, signature);
|
||||
case INVITED:
|
||||
case JOINED:
|
||||
case LEFT:
|
||||
@@ -145,10 +145,10 @@ class CreatorProtocolEngine extends AbstractProtocolEngine<CreatorSession> {
|
||||
}
|
||||
|
||||
private CreatorSession onLocalInvite(Transaction txn, CreatorSession s,
|
||||
@Nullable String message, long timestamp, byte[] signature)
|
||||
@Nullable String text, long timestamp, byte[] signature)
|
||||
throws DbException {
|
||||
// Send an INVITE message
|
||||
Message sent = sendInviteMessage(txn, s, message, timestamp, signature);
|
||||
Message sent = sendInviteMessage(txn, s, text, timestamp, signature);
|
||||
// Track the message
|
||||
messageTracker.trackOutgoingMessage(txn, sent);
|
||||
// Move to the INVITED state
|
||||
|
||||
@@ -260,7 +260,7 @@ class GroupInvitationManagerImpl extends ConversationClientImpl
|
||||
|
||||
@Override
|
||||
public void sendInvitation(GroupId privateGroupId, ContactId c,
|
||||
@Nullable String message, long timestamp, byte[] signature)
|
||||
@Nullable String text, long timestamp, byte[] signature)
|
||||
throws DbException {
|
||||
SessionId sessionId = getSessionId(privateGroupId);
|
||||
Transaction txn = db.startTransaction(false);
|
||||
@@ -283,7 +283,7 @@ class GroupInvitationManagerImpl extends ConversationClientImpl
|
||||
storageId = ss.storageId;
|
||||
}
|
||||
// Handle the invite action
|
||||
session = creatorEngine.onInviteAction(txn, session, message,
|
||||
session = creatorEngine.onInviteAction(txn, session, text,
|
||||
timestamp, signature);
|
||||
// Store the updated session
|
||||
storeSession(txn, storageId, session);
|
||||
@@ -416,7 +416,7 @@ class GroupInvitationManagerImpl extends ConversationClientImpl
|
||||
return new GroupInvitationRequest(m, contactGroupId,
|
||||
meta.getTimestamp(), meta.isLocal(), status.isSent(),
|
||||
status.isSeen(), meta.isRead(), sessionId, pg,
|
||||
invite.getMessage(), meta.isAvailableToAnswer(), canBeOpened);
|
||||
invite.getText(), meta.isAvailableToAnswer(), canBeOpened);
|
||||
}
|
||||
|
||||
private GroupInvitationResponse parseInvitationResponse(
|
||||
|
||||
@@ -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.checkSize;
|
||||
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.invitation.GroupInvitationFactory.SIGNING_LABEL_INVITE;
|
||||
import static org.briarproject.briar.privategroup.invitation.MessageType.ABORT;
|
||||
@@ -71,15 +71,15 @@ class GroupInvitationValidator extends BdfMessageValidator {
|
||||
|
||||
private BdfMessageContext validateInviteMessage(Message m, BdfList body)
|
||||
throws FormatException {
|
||||
// Message type, creator, group name, salt, optional message, signature
|
||||
// Message type, creator, group name, salt, optional text, signature
|
||||
checkSize(body, 6);
|
||||
BdfList creatorList = body.getList(1);
|
||||
String groupName = body.getString(2);
|
||||
checkLength(groupName, 1, MAX_GROUP_NAME_LENGTH);
|
||||
byte[] salt = body.getRaw(3);
|
||||
checkLength(salt, GROUP_SALT_LENGTH);
|
||||
String message = body.getOptionalString(4);
|
||||
checkLength(message, 1, MAX_GROUP_INVITATION_MSG_LENGTH);
|
||||
String text = body.getOptionalString(4);
|
||||
checkLength(text, 1, MAX_GROUP_INVITATION_TEXT_LENGTH);
|
||||
byte[] signature = body.getRaw(5);
|
||||
checkLength(signature, 1, MAX_SIGNATURE_LENGTH);
|
||||
|
||||
|
||||
@@ -16,16 +16,16 @@ class InviteMessage extends GroupInvitationMessage {
|
||||
private final Author creator;
|
||||
private final byte[] salt, signature;
|
||||
@Nullable
|
||||
private final String message;
|
||||
private final String text;
|
||||
|
||||
InviteMessage(MessageId id, GroupId contactGroupId, GroupId privateGroupId,
|
||||
long timestamp, String groupName, Author creator, byte[] salt,
|
||||
@Nullable String message, byte[] signature) {
|
||||
@Nullable String text, byte[] signature) {
|
||||
super(id, contactGroupId, privateGroupId, timestamp);
|
||||
this.groupName = groupName;
|
||||
this.creator = creator;
|
||||
this.salt = salt;
|
||||
this.message = message;
|
||||
this.text = text;
|
||||
this.signature = signature;
|
||||
}
|
||||
|
||||
@@ -42,8 +42,8 @@ class InviteMessage extends GroupInvitationMessage {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
String getMessage() {
|
||||
return message;
|
||||
String getText() {
|
||||
return text;
|
||||
}
|
||||
|
||||
byte[] getSignature() {
|
||||
|
||||
@@ -56,7 +56,7 @@ class InviteeProtocolEngine extends AbstractProtocolEngine<InviteeSession> {
|
||||
|
||||
@Override
|
||||
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
|
||||
}
|
||||
|
||||
@@ -330,7 +330,7 @@ class InviteeProtocolEngine extends AbstractProtocolEngine<InviteeSession> {
|
||||
SessionId sessionId = new SessionId(m.getPrivateGroupId().getBytes());
|
||||
return new GroupInvitationRequest(m.getId(), m.getContactGroupId(),
|
||||
m.getTimestamp(), false, false, true, false, sessionId, pg,
|
||||
m.getMessage(), true, false);
|
||||
m.getText(), true, false);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ interface MessageEncoder {
|
||||
|
||||
Message encodeInviteMessage(GroupId contactGroupId, GroupId privateGroupId,
|
||||
long timestamp, String groupName, Author creator, byte[] salt,
|
||||
@Nullable String message, byte[] signature);
|
||||
@Nullable String text, byte[] signature);
|
||||
|
||||
Message encodeJoinMessage(GroupId contactGroupId, GroupId privateGroupId,
|
||||
long timestamp, @Nullable MessageId previousMessageId);
|
||||
|
||||
@@ -76,7 +76,7 @@ class MessageEncoderImpl implements MessageEncoder {
|
||||
@Override
|
||||
public Message encodeInviteMessage(GroupId contactGroupId,
|
||||
GroupId privateGroupId, long timestamp, String groupName,
|
||||
Author creator, byte[] salt, @Nullable String message,
|
||||
Author creator, byte[] salt, @Nullable String text,
|
||||
byte[] signature) {
|
||||
BdfList creatorList = clientHelper.toList(creator);
|
||||
BdfList body = BdfList.of(
|
||||
@@ -84,7 +84,7 @@ class MessageEncoderImpl implements MessageEncoder {
|
||||
creatorList,
|
||||
groupName,
|
||||
salt,
|
||||
message,
|
||||
text,
|
||||
signature
|
||||
);
|
||||
try {
|
||||
|
||||
@@ -98,11 +98,11 @@ class MessageParserImpl implements MessageParser {
|
||||
@Override
|
||||
public InviteMessage parseInviteMessage(Message m, BdfList body)
|
||||
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);
|
||||
String groupName = body.getString(2);
|
||||
byte[] salt = body.getRaw(3);
|
||||
String message = body.getOptionalString(4);
|
||||
String text = body.getOptionalString(4);
|
||||
byte[] signature = body.getRaw(5);
|
||||
|
||||
// Format version, name, public key
|
||||
@@ -117,7 +117,7 @@ class MessageParserImpl implements MessageParser {
|
||||
groupName, creator, salt);
|
||||
return new InviteMessage(m.getId(), m.getGroupId(),
|
||||
privateGroup.getId(), m.getTimestamp(), groupName, creator,
|
||||
salt, message, signature);
|
||||
salt, text, signature);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -51,8 +51,7 @@ class PeerProtocolEngine extends AbstractProtocolEngine<PeerSession> {
|
||||
|
||||
@Override
|
||||
public PeerSession onInviteAction(Transaction txn, PeerSession s,
|
||||
@Nullable String message, long timestamp, byte[] signature)
|
||||
throws DbException {
|
||||
@Nullable String text, long timestamp, byte[] signature) {
|
||||
throw new UnsupportedOperationException(); // Invalid in this role
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ import javax.annotation.Nullable;
|
||||
@NotNullByDefault
|
||||
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;
|
||||
|
||||
S onJoinAction(Transaction txn, S session) throws DbException;
|
||||
|
||||
@@ -24,7 +24,7 @@ public class BlogInvitationFactoryImpl
|
||||
SessionId sessionId = new SessionId(m.getShareableId().getBytes());
|
||||
return new BlogInvitationRequest(m.getId(), m.getContactGroupId(),
|
||||
m.getTimestamp(), local, sent, seen, read, sessionId,
|
||||
m.getShareable(), m.getMessage(), available, canBeOpened);
|
||||
m.getShareable(), m.getText(), available, canBeOpened);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user