|
@@ -1,6 +1,7 @@
|
|
|
package com.drinkertea.test2smack;
|
|
|
|
|
|
import org.jivesoftware.smack.AbstractXMPPConnection;
|
|
|
+import org.jivesoftware.smack.MessageListener;
|
|
|
import org.jivesoftware.smack.chat2.ChatManager;
|
|
|
import org.jivesoftware.smack.packet.Message;
|
|
|
import org.jivesoftware.smack.packet.Presence;
|
|
@@ -9,17 +10,21 @@ import org.jivesoftware.smack.roster.RosterEntry;
|
|
|
import org.jivesoftware.smack.tcp.XMPPTCPConnection;
|
|
|
import org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration;
|
|
|
import org.jivesoftware.smackx.mam.MamManager;
|
|
|
+import org.jivesoftware.smackx.muc.HostedRoom;
|
|
|
import org.jivesoftware.smackx.muc.MultiUserChat;
|
|
|
import org.jivesoftware.smackx.muc.MultiUserChatManager;
|
|
|
+import org.jxmpp.jid.DomainBareJid;
|
|
|
import org.jxmpp.jid.EntityBareJid;
|
|
|
import org.jxmpp.jid.EntityFullJid;
|
|
|
import org.jxmpp.jid.impl.JidCreate;
|
|
|
import org.jxmpp.jid.parts.Resourcepart;
|
|
|
import org.jxmpp.stringprep.XmppStringprepException;
|
|
|
+import org.minidns.record.A;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Collection;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
public class XMPPClass {
|
|
|
|
|
@@ -30,15 +35,20 @@ public class XMPPClass {
|
|
|
public static EntityBareJid myJid;
|
|
|
public static ArrayList<ChatItem> chatItems = new ArrayList<ChatItem>();
|
|
|
public static List<Message> messages;
|
|
|
- public static MultiUserChat muc;
|
|
|
+ public static MultiUserChatManager manager;
|
|
|
+ public static List<MultiUserChat> listMuc = new ArrayList<>();
|
|
|
+ public static MultiUserChat activeMuc;
|
|
|
|
|
|
public static void XMPP_JoinRoom(String room_name, String nickname){
|
|
|
try {
|
|
|
- EntityBareJid jid = JidCreate.entityBareFrom(room_name);
|
|
|
- MultiUserChatManager manager = MultiUserChatManager.getInstanceFor(XMPPClass.connection);
|
|
|
- muc = manager.getMultiUserChat(jid);
|
|
|
+ EntityBareJid JIDRoom = JidCreate.entityBareFrom(room_name);
|
|
|
+ MultiUserChat muc = manager.getMultiUserChat(JIDRoom);
|
|
|
+ listMuc.add(muc);
|
|
|
Resourcepart room = Resourcepart.from(nickname);
|
|
|
- muc.join(room);
|
|
|
+ if(!muc.isJoined()){
|
|
|
+ muc.join(room);
|
|
|
+ }
|
|
|
+ activeMuc = muc;
|
|
|
for(EntityFullJid jid1 : muc.getOccupants()){
|
|
|
System.out.println(jid1);
|
|
|
}
|
|
@@ -81,17 +91,33 @@ public class XMPPClass {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public static void CreateRoomListMessage(int message_count){
|
|
|
+ public static List<Message> CreateRoomListMessage(int message_count, MultiUserChat muc_conn){
|
|
|
try {
|
|
|
- MamManager mamManager = MamManager.getInstanceFor(muc);
|
|
|
+
|
|
|
+ MamManager mamManager = MamManager.getInstanceFor(muc_conn);
|
|
|
MamManager.MamQueryArgs mamQueryArgs = MamManager.MamQueryArgs.builder()
|
|
|
.setResultPageSizeTo(message_count)
|
|
|
.queryLastPage()
|
|
|
.build();
|
|
|
MamManager.MamQuery mamQuery = mamManager.queryArchive(mamQueryArgs);
|
|
|
- messages = mamQuery.getMessages();
|
|
|
+ return mamQuery.getMessages();
|
|
|
}catch (Exception ex){
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static List<EntityBareJid> GenerateRoomList() throws Exception{
|
|
|
+ List<EntityBareJid> listRoom = new ArrayList<>();
|
|
|
+ manager = MultiUserChatManager.getInstanceFor(XMPPClass.connection);
|
|
|
+ List<DomainBareJid> domains = manager.getMucServiceDomains();
|
|
|
+ for (DomainBareJid domain : domains){
|
|
|
+ Map<EntityBareJid, HostedRoom> map = manager.getRoomsHostedBy(domain);
|
|
|
+ for(EntityBareJid ent : map.keySet()){
|
|
|
+ listRoom.add(ent);
|
|
|
+ System.out.println(ent);
|
|
|
+ }
|
|
|
}
|
|
|
+ return listRoom;
|
|
|
}
|
|
|
|
|
|
public static void GenerateChatList(){
|