- Android
- iOS
- JavaScript
- Flutter
- ReactNative
- HarmonyOS
You can register multiple listeners.
JIM.getInstance().getConversationManager().addListener("main", new IConversationManager.IConversationListener() {
/// conversation-added callback
@Override
public void onConversationInfoAdd(List<ConversationInfo> conversationInfoList) {
Log.i("TAG", "onConversationInfoAdd, count is " + conversationInfoList.size());
}
/// conversation-change callback; triggered whenever conversation information changes
@Override
public void onConversationInfoUpdate(List<ConversationInfo> conversationInfoList) {
Log.i("TAG", "onConversationInfoUpdate, count is " + conversationInfoList.size());
}
/// conversation-deleted callback
@Override
public void onConversationInfoDelete(List<ConversationInfo> conversationInfoList) {
Log.i("TAG", "onConversationInfoDelete, count is " + conversationInfoList.size());
}
/// total unread count change callback
@Override
public void onTotalUnreadMessageCountUpdate(int count) {
Log.i("TAG", "onTotalUnreadMessageCountUpdate, count is " + count);
}
});
You can register multiple delegates.
[JIM.shared.conversationManager addDelegate:self];
/// conversation-added callback
- (void)conversationInfoDidAdd:(NSArray<JConversationInfo *> *)conversationInfoList {
NSLog(@"conversationInfoDidAdd");
}
/// conversation-change callback; triggered whenever conversation information changes
- (void)conversationInfoDidUpdate:(NSArray<JConversationInfo *> *)conversationInfoList {
NSLog(@"conversationInfoDidUpdate");
}
/// conversation-deleted callback
- (void)conversationInfoDidDelete:(NSArray<JConversationInfo *> *)conversationInfoList {
NSLog(@"conversationInfoDidDelete");
}
/// total unread count change callback
- (void)totalUnreadMessageCountDidUpdate:(int)count {
NSLog(@"totalUnreadMessageCountDidUpdate");
}
API description: Listens for conversation additions, removals, and changes. Configure it only once globally; subsequent calls overwrite the previous listener.
Related enums: Conversation, Event
let { Event } = JIM;
// Conversation-added listener: triggered by the first sent or received message, a locally inserted conversation, or synchronized multi-device conversation operations
jim.on(Event.CONVERSATION_ADDED, ({ conversations }) => {
console.log(conversations);
});
// Conversation-deleted listener: triggered by explicitly calling the conversation-deletion API or by a deletion synchronized from another device
jim.on(Event.CONVERSATION_REMOVED, ({ conversations }) => {
console.log(conversations);
});
// Conversation-changed listener: triggered by messages after the first sent or received message, message deletion, message updates, Mute Notifications, pinning, or synchronized multi-device conversation operations
jim.on(Event.CONVERSATION_CHANGED, ({ conversations }) => {
console.log(conversations);
});
You can register multiple listeners.
//conversation-added listener
JuggleIm.instance.getConversationManager().addConversationAddListener((convers)=>{
})
//conversation-changed listener
JuggleIm.instance.getConversationManager().addConversationUpdateListener((convers)=>{
})
//conversation-deleted listener
JuggleIm.instance.getConversationManager().addConversationDeleteListener((convers)=>{
})
//total unread count change listener
JuggleIm.instance.getConnectionManager().addTotalUnreadCountUpdateListener((count)=>{
})
You can register multiple listeners. Each listener requires a unique key, and the returned function removes the listener.
Example
import JuggleIM from 'juggleim-rnsdk';
// Add a conversation listener. Returns a function that removes the listener.
const unsubscribeConversation = JuggleIM.addConversationListener('conversation_key', {
// Conversation-added callback: the first sent or received message, a locally inserted conversation, or synchronized multi-device conversation operations
onConversationInfoAdd: (conversations) => {
console.log('New conversations:', conversations);
},
// Conversation-changed callback: messages after the first sent or received message, message deletion, message updates, Mute Notifications, pinning, or synchronized multi-device conversation operations
onConversationInfoUpdate: (conversations) => {
console.log('Updated conversations:', conversations);
},
// Conversation-deleted callback: explicitly calling the conversation-deletion API or a deletion synchronized from another device
onConversationInfoDelete: (conversations) => {
console.log('Deleted conversations:', conversations);
},
// Total unread count change callback. Triggered by operations that change the unread count, such as receiving a countable message (text, image, and so on) or clearing unread counts.
onTotalUnreadMessageCountUpdate: (count) => {
console.log('Total unread count updated:', count);
}
});
// remove the listener
// unsubscribeConversation();
Only one listener is supported; subsequent configuration overwrites the previous listener. If multiple parts of the application need to listen, handle all states in one listener and distribute secondary events in the business layer.
// Conversation-added callback: the first sent or received message, a locally inserted conversation, or synchronized multi-device conversation operations
JuggleIm.instance.onConversationInfoAdd = (List<ConversationInfo> conversations){
};
// Conversation-changed callback: messages after the first sent or received message, message deletion, message updates, Mute Notifications, pinning, or synchronized multi-device conversation operations
JuggleIm.instance.onConversationInfoUpdate = (List<ConversationInfo> conversations){
};
// Conversation-deleted callback: explicitly calling the conversation-deletion API or a deletion synchronized from another device
JuggleIm.instance.onConversationInfoDelete = (List<ConversationInfo> conversations){
};
// Total unread count change callback. Triggered by operations that change the unread count, such as receiving a countable message (text, image, and so on) or clearing unread counts.
JuggleIm.instance.onTotalUnreadMessageCountUpdate = (list) {
};