Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add getLatestActiveMessage func #127

Merged
merged 1 commit into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading