提交 1b889120 编写于 作者: ruiruibupt's avatar ruiruibupt

#217

上级 c0a69986
......@@ -56,8 +56,6 @@ export enum Gender {
export type ContactQueryFilter = {
name?: string | RegExp
// remark should be deprecated
remark?: string | RegExp
alias?: string | RegExp
}
......@@ -226,18 +224,19 @@ export class Contact implements Sayable {
/**
* find contact by `name` or `alias`
*/
public static async findAll(queryArg?: ContactQueryFilter): Promise<Contact[]> {
public static async findAll(queryArg?: ContactQueryFilter | {remark: string | RegExp}): Promise<Contact[]> {
let query: ContactQueryFilter
if (queryArg) {
query = queryArg
if (queryArg[0] === 'remark') {
log.warn('Contact', 'Contact.findAll(remark:%s) DEPRECATED, use Contact.findAll(alias:%s) instead.')
query = { alias: queryArg[1]}
} else {
query = queryArg
}
} else {
query = { name: /.*/ }
}
if (query[0] === 'remark') {
log.warn('Contact', 'findAll(remark:%s) DEPRECATED, use findAll(alias:%s) instead.')
}
// log.verbose('Cotnact', 'findAll({ name: %s })', query.name)
log.verbose('Cotnact', 'findAll({ %s })'
, Object.keys(query)
......@@ -254,8 +253,6 @@ export class Contact implements Sayable {
const keyMap = {
name: 'NickName',
// should be deprecated
remark: 'RemarkName',
alias: 'RemarkName',
}
......@@ -335,6 +332,7 @@ export class Contact implements Sayable {
})
}
// function should be deprecated
public remark(newRemark?: string|null): Promise<boolean> | string | null {
log.warn('Contact', 'remark(%s) DEPRECATED, use alias(%s) instead.')
log.silly('Contact', 'remark(%s)', newRemark || '')
......@@ -349,8 +347,8 @@ export class Contact implements Sayable {
/**
* try to find a contact by filter: {name: string | RegExp}
*/
public static async find(query: ContactQueryFilter): Promise<Contact> {
log.verbose('Contact', 'find(%s)', query.name)
public static async find(query: ContactQueryFilter | {remark: string | RegExp}): Promise<Contact> {
log.verbose('Contact', 'find(%s)', query)
const contactList = await Contact.findAll(query)
if (!contactList || !contactList.length) {
......
......@@ -252,6 +252,7 @@ export class Room extends EventEmitter implements Sayable {
/**
* ISSUE #64 emoji need to be striped
* ISSUE #104 never use remark name because sys group message will never use that
* @rui: Wrong for 'never use remark name because sys group message will never use that', see more in the latest comment in #104
* @rui: cannot use argument NickName because it mix real name and alias
*/
mapList[member.UserName] = UtilLib.stripEmoji(tmpName)
......@@ -353,13 +354,10 @@ export class Room extends EventEmitter implements Sayable {
// should be deprecated
public nick(contact: Contact): string {
log.warn('Room', 'nick(Contact) DEPRECATED, use name(Contact) instead.')
if (!this.obj || !this.obj.nameMap) {
return ''
}
return this.obj.roomAliasMap[contact.id] || this.obj.nameMap[contact.id]
return this.alias(contact)
}
public name(contact: Contact): string {
public alias(contact: Contact): string {
if (!this.obj || !this.obj.nameMap) {
return ''
}
......
......@@ -111,14 +111,14 @@ test('Room smoking test', async t => {
const nick1 = r.nick(contact1)
t.is(nick1, EXPECTED.memberNick1, 'should get nick1 from roomAlias')
const name1 = r.name(contact1)
const name1 = r.alias(contact1)
t.is(name1, EXPECTED.memberNick1, 'should get name1 from roomAlias')
const contact2 = new Contact(EXPECTED.memberId2)
const nick2 = r.nick(contact2)
t.is(nick2, EXPECTED.memberNick2, 'should get nick2 from name because there is no roomAlias, ')
const name2 = r.name(contact2)
const name2 = r.alias(contact2)
t.is(name2, EXPECTED.memberNick2, 'should get nick2 from name because there is no roomAlias, ')
t.truthy(r.has(contact1), 'should has contact1')
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册