差别
这里会显示出您选择的修订版和当前版本之间的差别。
两侧同时换到之前的修订记录 前一修订版 后一修订版 | 前一修订版 | ||
start:400webimintegration:contact_management [2016/12/06 02:48] liulj [将好友移出黑名单] |
start:400webimintegration:contact_management [2017/01/22 08:58] liulj |
||
---|---|---|---|
行 5: | 行 5: | ||
查询好友列表时,要注意 subscription (both, to, from) 为不同值的处理。此处默认 both 和 to 的为好友,开发者自定义处理,保持跟 APP 端处理一致即可。 | 查询好友列表时,要注意 subscription (both, to, from) 为不同值的处理。此处默认 both 和 to 的为好友,开发者自定义处理,保持跟 APP 端处理一致即可。 | ||
- | <sxh javascript> | + | <code javascript> |
conn.getRoster({ | conn.getRoster({ | ||
success: function ( roster ) { | success: function ( roster ) { | ||
行 11: | 行 11: | ||
/** [ | /** [ | ||
{ | { | ||
- | jid:"asemoemo#chatdemoui_test1@easemob.com", | + | jid:'asemoemo#chatdemoui_test1@easemob.com', |
- | name:"test1", | + | name:'test1', |
- | subscription: "both" | + | subscription: 'both' |
} | } | ||
] | ] | ||
行 26: | 行 26: | ||
}, | }, | ||
}); | }); | ||
- | </sxh> | + | </code> |
===== 添加/删除好友请求 ===== | ===== 添加/删除好友请求 ===== | ||
行 32: | 行 32: | ||
通过 SDK 的 subscribe 和 unsubscribe 进行添加或者删除好友操作,登录用户通过注册 onPresence,监听对方的添加或者删除好友请求,并做相应的处理。 | 通过 SDK 的 subscribe 和 unsubscribe 进行添加或者删除好友操作,登录用户通过注册 onPresence,监听对方的添加或者删除好友请求,并做相应的处理。 | ||
- | <sxh javascript> | + | <code javascript> |
//easemobwebim-sdk中收到联系人订阅请求的处理方法,具体的type值所对应的值请参考xmpp协议规范 | //easemobwebim-sdk中收到联系人订阅请求的处理方法,具体的type值所对应的值请参考xmpp协议规范 | ||
var handlePresence = function ( e ) { | var handlePresence = function ( e ) { | ||
行 55: | 行 55: | ||
} | } | ||
}; | }; | ||
- | </sxh> | + | </code> |
===== 添加好友 ===== | ===== 添加好友 ===== | ||
- | <sxh javascript> | + | <code javascript> |
// 添加好友 | // 添加好友 | ||
var addFriends = function () { | var addFriends = function () { | ||
conn.subscribe({ | conn.subscribe({ | ||
- | to: "username", | + | to: 'username', |
// Demo里面接收方没有展现出来这个message,在status字段里面 | // Demo里面接收方没有展现出来这个message,在status字段里面 | ||
- | message: "加个好友呗!" | + | message: '加个好友呗!' |
}); | }); | ||
}; | }; | ||
- | </sxh> | + | </code> |
===== 处理好友请求 ===== | ===== 处理好友请求 ===== | ||
行 77: | 行 77: | ||
==== 同意添加对方为好友 ==== | ==== 同意添加对方为好友 ==== | ||
- | <sxh javascript> | + | <code javascript> |
conn.listen({ | conn.listen({ | ||
onPresence: function ( message ) { | onPresence: function ( message ) { | ||
行 93: | 行 93: | ||
/*同意添加好友操作的实现方法*/ | /*同意添加好友操作的实现方法*/ | ||
conn.subscribed({ | conn.subscribed({ | ||
- | to: "username", | + | to: 'username', |
- | message : "[resp:true]" | + | message : '[resp:true]' |
}); | }); | ||
conn.subscribe({//需要反向添加对方好友 | conn.subscribe({//需要反向添加对方好友 | ||
to: e.from, | to: e.from, | ||
- | message : "[resp:true]" | + | message : '[resp:true]' |
}); | }); | ||
} | } | ||
} | } | ||
- | </sxh> | + | </code> |
==== 拒绝添加对方为好友 ==== | ==== 拒绝添加对方为好友 ==== | ||
- | <sxh javascript> | + | <code javascript> |
conn.listen({ | conn.listen({ | ||
onPresence: function ( message ) { | onPresence: function ( message ) { | ||
行 122: | 行 122: | ||
/*拒绝添加好友的方法处理*/ | /*拒绝添加好友的方法处理*/ | ||
conn.unsubscribed({ | conn.unsubscribed({ | ||
- | to: "username", | + | to: 'username', |
- | message : "rejectAddFriend" | + | message : 'rejectAddFriend' |
}); | }); | ||
} | } | ||
} | } | ||
- | </sxh> | + | </code> |
===== 删除好友 ===== | ===== 删除好友 ===== | ||
- | <sxh javascript> | + | <code javascript> |
// 删除好友 | // 删除好友 | ||
var removeFriends = function () { | var removeFriends = function () { | ||
行 145: | 行 145: | ||
}); | }); | ||
}; | }; | ||
- | </sxh> | + | </code> |
===== 黑名单 ===== | ===== 黑名单 ===== | ||
行 153: | 行 153: | ||
将好友加入黑名单后,对方好友列表依然可以看到已方,但无法向已方发送消息。 | 将好友加入黑名单后,对方好友列表依然可以看到已方,但无法向已方发送消息。 | ||
- | <sxh javascript> | + | <code javascript> |
// list的结构为{username_1: {}, username_2: {}...},拉黑好友需要将拉黑后的黑名单里的好友信息全部传入, | // list的结构为{username_1: {}, username_2: {}...},拉黑好友需要将拉黑后的黑名单里的好友信息全部传入, | ||
// 如黑名单此时已有A,B两位好友,现想将C也拉进黑名单,正确的操作是同时将ABC的信息都传入接口中。 | // 如黑名单此时已有A,B两位好友,现想将C也拉进黑名单,正确的操作是同时将ABC的信息都传入接口中。 | ||
行 186: | 行 186: | ||
// user_1 | // user_1 | ||
asdfghj: { | asdfghj: { | ||
- | jid: "easemob-demo#chatdemoui_asdfghj@easemob.com", | + | jid: 'easemob-demo#chatdemoui_asdfghj@easemob.com', |
- | name: "asdfghj", | + | name: 'asdfghj', |
subscription: 'both', | subscription: 'both', | ||
order: 2, | order: 2, | ||
行 194: | 行 194: | ||
// user_2 | // user_2 | ||
wjy6: { | wjy6: { | ||
- | jid: "easemob-demo#chatdemoui_wjy6@easemob.com", | + | jid: 'easemob-demo#chatdemoui_wjy6@easemob.com', |
- | name: "wjy6", | + | name: 'wjy6', |
subscription: 'both', | subscription: 'both', | ||
order: 3, | order: 3, | ||
行 212: | 行 212: | ||
}); | }); | ||
} | } | ||
- | </sxh> | + | </code> |
==== 获取黑名单列表 ==== | ==== 获取黑名单列表 ==== | ||
行 218: | 行 218: | ||
调用getBlacklist函数获取好友黑名单列表。调用这个函数时,会回调conn.listen里的onBlacklistUpdate函数,具体细节请参照[[im:400webimintegration:25intiate|Web SDK基础功能]]。 | 调用getBlacklist函数获取好友黑名单列表。调用这个函数时,会回调conn.listen里的onBlacklistUpdate函数,具体细节请参照[[im:400webimintegration:25intiate|Web SDK基础功能]]。 | ||
- | <sxh javascript> | + | <code javascript> |
var getBlackList = function () { | var getBlackList = function () { | ||
conn.getBlacklist(); | conn.getBlacklist(); | ||
}; | }; | ||
- | </sxh> | + | </code> |
==== 将好友移出黑名单 ==== | ==== 将好友移出黑名单 ==== | ||
行 228: | 行 228: | ||
将好友移出黑名单的机制是,将移出后某好友后黑名单中的好友组成一个list,传入接口重建黑名单。例如,黑名单中有ABC三个人,需要移出A,则将B和C组合成一个list传入接口。若list为空,则清空黑名单。 | 将好友移出黑名单的机制是,将移出后某好友后黑名单中的好友组成一个list,传入接口重建黑名单。例如,黑名单中有ABC三个人,需要移出A,则将B和C组合成一个list传入接口。若list为空,则清空黑名单。 | ||
- | <sxh javascript> | + | <code javascript> |
// 将好友从黑名单拉出来 | // 将好友从黑名单拉出来 | ||
var removeBlackList = function () { | var removeBlackList = function () { | ||
行 234: | 行 234: | ||
{ | { | ||
wjy6: { | wjy6: { | ||
- | jid: "easemob-demo#chatdemoui_mengyuanyuan01@easemob.com", | + | jid: 'easemob-demo#chatdemoui_mengyuanyuan01@easemob.com', |
- | name: "mengyuanyuan01", | + | name: 'mengyuanyuan01', |
- | order: "2", | + | order: '2', |
- | type: "jid" | + | type: 'jid' |
} | } | ||
}, | }, | ||
{ | { | ||
mengyuanyuan: { | mengyuanyuan: { | ||
- | jid: "easemob-demo#chatdemoui_wjy6@easemob.com", | + | jid: 'easemob-demo#chatdemoui_wjy6@easemob.com', |
- | name: "wjy6", | + | name: 'wjy6', |
- | order: "4", | + | order: '4', |
- | type: "jid", | + | type: 'jid', |
} | } | ||
} | } | ||
行 260: | 行 260: | ||
}); | }); | ||
}; | }; | ||
- | </sxh> | + | </code> |