// Import corresponding packagesimport { MessageText, Channel, WKSDK, ChannelTypePerson, ChannelTypeGroup } from "wukongimjssdk";// Example: Send text message "hello" to user u10001const text = new MessageText("hello") // Text messageWKSDK.shared().chatManager.send(text, new Channel("u10001", ChannelTypePerson))// Example: Send text message "hello" to group channel g10001WKSDK.shared().chatManager.send(text, new Channel("g10001", ChannelTypeGroup))
When a message is sent, the reasonCode in the SendackPacket returned by the addMessageStatusListener indicates the result of the message delivery. Below are the descriptions for each status code:
{ startMessageSeq: number = 0 // Start message sequence (result includes message with startMessageSeq) endMessageSeq: number = 0 // End message sequence (result excludes message with endMessageSeq) 0 means no limit limit: number = 30 // Limit per request pullMode: PullMode = PullMode.Down // Pull mode 0: pull down 1: pull up}
Detailed explanation:
Using startMessageSeq as baseline, pullMode controls pull direction, endMessageSeq and limit control end position------------------ Pull Up ------------------pullMode = 1 means pull up, logic as follows:Messages start from startMessageSeq, load messages greater than or equal to startMessageSeq, load until exceeding endMessageSeq (result excludes endMessageSeq) or exceeding limit, if endMessageSeq is 0 then use limit as criterionExamples:startMessageSeq=100 endMessageSeq=200 limit=10 use limit, returns messages with messageSeq 100-110startMessageSeq=100 endMessageSeq=105 limit=10 use endMessageSeq, returns messages with messageSeq 100-104startMessageSeq=100 endMessageSeq=0 limit=10 use limit, returns messages with messageSeq 100-110------------------ Pull Down ------------------pullMode = 0 means pull down, logic as follows:Messages start from startMessageSeq, load messages less than or equal to startMessageSeq,load until exceeding endMessageSeq (result excludes endMessageSeq) or exceeding limit,if endMessageSeq is 0 then use limit as criterionExamples:startMessageSeq=100 endMessageSeq=50 limit=10 use limit, returns messages with messageSeq 100-91startMessageSeq=100 endMessageSeq=95 limit=10 use endMessageSeq, returns messages with messageSeq 100-96startMessageSeq=100 endMessageSeq=0 limit=10 use limit, returns messages with messageSeq 100-91If both startMessageSeq and endMessageSeq are 0, regardless of pullMode, load the latest limit messages.
In WuKongIM, to handle massive offline messages, an on-demand pull mechanism is adopted. For example, with 10 conversations each having 100,000 messages, WuKongIM will not pull all 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.