1
0
mirror of https://github.com/NekoX-Dev/NekoX.git synced 2024-12-14 08:29:49 +01:00

Fix: improve ignore blocked: fix DialogCell display

This commit is contained in:
luvletter2333 2021-03-25 20:35:29 +08:00
parent df00b507b3
commit 9560a1f58d
No known key found for this signature in database
GPG Key ID: BFD68B892BECC1D8
2 changed files with 37 additions and 1 deletions

View File

@ -71,6 +71,7 @@ import org.telegram.ui.SwipeGestureSettingsView;
import java.util.ArrayList;
import tw.nekomimi.nekogram.MessageHelper;
import tw.nekomimi.nekogram.NekoConfig;
public class DialogCell extends BaseCell {
@ -1942,7 +1943,8 @@ public class DialogCell extends BaseCell {
clearingDialog = MessagesController.getInstance(currentAccount).isClearingDialog(dialog.id);
message = MessagesController.getInstance(currentAccount).dialogMessage.get(dialog.id);
if (message != null && NekoConfig.ignoreBlocked && MessagesController.getInstance(currentAccount).blockePeers.indexOfKey(message.getSenderId()) >= 0) {
message = null;
message = MessageHelper.getInstance(currentAccount).getLastMessageFromUnblock(dialog.id);
// Username show may be abnormal if User who send `message` is not loaded in (never enter chat since boot, esp after cold starting)
}
lastUnreadState = message != null && message.isUnread();
if (dialog instanceof TLRPC.TL_dialogFolder) {

View File

@ -3,19 +3,24 @@ package tw.nekomimi.nekogram;
import android.content.Context;
import android.util.SparseArray;
import org.telegram.SQLite.SQLiteCursor;
import org.telegram.SQLite.SQLiteException;
import org.telegram.messenger.AndroidUtilities;
import org.telegram.messenger.BaseController;
import org.telegram.messenger.FileLog;
import org.telegram.messenger.MessageObject;
import org.telegram.messenger.MessagesController;
import org.telegram.messenger.NotificationCenter;
import org.telegram.messenger.Utilities;
import org.telegram.tgnet.ConnectionsManager;
import org.telegram.tgnet.NativeByteBuffer;
import org.telegram.tgnet.TLRPC;
import org.telegram.ui.ActionBar.AlertDialog;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Locale;
import tw.nekomimi.nekogram.utils.AlertUtil;
@ -300,4 +305,33 @@ public class MessageHelper extends BaseController {
});
}
public MessageObject getLastMessageFromUnblock(long dialogId) {
SQLiteCursor cursor;
MessageObject ret = null;
try {
cursor = getMessagesStorage().getDatabase().queryFinalized(String.format(Locale.US, "SELECT data,send_state,mid,date FROM messages WHERE uid = %d ORDER BY date DESC LIMIT %d,%d", dialogId, 0, 10));
while (cursor.next()) {
NativeByteBuffer data = cursor.byteBufferValue(0);
if (data == null)
continue;
TLRPC.Message message = TLRPC.Message.TLdeserialize(data, data.readInt32(false), false);
data.reuse();
if (getMessagesController().blockePeers.indexOfKey(message.from_id.user_id) < 0) {
// valid message
ret = new MessageObject(currentAccount, message, true, true);
message.send_state = cursor.intValue(1);
message.id = cursor.intValue(2);
message.date = cursor.intValue(3);
message.dialog_id = dialogId;
break;
}
}
cursor.dispose();
} catch (SQLiteException sqLiteException) {
FileLog.e("NekoX, ignoreBlocked, SQLiteException when read last message from unblocked user", sqLiteException);
return null;
}
return ret;
}
}