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 ...@@ -51,7 +51,7 @@ abstract class BaseControllerImpl extends DbControllerImpl
protected final IdentityManager identityManager; protected final IdentityManager identityManager;
protected final BlogManager blogManager; protected final BlogManager blogManager;
private final Map<MessageId, String> bodyCache = new ConcurrentHashMap<>(); private final Map<MessageId, String> textCache = new ConcurrentHashMap<>();
private final Map<MessageId, BlogPostHeader> headerCache = private final Map<MessageId, BlogPostHeader> headerCache =
new ConcurrentHashMap<>(); new ConcurrentHashMap<>();
...@@ -129,17 +129,17 @@ abstract class BaseControllerImpl extends DbControllerImpl ...@@ -129,17 +129,17 @@ abstract class BaseControllerImpl extends DbControllerImpl
public void loadBlogPost(BlogPostHeader header, public void loadBlogPost(BlogPostHeader header,
ResultExceptionHandler<BlogPostItem, DbException> handler) { ResultExceptionHandler<BlogPostItem, DbException> handler) {
String body = bodyCache.get(header.getId()); String text = textCache.get(header.getId());
if (body != null) { if (text != null) {
LOG.info("Loaded body from cache"); LOG.info("Loaded text from cache");
handler.onResult(new BlogPostItem(header, body)); handler.onResult(new BlogPostItem(header, text));
return; return;
} }
runOnDbThread(() -> { runOnDbThread(() -> {
try { try {
long start = now(); long start = now();
BlogPostItem item = getItem(header); BlogPostItem item = getItem(header);
logDuration(LOG, "Loading body", start); logDuration(LOG, "Loading text", start);
handler.onResult(item); handler.onResult(item);
} catch (DbException e) { } catch (DbException e) {
logException(LOG, WARNING, e); logException(LOG, WARNING, e);
...@@ -200,28 +200,28 @@ abstract class BaseControllerImpl extends DbControllerImpl ...@@ -200,28 +200,28 @@ abstract class BaseControllerImpl extends DbControllerImpl
@DatabaseExecutor @DatabaseExecutor
private BlogPostItem getItem(BlogPostHeader h) throws DbException { private BlogPostItem getItem(BlogPostHeader h) throws DbException {
String body; String text;
if (h instanceof BlogCommentHeader) { if (h instanceof BlogCommentHeader) {
BlogCommentHeader c = (BlogCommentHeader) h; BlogCommentHeader c = (BlogCommentHeader) h;
BlogCommentItem item = new BlogCommentItem(c); BlogCommentItem item = new BlogCommentItem(c);
body = getPostBody(item.getPostHeader().getId()); text = getPostText(item.getPostHeader().getId());
item.setBody(body); item.setText(text);
return item; return item;
} else { } else {
body = getPostBody(h.getId()); text = getPostText(h.getId());
return new BlogPostItem(h, body); return new BlogPostItem(h, text);
} }
} }
@DatabaseExecutor @DatabaseExecutor
private String getPostBody(MessageId m) throws DbException { private String getPostText(MessageId m) throws DbException {
String body = bodyCache.get(m); String text = textCache.get(m);
if (body == null) { if (text == null) {
body = HtmlUtils.clean(blogManager.getPostBody(m), ARTICLE); text = HtmlUtils.clean(blogManager.getPostText(m), ARTICLE);
bodyCache.put(m, body); textCache.put(m, text);
} }
//noinspection ConstantConditions //noinspection ConstantConditions
return body; return text;
} }
} }
...@@ -34,8 +34,8 @@ class BlogCommentItem extends BlogPostItem { ...@@ -34,8 +34,8 @@ class BlogCommentItem extends BlogPostItem {
} }
} }
public void setBody(String body) { public void setText(String text) {
this.body = body; this.text = text;
} }
@Override @Override
......
...@@ -15,12 +15,12 @@ import javax.annotation.concurrent.NotThreadSafe; ...@@ -15,12 +15,12 @@ import javax.annotation.concurrent.NotThreadSafe;
public class BlogPostItem implements Comparable<BlogPostItem> { public class BlogPostItem implements Comparable<BlogPostItem> {
private final BlogPostHeader header; private final BlogPostHeader header;
protected String body; protected String text;
private boolean read; private boolean read;
BlogPostItem(BlogPostHeader header, @Nullable String body) { BlogPostItem(BlogPostHeader header, @Nullable String text) {
this.header = header; this.header = header;
this.body = body; this.text = text;
this.read = header.isRead(); this.read = header.isRead();
} }
...@@ -44,8 +44,8 @@ public class BlogPostItem implements Comparable<BlogPostItem> { ...@@ -44,8 +44,8 @@ public class BlogPostItem implements Comparable<BlogPostItem> {
return header.getAuthorStatus(); return header.getAuthorStatus();
} }
public String getBody() { public String getText() {
return body; return text;
} }
public boolean isRssFeed() { public boolean isRssFeed() {
......
...@@ -41,7 +41,7 @@ class BlogPostViewHolder extends RecyclerView.ViewHolder { ...@@ -41,7 +41,7 @@ class BlogPostViewHolder extends RecyclerView.ViewHolder {
private final AuthorView reblogger; private final AuthorView reblogger;
private final AuthorView author; private final AuthorView author;
private final ImageButton reblogButton; private final ImageButton reblogButton;
private final TextView body; private final TextView text;
private final ViewGroup commentContainer; private final ViewGroup commentContainer;
private final boolean fullText; private final boolean fullText;
...@@ -63,7 +63,7 @@ class BlogPostViewHolder extends RecyclerView.ViewHolder { ...@@ -63,7 +63,7 @@ class BlogPostViewHolder extends RecyclerView.ViewHolder {
reblogger = v.findViewById(R.id.rebloggerView); reblogger = v.findViewById(R.id.rebloggerView);
author = v.findViewById(R.id.authorView); author = v.findViewById(R.id.authorView);
reblogButton = v.findViewById(R.id.commentView); reblogButton = v.findViewById(R.id.commentView);
body = v.findViewById(R.id.bodyView); text = v.findViewById(R.id.textView);
commentContainer = v.findViewById(R.id.commentContainer); commentContainer = v.findViewById(R.id.commentContainer);
} }
...@@ -111,17 +111,17 @@ class BlogPostViewHolder extends RecyclerView.ViewHolder { ...@@ -111,17 +111,17 @@ class BlogPostViewHolder extends RecyclerView.ViewHolder {
author.setAuthorNotClickable(); author.setAuthorNotClickable();
} }
// post body // post text
Spanned bodyText = getSpanned(item.getBody()); Spanned postText = getSpanned(item.getText());
if (fullText) { if (fullText) {
body.setText(bodyText); text.setText(postText);
body.setTextIsSelectable(true); text.setTextIsSelectable(true);
makeLinksClickable(body, fragmentManager); makeLinksClickable(text, fragmentManager);
} else { } else {
body.setTextIsSelectable(false); text.setTextIsSelectable(false);
if (bodyText.length() > TEASER_LENGTH) if (postText.length() > TEASER_LENGTH)
bodyText = getTeaser(ctx, bodyText); postText = getTeaser(ctx, postText);
body.setText(bodyText); text.setText(postText);
} }
// reblog button // reblog button
...@@ -163,15 +163,15 @@ class BlogPostViewHolder extends RecyclerView.ViewHolder { ...@@ -163,15 +163,15 @@ class BlogPostViewHolder extends RecyclerView.ViewHolder {
commentContainer, false); commentContainer, false);
AuthorView author = v.findViewById(R.id.authorView); AuthorView author = v.findViewById(R.id.authorView);
TextView body = v.findViewById(R.id.bodyView); TextView text = v.findViewById(R.id.textView);
author.setAuthor(c.getAuthor()); author.setAuthor(c.getAuthor());
author.setAuthorStatus(c.getAuthorStatus()); author.setAuthorStatus(c.getAuthorStatus());
author.setDate(c.getTimestamp()); author.setDate(c.getTimestamp());
// TODO make author clickable #624 // TODO make author clickable #624
body.setText(c.getComment()); text.setText(c.getComment());
if (fullText) body.setTextIsSelectable(true); if (fullText) text.setTextIsSelectable(true);
commentContainer.addView(v); commentContainer.addView(v);
} }
......
...@@ -35,7 +35,7 @@ import static android.view.View.GONE; ...@@ -35,7 +35,7 @@ import static android.view.View.GONE;
import static android.view.View.VISIBLE; import static android.view.View.VISIBLE;
import static java.util.logging.Level.WARNING; import static java.util.logging.Level.WARNING;
import static org.briarproject.bramble.util.LogUtils.logException; import static org.briarproject.bramble.util.LogUtils.logException;
import static org.briarproject.briar.api.blog.BlogConstants.MAX_BLOG_POST_BODY_LENGTH; import static org.briarproject.briar.api.blog.BlogConstants.MAX_BLOG_POST_TEXT_LENGTH;
public class WriteBlogPostActivity extends BriarActivity public class WriteBlogPostActivity extends BriarActivity
implements OnEditorActionListener, TextInputListener { implements OnEditorActionListener, TextInputListener {
...@@ -70,7 +70,7 @@ public class WriteBlogPostActivity extends BriarActivity ...@@ -70,7 +70,7 @@ public class WriteBlogPostActivity extends BriarActivity
setContentView(R.layout.activity_write_blog_post); setContentView(R.layout.activity_write_blog_post);
input = findViewById(R.id.bodyInput); input = findViewById(R.id.textInput);
input.setSendButtonEnabled(false); input.setSendButtonEnabled(false);
input.addTextChangedListener(new TextWatcher() { input.addTextChangedListener(new TextWatcher() {
@Override @Override
...@@ -132,23 +132,23 @@ public class WriteBlogPostActivity extends BriarActivity ...@@ -132,23 +132,23 @@ public class WriteBlogPostActivity extends BriarActivity
} }
@Override @Override
public void onSendClick(String body) { public void onSendClick(String text) {
// hide publish button, show progress bar // hide publish button, show progress bar
input.hideSoftKeyboard(); input.hideSoftKeyboard();
input.setVisibility(GONE); input.setVisibility(GONE);
progressBar.setVisibility(VISIBLE); progressBar.setVisibility(VISIBLE);
body = StringUtils.truncateUtf8(body, MAX_BLOG_POST_BODY_LENGTH); text = StringUtils.truncateUtf8(text, MAX_BLOG_POST_TEXT_LENGTH);
storePost(body); storePost(text);
} }
private void storePost(String body) { private void storePost(String text) {
runOnDbThread(() -> { runOnDbThread(() -> {
long timestamp = System.currentTimeMillis(); long timestamp = System.currentTimeMillis();
try { try {
LocalAuthor author = identityManager.getLocalAuthor(); LocalAuthor author = identityManager.getLocalAuthor();
BlogPost p = blogPostFactory BlogPost p = blogPostFactory
.createBlogPost(groupId, timestamp, null, author, body); .createBlogPost(groupId, timestamp, null, author, text);
blogManager.addLocalPost(p); blogManager.addLocalPost(p);
postPublished(); postPublished();
} catch (DbException | GeneralSecurityException } catch (DbException | GeneralSecurityException
......
...@@ -53,7 +53,7 @@ import org.briarproject.briar.android.activity.ActivityComponent; ...@@ -53,7 +53,7 @@ import org.briarproject.briar.android.activity.ActivityComponent;
import org.briarproject.briar.android.activity.BriarActivity; import org.briarproject.briar.android.activity.BriarActivity;
import org.briarproject.briar.android.blog.BlogActivity; import org.briarproject.briar.android.blog.BlogActivity;
import org.briarproject.briar.android.contact.ConversationAdapter.ConversationListener; import org.briarproject.briar.android.contact.ConversationAdapter.ConversationListener;
import org.briarproject.briar.android.contact.ConversationVisitor.BodyCache; import org.briarproject.briar.android.contact.ConversationVisitor.TextCache;
import org.briarproject.briar.android.forum.ForumActivity; import org.briarproject.briar.android.forum.ForumActivity;
import org.briarproject.briar.android.introduction.IntroductionActivity; import org.briarproject.briar.android.introduction.IntroductionActivity;
import org.briarproject.briar.android.privategroup.conversation.GroupActivity; import org.briarproject.briar.android.privategroup.conversation.GroupActivity;
...@@ -105,7 +105,7 @@ import static org.briarproject.briar.android.activity.RequestCodes.REQUEST_INTRO ...@@ -105,7 +105,7 @@ import static org.briarproject.briar.android.activity.RequestCodes.REQUEST_INTRO
import static org.briarproject.briar.android.settings.SettingsFragment.SETTINGS_NAMESPACE; import static org.briarproject.briar.android.settings.SettingsFragment.SETTINGS_NAMESPACE;
import static org.briarproject.briar.android.util.UiUtils.getAvatarTransitionName; import static org.briarproject.briar.android.util.UiUtils.getAvatarTransitionName;
import static org.briarproject.briar.android.util.UiUtils.getBulbTransitionName; import static org.briarproject.briar.android.util.UiUtils.getBulbTransitionName;
import static org.briarproject.briar.api.messaging.MessagingConstants.MAX_PRIVATE_MESSAGE_BODY_LENGTH; import static org.briarproject.briar.api.messaging.MessagingConstants.MAX_PRIVATE_MESSAGE_TEXT_LENGTH;
import static uk.co.samuelwall.materialtaptargetprompt.MaterialTapTargetPrompt.STATE_DISMISSED; import static uk.co.samuelwall.materialtaptargetprompt.MaterialTapTargetPrompt.STATE_DISMISSED;
import static uk.co.samuelwall.materialtaptargetprompt.MaterialTapTargetPrompt.STATE_FINISHED; import static uk.co.samuelwall.materialtaptargetprompt.MaterialTapTargetPrompt.STATE_FINISHED;
...@@ -113,7 +113,7 @@ import static uk.co.samuelwall.materialtaptargetprompt.MaterialTapTargetPrompt.S ...@@ -113,7 +113,7 @@ import static uk.co.samuelwall.materialtaptargetprompt.MaterialTapTargetPrompt.S
@ParametersNotNullByDefault @ParametersNotNullByDefault
public class ConversationActivity extends BriarActivity public class ConversationActivity extends BriarActivity
implements EventListener, ConversationListener, TextInputListener, implements EventListener, ConversationListener, TextInputListener,
BodyCache { TextCache {
public static final String CONTACT_ID = "briar.CONTACT_ID"; public static final String CONTACT_ID = "briar.CONTACT_ID";
...@@ -130,7 +130,7 @@ public class ConversationActivity extends BriarActivity ...@@ -130,7 +130,7 @@ public class ConversationActivity extends BriarActivity
@CryptoExecutor @CryptoExecutor
Executor cryptoExecutor; Executor cryptoExecutor;
private final Map<MessageId, String> bodyCache = new ConcurrentHashMap<>(); private final Map<MessageId, String> textCache = new ConcurrentHashMap<>();
private final MutableLiveData<String> contactName = new MutableLiveData<>(); private final MutableLiveData<String> contactName = new MutableLiveData<>();
private ConversationVisitor visitor; private ConversationVisitor visitor;
...@@ -370,28 +370,28 @@ public class ConversationActivity extends BriarActivity ...@@ -370,28 +370,28 @@ public class ConversationActivity extends BriarActivity
return items; return items;
} }
private void loadMessageBody(MessageId m) { private void loadMessageText(MessageId m) {
runOnDbThread(() -> { runOnDbThread(() -> {
try { try {
long start = now(); long start = now();
String body = messagingManager.getMessageBody(m); String text = messagingManager.getMessageText(m);
logDuration(LOG, "Loading body", start); logDuration(LOG, "Loading text", start);
displayMessageBody(m, body); displayMessageText(m, text);
} catch (DbException e) { } catch (DbException e) {
logException(LOG, WARNING, e); logException(LOG, WARNING, e);
} }
}); });
} }
private void displayMessageBody(MessageId m, String body) { private void displayMessageText(MessageId m, String text) {
runOnUiThreadUnlessDestroyed(() -> { runOnUiThreadUnlessDestroyed(() -> {
bodyCache.put(m, body); textCache.put(m, text);
SparseArray<ConversationItem> messages = SparseArray<ConversationItem> messages =
adapter.getPrivateMessages(); adapter.getPrivateMessages();
for (int i = 0; i < messages.size(); i++) { for (int i = 0; i < messages.size(); i++) {
ConversationItem item = messages.valueAt(i); ConversationItem item = messages.valueAt(i);
if (item.getId().equals(m)) { if (item.getId().equals(m)) {
item.setBody(body); item.setText(text);
adapter.notifyItemChanged(messages.keyAt(i)); adapter.notifyItemChanged(messages.keyAt(i));
list.scrollToPosition(adapter.getItemCount() - 1); list.scrollToPosition(adapter.getItemCount() - 1);
return; return;
...@@ -470,7 +470,7 @@ public class ConversationActivity extends BriarActivity ...@@ -470,7 +470,7 @@ public class ConversationActivity extends BriarActivity
} }
} else { } else {
addConversationItem(h.accept(visitor)); addConversationItem(h.accept(visitor));
loadMessageBody(h.getId()); loadMessageText(h.getId());
} }
}); });
} }
...@@ -495,8 +495,8 @@ public class ConversationActivity extends BriarActivity ...@@ -495,8 +495,8 @@ public class ConversationActivity extends BriarActivity
@Override @Override
public void onSendClick(String text) { public void onSendClick(String text) {
if (text.equals("")) return; if (text.isEmpty()) return;
text = StringUtils.truncateUtf8(text, MAX_PRIVATE_MESSAGE_BODY_LENGTH); text = StringUtils.truncateUtf8(text, MAX_PRIVATE_MESSAGE_TEXT_LENGTH);
long timestamp = System.currentTimeMillis(); long timestamp = System.currentTimeMillis();
timestamp = Math.max(timestamp, getMinTimestampForNewMessage()); timestamp = Math.max(timestamp, getMinTimestampForNewMessage());
if (messagingGroupId == null) loadGroupId(text, timestamp); if (messagingGroupId == null) loadGroupId(text, timestamp);
...@@ -510,12 +510,12 @@ public class ConversationActivity extends BriarActivity ...@@ -510,12 +510,12 @@ public class ConversationActivity extends BriarActivity
return item == null ? 0 : item.getTime() + 1; return item == null ? 0 : item.getTime() + 1;
} }
private void loadGroupId(String body, long timestamp) { private void loadGroupId(String text, long timestamp) {
runOnDbThread(() -> { runOnDbThread(() -> {
try { try {
messagingGroupId = messagingGroupId =
messagingManager.getConversationId(contactId); messagingManager.getConversationId(contactId);
createMessage(body, timestamp); createMessage(text, timestamp);
} catch (DbException e) { } catch (DbException e) {
logException(LOG, WARNING, e); logException(LOG, WARNING, e);
} }
...@@ -523,19 +523,19 @@ public class ConversationActivity extends BriarActivity ...@@ -523,19 +523,19 @@ public class ConversationActivity extends BriarActivity
}); });
} }
private void createMessage(String body, long timestamp) { private void createMessage(String text, long timestamp) {
cryptoExecutor.execute(() -> { cryptoExecutor.execute(() -> {
try { try {
//noinspection ConstantConditions init in loadGroupId() //noinspection ConstantConditions init in loadGroupId()
storeMessage(privateMessageFactory.createPrivateMessage( storeMessage(privateMessageFactory.createPrivateMessage(
messagingGroupId, timestamp, body), body); messagingGroupId, timestamp, text), text);
} catch (FormatException e) { } catch (FormatException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
}); });
} }
private void storeMessage(PrivateMessage m, String body) { private void storeMessage(PrivateMessage m, String text) {
runOnDbThread(() -> { runOnDbThread(() -> {
try { try {
long start = now(); long start = now();
...@@ -545,7 +545,7 @@ public class ConversationActivity extends BriarActivity ...@@ -545,7 +545,7 @@ public class ConversationActivity extends BriarActivity
PrivateMessageHeader h = new PrivateMessageHeader( PrivateMessageHeader h = new PrivateMessageHeader(
message.getId(), message.getGroupId(), message.getId(), message.getGroupId(),
message.getTimestamp(), true, false, false, false); message.getTimestamp(), true, false, false, false);
bodyCache.put(message.getId(), body); textCache.put(message.getId(), text);
addConversationItem(h.accept(visitor)); addConversationItem(h.accept(visitor));
} catch (DbException e) { } catch (DbException e) {
logException(LOG, WARNING, e); logException(LOG, WARNING, e);
...@@ -761,9 +761,9 @@ public class ConversationActivity extends BriarActivity ...@@ -761,9 +761,9 @@ public class ConversationActivity extends BriarActivity
@Nullable @Nullable
@Override @Override
public String getBody(MessageId m) { public String getText(MessageId m) {
String body = bodyCache.get(m); String text = textCache.get(m);
if (body == null) loadMessageBody(m); if (text == null) loadMessageText(m);
return body; return text;
} }
} }
...@@ -14,17 +14,17 @@ import javax.annotation.concurrent.NotThreadSafe; ...@@ -14,17 +14,17 @@ import javax.annotation.concurrent.NotThreadSafe;
abstract class ConversationItem { abstract class ConversationItem {
@Nullable @Nullable
protected String body; protected String text;
private final MessageId id; private final MessageId id;
private final GroupId groupId; private final GroupId groupId;
private final long time; private final long time;
private boolean read; private boolean read;
ConversationItem(MessageId id, GroupId groupId, @Nullable String body, ConversationItem(MessageId id, GroupId groupId, @Nullable String text,
long time, boolean read) { long time, boolean read) {
this.id = id; this.id = id;
this.groupId = groupId; this.groupId = groupId;
this.body = body; this.text = text;
this.time = time; this.time = time;
this.read = read; this.read = read;
} }
...@@ -37,13 +37,13 @@ abstract class ConversationItem { ...@@ -37,13 +37,13 @@ abstract class ConversationItem {
return groupId; return groupId;
} }
void setBody(String body) { void setText(String text) {
this.body = body; this.text = text;
} }
@Nullable @Nullable
public String getBody() { public String getText() {
return body; return text;
} }
long getTime() { long getTime() {
......
...@@ -29,10 +29,10 @@ class ConversationItemViewHolder extends ViewHolder { ...@@ -29,10 +29,10 @@ class ConversationItemViewHolder extends ViewHolder {
@CallSuper @CallSuper