yach.nim.util
Advanced tools
Comparing version 1.0.4 to 1.0.5
// yach.nim.common | ||
import * as util from "./yach.nim.common"; | ||
import * as util from './yach.nim.common'; | ||
// export yach.nim.common | ||
export * from "./yach.nim.common"; | ||
export * from './yach.nim.common'; | ||
// get user | ||
export function getUser(id) { | ||
return new Promise(function (resolve, reject) { | ||
window.nim.getUser({ | ||
account: id + "", | ||
done: function (err, obj) { | ||
if (err) return reject(err); | ||
return new Promise(function (resolve, reject) { | ||
window.nim.getUser({ | ||
account: id + '', | ||
done: function (err, obj) { | ||
if (err) return reject(err); | ||
if (obj) obj.yachNick = getCustomYachNick(obj); | ||
if (obj) obj.yachNick = getCustomYachNick(obj); | ||
return resolve(obj); | ||
}, | ||
return resolve(obj); | ||
}, | ||
}); | ||
}); | ||
}); | ||
} | ||
@@ -25,4 +25,4 @@ | ||
export function getCustomYachNick(user) { | ||
let userCustom = util.getJson(user.custom); | ||
return userCustom && userCustom.yach_nick ? userCustom.yach_nick : ""; | ||
let userCustom = util.getJson(user.custom); | ||
return userCustom && userCustom.yach_nick ? userCustom.yach_nick : ''; | ||
} | ||
@@ -32,11 +32,11 @@ | ||
export function getUsers(userIdList) { | ||
return new Promise(function (resolve, reject) { | ||
window.nim.getUsers({ | ||
accounts: userIdList, | ||
sync: true, | ||
done: function (err, msg) { | ||
return err ? reject(err) : resolve(msg); | ||
}, | ||
return new Promise(function (resolve, reject) { | ||
window.nim.getUsers({ | ||
accounts: userIdList, | ||
sync: true, | ||
done: function (err, msg) { | ||
return err ? reject(err) : resolve(msg); | ||
}, | ||
}); | ||
}); | ||
}); | ||
} | ||
@@ -46,36 +46,32 @@ | ||
let __getTeamTimes = 0; | ||
export function getTeam(id) { | ||
const doNotUseYachCache = localStorage.getItem("__doNotUseYachCache"); | ||
const tag = __getTeamTimes++; | ||
return new Promise(async function (resolve, reject) { | ||
util.logTime(`[${tag}]:===getTeamTime${id}`); | ||
if (!doNotUseYachCache) { | ||
try { | ||
let cachedTeam = sessionStorage.getItem('teamsCache'); | ||
cachedTeam = util.getJson(cachedTeam, {}); | ||
cachedTeam = cachedTeam[id]; | ||
export function getTeam(id, isDoNotUseYachCache = false) { | ||
const doNotUseYachCache = isDoNotUseYachCache || localStorage.getItem('__doNotUseYachCache'); | ||
const tag = __getTeamTimes++; | ||
return new Promise(async function (resolve, reject) { | ||
util.logTime(`[${tag}]:===getTeamTime${id}`); | ||
if (!doNotUseYachCache) { | ||
try { | ||
let cachedTeam = sessionStorage.getItem('teamsCache'); | ||
cachedTeam = util.getJson(cachedTeam, {}); | ||
cachedTeam = cachedTeam[id]; | ||
if (cachedTeam) { | ||
util.logTime(`[${tag}]:===getTeamTime${id}`, true); | ||
return resolve(cachedTeam); | ||
if (cachedTeam) { | ||
util.logTime(`[${tag}]:===getTeamTime${id}`, true); | ||
return resolve(cachedTeam); | ||
} | ||
} catch (error) { | ||
console.error('yach.nim.util getTeam缓存获取异常', error); | ||
} | ||
} | ||
} catch (error) { | ||
console.error("yach.nim.util getTeam缓存获取异常", error); | ||
} | ||
} | ||
window.nim.getTeam({ | ||
teamId: id, | ||
done: function (err, obj) { | ||
// console.warn(`[${tag}]:===getTeamTime${id}没走自定义缓存`); | ||
util.logTime(`[${tag}]:===getTeamTime${id}`, true); | ||
if (err) return reject(err); | ||
// !doNotUseYachCache && | ||
// yachDB.team.add({ | ||
// ...obj, | ||
// }); //更新下缓存 | ||
return resolve(obj); | ||
}, | ||
window.nim.getTeam({ | ||
teamId: id, | ||
done: function (err, obj) { | ||
// console.warn(`[${tag}]:===getTeamTime${id}没走自定义缓存`); | ||
util.logTime(`[${tag}]:===getTeamTime${id}`, true); | ||
if (err) return reject(err); | ||
return resolve(obj); | ||
}, | ||
}); | ||
}); | ||
}); | ||
} | ||
@@ -85,12 +81,12 @@ | ||
export function updateTeam(teamId, obj) { | ||
return new Promise(function (resolve, reject) { | ||
window.nim.updateTeam( | ||
Object.assign(obj, { | ||
teamId: teamId || "", | ||
done: function (err, obj) { | ||
return err ? reject(err) : resolve(obj); | ||
}, | ||
}) | ||
); | ||
}); | ||
return new Promise(function (resolve, reject) { | ||
window.nim.updateTeam( | ||
Object.assign(obj, { | ||
teamId: teamId || '', | ||
done: function (err, obj) { | ||
return err ? reject(err) : resolve(obj); | ||
}, | ||
}) | ||
); | ||
}); | ||
} | ||
@@ -100,10 +96,10 @@ | ||
export function applyTeam(id) { | ||
return new Promise(function (resolve, reject) { | ||
window.nim.applyTeam({ | ||
teamId: id, | ||
done: function (error, obj) { | ||
return error ? reject(error) : resolve(obj); | ||
}, | ||
return new Promise(function (resolve, reject) { | ||
window.nim.applyTeam({ | ||
teamId: id, | ||
done: function (error, obj) { | ||
return error ? reject(error) : resolve(obj); | ||
}, | ||
}); | ||
}); | ||
}); | ||
} | ||
@@ -113,10 +109,10 @@ | ||
export function leaveTeam(teamId) { | ||
return new Promise(function (resolve, reject) { | ||
window.nim.leaveTeam({ | ||
teamId: teamId || "", | ||
done: function (err, obj) { | ||
return err ? reject(err) : resolve(obj); | ||
}, | ||
return new Promise(function (resolve, reject) { | ||
window.nim.leaveTeam({ | ||
teamId: teamId || '', | ||
done: function (err, obj) { | ||
return err ? reject(err) : resolve(obj); | ||
}, | ||
}); | ||
}); | ||
}); | ||
} | ||
@@ -126,12 +122,12 @@ | ||
export function transferTeam(teamId, account, leave) { | ||
return new Promise(function (resolve, reject) { | ||
window.nim.transferTeam({ | ||
teamId: teamId || "", | ||
account: account || "", | ||
leave: leave || false, | ||
done: function (err, obj) { | ||
return err ? reject(err) : resolve(obj); | ||
}, | ||
return new Promise(function (resolve, reject) { | ||
window.nim.transferTeam({ | ||
teamId: teamId || '', | ||
account: account || '', | ||
leave: leave || false, | ||
done: function (err, obj) { | ||
return err ? reject(err) : resolve(obj); | ||
}, | ||
}); | ||
}); | ||
}); | ||
} | ||
@@ -141,10 +137,10 @@ | ||
export function dismissTeam(teamId) { | ||
return new Promise(function (resolve, reject) { | ||
window.nim.dismissTeam({ | ||
teamId: teamId, | ||
done: function (err, obj) { | ||
return err ? reject(err) : resolve(obj); | ||
}, | ||
return new Promise(function (resolve, reject) { | ||
window.nim.dismissTeam({ | ||
teamId: teamId, | ||
done: function (err, obj) { | ||
return err ? reject(err) : resolve(obj); | ||
}, | ||
}); | ||
}); | ||
}); | ||
} | ||
@@ -154,10 +150,10 @@ | ||
export function getTeamMembers(teamId) { | ||
return new Promise(function (resolve, reject) { | ||
window.nim.getTeamMembers({ | ||
teamId: teamId || "", | ||
done: function (err, obj) { | ||
return err ? reject(err) : resolve(obj); | ||
}, | ||
return new Promise(function (resolve, reject) { | ||
window.nim.getTeamMembers({ | ||
teamId: teamId || '', | ||
done: function (err, obj) { | ||
return err ? reject(err) : resolve(obj); | ||
}, | ||
}); | ||
}); | ||
}); | ||
} | ||
@@ -167,11 +163,11 @@ | ||
export function addTeamMembers(teamId, accounts) { | ||
return new Promise(function (resolve, reject) { | ||
window.nim.addTeamMembers({ | ||
teamId: teamId || "", | ||
accounts: accounts || [], | ||
done: function (err, obj) { | ||
return err ? reject(err) : resolve(obj); | ||
}, | ||
return new Promise(function (resolve, reject) { | ||
window.nim.addTeamMembers({ | ||
teamId: teamId || '', | ||
accounts: accounts || [], | ||
done: function (err, obj) { | ||
return err ? reject(err) : resolve(obj); | ||
}, | ||
}); | ||
}); | ||
}); | ||
} | ||
@@ -181,11 +177,11 @@ | ||
export function removeTeamMembers(teamId, accounts) { | ||
return new Promise(function (resolve, reject) { | ||
window.nim.removeTeamMembers({ | ||
teamId: teamId, | ||
accounts: accounts, | ||
done: function (err, obj) { | ||
return err ? reject(err) : resolve(obj); | ||
}, | ||
return new Promise(function (resolve, reject) { | ||
window.nim.removeTeamMembers({ | ||
teamId: teamId, | ||
accounts: accounts, | ||
done: function (err, obj) { | ||
return err ? reject(err) : resolve(obj); | ||
}, | ||
}); | ||
}); | ||
}); | ||
} | ||
@@ -195,11 +191,11 @@ | ||
export function removeTeamManagers(teamId, accounts) { | ||
return new Promise(function (resolve, reject) { | ||
window.nim.removeTeamManagers({ | ||
teamId: teamId || "", | ||
accounts: accounts || [], | ||
done: function (err, obj) { | ||
return err ? reject(err) : resolve(obj); | ||
}, | ||
return new Promise(function (resolve, reject) { | ||
window.nim.removeTeamManagers({ | ||
teamId: teamId || '', | ||
accounts: accounts || [], | ||
done: function (err, obj) { | ||
return err ? reject(err) : resolve(obj); | ||
}, | ||
}); | ||
}); | ||
}); | ||
} | ||
@@ -209,11 +205,11 @@ | ||
export function addTeamManagers(teamId, accounts) { | ||
return new Promise(function (resolve, reject) { | ||
window.nim.addTeamManagers({ | ||
teamId: teamId || "", | ||
accounts: accounts || [], | ||
done: function (err, obj) { | ||
return err ? reject(err) : resolve(obj); | ||
}, | ||
return new Promise(function (resolve, reject) { | ||
window.nim.addTeamManagers({ | ||
teamId: teamId || '', | ||
accounts: accounts || [], | ||
done: function (err, obj) { | ||
return err ? reject(err) : resolve(obj); | ||
}, | ||
}); | ||
}); | ||
}); | ||
} | ||
@@ -223,10 +219,10 @@ | ||
export function getLocalSession(id) { | ||
return new Promise(function (resolve, reject) { | ||
window.nim.getLocalSession({ | ||
sessionId: id, | ||
done: function (err, obj) { | ||
return err ? reject(err) : resolve(obj); | ||
}, | ||
return new Promise(function (resolve, reject) { | ||
window.nim.getLocalSession({ | ||
sessionId: id, | ||
done: function (err, obj) { | ||
return err ? reject(err) : resolve(obj); | ||
}, | ||
}); | ||
}); | ||
}); | ||
} | ||
@@ -236,13 +232,13 @@ | ||
export function insertLocalSession(type, id) { | ||
type = type == "record" ? "p2p" : type; | ||
type = type == 'record' ? 'p2p' : type; | ||
return new Promise(function (resolve, reject) { | ||
window.nim.insertLocalSession({ | ||
scene: type, | ||
to: id, | ||
done: function (err, obj) { | ||
return err ? reject(err) : resolve(obj); | ||
}, | ||
return new Promise(function (resolve, reject) { | ||
window.nim.insertLocalSession({ | ||
scene: type, | ||
to: id, | ||
done: function (err, obj) { | ||
return err ? reject(err) : resolve(obj); | ||
}, | ||
}); | ||
}); | ||
}); | ||
} | ||
@@ -252,11 +248,11 @@ | ||
export function updateLocalSession(id, local) { | ||
return new Promise(function (resolve, reject) { | ||
window.nim.updateLocalSession({ | ||
id: id, | ||
localCustom: JSON.stringify(local), | ||
done: function (err2, obj2) { | ||
return err2 ? reject(err2) : resolve(obj2); | ||
}, | ||
return new Promise(function (resolve, reject) { | ||
window.nim.updateLocalSession({ | ||
id: id, | ||
localCustom: JSON.stringify(local), | ||
done: function (err2, obj2) { | ||
return err2 ? reject(err2) : resolve(obj2); | ||
}, | ||
}); | ||
}); | ||
}); | ||
} | ||
@@ -266,18 +262,18 @@ | ||
export function updateTeamMute(teamId, mute, type) { | ||
return new Promise(function (resolve, reject) { | ||
let custom = {}; | ||
if (type === "team") { | ||
custom = { | ||
muteNotiType: mute ? 1 : 0, | ||
}; | ||
} | ||
window.nim.updateInfoInTeam({ | ||
teamId: teamId, | ||
muteTeam: mute, | ||
...custom, | ||
done: function (err, obj) { | ||
return err ? reject(err) : resolve(obj); | ||
}, | ||
return new Promise(function (resolve, reject) { | ||
let custom = {}; | ||
if (type === 'team') { | ||
custom = { | ||
muteNotiType: mute ? 1 : 0, | ||
}; | ||
} | ||
window.nim.updateInfoInTeam({ | ||
teamId: teamId, | ||
muteTeam: mute, | ||
...custom, | ||
done: function (err, obj) { | ||
return err ? reject(err) : resolve(obj); | ||
}, | ||
}); | ||
}); | ||
}); | ||
} | ||
@@ -287,11 +283,11 @@ | ||
export function updatePersonMute(id, mute) { | ||
return new Promise(function (resolve, reject) { | ||
window.nim.markInMutelist({ | ||
account: id, | ||
isAdd: mute, | ||
done: function (err, obj) { | ||
return err ? reject(err) : resolve(obj); | ||
}, | ||
return new Promise(function (resolve, reject) { | ||
window.nim.markInMutelist({ | ||
account: id, | ||
isAdd: mute, | ||
done: function (err, obj) { | ||
return err ? reject(err) : resolve(obj); | ||
}, | ||
}); | ||
}); | ||
}); | ||
} | ||
@@ -301,9 +297,9 @@ | ||
export function getPersonMute() { | ||
return new Promise(function (resolve, reject) { | ||
window.nim.getRelations({ | ||
done: function (err, obj) { | ||
return err ? reject(err) : resolve(obj); | ||
}, | ||
return new Promise(function (resolve, reject) { | ||
window.nim.getRelations({ | ||
done: function (err, obj) { | ||
return err ? reject(err) : resolve(obj); | ||
}, | ||
}); | ||
}); | ||
}); | ||
} | ||
@@ -313,13 +309,13 @@ | ||
export function forwardMsg(forwardmsg, scene, to, cb) { | ||
return new Promise(function (resolve, reject) { | ||
let msg = window.nim.forwardMsg({ | ||
msg: forwardmsg, | ||
scene: scene, | ||
to: to, | ||
done: function (err, msg) { | ||
return err ? reject(err) : resolve(msg); | ||
}, | ||
return new Promise(function (resolve, reject) { | ||
let msg = window.nim.forwardMsg({ | ||
msg: forwardmsg, | ||
scene: scene, | ||
to: to, | ||
done: function (err, msg) { | ||
return err ? reject(err) : resolve(msg); | ||
}, | ||
}); | ||
cb && cb(msg); | ||
}); | ||
cb && cb(msg); | ||
}); | ||
} | ||
@@ -329,10 +325,10 @@ | ||
export function resendMsg(someMsg) { | ||
return new Promise(function (resolve, reject) { | ||
window.nim.resendMsg({ | ||
msg: someMsg, | ||
done: function (err, obj) { | ||
return err ? reject(err) : resolve(obj); | ||
}, | ||
return new Promise(function (resolve, reject) { | ||
window.nim.resendMsg({ | ||
msg: someMsg, | ||
done: function (err, obj) { | ||
return err ? reject(err) : resolve(obj); | ||
}, | ||
}); | ||
}); | ||
}); | ||
} | ||
@@ -342,10 +338,10 @@ | ||
export function deleteMsg(someMsg) { | ||
return new Promise(function (resolve, reject) { | ||
window.nim.deleteMsg({ | ||
msg: someMsg.item, | ||
done: function (err, msg) { | ||
return err ? reject(err) : resolve(msg); | ||
}, | ||
return new Promise(function (resolve, reject) { | ||
window.nim.deleteMsg({ | ||
msg: someMsg.item, | ||
done: function (err, msg) { | ||
return err ? reject(err) : resolve(msg); | ||
}, | ||
}); | ||
}); | ||
}); | ||
} | ||
@@ -355,10 +351,10 @@ | ||
export function deleteLocalMsg(msg) { | ||
return new Promise(function (resolve, reject) { | ||
window.nim.deleteLocalMsg({ | ||
msg: msg, | ||
done: function (err, msg) { | ||
return err ? reject(err) : resolve(msg); | ||
}, | ||
return new Promise(function (resolve, reject) { | ||
window.nim.deleteLocalMsg({ | ||
msg: msg, | ||
done: function (err, msg) { | ||
return err ? reject(err) : resolve(msg); | ||
}, | ||
}); | ||
}); | ||
}); | ||
} | ||
@@ -368,11 +364,11 @@ | ||
export function updateLocalMsg(idClient, localCustom) { | ||
return new Promise(function (resolve, reject) { | ||
window.nim.updateLocalMsg({ | ||
idClient, | ||
localCustom, | ||
done: function (err, msg) { | ||
return err ? reject(err) : resolve(msg); | ||
}, | ||
return new Promise(function (resolve, reject) { | ||
window.nim.updateLocalMsg({ | ||
idClient, | ||
localCustom, | ||
done: function (err, msg) { | ||
return err ? reject(err) : resolve(msg); | ||
}, | ||
}); | ||
}); | ||
}); | ||
} | ||
@@ -382,16 +378,16 @@ | ||
export function getHistoryMsgs(scene, id, time, num, reverse) { | ||
return new Promise(function (resolve, reject) { | ||
window.nim.getHistoryMsgs({ | ||
scene: scene, | ||
to: id, | ||
limit: num || 30, | ||
asc: !reverse, | ||
endTime: !reverse ? time : 0, | ||
beginTime: reverse ? time : 0, | ||
reverse: reverse || false, | ||
done: function (err, obj) { | ||
return err ? reject(err) : resolve(obj); | ||
}, | ||
return new Promise(function (resolve, reject) { | ||
window.nim.getHistoryMsgs({ | ||
scene: scene, | ||
to: id, | ||
limit: num || 30, | ||
asc: !reverse, | ||
endTime: !reverse ? time : 0, | ||
beginTime: reverse ? time : 0, | ||
reverse: reverse || false, | ||
done: function (err, obj) { | ||
return err ? reject(err) : resolve(obj); | ||
}, | ||
}); | ||
}); | ||
}); | ||
} | ||
@@ -401,12 +397,12 @@ | ||
export function deleteLocalMsgsBySession(scene, to) { | ||
return new Promise(function (resolve, reject) { | ||
window.nim.deleteLocalMsgsBySession({ | ||
scene: scene, | ||
to: to, | ||
delLastMsg: true, | ||
done: function (err, obj) { | ||
return err ? reject(err) : resolve(obj); | ||
}, | ||
return new Promise(function (resolve, reject) { | ||
window.nim.deleteLocalMsgsBySession({ | ||
scene: scene, | ||
to: to, | ||
delLastMsg: true, | ||
done: function (err, obj) { | ||
return err ? reject(err) : resolve(obj); | ||
}, | ||
}); | ||
}); | ||
}); | ||
} | ||
@@ -416,10 +412,10 @@ | ||
export function getLocalMsgByIdClient(idClient) { | ||
return new Promise(function (resolve, reject) { | ||
window.nim.getLocalMsgByIdClient({ | ||
idClient, | ||
done: function (err, msg) { | ||
return err ? reject(err) : resolve(msg); | ||
}, | ||
return new Promise(function (resolve, reject) { | ||
window.nim.getLocalMsgByIdClient({ | ||
idClient, | ||
done: function (err, msg) { | ||
return err ? reject(err) : resolve(msg); | ||
}, | ||
}); | ||
}); | ||
}); | ||
} | ||
@@ -429,10 +425,10 @@ | ||
export function notifyForNewTeamMsg(teamId) { | ||
return new Promise(function (resolve, reject) { | ||
window.nim.notifyForNewTeamMsg({ | ||
teamIds: teamId, | ||
done: function (err, obj) { | ||
return err ? reject(err) : resolve(obj); | ||
}, | ||
return new Promise(function (resolve, reject) { | ||
window.nim.notifyForNewTeamMsg({ | ||
teamIds: teamId, | ||
done: function (err, obj) { | ||
return err ? reject(err) : resolve(obj); | ||
}, | ||
}); | ||
}); | ||
}); | ||
} | ||
@@ -442,10 +438,10 @@ | ||
export function sendTeamMsgReceipt(item) { | ||
return new Promise(function (resolve, reject) { | ||
window.nim.sendTeamMsgReceipt({ | ||
teamMsgReceipts: item, | ||
done: function (err2, obj2) { | ||
return err2 ? reject(err2) : resolve(obj2); | ||
}, | ||
return new Promise(function (resolve, reject) { | ||
window.nim.sendTeamMsgReceipt({ | ||
teamMsgReceipts: item, | ||
done: function (err2, obj2) { | ||
return err2 ? reject(err2) : resolve(obj2); | ||
}, | ||
}); | ||
}); | ||
}); | ||
} | ||
@@ -455,16 +451,16 @@ | ||
export function getTeamMsgReads(id, idServer) { | ||
let teamMsgReceipts = [ | ||
{ | ||
teamId: id, | ||
idServer: idServer, | ||
}, | ||
]; | ||
return new Promise(function (resolve, reject) { | ||
window.nim.getTeamMsgReads({ | ||
teamMsgReceipts: teamMsgReceipts, | ||
done: function (err, obj, content) { | ||
return err ? reject(err) : resolve(content); | ||
}, | ||
let teamMsgReceipts = [ | ||
{ | ||
teamId: id, | ||
idServer: idServer, | ||
}, | ||
]; | ||
return new Promise(function (resolve, reject) { | ||
window.nim.getTeamMsgReads({ | ||
teamMsgReceipts: teamMsgReceipts, | ||
done: function (err, obj, content) { | ||
return err ? reject(err) : resolve(content); | ||
}, | ||
}); | ||
}); | ||
}); | ||
} | ||
@@ -474,14 +470,14 @@ | ||
export function getTeamMsgReadAccounts(id, idServer) { | ||
let teamMsgReceipts = { | ||
teamId: id, | ||
idServer: idServer, | ||
}; | ||
return new Promise(function (resolve, reject) { | ||
window.nim.getTeamMsgReadAccounts({ | ||
teamMsgReceipt: teamMsgReceipts, | ||
done: function (err, obj, content) { | ||
return err ? reject(err) : resolve(content); | ||
}, | ||
let teamMsgReceipts = { | ||
teamId: id, | ||
idServer: idServer, | ||
}; | ||
return new Promise(function (resolve, reject) { | ||
window.nim.getTeamMsgReadAccounts({ | ||
teamMsgReceipt: teamMsgReceipts, | ||
done: function (err, obj, content) { | ||
return err ? reject(err) : resolve(content); | ||
}, | ||
}); | ||
}); | ||
}); | ||
} | ||
@@ -492,12 +488,12 @@ | ||
*/ | ||
export function stopAllNoSpeaking(teamId, type = "normal") { | ||
return new Promise(function (resolve, reject) { | ||
window.nim.muteTeamAll({ | ||
teamId, | ||
mute: type === "normal" ? 1 : 0, | ||
done: function (err, obj) { | ||
return err ? reject(err) : resolve(obj); | ||
}, | ||
export function stopAllNoSpeaking(teamId, type = 'normal') { | ||
return new Promise(function (resolve, reject) { | ||
window.nim.muteTeamAll({ | ||
teamId, | ||
mute: type === 'normal' ? 1 : 0, | ||
done: function (err, obj) { | ||
return err ? reject(err) : resolve(obj); | ||
}, | ||
}); | ||
}); | ||
}); | ||
} | ||
@@ -507,13 +503,13 @@ | ||
export function publishEvent(value, custom) { | ||
return new Promise(function (resolve, reject) { | ||
window.nim.publishEvent({ | ||
type: 1, //传入1即可。 | ||
value: value, //value为10000以上(1-9999为云信预定义值,开发者不可使用) | ||
custom: JSON.stringify(custom), | ||
sync: true, | ||
done: function (err, obj) { | ||
return err ? reject(err) : resolve(obj); | ||
}, | ||
return new Promise(function (resolve, reject) { | ||
window.nim.publishEvent({ | ||
type: 1, //传入1即可。 | ||
value: value, //value为10000以上(1-9999为云信预定义值,开发者不可使用) | ||
custom: JSON.stringify(custom), | ||
sync: true, | ||
done: function (err, obj) { | ||
return err ? reject(err) : resolve(obj); | ||
}, | ||
}); | ||
}); | ||
}); | ||
} | ||
@@ -523,11 +519,11 @@ | ||
export function getLocalSessions(lastSessionId, limit = 100) { | ||
return new Promise(function (resolve, reject) { | ||
window.nim.getLocalSessions({ | ||
lastSessionId, | ||
limit, | ||
done: function (err, obj) { | ||
return err ? reject(err) : resolve(obj); | ||
}, | ||
return new Promise(function (resolve, reject) { | ||
window.nim.getLocalSessions({ | ||
lastSessionId, | ||
limit, | ||
done: function (err, obj) { | ||
return err ? reject(err) : resolve(obj); | ||
}, | ||
}); | ||
}); | ||
}); | ||
} | ||
@@ -537,10 +533,10 @@ | ||
export function getSessionsWithMoreRoaming(sessionId) { | ||
return new Promise(function (resolve, reject) { | ||
window.nim.getSessionsWithMoreRoaming({ | ||
id: sessionId, | ||
done: function (err, obj) { | ||
return err ? reject(err) : resolve(obj); | ||
}, | ||
return new Promise(function (resolve, reject) { | ||
window.nim.getSessionsWithMoreRoaming({ | ||
id: sessionId, | ||
done: function (err, obj) { | ||
return err ? reject(err) : resolve(obj); | ||
}, | ||
}); | ||
}); | ||
}); | ||
} | ||
@@ -550,10 +546,10 @@ | ||
export function updateSessionsWithMoreRoaming(msg) { | ||
return new Promise(function (resolve, reject) { | ||
window.nim.updateSessionsWithMoreRoaming({ | ||
msg, | ||
done: function (err, obj) { | ||
return err ? reject(err) : resolve(obj); | ||
}, | ||
return new Promise(function (resolve, reject) { | ||
window.nim.updateSessionsWithMoreRoaming({ | ||
msg, | ||
done: function (err, obj) { | ||
return err ? reject(err) : resolve(obj); | ||
}, | ||
}); | ||
}); | ||
}); | ||
} | ||
@@ -563,9 +559,9 @@ | ||
export function getTeams() { | ||
return new Promise(function (resolve, reject) { | ||
window.nim.getTeams({ | ||
done: function (error, obj) { | ||
return error ? reject(error) : resolve(obj); | ||
}, | ||
return new Promise(function (resolve, reject) { | ||
window.nim.getTeams({ | ||
done: function (error, obj) { | ||
return error ? reject(error) : resolve(obj); | ||
}, | ||
}); | ||
}); | ||
}); | ||
} | ||
@@ -580,11 +576,11 @@ | ||
export function deleteMsgSelf(msg, custom = {}) { | ||
return new Promise((resolve, reject) => { | ||
window.nim.deleteMsgSelf({ | ||
msg, | ||
custom, | ||
done: function (err, obj) { | ||
return err ? reject(err) : resolve(obj); | ||
}, | ||
return new Promise((resolve, reject) => { | ||
window.nim.deleteMsgSelf({ | ||
msg, | ||
custom, | ||
done: function (err, obj) { | ||
return err ? reject(err) : resolve(obj); | ||
}, | ||
}); | ||
}); | ||
}); | ||
} | ||
@@ -598,18 +594,14 @@ | ||
*/ | ||
export function deleteLocalMsgs( | ||
sessionId, | ||
start = 1514736000000, | ||
end = 1590830530214 | ||
) { | ||
return new Promise((resolve, reject) => { | ||
window.nim.deleteLocalMsgs({ | ||
sessionId: sessionId, | ||
start, | ||
end, | ||
updateSession: true, | ||
done: function (err, obj) { | ||
return err ? reject(err) : resolve(obj); | ||
}, | ||
export function deleteLocalMsgs(sessionId, start = 1514736000000, end = 1590830530214) { | ||
return new Promise((resolve, reject) => { | ||
window.nim.deleteLocalMsgs({ | ||
sessionId: sessionId, | ||
start, | ||
end, | ||
updateSession: true, | ||
done: function (err, obj) { | ||
return err ? reject(err) : resolve(obj); | ||
}, | ||
}); | ||
}); | ||
}); | ||
} | ||
@@ -623,11 +615,11 @@ | ||
export function getTeamMemberByTeamIdAndAccount(tid, uid) { | ||
return new Promise((resolve, reject) => { | ||
window.nim.getTeamMemberByTeamIdAndAccount({ | ||
teamId: tid, | ||
account: uid, | ||
done: function (error, obj) { | ||
return error ? reject(error) : resolve(obj); | ||
}, | ||
return new Promise((resolve, reject) => { | ||
window.nim.getTeamMemberByTeamIdAndAccount({ | ||
teamId: tid, | ||
account: uid, | ||
done: function (error, obj) { | ||
return error ? reject(error) : resolve(obj); | ||
}, | ||
}); | ||
}); | ||
}); | ||
} | ||
@@ -640,4 +632,4 @@ | ||
export function resetCurrSession(id) { | ||
console.log("resetCurrSession", id); | ||
window.nim.resetCurrSession(id); | ||
console.log('resetCurrSession', id); | ||
window.nim.resetCurrSession(id); | ||
} | ||
@@ -650,4 +642,4 @@ | ||
export function setCurrSession(id) { | ||
console.log("setCurrSession", id); | ||
window.nim.setCurrSession(id); | ||
console.log('setCurrSession', id); | ||
window.nim.setCurrSession(id); | ||
} | ||
@@ -660,11 +652,11 @@ | ||
export function deleteLocalSession(id) { | ||
return new Promise(function (resolve, reject) { | ||
window.nim.deleteLocalSession({ | ||
id, | ||
isLogic: true, | ||
done: function (err, obj) { | ||
return err ? reject(err) : resolve(obj); | ||
}, | ||
return new Promise(function (resolve, reject) { | ||
window.nim.deleteLocalSession({ | ||
id, | ||
isLogic: true, | ||
done: function (err, obj) { | ||
return err ? reject(err) : resolve(obj); | ||
}, | ||
}); | ||
}); | ||
}); | ||
} | ||
@@ -683,31 +675,22 @@ | ||
*/ | ||
export function getLocalMsgs( | ||
scene, | ||
type, | ||
id, | ||
time, | ||
num, | ||
desc = true, | ||
keyword, | ||
types | ||
) { | ||
var nimId = ""; | ||
if (scene && id) { | ||
nimId = util.getNimId(scene, id); | ||
} | ||
return new Promise(function (resolve, reject) { | ||
window.nim.getLocalMsgs({ | ||
sessionId: nimId, | ||
limit: num || 30, | ||
type: type || "", | ||
types: types || [], | ||
start: !desc ? time : 0, | ||
end: desc ? time : Infinity, | ||
desc: desc, | ||
keyword: keyword || "", | ||
done: function (err, obj) { | ||
return err ? reject(err) : resolve(obj); | ||
}, | ||
export function getLocalMsgs(scene, type, id, time, num, desc = true, keyword, types) { | ||
var nimId = ''; | ||
if (scene && id) { | ||
nimId = util.getNimId(scene, id); | ||
} | ||
return new Promise(function (resolve, reject) { | ||
window.nim.getLocalMsgs({ | ||
sessionId: nimId, | ||
limit: num || 30, | ||
type: type || '', | ||
types: types || [], | ||
start: !desc ? time : 0, | ||
end: desc ? time : Infinity, | ||
desc: desc, | ||
keyword: keyword || '', | ||
done: function (err, obj) { | ||
return err ? reject(err) : resolve(obj); | ||
}, | ||
}); | ||
}); | ||
}); | ||
} | ||
@@ -720,17 +703,17 @@ | ||
export function sendTipMsg(msg, ac) { | ||
return new Promise(function (resolve, reject) { | ||
window.nim.sendTipMsg({ | ||
isLocal: true, | ||
custom: msg.custom, | ||
idClient: msg.idClient || null, | ||
scene: msg.scene, | ||
to: msg.to == ac ? msg.from : msg.to, | ||
tip: msg.text || "", | ||
time: msg.time, | ||
text: msg.text, | ||
done: function (err, msg) { | ||
return err ? reject(err) : resolve(msg); | ||
}, | ||
return new Promise(function (resolve, reject) { | ||
window.nim.sendTipMsg({ | ||
isLocal: true, | ||
custom: msg.custom, | ||
idClient: msg.idClient || null, | ||
scene: msg.scene, | ||
to: msg.to == ac ? msg.from : msg.to, | ||
tip: msg.text || '', | ||
time: msg.time, | ||
text: msg.text, | ||
done: function (err, msg) { | ||
return err ? reject(err) : resolve(msg); | ||
}, | ||
}); | ||
}); | ||
}); | ||
} | ||
@@ -741,10 +724,10 @@ | ||
export function sendMsgReceipt(obj) { | ||
return new Promise(function (resolve, reject) { | ||
window.nim.sendMsgReceipt({ | ||
msg: obj.lastMsg, | ||
done: function (err, obj2) { | ||
return err ? reject(err) : resolve(obj2); | ||
}, | ||
return new Promise(function (resolve, reject) { | ||
window.nim.sendMsgReceipt({ | ||
msg: obj.lastMsg, | ||
done: function (err, obj2) { | ||
return err ? reject(err) : resolve(obj2); | ||
}, | ||
}); | ||
}); | ||
}); | ||
} | ||
@@ -763,34 +746,24 @@ | ||
*/ | ||
export function sendText( | ||
scene, | ||
id, | ||
text, | ||
apns, | ||
custom, | ||
pushContent, | ||
cb, | ||
pushPayload, | ||
isPushable | ||
) { | ||
scene = scene == "record" ? "p2p" : scene; | ||
export function sendText(scene, id, text, apns, custom, pushContent, cb, pushPayload, isPushable) { | ||
scene = scene == 'record' ? 'p2p' : scene; | ||
return new Promise(function (resolve, reject) { | ||
let msg = window.nim.sendText({ | ||
scene: scene, | ||
to: id, | ||
text: text, | ||
isPushable, | ||
apns: apns || {}, | ||
pushContent: pushContent || "", | ||
needMsgReceipt: scene == "team", | ||
custom: custom || {}, | ||
needPushNick: false, | ||
pushPayload, | ||
done: function (err, msg) { | ||
return err ? reject({ err, msg }) : resolve(msg); | ||
}, | ||
return new Promise(function (resolve, reject) { | ||
let msg = window.nim.sendText({ | ||
scene: scene, | ||
to: id, | ||
text: text, | ||
isPushable, | ||
apns: apns || {}, | ||
pushContent: pushContent || '', | ||
needMsgReceipt: scene == 'team', | ||
custom: custom || {}, | ||
needPushNick: false, | ||
pushPayload, | ||
done: function (err, msg) { | ||
return err ? reject({ err, msg }) : resolve(msg); | ||
}, | ||
}); | ||
cb && cb(msg); | ||
}); | ||
cb && cb(msg); | ||
}); | ||
} | ||
@@ -813,34 +786,34 @@ | ||
export function sendCustomMsg( | ||
scene, | ||
id, | ||
content, | ||
apns, | ||
text, | ||
custom, | ||
pushContent, | ||
cb, | ||
others, | ||
isPushable, | ||
factoryPushPayload | ||
scene, | ||
id, | ||
content, | ||
apns, | ||
text, | ||
custom, | ||
pushContent, | ||
cb, | ||
others, | ||
isPushable, | ||
factoryPushPayload | ||
) { | ||
return new Promise(function (resolve, reject) { | ||
let msg = window.nim.sendCustomMsg({ | ||
scene: scene, | ||
to: id, | ||
content: content, | ||
isPushable, | ||
apns: apns || {}, | ||
text: text || "", | ||
custom: custom || {}, | ||
pushContent: pushContent || "", | ||
needMsgReceipt: scene == "team", | ||
needPushNick: false, | ||
pushPayload: factoryPushPayload, | ||
...others, | ||
done: function (err, msg) { | ||
return err ? reject({ err, msg }) : resolve(msg); | ||
}, | ||
return new Promise(function (resolve, reject) { | ||
let msg = window.nim.sendCustomMsg({ | ||
scene: scene, | ||
to: id, | ||
content: content, | ||
isPushable, | ||
apns: apns || {}, | ||
text: text || '', | ||
custom: custom || {}, | ||
pushContent: pushContent || '', | ||
needMsgReceipt: scene == 'team', | ||
needPushNick: false, | ||
pushPayload: factoryPushPayload, | ||
...others, | ||
done: function (err, msg) { | ||
return err ? reject({ err, msg }) : resolve(msg); | ||
}, | ||
}); | ||
cb && cb(msg); | ||
}); | ||
cb && cb(msg); | ||
}); | ||
} | ||
@@ -853,35 +826,35 @@ | ||
export function saveMsgsToLocal(msgs) { | ||
return new Promise(function (resolve, reject) { | ||
window.nim.saveMsgsToLocal({ | ||
msgs: msgs, | ||
done: function (err, obj) { | ||
return err ? reject(err) : resolve(obj); | ||
}, | ||
return new Promise(function (resolve, reject) { | ||
window.nim.saveMsgsToLocal({ | ||
msgs: msgs, | ||
done: function (err, obj) { | ||
return err ? reject(err) : resolve(obj); | ||
}, | ||
}); | ||
}); | ||
}); | ||
} | ||
export function searchHistoryMsgs( | ||
scene, | ||
to, | ||
keyword, | ||
beginTime = 0, | ||
endTime = Date.now(), | ||
reverse = false, | ||
asc = false | ||
scene, | ||
to, | ||
keyword, | ||
beginTime = 0, | ||
endTime = Date.now(), | ||
reverse = false, | ||
asc = false | ||
) { | ||
return new Promise(function (resolve, reject) { | ||
window.nim.searchHistoryMsgs({ | ||
scene, | ||
to, | ||
keyword, | ||
beginTime, | ||
endTime, | ||
reverse, | ||
asc, | ||
done: function (error, obj) { | ||
return error ? reject(error) : resolve(obj); | ||
}, | ||
return new Promise(function (resolve, reject) { | ||
window.nim.searchHistoryMsgs({ | ||
scene, | ||
to, | ||
keyword, | ||
beginTime, | ||
endTime, | ||
reverse, | ||
asc, | ||
done: function (error, obj) { | ||
return error ? reject(error) : resolve(obj); | ||
}, | ||
}); | ||
}); | ||
}); | ||
} |
{ | ||
"name": "yach.nim.util", | ||
"version": "1.0.4", | ||
"license": "MIT", | ||
"description": "yach nim: util", | ||
"main": "index.js", | ||
"author": "qiaowenbin", | ||
"scripts": {}, | ||
"dependencies": {}, | ||
"peerDependencies": { | ||
"qiao.ls.js": "0.1.0" | ||
} | ||
"name": "yach.nim.util", | ||
"version": "1.0.5", | ||
"license": "MIT", | ||
"description": "yach nim: util", | ||
"main": "index.js", | ||
"author": "qiaowenbin", | ||
"scripts": {}, | ||
"dependencies": {}, | ||
"peerDependencies": { | ||
"qiao.ls.js": "0.1.0" | ||
} | ||
} |
@@ -41,3 +41,3 @@ # yach.nim.util | ||
``` | ||
## getTeam(id) { | ||
## getTeam(id, isDoNotUseYachCache = false) { | ||
>群信息: 开发者可以调用此接口获取群资料 | ||
@@ -354,2 +354,5 @@ | ||
## version | ||
### 1.0.5.20201207 | ||
1. getTeam增加强制走缓存参数:getTeam(id, isDoNotUseYachCache = false) | ||
### 0.1.0.20201103 | ||
@@ -356,0 +359,0 @@ 1. ncu |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
32122
387
783