【问题标题】:XMPP block messagesXMPP 阻止消息
【发布时间】:2014-02-27 17:32:34
【问题描述】:

我试图阻止我的 XMPP 客户端中的通信(基于 strophe.js 构建)。问题是它只会阻止我向我试图“静音”的联系人发送消息,但不会阻止来自该联系人的任何传入消息。

这里是逻辑(基于http://xmpp.org/rfcs/rfc3921.html#privacy):

1) 将“bill@domain.me”添加到我的“阻止”列表中

var recipient = "bill@domain.me"
var block = $iq({type: 'set'}).c('query', {xmlns: 'jabber:iq:privacy'}).
c('list', {name: 'block'}).
c('item', {type: 'jid', value: recipient, action: 'deny', order: 1}).
c('message');

2) 激活此列表

var setListActive = $iq({type: 'set'}).c('query', {xmlns: 'jabber:iq:privacy'}).c("active", {name: "block"});           
SGN.connection.sendIQ(setListActive);

可能是什么问题?

【问题讨论】:

    标签: xmpp strophe


    【解决方案1】:

    我可能错了,但我的理解是它应该是这样工作的。

    如果您检查要添加 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) });
    

    但是,如果您想阻止收到的邮件,则必须在每次收到邮件时手动检查发件人的 jids 与此列表。

    【讨论】:

      【解决方案2】:

      您还必须向该好友发送取消订阅状态。并且必须放置一个处理程序来处理存在类型=“未订阅”。在该处理程序上,发送取消订阅状态。

      屏蔽好友代码

      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;
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-12-02
        • 2014-12-02
        • 2015-03-04
        • 2012-02-07
        • 2023-03-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多