First of all, XEP-0022 is obsoleted. It's best to follow the XSF advice - it's the foundation which standardizes XMPP - and use more modern XEPs addressing the issue. That being said, I would use XEP-0085: Chat State Notifications for <composing/>
like notifications and XEP-0333: Chat Markers for <received/>
or <displayed/>
receipts.
How can I ensure that the message is delivered and displayed to the 2nd user without the headache of making both online at the same time.
You should use XEP-313: Message Archive Management implemented by MongooseIM's (or ejabberd's) mod_mam. It keeps chat history in a database of the server, allowing you to fetch past conversations at any time, without the chat partners being online anymore.
By default, mod_mam does not store messages which do not carry text (have no or empty <body/>
subelement to be precise), but it's configurable and in order to store XEP-333 chat markers, you would have to reconfigure it. It probably doesn't make sense to store XEP-85 notifications, since they only make sense when both users are online.
Once you're able to fetch chat markers, the client app would have to query the message archive, process the results and find any chat markers which correspond to messages from users who are now offline. Please bear in mind that while a regular marker sent from an online user would look like this (example 4 from XEP-333):
<message from='[email protected]/throne'
id='message-2'
to='[email protected]/westminster'>
<thread>sleeping</thread>
<received xmlns='urn:xmpp:chat-markers:0' id='message-1'/>
</message>
A chat marker returned from the archive for user [email protected]
would look like this - it would be wrapped in an "envelope" marking that it's an archive query result:
<message id='aeb213'
from='[email protected]'
to='[email protected]/westminster'>
<result xmlns='urn:xmpp:mam:2' queryid='f27' id='28482-98726-73623'>
<forwarded xmlns='urn:xmpp:forward:0'>
<delay xmlns='urn:xmpp:delay' stamp='2010-07-10T23:08:25Z'/>
<message from='[email protected]/throne'
id='message-2'
to='[email protected]/westminster'>
<thread>sleeping</thread>
<received xmlns='urn:xmpp:chat-markers:0' id='message-1'/>
</message>
</forwarded>
</result>
</message>
This way [email protected]
knows that [email protected]
has received <message id='message-1'/>
, even if [email protected]
is currently offline.