Hosting user relationship data
Update time: 2024/03/14 18:45:31
SDK provides a service of hosting user relationship, including blacklist and mute list.
Blacklist
- If an user is added to the blacklist, you cannot receive any message from the user.
- If an user is removed from the blacklist, you will receive message from the user again.
Mute list
- SDK is used to maintain the mute list only, which will be determined by the developer based on mute list.
Initialization parameters
- Not all initialization parameters are listed here. Please refer to Initialize SDK, and initialization parameters are given in other chapters.
- Initialization parameters for connection
- Initialization parameters for multi-device login
- Initialization parameters for messages
- Initialization parameters for team
- Initialization parameters for user profile
- Initialization parameters for friendship
- Initialization parameters for user relationship
- Initialization parameters for session
- Initialization parameters for system notifications
- Synchronization completed
- Complete initialization codes
Sample codes
javascriptvar nim = NIM.getInstance({
onblacklist: onBlacklist,
onsyncmarkinblacklist: onMarkInBlacklist,
onmutelist: onMutelist,
onsyncmarkinmutelist: onMarkInMutelist
});
function onBlacklist(blacklist) {
console.log('receive blacklist', blacklist);
data.blacklist = nim.mergeRelations(data.blacklist, blacklist);
data.blacklist = nim.cutRelations(data.blacklist, blacklist.invalid);
refreshBlacklistUI();
}
function onMarkInBlacklist(obj) {
console.log(obj);
console.log(obj.account + 'is' + (obj.isAdd ? 'added to' : 'removed from') + 'blacklist');
if (obj.isAdd) {
addToBlacklist(obj);
} else {
removeFromBlacklist(obj);
}
}
function addToBlacklist(obj) {
data.blacklist = nim.mergeRelations(data.blacklist, obj.record);
refreshBlacklistUI();
}
function removeFromBlacklist(obj) {
data.blacklist = nim.cutRelations(data.blacklist, obj.record);
refreshBlacklistUI();
}
function refreshBlacklistUI() {
// Refresh The API
}
function onMutelist(mutelist) {
console.log('receive mute list', mutelist);
data.mutelist = nim.mergeRelations(data.mutelist, mutelist);
data.mutelist = nim.cutRelations(data.mutelist, mutelist.invalid);
refreshMutelistUI();
}
function onMarkInMutelist(obj) {
console.log(obj);
console.log(obj.account + 'inactively' + (obj.isAdd ? 'added' : 'removed') + 'mute list');
if (obj.isAdd) {
addToMutelist(obj);
} else {
removeFromMutelist(obj);
}
}
function addToMutelist(obj) {
data.mutelist = nim.mergeRelations(data.mutelist, obj.record);
refreshMutelistUI();
}
function removeFromMutelist(obj) {
data.mutelist = nim.cutRelations(data.mutelist, obj.record);
refreshMutelistUI();
}
function refreshMutelistUI() {
// Refresh The API
}
Parameter description
onblacklist
: It is a callback for synchronizing blacklist, , by which blacklist is inputblacklist
.- The attribute
invalid
ofblacklist
contains deleted blacklist. - It is an increment callback, and nim.mergeRelations and nim.cutRelations can be invoked to merge data.
- The attribute
onsyncmarkinblacklist
: It is a callback by current user after "Add to a blocklist/Remove from a blocklist" operation at other clients, and a parameter containing two fields will be input:account
: It is the account to be added to or removed from the blocklist.isAdd
:true
means adding to the blacklist;false
means removing from the blacklist.reocrd
: It is an assembled object.
onmutelist
: It is the callback for synchronizing mute list, and the mute listmutelist
will be input.- The attribute
invalid
ofmutelist
contains deleted mute list. - It is an increment callback, and nim.mergeRelations and nim.cutRelations can be invoked to merge data.
- The attribute
onsyncmarkinmutelist
: It is a callback by current user after "Add to mute list/removed from mute list" operation at other clients, and a parameter containing two fields will be input:account
: It is the account to be added to or removed from mute list.isAdd
:true
means adding to the mute list;false
means removing from the mute list.reocrd
: It is an assembled object.
Add to a blocklist/Remove from a blocklist
- The following two features can be enabled with this API. The actual features are determined by parameter
isAdd
.- If
isAdd
istrue
, theaccount
will be added to blacklist.- If an user is added to the blacklist, you cannot receive any message from the user.
- If
isAdd
isfalse
, theaccount
will be removed from blacklist.- If an user is removed from the blacklist, you will receive message from the user again.
- If
- For each feature, SDK provides related independent API.
javascriptnim.markInBlacklist({
account: 'account',
// `true` means to be added to the blacklist; `false` means to be removed from the blocklist.
isAdd: true,
done: markInBlacklistDone
});
function markInBlacklistDone(error, obj) {
console.log(error);
console.log(obj);
console.log('is' + obj.account + (isAdd ? 'added to blacklist' : 'removed from blacklist') + (!error?'Successful':'failed'));
if (!error) {
onMarkInBlacklist(obj);
}
}
Add to a blocklist
- If an user is added to the blacklist, you cannot receive any message from the user.
- nim.markInBlacklist will be called in SDK to complete actual work.
javascriptnim.addToBlacklist({
account: 'account',
done: addToBlacklistDone
});
function addToBlacklistDone(error, obj) {
console.log(error);
console.log(obj);
console.log('added to blacklist' + (!error?'Successful':'failed'));
if (!error) {
addToBlacklist(obj);
}
}
Remove from a blocklist
- If an user is removed from the blacklist, you will receive message from the user again.
- nim.markInBlacklist will be called in SDK to complete actual work.
javascriptnim.removeFromBlacklist({
account: 'account',
done: removeFromBlacklistDone
});
function removeFromBlacklistDone(error, obj) {
console.log(error);
console.log(obj);
console.log('removed from blacklist' + (!error?'Successful':'failed'));
if (!error) {
removeFromBlacklist(obj);
}
}
Add to mute list/remove from mute list
- The following two features can be enabled with this API. The actual features are determined by parameter
isAdd
.- If
isAdd
istrue
, theaccount
will be added to mute list. - If
isAdd
isfalse
, theaccount
will be removed from mute list.
- If
- For each feature, SDK provides related independent API.
javascriptnim.markInMutelist({
account: 'account',
// `true` means to be added to the mute list; `false` means to be removed from the mute list.
isAdd: 'true',
done: markInMutelistDone
});
function markInMutelistDone(error, obj) {
console.log(error);
console.log(obj);
console.log('is' + obj.account + (isAdd ? 'added to the mute list' : 'removed from the mute list') + (!error?'Successful':'failed'));
if (!error) {
onMarkInMutelist(obj);
}
}
Add to mute list
- SDK is used to maintain the mute list only, which will be determined by the developer based on mute list.
- nim.markInMutelist will be called in SDK to complete actual work.
javascriptnim.addToMutelist({
account: 'account',
done: addToMutelistDone
});
function addToMutelistDone(error, obj) {
console.log(error);
console.log(obj);
console.log('added to the mute list' + (!error?'Successful':'failed'));
if (!error) {
addToMutelist(obj);
}
}
Remove from mute list
- SDK is used to maintain the mute list only, which will be determined by the developer based on mute list.
- nim.markInMutelist will be called in SDK to complete actual work.
javascriptnim.removeFromMutelist({
account: 'account',
done: removeFromMutelistDone
});
function removeFromMutelistDone(error, obj) {
console.log(error);
console.log(obj);
console.log('removed from the mute list' + (!error?'Successful':'failed'));
if (!error) {
removeFromMutelist(obj);
}
}
Get a blocklist and mute list
- If the developer sets
syncRelations
tofalse
for "Initializing SDK", then the developer cannot getonblacklist
andonmutelist
callback, but can call this API to get the blacklist and mute list.
javascriptnim.getRelations({
done: getRelationsDone
});
function getRelationsDone(error, obj) {
console.log('Get the mute list' + (!error?'Successful':'failed'), error, obj);
if (!error) {
onBlacklist(obj.blacklist);
onMutelist(obj.mutelist);
}
}
Was this page helpful?