Verified Commit 79d56126 authored by akwizgran's avatar akwizgran

Use "text" to refer to message text.

parent a030f922
......@@ -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);
});