WuKongIM Flutter SDK reminder management functionality, including @mentions, system reminders and custom reminders
Reminder management is responsible for handling various types of reminder messages, such as @mentions, group join requests, system notifications, etc. Conversation reminders currently only support server-issued commands, and clients only need to listen for sync conversation reminders and refresh conversation messages.
Reminder items can only be sent from the server, clients are mainly responsible for receiving, displaying and managing reminder status
class ReminderManager { // Get reminders for specific channel static List<WKReminder> getChannelReminders(String channelId, int channelType) { try { final reminders = WKIM.shared.reminderManager.getWithChannel(channelId, channelType); print('Retrieved ${reminders.length} reminders'); return reminders; } catch (error) { print('Failed to get reminders: $error'); return []; } } // Get all pending reminders static List<WKReminder> getAllPendingReminders() { // Here we need to iterate through all channels to get reminders // Actual implementation may need SDK to provide corresponding API final List<WKReminder> allReminders = []; // Example: Get reminders for all conversations final conversations = WKIM.shared.conversationManager.getAll(); for (final conv in conversations) { final reminders = getChannelReminders(conv.channelID, conv.channelType); final pendingReminders = reminders.where((r) => r.done == 0).toList(); allReminders.addAll(pendingReminders); } return allReminders; } // Get reminders by type static List<WKReminder> getRemindersByType(String channelId, int channelType, int type) { final allReminders = getChannelReminders(channelId, channelType); return allReminders.where((reminder) => reminder.type == type).toList(); } // Get @mention reminders static List<WKReminder> getMentionReminders(String channelId, int channelType) { return getRemindersByType(channelId, channelType, ReminderType.mention); } // Get join request reminders static List<WKReminder> getJoinRequestReminders(String channelId, int channelType) { return getRemindersByType(channelId, channelType, ReminderType.joinRequest); } // Get system notice reminders static List<WKReminder> getSystemNoticeReminders(String channelId, int channelType) { return getRemindersByType(channelId, channelType, ReminderType.systemNotice); } // Get unread voice reminders static List<WKReminder> getUnreadVoiceReminders(String channelId, int channelType) { return getRemindersByType(channelId, channelType, ReminderType.unreadVoice); } // Count total reminders static int getTotalReminderCount() { final allReminders = getAllPendingReminders(); return allReminders.length; } // Count reminders by type static Map<int, int> getReminderCountByType() { final allReminders = getAllPendingReminders(); final Map<int, int> countMap = {}; for (final reminder in allReminders) { countMap[reminder.type] = (countMap[reminder.type] ?? 0) + 1; } return countMap; } // Check if has unread reminders static bool hasUnreadReminders(String channelId, int channelType) { final reminders = getChannelReminders(channelId, channelType); return reminders.any((reminder) => reminder.done == 0); } // Get reminder display text static String getReminderDisplayText(WKReminder reminder) { if (reminder.text.isNotEmpty) { return reminder.text; } // Return default text based on type switch (reminder.type) { case ReminderType.mention: return 'Someone mentioned me'; case ReminderType.joinRequest: return 'Join request'; case ReminderType.systemNotice: return 'System notice'; case ReminderType.unreadVoice: return 'Unread voice'; default: return 'New reminder'; } }}// Reminder type constantsclass ReminderType { static const int mention = 1; // @mention static const int joinRequest = 2; // Join request static const int systemNotice = 3; // System notice static const int unreadVoice = 4; // Unread voice static const int custom = 99; // Custom reminder}
// Listen for new remindersWKIM.shared.reminderManager.addOnNewReminderListener('key', (reminder) { // Handle new reminders});// Remove listenerWKIM.shared.reminderManager.removeOnNewReminderListener('key');
The key is a unique identifier for the listener, can be any string. The same key must be used when adding and removing listeners.
class WKReminder { int reminderID = 0; // Reminder ID String messageID = ''; // Message ID String channelID = ''; // Channel ID int channelType = 0; // Channel type int messageSeq = 0; // Message sequence number int type = 0; // Reminder type String text = ''; // Reminder content dynamic data; // Additional data int version = 0; // Version number int done = 0; // Completion status int needUpload = 0; // Whether needs upload (to business server) String publisher = ''; // Publisher}