您还必须向该好友发送取消订阅状态。并且必须放置一个处理程序来处理存在类型=“未订阅”。在该处理程序上,发送取消订阅状态。
屏蔽好友代码
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;
}