XMPP块消息
我试图阻止XMPP客户端(构建在strophe.js之上)中的通信。问题是,它只会阻止我发送给某个联系人的消息,而不会阻止该联系人发送的任何传入消息 以下是逻辑(基于): 1) 加上“bill@domain.me到我的“阻止”列表 2) 使此列表处于活动状态XMPP块消息,xmpp,strophe,Xmpp,Strophe,我试图阻止XMPP客户端(构建在strophe.js之上)中的通信。问题是,它只会阻止我发送给某个联系人的消息,而不会阻止该联系人发送的任何传入消息 以下是逻辑(基于): 1) 加上“bill@domain.me到我的“阻止”列表 2) 使此列表处于活动状态 var setListActive = $iq({type: 'set'}).c('query', {xmlns: 'jabber:iq:privacy'}).c("active", {name: "block"});
var setListActive = $iq({type: 'set'}).c('query', {xmlns: 'jabber:iq:privacy'}).c("active", {name: "block"});
SGN.connection.sendIQ(setListActive);
有什么问题吗?我可能错了,但我所理解的是它应该是这样工作的
如果您查看要添加JID的列表,您将看到它们都在那里:
var getMyPrivacyList = $iq({type: 'get'}).c('query', {xmlns: 'jabber:iq:privacy'}).c("list", {name: "block"});
APP.connection.sendIQ(getMyPrivacyList,function success(response) { console.log(response) });
但是,如果您想阻止传入的邮件,则必须在每次收到邮件时根据此列表手动检查发件人的JID。您还必须将取消订阅状态发送给该好友。并且必须放置一个处理程序来处理presence type=“unsubscribed”。在该处理程序上,发送“取消订阅状态” 阻止好友的代码
const blockFriend_Stanza=function(fromJid, friendJid,cb_success){
connection.send($pres({ to: friendJid, type: "unavailable", }));
connection.send($pres({ to: friendJid, type: "unsubscribe" }));
let UnblockIq=$iq({ 'type': 'set', 'id': 'blockFriend', from: fromJid })
.c("block", {xmlns: "urn:xmpp:blocking"}).c("item", {jid: friendJid});
connection.sendIQ(UnblockIq,
response=>{
console.log("onClick_lnkBlockFriend",response)
if(response.getAttribute("type")=="result"){
cb_success();
}
},
error=>{
console.log("onClick_lnkBlockFriend Error",error)
}
);
let updateRosterIq=$iq({ 'type': 'set', 'id': 'acceptedReq' })
.c("query", {xmlns: Strophe.NS.ROSTER}).c("item", {jid: friendJid,ask:null, subscription: "remove"});
connection.sendIQ(updateRosterIq,response=>{ console.log("onClick_lnkBlockFriend_rosterRemoval",response)},error=>{ console.log("onClick_lnkBlockFriend_rosterRemoval Error",error)});
}
取消订阅处理程序的代码
function onPresence(presence) {
console.log("presense obj",presence);
var presence_type = $(presence).attr('type'); // unavailable, subscribed, etc...
var from = $(presence).attr('from'); // presence coming from jabber_id
var to = $(presence).attr('to'); // presence coming to jabber_id
if(presence_type == 'unsubscribe')
{
connection.send($pres({ to: from, type: "unsubscribed" }));
connection.send($pres({ to: from, type: "unavailable", }));
}
return true;
}
function onPresence(presence) {
console.log("presense obj",presence);
var presence_type = $(presence).attr('type'); // unavailable, subscribed, etc...
var from = $(presence).attr('from'); // presence coming from jabber_id
var to = $(presence).attr('to'); // presence coming to jabber_id
if(presence_type == 'unsubscribe')
{
connection.send($pres({ to: from, type: "unsubscribed" }));
connection.send($pres({ to: from, type: "unavailable", }));
}
return true;
}