// Text messagelet textModel: WKTextContent = new WKTextContent('Hello, WuKong')// Send to user AWKIM.shared.messageManager().send(textModel, new WKChannel('A', WKChannelType.personal));
// Image messagelet imageModel: WKImageContent = new WKImageContent(localPath)imageModel.width = 100imageModel.height = 100// Send to user AWKIM.shared.messageManager().send(imageModel, new WKChannel('A', WKChannelType.personal));
When sending messages, the SDK will trigger a storage callback after saving the message to the local database. At this point, the message has not been sent yet, and you can display the message in the UI in this listener.
Copy
// Listen for message storageWKIM.shared.messageManager().addInsertedListener((msg) => { // Display message in UI})
// New message listenernewMsgsListener = (msgs: WKMsg[]) => { // Handle new messages }// Listen for new messagesWKIM.shared.messageManager().addNewMsgListener(this.newMsgsListener)// Remove new message listenerWKIM.shared.messageManager().removeNewMsgListener(this.newMsgsListener)
When the SDK updates messages, such as: message send status, someone likes a message, message read receipt, message recall, message editing, etc., the SDK will callback the following event. The UI can determine which specific message has changed through the clientMsgNO of the message object WKMsg.
When a message is sent, the reasonCode in the WKMsg object returned by the addRefreshListener indicates the result of the message delivery. Below are the descriptions for each status code:
let option = new ChannelMsgOptions(() => { // Syncing - show loading as needed }, (list) => { // Message data })option.oldestOrderSeq = 0 // Last message's large orderSeq, pass 0 for first entry into chatoption.contain = false // Whether to include the oldestOrderSeq messageoption.pullMode = 1 // Pull mode 0: pull down 1: pull upoption.limit = 20 // Number to get each timeoption.aroundMsgOrderSeq = 0 // Query messages around this message, e.g. aroundMsgOrderSeq=20 returns [16,17,19,20,21,22,23,24,25]// View chat information for a channelWKIM.shared.messageManager().getOrSyncHistoryMessages(channel, option)
Getting history messages is not a synchronous method, as there may be non-continuous data that needs to be synced from the server
Need to implement sync channel message data sourceChannel Message Data SourceBecause WuKongIM supports permanent message storage, it will generate massive offline messages. For this, we adopt an on-demand pull mechanism. For example, with 10 conversations each having 100,000 messages, WuKongIM will not pull all 10*100,000=1 million messages to local storage. Instead, it pulls information for these 10 conversations and the corresponding latest 20 messages, which means actually only 200 messages are pulled. Compared to 1 million messages, this greatly improves offline pull speed. Users will only pull messages for a specific conversation when they enter that conversation. These mechanisms are already encapsulated within the SDK, so users don’t need to worry about them. Users only need to focus on recent conversation changes and listen for data retrieval callbacks.