Skip to content

Commit 82fc7b7

Browse files
committed
1,添加按照时间获取会话消息功能
2,更新协议栈,解决当会话被删除时,获取会话得到置顶和静音状态不对的问题
1 parent 1592ccd commit 82fc7b7

File tree

4 files changed

+44
-0
lines changed

4 files changed

+44
-0
lines changed

client/src/main/aidl/cn/wildfirechat/client/IRemoteClient.aidl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ interface IRemoteClient {
9292
oneway void getMessagesInStatusAsync(in Conversation conversation, in int[] messageStatus, in long fromIndex, in boolean before, in int count, in String withUser, in IGetMessageCallback callback);
9393
oneway void getMessagesExAsync(in int[] conversationTypes, in int[] lines, in int[] contentTypes, in long fromIndex, in boolean before, in int count, in String withUser, in IGetMessageCallback callback);
9494
oneway void getMessagesEx2Async(in int[] conversationTypes, in int[] lines, in int[] messageStatus, in long fromIndex, in boolean before, in int count, in String withUser, in IGetMessageCallback callback);
95+
oneway void getMessagesInTypesAndTimestampAsync(in Conversation conversation, in int[] contentTypes, in long timestamp, in boolean before, in int count, in String withUser, in IGetMessageCallback callback);
9596

9697
oneway void getUserMessages(in String userId, in Conversation conversation, in long fromIndex, in boolean before, in int count, in IGetMessageCallback callback);
9798
oneway void getUserMessagesEx(in String userId, in int[] conversationTypes, in int[] lines, in int[] contentTypes, in long fromIndex, in boolean before, in int count, in IGetMessageCallback callback);

client/src/main/java/cn/wildfirechat/client/ClientService.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,12 @@ public void getMessagesEx2Async(int[] conversationTypes, int[] lines, int[] mess
512512
safeMessagesCallback(protoMessages, before, callback);
513513
}
514514

515+
@Override
516+
public void getMessagesInTypesAndTimestampAsync(Conversation conversation, int[] contentTypes, long timestamp, boolean before, int count, String withUser, IGetMessageCallback callback) throws RemoteException {
517+
ProtoMessage[] protoMessages = ProtoLogic.getMessagesInTypesAndTimestamp(conversation.type.ordinal(), conversation.target, conversation.line, contentTypes, timestamp, before, count, withUser);
518+
safeMessagesCallback(protoMessages, before, callback);
519+
}
520+
515521
@Override
516522
public void getUserMessages(String userId, Conversation conversation, long fromIndex, boolean before, int count, IGetMessageCallback callback) throws RemoteException {
517523
ProtoMessage[] protoMessages = ProtoLogic.getUserMessages(userId, conversation.type.ordinal(), conversation.target, conversation.line, fromIndex, before, count);

client/src/main/java/cn/wildfirechat/remote/ChatManager.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2195,6 +2195,43 @@ public void onFailure(int errorCode) throws RemoteException {
21952195
}
21962196
}
21972197

2198+
/**
2199+
* 按照时间戳获取会话消息
2200+
*
2201+
* @param conversation 会话
2202+
* @param contentTypes 消息类型列表
2203+
* @param timestamp 时间戳
2204+
* @param before true, 获取fromIndex之前的消息,即更旧的消息;false,获取fromIndex之后的消息,即更新的消息。都不包含fromIndex对应的消息
2205+
* @param count 获取消息条数
2206+
* @param withUser 只有会话类型为{@link cn.wildfirechat.model.Conversation.ConversationType#Channel}时生效, channel主用来查询和某个用户的所有消息
2207+
* @param callback 消息回调,当消息比较多,或者消息体比较大时,可能会回调多次
2208+
*/
2209+
public void getMessagesByTimestamp(Conversation conversation, List<Integer> contentTypes, long timestamp, boolean before, int count, String withUser, GetMessageCallback callback) {
2210+
if (callback == null) {
2211+
return;
2212+
}
2213+
if (!checkRemoteService()) {
2214+
callback.onFail(ErrorCode.SERVICE_DIED);
2215+
return;
2216+
}
2217+
2218+
try {
2219+
mClient.getMessagesInTypesAndTimestampAsync(conversation, convertIntegers(contentTypes), timestamp, before, count, withUser, new IGetMessageCallback.Stub() {
2220+
@Override
2221+
public void onSuccess(List<Message> messages, boolean hasMore) throws RemoteException {
2222+
mainHandler.post(() -> callback.onSuccess(messages, hasMore));
2223+
}
2224+
2225+
@Override
2226+
public void onFailure(int errorCode) throws RemoteException {
2227+
mainHandler.post(() -> callback.onFail(errorCode));
2228+
}
2229+
});
2230+
} catch (RemoteException e) {
2231+
e.printStackTrace();
2232+
mainHandler.post(() -> callback.onFail(ErrorCode.SERVICE_EXCEPTION));
2233+
}
2234+
}
21982235
/**
21992236
* 获取会话消息
22002237
*
5.56 KB
Binary file not shown.

0 commit comments

Comments
 (0)