问题
I can creating and joining MUC rooms. But user disconnects from the Openfire server, he is removed from the group on the server side. How can i similar to what Whatsapp does, i.e. even if the user goes offline, he is still part of the MUC room (which is configured to be persistent on the server side) and will receive messages from other occupants.
回答1:
When inviting an user, you have to grant him Membership:
MultiUserChat muc = multiUserChatManager.getMultiUserChat("foo@conference.myserver");
muc.invite("jhondoe@myserver","Join this groupchat!");
then you can grant him voice and you must grantMembership (or Ownership or Moderation as you like/need):
muc.grantVoice("jhondoe@myserver");
muc.grantMembership("jhondoe@myserver");
finally you have to integrate a list like that with your client:
public List<String> retriveAllAffialiateOfMuc(MultiUserChat muc) throws NoResponseException, XMPPErrorException, NotConnectedException
{
List<Affiliate> affiliatesMembers = new ArrayList<Affiliate>();
if (muc.getAdmins() != null)
{
affiliatesMembers.addAll( muc.getAdmins() );
}
if ( muc.getMembers() != null)
{
affiliatesMembers.addAll( muc.getMembers() );
}
if ( muc.getOwners() != null )
{
affiliatesMembers.addAll( muc.getOwners() );
}
if (affiliatesMembers.size() == 0)
{
System.out.println("Error: looking for a non existant room");
return new ArrayList<String>(0);
}
List<String> affiliateMembersNames = new ArrayList<String>(affiliatesMembers.size());
for (Affiliate affiliate : affiliatesMembers)
{
affiliateMembersNames.add(affiliate.getJid().toString());
}
return affiliateMembersNames;
}
So you'll have a list of all users affiliate to the room. You can use this list in some callback to make a list of "all members" like in WhatsApp.
Look at the end of this page: https://www.igniterealtime.org/builds/smack/dailybuilds/documentation/extensions/muc.html
(dont' forget to vote!)
来源:https://stackoverflow.com/questions/37431642/create-muc-group-like-whatsapp-android