mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-19 06:09:55 +01:00
Load forum post text lazily.
This commit is contained in:
@@ -54,7 +54,7 @@ public class ForumActivity extends
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ThreadItemAdapter<ForumPostItem> createAdapter() {
|
protected ThreadItemAdapter<ForumPostItem> createAdapter() {
|
||||||
return new ThreadItemAdapter<>(this);
|
return new ThreadItemAdapter<>(this, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -6,10 +6,10 @@ import org.briarproject.briar.api.forum.ForumPostHeader;
|
|||||||
import javax.annotation.concurrent.NotThreadSafe;
|
import javax.annotation.concurrent.NotThreadSafe;
|
||||||
|
|
||||||
@NotThreadSafe
|
@NotThreadSafe
|
||||||
class ForumPostItem extends ThreadItem {
|
public class ForumPostItem extends ThreadItem {
|
||||||
|
|
||||||
ForumPostItem(ForumPostHeader h, String text) {
|
ForumPostItem(ForumPostHeader h) {
|
||||||
super(h.getId(), h.getParentId(), text, h.getTimestamp(), h.getAuthor(),
|
super(h.getId(), h.getParentId(), null, h.getTimestamp(), h.getAuthor(),
|
||||||
h.getAuthorInfo(), h.isRead());
|
h.getAuthorInfo(), h.isRead());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -91,9 +91,7 @@ class ForumViewModel extends ThreadListViewModel<ForumPostItem> {
|
|||||||
ForumPostReceivedEvent f = (ForumPostReceivedEvent) e;
|
ForumPostReceivedEvent f = (ForumPostReceivedEvent) e;
|
||||||
if (f.getGroupId().equals(groupId)) {
|
if (f.getGroupId().equals(groupId)) {
|
||||||
LOG.info("Forum post received, adding...");
|
LOG.info("Forum post received, adding...");
|
||||||
ForumPostItem item =
|
addItem(new ForumPostItem(f.getHeader()), false);
|
||||||
new ForumPostItem(f.getHeader(), f.getText());
|
|
||||||
addItem(item, false);
|
|
||||||
}
|
}
|
||||||
} else if (e instanceof ForumInvitationResponseReceivedEvent) {
|
} else if (e instanceof ForumInvitationResponseReceivedEvent) {
|
||||||
ForumInvitationResponseReceivedEvent f =
|
ForumInvitationResponseReceivedEvent f =
|
||||||
@@ -139,22 +137,14 @@ class ForumViewModel extends ThreadListViewModel<ForumPostItem> {
|
|||||||
List<ForumPostHeader> headers =
|
List<ForumPostHeader> headers =
|
||||||
forumManager.getPostHeaders(txn, groupId);
|
forumManager.getPostHeaders(txn, groupId);
|
||||||
logDuration(LOG, "Loading headers", start);
|
logDuration(LOG, "Loading headers", start);
|
||||||
start = now();
|
|
||||||
List<ForumPostItem> items = new ArrayList<>();
|
List<ForumPostItem> items = new ArrayList<>();
|
||||||
for (ForumPostHeader header : headers) {
|
for (ForumPostHeader header : headers) {
|
||||||
items.add(loadItem(txn, header));
|
items.add(new ForumPostItem(header));
|
||||||
}
|
}
|
||||||
logDuration(LOG, "Loading bodies and creating items", start);
|
|
||||||
return items;
|
return items;
|
||||||
}, this::setItems);
|
}, this::setItems);
|
||||||
}
|
}
|
||||||
|
|
||||||
private ForumPostItem loadItem(Transaction txn, ForumPostHeader header)
|
|
||||||
throws DbException {
|
|
||||||
String text = forumManager.getPostText(txn, header.getId());
|
|
||||||
return new ForumPostItem(header, text);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void createAndStoreMessage(String text,
|
public void createAndStoreMessage(String text,
|
||||||
@Nullable MessageId parentId) {
|
@Nullable MessageId parentId) {
|
||||||
@@ -175,21 +165,17 @@ class ForumViewModel extends ThreadListViewModel<ForumPostItem> {
|
|||||||
@Nullable MessageId parentId, LocalAuthor author) {
|
@Nullable MessageId parentId, LocalAuthor author) {
|
||||||
cryptoExecutor.execute(() -> {
|
cryptoExecutor.execute(() -> {
|
||||||
LOG.info("Creating forum post...");
|
LOG.info("Creating forum post...");
|
||||||
ForumPost msg = forumManager.createLocalPost(groupId, text,
|
storePost(forumManager.createLocalPost(groupId, text,
|
||||||
timestamp, parentId, author);
|
timestamp, parentId, author));
|
||||||
storePost(msg, text);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void storePost(ForumPost msg, String text) {
|
private void storePost(ForumPost msg) {
|
||||||
runOnDbThread(false, txn -> {
|
runOnDbThread(false, txn -> {
|
||||||
long start = now();
|
long start = now();
|
||||||
ForumPostHeader header = forumManager.addLocalPost(txn, msg);
|
ForumPostHeader header = forumManager.addLocalPost(txn, msg);
|
||||||
logDuration(LOG, "Storing forum post", start);
|
logDuration(LOG, "Storing forum post", start);
|
||||||
txn.attach(() -> {
|
txn.attach(() -> addItem(new ForumPostItem(header), true));
|
||||||
ForumPostItem item = new ForumPostItem(header, text);
|
|
||||||
addItem(item, true);
|
|
||||||
});
|
|
||||||
}, this::handleException);
|
}, this::handleException);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -229,4 +215,9 @@ class ForumViewModel extends ThreadListViewModel<ForumPostItem> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String getMessageText(Transaction txn, MessageId m)
|
||||||
|
throws DbException {
|
||||||
|
return forumManager.getPostText(txn, m);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ import org.briarproject.briar.android.privategroup.memberlist.GroupMemberListAct
|
|||||||
import org.briarproject.briar.android.privategroup.reveal.RevealContactsActivity;
|
import org.briarproject.briar.android.privategroup.reveal.RevealContactsActivity;
|
||||||
import org.briarproject.briar.android.threaded.ThreadListActivity;
|
import org.briarproject.briar.android.threaded.ThreadListActivity;
|
||||||
import org.briarproject.briar.android.threaded.ThreadListViewModel;
|
import org.briarproject.briar.android.threaded.ThreadListViewModel;
|
||||||
import org.briarproject.briar.android.widget.LinkDialogFragment;
|
|
||||||
import org.briarproject.nullsafety.MethodsNotNullByDefault;
|
import org.briarproject.nullsafety.MethodsNotNullByDefault;
|
||||||
import org.briarproject.nullsafety.ParametersNotNullByDefault;
|
import org.briarproject.nullsafety.ParametersNotNullByDefault;
|
||||||
|
|
||||||
@@ -56,7 +55,7 @@ public class GroupActivity extends
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected GroupMessageAdapter createAdapter() {
|
protected GroupMessageAdapter createAdapter() {
|
||||||
return new GroupMessageAdapter(this);
|
return new GroupMessageAdapter(this, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -160,12 +159,6 @@ public class GroupActivity extends
|
|||||||
if (isDissolved != null && !isDissolved) super.onReplyClick(item);
|
if (isDissolved != null && !isDissolved) super.onReplyClick(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onLinkClick(String url){
|
|
||||||
LinkDialogFragment f = LinkDialogFragment.newInstance(url);
|
|
||||||
f.show(getSupportFragmentManager(), f.getUniqueTag());
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setGroupEnabled(boolean enabled) {
|
private void setGroupEnabled(boolean enabled) {
|
||||||
sendController.setReady(enabled);
|
sendController.setReady(enabled);
|
||||||
list.getRecyclerView().setAlpha(enabled ? 1f : 0.5f);
|
list.getRecyclerView().setAlpha(enabled ? 1f : 0.5f);
|
||||||
|
|||||||
@@ -11,16 +11,19 @@ import org.briarproject.briar.android.threaded.ThreadPostViewHolder;
|
|||||||
import org.briarproject.nullsafety.NotNullByDefault;
|
import org.briarproject.nullsafety.NotNullByDefault;
|
||||||
|
|
||||||
import androidx.annotation.LayoutRes;
|
import androidx.annotation.LayoutRes;
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.UiThread;
|
import androidx.annotation.UiThread;
|
||||||
|
import androidx.lifecycle.LifecycleOwner;
|
||||||
|
|
||||||
@UiThread
|
@UiThread
|
||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
class GroupMessageAdapter extends ThreadItemAdapter<GroupMessageItem> {
|
public class GroupMessageAdapter extends ThreadItemAdapter<GroupMessageItem> {
|
||||||
|
|
||||||
private boolean isCreator = false;
|
private boolean isCreator = false;
|
||||||
|
|
||||||
GroupMessageAdapter(ThreadItemListener<GroupMessageItem> listener) {
|
GroupMessageAdapter(LifecycleOwner lifecycleOwner,
|
||||||
super(listener);
|
ThreadItemListener<GroupMessageItem> listener) {
|
||||||
|
super(lifecycleOwner, listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
@LayoutRes
|
@LayoutRes
|
||||||
@@ -30,6 +33,7 @@ class GroupMessageAdapter extends ThreadItemAdapter<GroupMessageItem> {
|
|||||||
return item.getLayout();
|
return item.getLayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public BaseThreadItemViewHolder<GroupMessageItem> onCreateViewHolder(
|
public BaseThreadItemViewHolder<GroupMessageItem> onCreateViewHolder(
|
||||||
ViewGroup parent, int type) {
|
ViewGroup parent, int type) {
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
package org.briarproject.briar.android.privategroup.conversation;
|
package org.briarproject.briar.android.privategroup.conversation;
|
||||||
|
|
||||||
import org.briarproject.bramble.api.identity.Author;
|
import org.briarproject.bramble.api.identity.Author;
|
||||||
import org.briarproject.briar.api.identity.AuthorInfo;
|
|
||||||
import org.briarproject.bramble.api.sync.GroupId;
|
import org.briarproject.bramble.api.sync.GroupId;
|
||||||
import org.briarproject.bramble.api.sync.MessageId;
|
import org.briarproject.bramble.api.sync.MessageId;
|
||||||
import org.briarproject.briar.R;
|
import org.briarproject.briar.R;
|
||||||
import org.briarproject.briar.android.threaded.ThreadItem;
|
import org.briarproject.briar.android.threaded.ThreadItem;
|
||||||
|
import org.briarproject.briar.api.identity.AuthorInfo;
|
||||||
import org.briarproject.briar.api.privategroup.GroupMessageHeader;
|
import org.briarproject.briar.api.privategroup.GroupMessageHeader;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
@@ -16,7 +16,7 @@ import androidx.annotation.UiThread;
|
|||||||
|
|
||||||
@UiThread
|
@UiThread
|
||||||
@NotThreadSafe
|
@NotThreadSafe
|
||||||
class GroupMessageItem extends ThreadItem {
|
public class GroupMessageItem extends ThreadItem {
|
||||||
|
|
||||||
private final GroupId groupId;
|
private final GroupId groupId;
|
||||||
|
|
||||||
|
|||||||
@@ -284,4 +284,9 @@ class GroupViewModel extends ThreadListViewModel<GroupMessageItem> {
|
|||||||
return isDissolved;
|
return isDissolved;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String getMessageText(Transaction txn, MessageId m)
|
||||||
|
throws DbException {
|
||||||
|
return privateGroupManager.getMessageText(txn, m);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import org.briarproject.briar.android.threaded.ThreadItemAdapter.ThreadItemListe
|
|||||||
import org.briarproject.nullsafety.NotNullByDefault;
|
import org.briarproject.nullsafety.NotNullByDefault;
|
||||||
|
|
||||||
import androidx.annotation.UiThread;
|
import androidx.annotation.UiThread;
|
||||||
|
import androidx.lifecycle.LifecycleOwner;
|
||||||
|
|
||||||
import static org.briarproject.briar.api.identity.AuthorInfo.Status.OURSELVES;
|
import static org.briarproject.briar.api.identity.AuthorInfo.Status.OURSELVES;
|
||||||
|
|
||||||
@@ -25,9 +26,9 @@ class JoinMessageItemViewHolder
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void bind(GroupMessageItem item,
|
public void bind(GroupMessageItem item, LifecycleOwner lifecycleOwner,
|
||||||
ThreadItemListener<GroupMessageItem> listener) {
|
ThreadItemListener<GroupMessageItem> listener) {
|
||||||
super.bind(item, listener);
|
super.bind(item, lifecycleOwner, listener);
|
||||||
|
|
||||||
if (isCreator) bindForCreator((JoinMessageItem) item);
|
if (isCreator) bindForCreator((JoinMessageItem) item);
|
||||||
else bind((JoinMessageItem) item);
|
else bind((JoinMessageItem) item);
|
||||||
|
|||||||
@@ -10,17 +10,22 @@ import android.view.ViewGroup;
|
|||||||
import android.view.animation.AccelerateInterpolator;
|
import android.view.animation.AccelerateInterpolator;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import org.briarproject.bramble.util.StringUtils;
|
import org.briarproject.bramble.api.sync.MessageId;
|
||||||
import org.briarproject.briar.R;
|
import org.briarproject.briar.R;
|
||||||
import org.briarproject.briar.android.threaded.ThreadItemAdapter.ThreadItemListener;
|
import org.briarproject.briar.android.threaded.ThreadItemAdapter.ThreadItemListener;
|
||||||
import org.briarproject.briar.android.view.AuthorView;
|
import org.briarproject.briar.android.view.AuthorView;
|
||||||
import org.briarproject.nullsafety.NotNullByDefault;
|
import org.briarproject.nullsafety.NotNullByDefault;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
import androidx.annotation.CallSuper;
|
import androidx.annotation.CallSuper;
|
||||||
import androidx.annotation.UiThread;
|
import androidx.annotation.UiThread;
|
||||||
|
import androidx.lifecycle.LifecycleOwner;
|
||||||
|
import androidx.lifecycle.LiveData;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
import static androidx.core.content.ContextCompat.getColor;
|
import static androidx.core.content.ContextCompat.getColor;
|
||||||
|
import static org.briarproject.bramble.util.StringUtils.trim;
|
||||||
import static org.briarproject.briar.android.util.UiUtils.makeLinksClickable;
|
import static org.briarproject.briar.android.util.UiUtils.makeLinksClickable;
|
||||||
|
|
||||||
@UiThread
|
@UiThread
|
||||||
@@ -33,6 +38,8 @@ public abstract class BaseThreadItemViewHolder<I extends ThreadItem>
|
|||||||
protected final TextView textView;
|
protected final TextView textView;
|
||||||
private final ViewGroup layout;
|
private final ViewGroup layout;
|
||||||
private final AuthorView author;
|
private final AuthorView author;
|
||||||
|
@Nullable
|
||||||
|
private MessageId boundMessageId = null;
|
||||||
|
|
||||||
public BaseThreadItemViewHolder(View v) {
|
public BaseThreadItemViewHolder(View v) {
|
||||||
super(v);
|
super(v);
|
||||||
@@ -43,8 +50,22 @@ public abstract class BaseThreadItemViewHolder<I extends ThreadItem>
|
|||||||
}
|
}
|
||||||
|
|
||||||
@CallSuper
|
@CallSuper
|
||||||
public void bind(I item, ThreadItemListener<I> listener) {
|
public void bind(I item, LifecycleOwner lifecycleOwner,
|
||||||
textView.setText(StringUtils.trim(item.getText()));
|
ThreadItemListener<I> listener) {
|
||||||
|
boundMessageId = item.getId();
|
||||||
|
String text = item.getText();
|
||||||
|
if (text == null) {
|
||||||
|
textView.setText(null);
|
||||||
|
LiveData<String> textLiveData = listener.loadItemText(item.getId());
|
||||||
|
textLiveData.observe(lifecycleOwner, t -> {
|
||||||
|
// Check that the ViewHolder hasn't been re-bound while loading
|
||||||
|
if (item.getId().equals(boundMessageId)) {
|
||||||
|
textView.setText(t);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
textView.setText(trim(text));
|
||||||
|
}
|
||||||
Linkify.addLinks(textView, Linkify.WEB_URLS);
|
Linkify.addLinks(textView, Linkify.WEB_URLS);
|
||||||
makeLinksClickable(textView, listener::onLinkClick);
|
makeLinksClickable(textView, listener::onLinkClick);
|
||||||
|
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ public abstract class ThreadItem implements MessageNode {
|
|||||||
private final MessageId messageId;
|
private final MessageId messageId;
|
||||||
@Nullable
|
@Nullable
|
||||||
private final MessageId parentId;
|
private final MessageId parentId;
|
||||||
|
@Nullable
|
||||||
private final String text;
|
private final String text;
|
||||||
private final long timestamp;
|
private final long timestamp;
|
||||||
private final Author author;
|
private final Author author;
|
||||||
@@ -27,8 +28,8 @@ public abstract class ThreadItem implements MessageNode {
|
|||||||
private boolean isRead, highlighted;
|
private boolean isRead, highlighted;
|
||||||
|
|
||||||
public ThreadItem(MessageId messageId, @Nullable MessageId parentId,
|
public ThreadItem(MessageId messageId, @Nullable MessageId parentId,
|
||||||
String text, long timestamp, Author author, AuthorInfo authorInfo,
|
@Nullable String text, long timestamp, Author author,
|
||||||
boolean isRead) {
|
AuthorInfo authorInfo, boolean isRead) {
|
||||||
this.messageId = messageId;
|
this.messageId = messageId;
|
||||||
this.parentId = parentId;
|
this.parentId = parentId;
|
||||||
this.text = text;
|
this.text = text;
|
||||||
@@ -39,6 +40,7 @@ public abstract class ThreadItem implements MessageNode {
|
|||||||
this.highlighted = false;
|
this.highlighted = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public String getText() {
|
public String getText() {
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ import javax.annotation.Nullable;
|
|||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.UiThread;
|
import androidx.annotation.UiThread;
|
||||||
|
import androidx.lifecycle.LifecycleOwner;
|
||||||
|
import androidx.lifecycle.LiveData;
|
||||||
import androidx.recyclerview.widget.DiffUtil;
|
import androidx.recyclerview.widget.DiffUtil;
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||||
import androidx.recyclerview.widget.ListAdapter;
|
import androidx.recyclerview.widget.ListAdapter;
|
||||||
@@ -27,9 +29,11 @@ public class ThreadItemAdapter<I extends ThreadItem>
|
|||||||
|
|
||||||
static final int UNDEFINED = -1;
|
static final int UNDEFINED = -1;
|
||||||
|
|
||||||
|
private final LifecycleOwner lifecycleOwner;
|
||||||
private final ThreadItemListener<I> listener;
|
private final ThreadItemListener<I> listener;
|
||||||
|
|
||||||
public ThreadItemAdapter(ThreadItemListener<I> listener) {
|
public ThreadItemAdapter(LifecycleOwner lifecycleOwner,
|
||||||
|
ThreadItemListener<I> listener) {
|
||||||
super(new DiffUtil.ItemCallback<I>() {
|
super(new DiffUtil.ItemCallback<I>() {
|
||||||
@Override
|
@Override
|
||||||
public boolean areItemsTheSame(I a, I b) {
|
public boolean areItemsTheSame(I a, I b) {
|
||||||
@@ -42,6 +46,7 @@ public class ThreadItemAdapter<I extends ThreadItem>
|
|||||||
a.isRead() == b.isRead();
|
a.isRead() == b.isRead();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
this.lifecycleOwner = lifecycleOwner;
|
||||||
this.listener = listener;
|
this.listener = listener;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,7 +63,7 @@ public class ThreadItemAdapter<I extends ThreadItem>
|
|||||||
public void onBindViewHolder(@NonNull BaseThreadItemViewHolder<I> ui,
|
public void onBindViewHolder(@NonNull BaseThreadItemViewHolder<I> ui,
|
||||||
int position) {
|
int position) {
|
||||||
I item = getItem(position);
|
I item = getItem(position);
|
||||||
ui.bind(item, listener);
|
ui.bind(item, lifecycleOwner, listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
int findItemPosition(MessageId id) {
|
int findItemPosition(MessageId id) {
|
||||||
@@ -136,8 +141,12 @@ public class ThreadItemAdapter<I extends ThreadItem>
|
|||||||
}
|
}
|
||||||
|
|
||||||
public interface ThreadItemListener<I> {
|
public interface ThreadItemListener<I> {
|
||||||
|
|
||||||
void onReplyClick(I item);
|
void onReplyClick(I item);
|
||||||
|
|
||||||
void onLinkClick(String url);
|
void onLinkClick(String url);
|
||||||
|
|
||||||
|
LiveData<String> loadItemText(MessageId m);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -257,4 +257,8 @@ public abstract class ThreadListActivity<I extends ThreadItem, A extends ThreadI
|
|||||||
|
|
||||||
protected abstract int getMaxTextLength();
|
protected abstract int getMaxTextLength();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LiveData<String> loadItemText(MessageId m) {
|
||||||
|
return getViewModel().loadMessageText(m);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import org.briarproject.bramble.api.crypto.CryptoExecutor;
|
|||||||
import org.briarproject.bramble.api.db.DatabaseExecutor;
|
import org.briarproject.bramble.api.db.DatabaseExecutor;
|
||||||
import org.briarproject.bramble.api.db.DbException;
|
import org.briarproject.bramble.api.db.DbException;
|
||||||
import org.briarproject.bramble.api.db.NoSuchGroupException;
|
import org.briarproject.bramble.api.db.NoSuchGroupException;
|
||||||
|
import org.briarproject.bramble.api.db.Transaction;
|
||||||
import org.briarproject.bramble.api.db.TransactionManager;
|
import org.briarproject.bramble.api.db.TransactionManager;
|
||||||
import org.briarproject.bramble.api.event.Event;
|
import org.briarproject.bramble.api.event.Event;
|
||||||
import org.briarproject.bramble.api.event.EventBus;
|
import org.briarproject.bramble.api.event.EventBus;
|
||||||
@@ -260,4 +261,14 @@ public abstract class ThreadListViewModel<I extends ThreadItem>
|
|||||||
return scrollToItem.getAndSet(null);
|
return scrollToItem.getAndSet(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public LiveData<String> loadMessageText(MessageId m) {
|
||||||
|
MutableLiveData<String> textLiveData = new MutableLiveData<>();
|
||||||
|
runOnDbThread(true, txn ->
|
||||||
|
textLiveData.postValue(getMessageText(txn, m)),
|
||||||
|
this::handleException);
|
||||||
|
return textLiveData;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract String getMessageText(Transaction txn, MessageId m)
|
||||||
|
throws DbException;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import org.briarproject.nullsafety.NotNullByDefault;
|
|||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
import androidx.annotation.UiThread;
|
import androidx.annotation.UiThread;
|
||||||
|
import androidx.lifecycle.LifecycleOwner;
|
||||||
|
|
||||||
import static android.view.View.GONE;
|
import static android.view.View.GONE;
|
||||||
import static android.view.View.VISIBLE;
|
import static android.view.View.VISIBLE;
|
||||||
@@ -40,8 +41,9 @@ public class ThreadPostViewHolder<I extends ThreadItem>
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void bind(I item, ThreadItemListener<I> listener) {
|
public void bind(I item, LifecycleOwner lifecycleOwner,
|
||||||
super.bind(item, listener);
|
ThreadItemListener<I> listener) {
|
||||||
|
super.bind(item, lifecycleOwner, listener);
|
||||||
|
|
||||||
for (int i = 0; i < lvls.length; i++) {
|
for (int i = 0; i < lvls.length; i++) {
|
||||||
lvls[i].setVisibility(i < item.getLevel() ? VISIBLE : GONE);
|
lvls[i].setVisibility(i < item.getLevel() ? VISIBLE : GONE);
|
||||||
|
|||||||
@@ -16,13 +16,10 @@ public class ForumPostReceivedEvent extends Event {
|
|||||||
|
|
||||||
private final GroupId groupId;
|
private final GroupId groupId;
|
||||||
private final ForumPostHeader header;
|
private final ForumPostHeader header;
|
||||||
private final String text;
|
|
||||||
|
|
||||||
public ForumPostReceivedEvent(GroupId groupId, ForumPostHeader header,
|
public ForumPostReceivedEvent(GroupId groupId, ForumPostHeader header) {
|
||||||
String text) {
|
|
||||||
this.groupId = groupId;
|
this.groupId = groupId;
|
||||||
this.header = header;
|
this.header = header;
|
||||||
this.text = text;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public GroupId getGroupId() {
|
public GroupId getGroupId() {
|
||||||
@@ -32,8 +29,4 @@ public class ForumPostReceivedEvent extends Event {
|
|||||||
public ForumPostHeader getHeader() {
|
public ForumPostHeader getHeader() {
|
||||||
return header;
|
return header;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getText() {
|
|
||||||
return text;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -83,10 +83,7 @@ class ForumManagerImpl extends BdfIncomingMessageHook implements ForumManager {
|
|||||||
messageTracker.trackIncomingMessage(txn, m);
|
messageTracker.trackIncomingMessage(txn, m);
|
||||||
|
|
||||||
ForumPostHeader header = getForumPostHeader(txn, m.getId(), meta);
|
ForumPostHeader header = getForumPostHeader(txn, m.getId(), meta);
|
||||||
String text = getPostText(body);
|
txn.attach(new ForumPostReceivedEvent(m.getGroupId(), header));
|
||||||
ForumPostReceivedEvent event =
|
|
||||||
new ForumPostReceivedEvent(m.getGroupId(), header, text);
|
|
||||||
txn.attach(event);
|
|
||||||
|
|
||||||
return ACCEPT_SHARE;
|
return ACCEPT_SHARE;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user