Top

iOS SDK 2.8.0 | kSearchDidFoundMessagesInAConversation

Comments

6 comments

  • Vladimir VYSKOCIL

    Hello,

    I asked the team about the issue, the response was the following :

    when receiving `kSearchDidFoundMessagesInAConversation` and iterate the `occurences` you need to to get the real messages from the found results using the time stamps of the messages `-(void) searchContextMessagesWithPeer:(id<PeerProtocol> _Nonnull)peer aroundTimestamps:(NSArray * _Nonnull)timestamps`

    After calling this method you will receive the same notification and could parse the result messages using `messages` key

    0
    Comment actions Permalink
  • Patrik Spisak

    What type of aroundTimestamps is expected? I see array of any 

    aroundTimestamps:(NSArray * _Nonnull)timestamps

    But If I pass an array of [Date] I got crash.

    var timeStamps = [Date]()

            

            if let messages = (notification.object as? NSDictionary)?["occurences"] as? [Message], let peer = conversation?.peer {

                

                for message in messages {

                    if let timeStamp = message.timestamp {

                        timeStamps.append(timeStamp)

                    }

                }

                

                serviceManager.conversationsSearchHelper.searchContextMessages(withPeer: peer, aroundTimestamps: timeStamps)

            }

    Also tried convert  message.tiemstamp to string in format "yyyy-MM-dd HH:mm:ss". This does not make application crash but still cant get second notification with "messages" key

    0
    Comment actions Permalink
  • Vladimir VYSKOCIL

    Hello Patrik,

    The type of the array elements is NSNumber.

    We have started working on better support of Swift for the iOS SDK, one of the task is to type array elements, here the declaration should have been (NSArray<NSNumber *> * _Nonnull) timestamps

    0
    Comment actions Permalink
  • Patrik Spisak

    Im still not able to get second call of notification. Something definitely Im doing wrong.

    var timeStamps = [NSNumber]()

            

            if let messages = (notification.object as? NSDictionary)?["occurences"] as? [Message], let peer = conversation?.peer {

                

                for message in messages {

                    if let timeStamp = message.timestamp {

                       

                        timeStamps.append((timeStamp.timeIntervalSince1970 as? NSNumber)!)

                    }

                }

                

                serviceManager.conversationsSearchHelper.searchContextMessages(withPeer: peer, aroundTimestamps: timeStamps)

            }

    searchContextMessages aroundTimestamps does not triggering notification with "messages" key.

    0
    Comment actions Permalink
  • Vladimir VYSKOCIL

    Here is the code we are using to achieve this :

    ```

        /**
         *  Request for the messages before and after a specific date. The messages are returned in didFindMessagesInConversation.
         *
         *  - Parameter beforeAndAfter: reference date
         *
         *  - Returns:
         */
        func getMessages(beforeAndAfter: [Date]) {
            var timestamps: Array<NSNumber> = []
            for date in beforeAndAfter {
                let timeInterval = NSNumber(value: UInt(date.timeIntervalSince1970 * 10E5))
                timestamps.append(timeInterval)
            }
            
            ServicesManager.sharedInstance()?.conversationsSearchHelper.searchContextMessages(withPeer: conversation.peer, aroundTimestamps: timestamps)
        }

    ```

    0
    Comment actions Permalink
  • Patrik Spisak

    Thanks,

    This was crucial thing what I missed in my code

    10E5
    0
    Comment actions Permalink

Please sign in to leave a comment.

Still can't find what you need?

  • Contact Us

    Do you have any question about Rainbow? Leave us a message to get more information.

    Contact
  • Ask the Community

    Do you need help? Ask your questions to the Community and get answers from other Rainbow users.

    Post message