5

How to get the DiscussionHistory of a MUC room from MultiUserChat? I am able to create MultiUserChat instance and room by using aSmack library, now I want to show all the previous conversations that happened in the room.

Anybody experienced in the same please help me. I Google searched a lot about this but still I did't get any proper documentation / explanation on this.

Flow
  • 23,572
  • 15
  • 99
  • 156
RajaReddy PolamReddy
  • 22,428
  • 19
  • 115
  • 166

1 Answers1

14
DiscussionHistory history = new DiscussionHistory();
history.setSince(date);

muc.join(nickname, null, history, SmackConfiguration.getReplyTimeout());

// Get historical message;
Message oldMsg = muc.nextMessage(timeout);

You can also use

history.setMaxChars()
history.setMaxStanzas()
history.setSeconds()

Some examples are in the test code. Check the test testDiscussionHistory.

http://fisheye.igniterealtime.org/browse/smack/trunk/test/org/jivesoftware/smackx/muc/MultiUserChatTest.java?hb=true

Robin
  • 24,062
  • 5
  • 49
  • 58
  • Here is it required to maintain same instance for MUC or we can create whatever we want. if single instance required how to maintain that MUC as single instance in throughout the application. – RajaReddy PolamReddy Apr 10 '13 at 04:45
  • here by using your code i am getting just one message from history(i.e first message ). even i set `history.setMaxStanzas(20)`. i want to get last 20 message from this history. please help me on this. – RajaReddy PolamReddy Apr 12 '13 at 05:02
  • 1
    You simply call nextMessage multiple times. Each call retrieves the next message. Eventually you will retrieve all the historical messages and block waiting for the next real time one. – Robin Apr 14 '13 at 19:00
  • i have one problem here, when i entered into a room i am getting history of that room properly. when i gone for another room immediately from that to room i am getting NPE at this line `Message oldMsg = muc.nextMessage(timeout);` how to avoid that even user enters into different rooms at any time..and also what is the best value for `timeout` here – RajaReddy PolamReddy Apr 15 '13 at 10:40
  • That is application dependent. Just check the return value for null. You can call the nextMessage() with no parameter if you want to block indefinitely. This would never return null as it will not return unless another message is available. This would require an interrupt though to stop the wait, which makes things more complex. – Robin Apr 15 '13 at 15:34
  • when use like this nextMessage() it's blocking the UI for long time when i was back into new room immediately from another room. i am still confusing and not able to solve the issue. can u please help me on this issue.. – RajaReddy PolamReddy Apr 17 '13 at 05:00
  • Hi all I am getting this error "This room is not Anonymus". Any ideas – KK_07k11A0585 Aug 24 '13 at 10:13