mirror of
https://github.com/oxen-io/session-android.git
synced 2025-06-09 08:08:33 +00:00
Fix potential issues with ConversationDataSource boundaries.
This commit is contained in:
parent
35a0162d5c
commit
e714cb6423
@ -357,7 +357,7 @@ public class ConversationAdapter<V extends View & BindableConversationItem>
|
|||||||
* Momentarily highlights a row at the requested position.
|
* Momentarily highlights a row at the requested position.
|
||||||
*/
|
*/
|
||||||
void pulseHighlightItem(int position) {
|
void pulseHighlightItem(int position) {
|
||||||
if (position < getItemCount()) {
|
if (position >= 0 && position < getItemCount()) {
|
||||||
recordToPulseHighlight = getItem(position);
|
recordToPulseHighlight = getItem(position);
|
||||||
notifyItemChanged(position);
|
notifyItemChanged(position);
|
||||||
}
|
}
|
||||||
@ -430,7 +430,10 @@ public class ConversationAdapter<V extends View & BindableConversationItem>
|
|||||||
pool.setMaxRecycledViews(MESSAGE_TYPE_UPDATE, 5);
|
pool.setMaxRecycledViews(MESSAGE_TYPE_UPDATE, 5);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@MainThread
|
||||||
private void cleanFastRecords() {
|
private void cleanFastRecords() {
|
||||||
|
Util.assertMainThread();
|
||||||
|
|
||||||
synchronized (releasedFastRecords) {
|
synchronized (releasedFastRecords) {
|
||||||
Iterator<MessageRecord> recordIterator = fastRecords.iterator();
|
Iterator<MessageRecord> recordIterator = fastRecords.iterator();
|
||||||
while (recordIterator.hasNext()) {
|
while (recordIterator.hasNext()) {
|
||||||
|
@ -16,6 +16,7 @@ import org.thoughtcrime.securesms.util.Util;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Core data source for loading an individual conversation.
|
* Core data source for loading an individual conversation.
|
||||||
@ -58,7 +59,20 @@ class ConversationDataSource extends PositionalDataSource<MessageRecord> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
callback.onResult(records, params.requestedStartPosition, db.getConversationCount(threadId));
|
int effectiveCount = records.size() + params.requestedStartPosition;
|
||||||
|
int totalCount = db.getConversationCount(threadId);
|
||||||
|
|
||||||
|
if (effectiveCount > totalCount) {
|
||||||
|
Log.w(TAG, String.format(Locale.ENGLISH, "Miscalculation! Records: %d, Start Position: %d, Total: %d. Adjusting total.",
|
||||||
|
records.size(),
|
||||||
|
params.requestedStartPosition,
|
||||||
|
totalCount));
|
||||||
|
totalCount = effectiveCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
records = ensureMultipleOfPageSize(records, params.pageSize, totalCount);
|
||||||
|
|
||||||
|
callback.onResult(records, params.requestedStartPosition, totalCount);
|
||||||
Util.runOnMain(dataUpdateCallback::onDataUpdated);
|
Util.runOnMain(dataUpdateCallback::onDataUpdated);
|
||||||
|
|
||||||
Log.d(TAG, "[Initial Load] " + (System.currentTimeMillis() - start) + " ms" + (isInvalid() ? " -- invalidated" : ""));
|
Log.d(TAG, "[Initial Load] " + (System.currentTimeMillis() - start) + " ms" + (isInvalid() ? " -- invalidated" : ""));
|
||||||
@ -84,6 +98,15 @@ class ConversationDataSource extends PositionalDataSource<MessageRecord> {
|
|||||||
Log.d(TAG, "[Update] " + (System.currentTimeMillis() - start) + " ms" + (isInvalid() ? " -- invalidated" : ""));
|
Log.d(TAG, "[Update] " + (System.currentTimeMillis() - start) + " ms" + (isInvalid() ? " -- invalidated" : ""));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static @NonNull List<MessageRecord> ensureMultipleOfPageSize(@NonNull List<MessageRecord> records, int pageSize, int total) {
|
||||||
|
if (records.size() != total && records.size() % pageSize != 0) {
|
||||||
|
int overflow = records.size() % pageSize;
|
||||||
|
return records.subList(0, records.size() - overflow);
|
||||||
|
} else {
|
||||||
|
return records;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
interface DataUpdatedCallback {
|
interface DataUpdatedCallback {
|
||||||
void onDataUpdated();
|
void onDataUpdated();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user