Skip to content

Commit

Permalink
feat: release 3.8.3 (#160)
Browse files Browse the repository at this point in the history
  • Loading branch information
Bloomingg authored Jan 8, 2025
1 parent 58891a4 commit 4c3cb14
Show file tree
Hide file tree
Showing 10 changed files with 95 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@openim/wasm-client-sdk",
"version": "3.8.2-3",
"version": "3.8.3",
"description": "open im sdk for web",
"source": "src/index.ts",
"main": "lib/index.js",
Expand Down
42 changes: 42 additions & 0 deletions src/api/database/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
ClientMessage,
getMessage as databaseGetMessage,
getAlreadyExistSeqList as databaseGetAlreadyExistSeqList,
getLatestValidServerMessage as databaseGetLatestValidServerMessage,
getMessageBySeq as databaseGetMessageBySeq,
getMessagesByClientMsgIDs as databaseGetMessagesByClientMsgIDs,
getMessagesBySeqs as databaseGetMessagesBySeqs,
Expand Down Expand Up @@ -107,6 +108,47 @@ export async function getAlreadyExistSeqList(
}
}

export async function getLatestValidServerMessage(
conversationID: string,
startTime: number,
isReverse: boolean
): Promise<string> {
try {
const db = await getInstance();

const execResult = databaseGetLatestValidServerMessage(
db,
conversationID,
startTime,
isReverse
);

const message = converSqlExecResult(execResult[0], 'CamelCase', [
'isRead',
'isReact',
'isExternalExtensions',
])[0];

if (!message) {
return formatResponse(
'',
DatabaseErrorCode.ErrorNoRecord,
`no message with conversationID ${conversationID}`
);
}

return formatResponse(message);
} catch (e) {
console.error(e);

return formatResponse(
undefined,
DatabaseErrorCode.ErrorInit,
JSON.stringify(e)
);
}
}

export async function getMessageList(
conversationID: string,
count: number,
Expand Down
3 changes: 3 additions & 0 deletions src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,9 @@ export function initDatabaseAPI(isLogStandardOutput = true): void {
window.getAlreadyExistSeqList = registeMethodOnWindow(
'getAlreadyExistSeqList'
);
window.getLatestValidServerMessage = registeMethodOnWindow(
'getLatestValidServerMessage'
);
window.getMessageBySeq = registeMethodOnWindow('getMessageBySeq');
window.getMessagesByClientMsgIDs = registeMethodOnWindow(
'getMessagesByClientMsgIDs'
Expand Down
2 changes: 2 additions & 0 deletions src/api/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ import {
getPageFriendList,
getGroupMemberAllGroupIDs,
getAlreadyExistSeqList,
getLatestValidServerMessage,
markConversationAllMessageAsRead,
searchAllMessageByContentType,
deleteConversationMsgs,
Expand Down Expand Up @@ -249,6 +250,7 @@ rpc.registerMethod(
updateMsgSenderFaceURLAndSenderNickname
);
rpc.registerMethod('getAlreadyExistSeqList', getAlreadyExistSeqList);
rpc.registerMethod('getLatestValidServerMessage', getLatestValidServerMessage);
rpc.registerMethod('getMessageBySeq', getMessageBySeq);
rpc.registerMethod('getMessagesByClientMsgIDs', getMessagesByClientMsgIDs);
rpc.registerMethod('getMessagesBySeqs', getMessagesBySeqs);
Expand Down
11 changes: 11 additions & 0 deletions src/sdk/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ import {
GetSpecifiedFriendsParams,
ChangeInputStatesParams,
GetInputstatesParams,
FetchSurroundingParams,
} from '../types/params';

import {
Expand Down Expand Up @@ -299,6 +300,16 @@ class SDK extends Emitter {
[operationID, JSON.stringify(params)]
);
};
fetchSurroundingMessages = (
params: FetchSurroundingParams,
operationID = uuidv4()
) => {
return this._invoker<{ messageList: MessageItem[] }>(
'fetchSurroundingMessages',
window.fetchSurroundingMessages,
[operationID, JSON.stringify(params)]
);
};
getSpecifiedGroupsInfo = (params: string[], operationID = uuidv4()) => {
return this._invoker<GroupItem[]>(
'getSpecifiedGroupsInfo',
Expand Down
19 changes: 19 additions & 0 deletions src/sqls/localChatLogsConversationID.ts
Original file line number Diff line number Diff line change
Expand Up @@ -586,3 +586,22 @@ export function getLatestActiveMessage(
`
);
}

export function getLatestValidServerMessage(
db: Database,
conversationID: string,
startTime: number,
isReverse: boolean
): QueryExecResult[] {
_initLocalChatLogsTable(db, conversationID);
const order = isReverse ? 'ASC' : 'DESC';
return db.exec(
`
SELECT * FROM 'chat_logs_${conversationID}' WHERE send_time ${
isReverse ? '<' : '>'
} ${startTime} AND seq != 0 ORDER BY send_time ${
isReverse ? 'DESC' : 'ASC'
} LIMIT 1
`
);
}
1 change: 0 additions & 1 deletion src/types/entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,6 @@ export type SearchMessageResultItem = {

export type AdvancedGetMessageResult = {
isEnd: boolean;
lastMinSeq: number;
errCode: number;
errMsg: string;
messageList: MessageItem[];
Expand Down
4 changes: 4 additions & 0 deletions src/types/enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,7 @@ export enum GroupMessageReaderFilter {
Read = 0,
UnRead = 1,
}
export enum ViewType {
History = 0,
Search = 1,
}
5 changes: 5 additions & 0 deletions src/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ declare global {
updateGroupMessageHasRead: DatabaseApi;
updateMessageStatusBySourceID: DatabaseApi;
getAlreadyExistSeqList: DatabaseApi;
getLatestValidServerMessage: DatabaseApi;
getMessageBySeq: DatabaseApi;
getMessagesByClientMsgIDs: DatabaseApi;
getMessagesBySeqs: DatabaseApi;
Expand Down Expand Up @@ -267,6 +268,10 @@ declare global {
operationID: string,
getAdvancedHistoryMessageListReverseParamsStr: string
) => Promise<string>;
fetchSurroundingMessages: (
operationID: string,
fetchSurroundingMessagesParamsStr: string
) => Promise<string>;
getHistoryMessageList: (
operationID: string,
getHistoryMsgParamsParamsStr: string
Expand Down
11 changes: 8 additions & 3 deletions src/types/params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
LogLevel,
GroupMessageReaderFilter,
GroupAtType,
ViewType,
} from './enum';

export type WasmPathConfig = {
Expand All @@ -44,13 +45,17 @@ export type GetOneConversationParams = {
sessionType: number;
};
export type GetAdvancedHistoryMsgParams = {
userID?: string;
groupID?: string;
lastMinSeq: number;
count: number;
viewType: ViewType;
startClientMsgID: string;
conversationID: string;
};
export type FetchSurroundingParams = {
startMessage: MessageItem;
viewType: ViewType;
before: number;
after: number;
};
export type GetHistoryMsgParams = {
userID: string;
groupID: string;
Expand Down

0 comments on commit 4c3cb14

Please sign in to comment.