[英]I want to receive all users message using smack(Not in Group Chat)
I am creating a chat application,one to one chatting is working properly,but when comes to multi user chat i am not able to listen their messages I am using smack for implementing the XMPP protocol Here is the code我正在创建一个聊天应用程序,一对一聊天工作正常,但是当涉及到多用户聊天时,我无法收听他们的消息我正在使用 smack 来实现 XMPP 协议这是代码
Server configuration part is
服务器配置部分是
public void serverCongig() throws XMPPException {
LOGGER.info(String.format("Initializing connection to server %1$s port
%2$d", server, port));
SmackConfiguration.setPacketReplyTimeout(packetReplyTimeout);
config = new ConnectionConfiguration(server,
port,PropertyReader.getPropertiesValue("server_domain"));
// config.setSASLAuthenticationEnabled(false);
config.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled);
connection = new XMPPConnection(config);
try
{
connection.connect();
LOGGER.info("Connected: " + connection.isConnected()+" Service
name"+connection.getServiceName());
chatManager = connection.getChatManager();
messageListener = new MyMessageListener();
}
catch(Exception e)
{
callThread();
e.printStackTrace();
}
finally
{
callThread();
}
}
Message listening part is class MyMessageListener implements MessageListener {消息监听部分是class MyMessageListener implements MessageListener {
@Override
public void processMessage(Chat chat, Message message) {
try
{
String from = message.getTo();
String body = message.getBody();
String toUser="";
LOGGER.info(String.format("Received message '%1$s' from %2$s", body, from));
String[] user=from.split("@");
for(int i=0;i<user.length;i++)
toUser=user[0];
LOGGER.info("Receiver Phone number"+toUser);
SendMsgToWhatsapp create=new SendMsgToWhatsapp();
try {
if(!body.equalsIgnoreCase(null))
{
create.processWhatsappMessage(toUser, body);
}
} catch (Exception ex) {
callThread();
// Logger.getLogger(XmppManager.class.getName()).log(Level.SEVERE, null, ex); // Logger.getLogger(XmppManager.class.getName()).log(Level.SEVERE, null, ex); } } catch(Exception e) { e.printStackTrace();
} } 捕捉(异常 e){ e.printStackTrace(); callThread();
调用线程(); } }
} }
I had a similar question and that's what I found: XEP-0313: Message Archive Management ( https://xmpp.org/extensions/xep-0313.html ) describes to work with the message archive.我有一个类似的问题,这就是我发现的: XEP-0313: Message Archive Management ( https://xmpp.org/extensions/xep-0313.html ) 描述了使用消息存档。
In smack you can use it like that在 smack 中你可以这样使用它
MamManager mamManager = MamManager.getInstanceFor(connection);
MamManager.MamQueryArgs mamQueryArgs = MamManager.MamQueryArgs.builder()
.limitResultsToJid(jid)
.setResultPageSizeTo(10)
.queryLastPage()
.build();
MamManager.MamQuery mamQuery = mamManager.queryArchive(mamQueryArgs);
List<Message> messages = mamQuery.getMessages();
for (Message m : messages) {
System.out.println(m.getBody());
}
But when I tried to use it, I received problems with dependencies in maven, so I loaded smack jar manually from dailybuilds ( https://download.igniterealtime.org/smack/dailybuilds/smack-SNAPSHOT-2020-07-21.zip ) and the remaining dependencies added through maven But when I tried to use it, I received problems with dependencies in maven, so I loaded smack jar manually from dailybuilds ( https://download.igniterealtime.org/smack/dailybuilds/smack-SNAPSHOT-2020-07-21.zip ) 以及通过 maven 添加的其余依赖项
In my case it work.就我而言,它有效。
https://download.igniterealtime.org/smack/docs/latest/javadoc/org/jivesoftware/smackx/mam/package-summary.html (smackx.mam javadoc) https://download.igniterealtime.org/smack/docs/latest/javadoc/org/jivesoftware/smackx/mam/package-summary.html (smackx.mam javadoc)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.