Skip to content

Commit

Permalink
feat: add getLatestActiveMessage func (#127)
Browse files Browse the repository at this point in the history
  • Loading branch information
lgz5689 authored Sep 3, 2024
1 parent 43e7941 commit e964235
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 1 deletion.
Binary file modified assets/openIM.wasm
100644 → 100755
Binary file not shown.
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-beta.1",
"version": "3.8.2-beta.2",
"description": "open im sdk for web",
"source": "src/index.ts",
"main": "lib/index.js",
Expand Down
32 changes: 32 additions & 0 deletions src/api/database/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
getUnreadMessage as databaseGetUnreadMessage,
markConversationMessageAsReadBySeqs as databaseMarkConversationMessageAsReadBySeqs,
markConversationMessageAsRead as databaseMarkConversationMessageAsRead,
getLatestActiveMessage as databaseGetLatestActiveMessage,
} from '@/sqls';
import {
converSqlExecResult,
Expand Down Expand Up @@ -950,3 +951,34 @@ export async function searchAllMessageByContentType(
);
}
}

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

const execResult = databaseGetLatestActiveMessage(
db,
conversationID,
isReverse
);

return formatResponse(
converSqlExecResult(execResult[0], 'CamelCase', [
'isRead',
'isReact',
'isExternalExtensions',
])
);
} catch (e) {
console.error(e);

return formatResponse(
undefined,
DatabaseErrorCode.ErrorInit,
JSON.stringify(e)
);
}
}
3 changes: 3 additions & 0 deletions src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,9 @@ export function initDatabaseAPI(isLogStandardOutput = true): void {
);
window.getAllConversations = registeMethodOnWindow('getAllConversations');
window.searchConversations = registeMethodOnWindow('searchConversations');
window.getLatestActiveMessage = registeMethodOnWindow(
'getLatestActiveMessage'
);

// users
window.getLoginUser = registeMethodOnWindow('getLoginUser');
Expand Down
2 changes: 2 additions & 0 deletions src/api/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
insertSendingMessage,
deleteSendingMessage,
getAllSendingMessages,
getLatestActiveMessage,

// conversation
getAllConversationList,
Expand Down Expand Up @@ -284,6 +285,7 @@ rpc.registerMethod(
rpc.registerMethod('insertSendingMessage', insertSendingMessage);
rpc.registerMethod('deleteSendingMessage', deleteSendingMessage);
rpc.registerMethod('getAllSendingMessages', getAllSendingMessages);
rpc.registerMethod('getLatestActiveMessage', getLatestActiveMessage);

// conversation
rpc.registerMethod('getAllConversationList', getAllConversationList);
Expand Down
14 changes: 14 additions & 0 deletions src/sqls/localChatLogsConversationID.ts
Original file line number Diff line number Diff line change
Expand Up @@ -572,3 +572,17 @@ export function searchAllMessageByContentType(
`
);
}

export function getLatestActiveMessage(
db: Database,
conversationID: string,
isReverse: boolean
): QueryExecResult[] {
_initLocalChatLogsTable(db, conversationID);
const order = isReverse ? 'ASC' : 'DESC';
return db.exec(
`
SELECT * FROM 'chat_logs_${conversationID}' WHERE status < 4 ORDER BY send_time ${order};
`
);
}
1 change: 1 addition & 0 deletions src/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ declare global {
insertSendingMessage: DatabaseApi;
deleteSendingMessage: DatabaseApi;
getAllSendingMessages: DatabaseApi;
getLatestActiveMessage: DatabaseApi;
// conversation
getAllConversationListDB: DatabaseApi;
getAllConversationListToSync: DatabaseApi;
Expand Down

0 comments on commit e964235

Please sign in to comment.