当前知识库站点已不再维护。请移步新版知识库:https://help.rongcloud.cn/

会话列表过滤某个特定会话

会话列本可以按类型来显示会话,但是如果想要过滤某个类型中某个特定的会话,可以参考本知识库实现。
发布时间: 2019-08-06 15:23

回答:

实现思路:

分别在加载数据源和接收消息时候进行过滤。


实现代码:

1. 在加载数据源时候过滤

- (NSMutableArray *)willReloadTableData:(NSMutableArray *)dataSource {
    NSArray *temp = [dataSource copy];
    for (int i = 0;i< temp.count;i++) {
        RCConversationModel *model = temp[i];
        if ([model.senderUserId isEqualToString:@"需要过滤的发送消息者的 userId"]) {
            [dataSource removeObjectAtIndex:i];
        }
    }
    return dataSource;
}


2. 在接收消息时候过滤:

- (void)didReceiveMessageNotification:(NSNotification *)notification {
    RCMessage *message = notification.object;
    if (![message.senderUserId isEqualToString:@"需要过滤的发送消息者的 userId"]) {
        [super didReceiveMessageNotification:notification];
    }
}


3. 如果需要屏蔽对应的提示音:

- (BOOL)onRCIMCustomAlertSound:(RCMessage *)message {
    if ([message.senderUserId isEqualToString:@"需要过滤的发送消息者的 userId"]) {
        return YES;
    }
    return NO;
}