gpt4 book ai didi

xmpp - XMPP 多用户 session 室收到重复消息

转载 作者:行者123 更新时间:2023-12-04 22:18:48 24 4
gpt4 key购买 nike

当device1向 session 室“del@conference.jabber.org”发送消息时该消息显示在聊天列表中,同时显示由 session 室“del@conference.jabber.org”发送的重复消息。我卡住了,为什么我收到重复的消息。

public void setConnection(XMPPConnection connection) {
this.connection = connection;
if (connection != null) {
PacketFilter filter = new MessageTypeFilter(Message.Type.groupchat);
connection.addPacketListener(new PacketListener() {
@Override
public void processPacket(Packet packet) {
Message message = (Message) packet;
if (message.getBody() != null) {
String fromName = StringUtils.parseBareAddress(message.getFrom());
String[] parts = fromName.split("@");
String from = parts[0].trim();
messages.add(from + ":");
messages.add(message.getBody());
// Add the incoming message to the list view
mHandler.post(new Runnable() {
public void run() {
setListAdapter();
}
});
}
}
}, filter);
}
}

发送消息是点击按钮,如下所示

Button send = (Button) this.findViewById(R.id.sendBtn);
send.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Message mg = muc.createMessage();
String text = textMessage.getText().toString();
mg.setBody(text);
Log.i("XMPPChatDemoActivity ", "Sending text ");
if (connection != null) {
connection.sendPacket(mg);
messages.add("Me :");
messages.add(text);
setListAdapter();
}
textMessage.setText("");
}
});

这是我为连接 session 室而写的

muc = new MultiUserChat(connection, "del@conference.jabber.org");
muc.join("alias name","password");

发送消息时输出我得到的信息

me: hello
del: hello

我想要的是当我发送消息时没有重复的消息,即

me: hello

最佳答案

当您在 MUC 房间时,您会收到所有消息的副本,包括您自己的消息。 http://xmpp.org/extensions/xep-0045.html#message - “并将消息反射(reflect)到每个乘员的完整 JID。”

因此对于 MUC(不是直接消息),如果您同时登录发送和接收(假设您有足够的权限发布等),您将得到一个副本。您的选择主要是要么在发送时不记录它(这是大多数客户选择的选项),要么尝试进行智能消息匹配以检测您何时收到自己的消息并将其删除。前一个选项确保每个人都能看到一致的消息排序 View ,有些人认为这非常有用。

关于xmpp - XMPP 多用户 session 室收到重复消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25519721/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com