You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
OpenIM.iMManager.conversationManager.getAllConversationList().then((list) {
// Return to the conversation list
});
6,Get contact list
OpenIM.iMManager.friendshipManager.getFriendList().then((list) {
// Return to friends list
});
7,Get chat history
List<Message> chatMsgList = List.empty(growable: true);
/// Custom message listener, the arrival of a new message will trigger the onNewMessage method callback
class CustomAdvancedMsgListener extends AdvancedMsgListener {
final ValueChanged<Message>? onNewMessage;
CustomAdvancedMsgListener({
this.onNewMessage,
});
@override
void onRecvNewMessage(Message msg) {
if (null != onNewMessage) onNewMessage!(msg);
}
}
History news
// If userID is not null and groupID is null, get a single chat message list
// If the userID is null and the groupID is not null, get a group chat message list
OpenIM.iMManager.messageManager.getHistoryMessageList(
userID: uid,//User id
startMsg: startMsg,//Last message, take chatMsgList[0]
groupID: gid,//Group id
count: 12,//Page Size
)
.then((list) => chatMsgList.addAll(list));
New news
// Create a message listener
// After entering the chat page, you need to listen for new messages and then render the UI
// Each chat window has a unique uid (user id) or gid (group id)
// Determine whether the received message belongs to the current window according to uid or gid
var msgListener = CustomAdvancedMsgListener(onNewMessage: (message) {
// If the sender user id is equal to the user id of the current chat page,
// or the group id is equal to the current group id of the current chat page
if (message.sendID == uid || message.groupID == gid) {
if (!chatMsgList.contains(message)) {
// New message in current chat page
chatMsgList.add(event.message);
}
}
});
// Add message listener
OpenIM.iMManager.messageManager.addAdvancedMsgListener(msgListener);
// Remove message monitoring
// After adding a message listener, if the page disposes, please remove the listener
// OpenIM.iMManager.messageManager.removeAdvancedMsgListener(msgListener);
8,Send a message
// Create message
var message = await OpenIM.iMManager.messageManager.createTextMessage(
text: 'I am the content of the message',
);
// Send
OpenIM.iMManager.messageManager.sendMessage(
message: message,
onlineUserOnly: false,
userID: uid, // Single chat value is not null
groupID: gid, // The group chat value is not null
).then((v) {
// Sent successfully
}).catchError((e){
// Failed to send
});