Skip to content
This repository has been archived by the owner on Aug 1, 2019. It is now read-only.

[readme] Better description of integration with messaging service #95

Open
dodikk opened this issue Feb 24, 2017 · 11 comments
Open

[readme] Better description of integration with messaging service #95

dodikk opened this issue Feb 24, 2017 · 11 comments

Comments

@dodikk
Copy link

dodikk commented Feb 24, 2017

As a new user, I can't figure out which method is responsible for handling user's input.
It's not quite clear where to put the networking code invocation. Is it sendText ?
Oh, I'm subclassing the NMessengerViewController.

Ideally, I'd like to have the following topics documented :

  1. Where to invoke send message to network action ?
  2. How to handle the message received from network event properly?
  3. How to interact with the service while doing a Head Prefetching ?
@dodikk
Copy link
Author

dodikk commented Feb 27, 2017

So, in order to send a message, I have to make an override :

// Declared in NMessengerViewController
//
 override func sendText(_ text: String, isIncomingMessage:Bool) -> GeneralMessengerCell
    {
        let shouldSendToServer = !isIncomingMessage
        if (shouldSendToServer)
        {
            // trigger network service
            self.controller?.sendMessageAsync(text)
        }
        
        // otherwise - just render 
        return super.sendText(text, isIncomingMessage: isIncomingMessage)
    }

@dodikk
Copy link
Author

dodikk commented Feb 27, 2017

Here is a take on error handling #25
Haven't tried it yet.

@dodikk
Copy link
Author

dodikk commented Feb 27, 2017

Receiving a message from the network service :

    func chatDidReceiveMessages(_ messageList: ChatMessageList)
    {
        messageList.forEach
        {
            _ = self.sendText($0.text, isIncomingMessage: true)
        }
    }

@dodikk
Copy link
Author

dodikk commented Feb 27, 2017

I'm going to prepare a PR with readme changes these days.

@atainter
Copy link
Contributor

atainter commented Mar 1, 2017

Thank you. I'll merge it in.

@dodikk
Copy link
Author

dodikk commented Mar 1, 2017

@atainter , I still have some difficulties with the understanding of "async head prefetching". I'd like to cover this topic in my PR as well. Could you explain in a bit more details, please? #97

As a rule, a chat application involves the following actions :

  1. I have to request the history and subscribe to incoming chat messages in ViewDidLoad.
  2. As new messages arrive I should invoke "sendText()" or other "send__" functions on NMessengerViewController simultaneously (in order to not miss any messages).

I have not figured out yet how to insert the bubbles for past messages to the top. Is "clearALLMessages()" and invoke "send___()" in a loop the only way for doing that? Is it a correct approach? Does NMessenger take care of the unintended "blinking" animation in such case?

My use case might even require inserting messages in the middle of the conversation. Several thousand users per room (text conference) are expected.

So the idea is

Showing "latest N" messages as a new batch arrives and ignore the rest of the batch until the user scrolls up to see those. 

Not sure how to implement that with NMessenger although it seems promising as it's built on top of AsyncDisplayKit.

@dodikk
Copy link
Author

dodikk commented Apr 1, 2017

@atainter , the README has been updated. #114
Not sure how to complete history related part: I don't like "purge everything" approach but I have not figured out the alternative.

P.S. sorry for such a delay making this PR.

@dodikk
Copy link
Author

dodikk commented Jun 8, 2017

Not sure how to complete history related part: I don't like "purge everything" approach but I have not figured out the alternative.

Actually, it's possible to make a custom insertion using the method below.

super.messengerView.addMessages(_,
                                atIndex:,
                        scrollToMessage:,
                              animation:,
                             completion:)

The method is used as a part of batch fetching implementation.
https://github.com/eBay/NMessenger/blob/master/nMessenger/Source/Messenger/Components/NMessenger.swift#L203

@kurry421
Copy link

kurry421 commented Sep 21, 2017

@dodikk @atainter is it possible to send a typed message withOUT rendering on the ui?.. IE I just want to update the DB when a message is typed


override func sendText(_ text: String, isIncomingMessage:Bool) -> GeneralMessengerCell
   {
       let shouldSendToServer = !isIncomingMessage
       if (shouldSendToServer)
       {
           // trigger network service
           self.controller?.sendMessageAsync(text)
       }
      // otherwise - just render (To NOT DO This part)
       return super.sendText(text, isIncomingMessage: isIncomingMessage)
}

@dodikk
Copy link
Author

dodikk commented Sep 21, 2017

is it possible to send a typed message withOUT rendering on the ui

Override the function below and do not call super.

open override func onSendButtonTapped(havingText currentText: String)

@dodikk
Copy link
Author

dodikk commented Sep 21, 2017

Still, It might be a good idea to render the message before receiving an xmpp delivery confirmation to provide the user with some feedback.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants