Skip to content
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

Merged
merged 6 commits into from
Feb 8, 2017

Conversation

lijiarui
Copy link
Member

@lijiarui lijiarui commented Feb 6, 2017

No description provided.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.2%) to 55.733% when pulling 39e1955 on lijiarui:217 into ee51219 on wechaty:master.

1 similar comment
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.2%) to 55.733% when pulling 39e1955 on lijiarui:217 into ee51219 on wechaty:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.002%) to 55.886% when pulling c0a6998 on lijiarui:217 into ee51219 on wechaty:master.

1 similar comment
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.002%) to 55.886% when pulling c0a6998 on lijiarui:217 into ee51219 on wechaty:master.

Copy link
Member

@huan huan left a 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
Copy link
Member

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.

Copy link
Member Author

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?

Copy link
Member

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.

Copy link
Member Author

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.')
Copy link
Member

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.

Copy link
Member Author

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

Copy link
Member

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',
Copy link
Member

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 {
Copy link
Member

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>
Copy link
Member

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.

Copy link
Member Author

@lijiarui lijiarui Feb 6, 2017

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 > nickName

system message

When room event happens(join, leave, changetopic), system message recognise the name order as follows:
remark > nickName

on-screen Names

The contact name showed to the wechat user in the group
remark > displayName > nickName

Copy link
Member Author

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

Copy link
Member

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'
Copy link
Member

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no roomAlias.

@coveralls
Copy link

coveralls commented Feb 6, 2017

Coverage Status

Coverage decreased (-0.02%) to 55.873% when pulling 1b88912 on lijiarui:217 into ee51219 on wechaty:master.

Copy link
Member

@huan huan left a 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)
Copy link
Member

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.

Copy link
Member Author

@lijiarui lijiarui Feb 6, 2017

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.')
Copy link
Member

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})
Copy link
Member

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.

@lijiarui
Copy link
Member Author

lijiarui commented Feb 6, 2017

I guess Coverage decrease because I deleted const name2 = r.name(contact2) in room.spec.ts, because it is a wrong function caused by me in the first commit.

I'm sorry in my first commit I add a wrong function Room.name(contact), but after read your request, I changed function name() into alias().

@coveralls
Copy link

coveralls commented Feb 7, 2017

Coverage Status

Coverage decreased (-0.05%) to 55.836% when pulling 04987d0 on lijiarui:217 into ee51219 on wechaty:master.

Copy link
Member

@huan huan left a 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') {
Copy link
Member

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) {

Copy link
Member Author

@lijiarui lijiarui Feb 8, 2017

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'.

Copy link
Member

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']}
Copy link
Member

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 }

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it will throw error

Copy link
Member

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'
Copy link
Member

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?

Copy link
Member Author

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 ''
Copy link
Member

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]
Copy link
Member

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?

Copy link
Member Author

@lijiarui lijiarui Feb 8, 2017

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']}
Copy link
Member

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') {
Copy link
Member

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()
Copy link
Member

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')
Copy link
Member

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':
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

confusing names & logic here...

Copy link
Member

@huan huan left a 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]
Copy link
Member

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[]> {
Copy link
Member

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

Copy link
Member Author

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

Copy link
Member

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.

@huan huan merged commit 03d3991 into wechaty:master Feb 8, 2017
@lijiarui lijiarui deleted the 217 branch February 8, 2017 03:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants