注册

消息内容检索

在会话列表界面实现消息内容的搜索 环信现在可以实现吗
已邀请:
可以,调用我们的搜索的方法去搜索就行
/*!

 *  \~chinese

 *  从数据库获取包含指定内容的消息,取到的消息按时间排序,如果参考的时间戳为负数,则从最新消息向前取,如果aCount小于等于0当作1处理

 *

 *  @param aKeywords        搜索关键字,如果为空则忽略

 *  @param aTimestamp       参考时间戳

 *  @param aCount           获取的条数

 *  @param aSender          消息发送方,如果为空则忽略

 *  @param aDirection       消息搜索方向

 *  @param aCompletionBlock 完成的回调

 *

 *  \~english

 *  Load messages with specified keyword, returning messages are sorted by receiving timestamp. If reference timestamp is negative, load from the latest messages; if message count is negative, count deal with 1 and load one message that meet the condition.

 *

 *  @param aKeywords        Search content, will ignore it if it's empty

 *  @param aTimestamp       Reference timestamp

 *  @param aCount           Count of messages to load

 *  @param aSender          Message sender (optional)

 *  @param aDirection       Message search direction

 *  @param aCompletionBlock The callback block of completion

 *

 */

- (void)loadMessagesWithKeyword:(NSString*)aKeyword

                      timestamp:(long long)aTimestamp

                          count:(int)aCount

                       fromUser:(NSString*)aSender

                searchDirection:(EMMessageSearchDirection)aDirection

                     completion:(void (^)(NSArray *aMessages, EMError *aError))aCompletionBlock;这个方法
我参考demo里面的群组查找聊天记录 
_conversation = [[EMClient sharedClient].chatManager getConversation:self.conversation type:EMConversationTypeChat createIfNotExist:NO];
在会话列表界面 会话ID和会话类型 这两个参数 要怎么写
      [self.conversation loadMessagesWithKeyword:searchBar.text timestamp:[self.datePicker.date timeIntervalSince1970]*1000 count:SEARCHMESSAGE_PAGE_SIZE fromUser:self.textField.text searchDirection:EMMessageSearchDirectionUp completion:^(NSArray *aMessages, EMError *aError) {

          ConversationListController *strongSelf = weakSelf;

          if (strongSelf) {

              if([aMessages count]<SEARCHMESSAGE_PAGE_SIZE) {

                  strongSelf.hasMore = NO;

              } else {

                  strongSelf.hasMore = YES;

              }

              [strongSelf.searchController.resultsSource removeAllObjects];

              [strongSelf.searchController.resultsSource addObjectsFromArray:[[aMessages reverseObjectEnumerator] allObjects]];

              [strongSelf.searchController.searchResultsTableView reloadData];

          }

      }];
 
会话ID  接收方的id  会话类型   单聊或者群聊,聊天室
可是会话列表有很多不同id的会话, 类型 有单聊也有群聊 怎么写
这个只能遍历去搜索了,没有其他的办法了
那环信这边有没有一个可以获取所有会话ID和类型的方法
这样遍历搜索后 为什么只能搜索到会话列表第一条会话的消息内容 for(int i =0;i<self.conversationsArray.count;i++){

          EMConversation * Conversation = self.conversationsArray[i];

          self.conversation = [[EMClient sharedClient].chatManager getConversation:Conversation.conversationId type:Conversation.type createIfNotExist:NO];

          __weak typeof(self) weakSelf = self;

          [self.conversation loadMessagesWithKeyword:searchBar.text timestamp:[self.datePicker.date timeIntervalSince1970]*1000 count:SEARCHMESSAGE_PAGE_SIZE fromUser:self.textField.text searchDirection:EMMessageSearchDirectionUp completion:^(NSArray *aMessages, EMError *aError) {

              ConversationListController *strongSelf = weakSelf;

              if (strongSelf) {

                  if([aMessages count]<SEARCHMESSAGE_PAGE_SIZE) {

                      strongSelf.hasMore = NO;

                  }else {

                      strongSelf.hasMore = YES;

                  }

                  [strongSelf.searchController.resultsSource removeAllObjects];

                  [strongSelf.searchController.resultsSource addObjectsFromArray:[[aMessages reverseObjectEnumerator] allObjects]];

                  [strongSelf.searchController.searchResultsTableView reloadData];

              }

          }];

      }
 
          [self.conversation loadMessagesWithKeyword:searchBar.text timestamp:[self.datePicker.date timeIntervalSince1970]*1000 count:SEARCHMESSAGE_PAGE_SIZE fromUser:self.textField.text searchDirection:EMMessageSearchDirectionUp completion:^(NSArray *aMessages, EMError *aError) {
fromUser:传 nil        时间戳单位要求是毫秒,
搜索出结果后点击cell 怎么就崩了 环信的demo也会崩
这个是群组搜索聊天记录崩溃吗
在EaseMessageViewController.h中声明这个方法 - (NSArray *)formatMessages:(NSArray *)messages;
然后SearchChatViewController 在这个类 98行 加上这段代码//MARK:搜索崩溃处理

                    [strongSelf.messsagesSource removeAllObjects];

                    [strongSelf.dataArray removeAllObjects];

                    NSArray *formattedMessages = [self formatMessages:aMessages];
在会话列表搜索出消息内容后点击跳到SearchChatViewController.m 这个类后怎么传相对应的会话标题到这个界面
SearchMessageViewController 198行跳转时自己添加
刚发的消息内容 然后搜索就搜索不到 退出一下程序 再进来 才能搜索到 怎么回事
先到本地沙盒看下DB中有没有保存该条消息,有保存就能搜索到
那应该没有插入db,消息有没有发送成功 这些都是从本地数据查询的

要回复问题请先登录注册