-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
rename the nick/remark/display for contact/room #217 #234
Conversation
1 similar comment
1 similar comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please follow my change requests.
src/contact.ts
Outdated
@@ -55,8 +55,10 @@ export enum Gender { | |||
} | |||
|
|||
export type ContactQueryFilter = { | |||
name?: string | RegExp | |||
name?: string | RegExp | |||
// remark should be deprecated | |||
remark?: string | RegExp |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there's no reason to keep remark
here anymore. remove it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then we should deprecate function Contact.find(remark: string)
right now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
deprecate right now. but it should still functional.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, I guess I can use function Contact.find(query: ContactQueryFilter | {remark: string})
instead, is it right?
src/contact.ts
Outdated
@@ -232,6 +234,10 @@ export class Contact implements Sayable { | |||
query = { name: /.*/ } | |||
} | |||
|
|||
if (query[0] === 'remark') { | |||
log.warn('Contact', 'findAll(remark:%s) DEPRECATED, use findAll(alias:%s) instead.') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add query[0] = 'alias'
to the next line.
then you can only deal with alias
in the following code, without remark
anymore.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need to add query[0] = 'alias'
, because I had deal the alias in the following code:
const keyMap = {
name: 'NickName',
// should be deprecated
remark: 'RemarkName',
alias: 'RemarkName',
}
...
if (filterValue instanceof RegExp) {
filterFunction = `(function (c) { return ${filterValue.toString()}.test(c.${filterKey}) })`
} else if (typeof filterValue === 'string') {
filterValue = filterValue.replace(/'/g, '\\\'')
filterFunction = `(function (c) { return c.${filterKey} === '${filterValue}' })`
} else {
throw new Error('unsupport name type')
}
If you are sure to deprecate function Contact.find(remark:string)
right now, I will delete this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no, you misunderstand.
you should remove remark
in keyMap first, then you will have to follow my request.
src/contact.ts
Outdated
@@ -248,7 +254,9 @@ export class Contact implements Sayable { | |||
|
|||
const keyMap = { | |||
name: 'NickName', | |||
// should be deprecated | |||
remark: 'RemarkName', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove remark
src/contact.ts
Outdated
return false // fail safe | ||
}) | ||
} | ||
|
||
public remark(newRemark?: string|null): Promise<boolean> | string | null { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a // @deprecated comment above the function
src/room.ts
Outdated
displayMap: Map<string, string> | ||
nameMap: Map<string, string> | ||
aliasMap: Map<string, string> | ||
roomAliasMap: Map<string, string> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove roomAliasMap
here. Because aliasMap
should be roomAliasMap
The room should only in charge of search alias in room. Search contact alias should use Contact.find()
instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we use Contact.find() instead, then when use function member()
to get Contact would be asynchronous, which means it will use
public async member(queryArg: MemberQueryFilter | string): Promise<Contact | null>
but actually we want to use synchronous function.
because we use function member()
in firer.ts
And, we must use alias(remark) in room, which I have said in #104 :
You said in room.ts
ISSUE #104 never use remark name because sys group message will never use that
But sys group message use remark.
For example, when the bot set remark for A, then A changed the topic, then sys message shows the remark, not roomAlias.
I have summarize in #173:
Display order:
@ Event
When someone @ a contact in a room, wechat recognise the name order as follows:
displayName > nickNamesystem message
When room event happens(join, leave, changetopic), system message recognise the name order as follows:
remark > nickNameon-screen Names
The contact name showed to the wechat user in the group
remark > displayName > nickName
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So,I recommend we should use three kind of map:
nameMap
aliasMap
roomAliasMap
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, you are right.
Agreed.
src/room.ts
Outdated
} | ||
|
||
type NameType = 'nick' | 'display' | 'remark' | ||
type NameType = 'name' | 'alias' | 'roomAlias' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no roomAlias
. alias
is for room only.
src/room.ts
Outdated
display?: string | ||
name?: string | ||
alias?: string | ||
roomAlias?: string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no roomAlias.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good, please follow my new reviews.
Also, please make sure the test coverage is not decreasing. last time your PR caused a coverage decrease:
Coverage decreased (-0.002%) to 55.886% when pulling c0a6998 on lijiarui:217 into ee51219
src/contact.ts
Outdated
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should also log.warn()
for remark
in find()
function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think no need to add log.warn()
here, because find()
use findAll()
, and I had add log.warn()
for findAll()
.
Do you agree?
src/room.ts
Outdated
public nick(contact: Contact): string { | ||
if (!this.obj || !this.obj.nickMap) { | ||
log.warn('Room', 'nick(Contact) DEPRECATED, use name(Contact) instead.') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
name(Contact)
here should be alias(Contact)
?
src/room.ts
Outdated
@@ -399,7 +406,7 @@ export class Room extends EventEmitter implements Sayable { | |||
|
|||
public member(queryArg: MemberQueryFilter | string): Contact | null { | |||
if (typeof queryArg === 'string') { | |||
return this.member({remark: queryArg}) || this.member({display: queryArg}) || this.member({nick: queryArg}) | |||
return this.member({alias: queryArg}) || this.member({roomAlias: queryArg}) || this.member({name: queryArg}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here alias
& roomAlias
is a bit confused.
consider to rename to contactAlias
& roomAlias
to declare them more clearly.
I guess Coverage decrease because I deleted I'm sorry in my first commit I add a wrong function |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's part of code is confusing me a lot.
src/contact.ts
Outdated
@@ -227,9 +227,9 @@ export class Contact implements Sayable { | |||
public static async findAll(queryArg?: ContactQueryFilter | {remark: string | RegExp}): Promise<Contact[]> { | |||
let query: ContactQueryFilter | |||
if (queryArg) { | |||
if (queryArg[0] === 'remark') { | |||
if (Object.keys(queryArg)[0] === 'remark') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
change to: if (queryArg.remark) {
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried it before, but it isn't compiled successfully:
public static async findAll(queryArg?: ContactQueryFilter | {remark: string | RegExp}): Promise<Contact[]> {
let query: ContactQueryFilter
if (queryArg) {
if (queryArg.remark) {
query = { alias: queryArg.remark}
}
error throw:
src/contact.ts(230,20): error TS2339: Property 'remark' does not exist on type 'ContactQueryFilter | { remark: string | RegExp; }'.
Property 'remark' does not exist on type 'ContactQueryFilter'.
src/contact.ts(231,35): error TS2339: Property 'remark' does not exist on type 'ContactQueryFilter | { remark: string | RegExp; }'.
Property 'remark' does not exist on type 'ContactQueryFilter'.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
src/contact.ts
Outdated
log.warn('Contact', 'Contact.findAll(remark:%s) DEPRECATED, use Contact.findAll(alias:%s) instead.') | ||
query = { alias: queryArg[1]} | ||
query = { alias: queryArg['remark']} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
change to: query = { alias: queryArg.remark }
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it will throw error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
src/room.ts
Outdated
} | ||
|
||
type NameType = 'name' | 'alias' | 'roomAlias' | ||
type NameType = 'nick' | 'alias' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nick
??? why nick, I think it should be name
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry, my fault..
src/room.ts
Outdated
return this.alias(contact) | ||
} | ||
|
||
public alias(contact: Contact): string { | ||
if (!this.obj || !this.obj.nameMap) { | ||
if (!this.obj) { | ||
return '' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should return null
be better?
src/room.ts
Outdated
return '' | ||
} | ||
return this.obj.roomAliasMap[contact.id] || this.obj.nameMap[contact.id] | ||
return this.obj.aliasMap[contact.id] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if no aliasMap[contact.id]
, here'll return a undefined
, which is not expected?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if no aliasMap[contact.id]
here, it should return undefiend. Actually, I have deal alias in parse aliasMap as follows:
private parseMap(memberList: RoomRawMember[], parseContent: NameType): Map<string, string> {
const mapList: Map<string, string> = new Map<string, string>()
if (memberList && memberList.map) {
memberList.forEach(member => {
let tmpName: string
let contact = Contact.load(member.UserName)
switch (parseContent) {
case 'name':
tmpName = contact.alias() || contact.name()
break
case 'alias':
tmpName = member.DisplayName || contact.name()
break
default:
throw new Error('parseMap failed, member not found')
}
if no DisplayName
, this code tmpName = member.DisplayName || contact.name()
will get contact.name()
So, no need to add this.obj.nameMap[contact.id]
here, what do you think about it?
src/contact.ts
Outdated
query = queryArg | ||
if (Object.keys(queryArg)[0] === 'remark') { | ||
log.warn('Contact', 'Contact.findAll(remark:%s) DEPRECATED, use Contact.findAll(alias:%s) instead.') | ||
query = { alias: queryArg['remark']} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
queryArg.remark
src/contact.ts
Outdated
let query: ContactQueryFilter | ||
if (queryArg) { | ||
query = queryArg | ||
if (Object.keys(queryArg)[0] === 'remark') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (queryArg.remark) {
src/contact.ts
Outdated
if (newRemark) { | ||
return this.alias(newRemark) | ||
} else { | ||
return this.alias() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
when newRemark = null
, will run code here, which is not expected.
src/room.ts
Outdated
const remarkMap = this.parseMap(rawObj.MemberList, 'remark') | ||
const displayMap = this.parseMap(rawObj.MemberList, 'display') | ||
const memberList = this.parseMemberList(rawObj.MemberList) | ||
const nameMap = this.parseMap(rawObj.MemberList, 'nick') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why nameMap
use arg name with nick
here?
should be consistent.
src/room.ts
Outdated
@@ -238,21 +234,20 @@ export class Room extends EventEmitter implements Sayable { | |||
let contact = Contact.load(member.UserName) | |||
switch (parseContent) { | |||
case 'nick': |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
confusing names & logic here...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Almost merage-able.
src/room.ts
Outdated
} | ||
return this.obj.displayMap[contact.id] || this.obj.nickMap[contact.id] | ||
return this.obj.aliasMap[contact.id] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return this.obj.aliasMap[contact.id] || null
src/contact.ts
Outdated
*/ | ||
public static async findAll(queryArg?: ContactQueryFilter): Promise<Contact[]> { | ||
public static async findAll(queryArg?: ContactQueryFilter | {remark: string | RegExp}): Promise<Contact[]> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move remark: string | RegExp
to ContactQueryFilter
with a comment noticing DEPRECATED
then you could use .remark
again
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there's no reason to keep remark here anymore. remove it.
you just told me to remove remark from ContactQueryFilter
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, let me tell u one more:
Next time, if u still only know what instead of knowing why, and make stupid argue like this, then kick your ass 10 times by yourself.
No description provided.