Skip to content

Commit eaea284

Browse files
committed
gethistoryMessages: add isDescend
1 parent c8db576 commit eaea284

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

android/src/main/java/com/jiguang/jmessageflutter/JmessageFlutterPlugin.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import java.io.FileNotFoundException;
2626
import java.lang.reflect.Method;
2727
import java.util.ArrayList;
28+
import java.util.Collections;
2829
import java.util.HashMap;
2930
import java.util.Iterator;
3031
import java.util.List;
@@ -1106,7 +1107,7 @@ private void getHistoryMessages(MethodCall call, Result result) {
11061107
HashMap<String, Object> map = call.arguments();
11071108
Conversation conversation;
11081109
int from, limit;
1109-
1110+
boolean isDescend;
11101111
try {
11111112
JSONObject params = new JSONObject(map);
11121113

@@ -1116,6 +1117,8 @@ private void getHistoryMessages(MethodCall call, Result result) {
11161117
return;
11171118
}
11181119

1120+
isDescend = params.has("isDescend") ? params.getBoolean("isDescend") : false;
1121+
11191122
from = params.getInt("from");
11201123
limit = params.getInt("limit");
11211124

@@ -1143,6 +1146,10 @@ private void getHistoryMessages(MethodCall call, Result result) {
11431146
messageList = conversation.getMessagesFromNewest(from, limit);
11441147
}
11451148

1149+
if (!isDescend) {
1150+
Collections.reverse(messageList);
1151+
}
1152+
11461153
ArrayList messageJSONArr = new ArrayList();
11471154

11481155
for (Message msg : messageList) {

lib/jmessage_flutter.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -614,12 +614,14 @@ class JmessageFlutter {
614614
@required dynamic type, /// (JMSingle | JMGroup)
615615
@required int from,
616616
@required int limit,
617+
bool isDescend = false
617618
}) async {
618619
Map param = type.toJson();
619620

620621
param..addAll({
621622
'from': from,
622623
'limit': limit,
624+
'isDescend': isDescend
623625
});
624626

625627
List resArr = await _channel.invokeMethod('getHistoryMessages',
@@ -2120,11 +2122,13 @@ class JMConversationInfo {
21202122
Future<List> getHistoryMessages({
21212123
@required int from,
21222124
@required int limit,
2125+
bool isDescend = false
21232126
}) async {
21242127
List msgs = await JmessageFlutter().getHistoryMessages(
21252128
type: target.targetType,
21262129
from: from,
2127-
limit: limit
2130+
limit: limit,
2131+
isDescend: isDescend
21282132
);
21292133
return msgs;
21302134
}

0 commit comments

Comments
 (0)