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

room.member() can not return right result #437

Closed
lvsjack opened this issue Apr 25, 2017 · 9 comments
Closed

room.member() can not return right result #437

lvsjack opened this issue Apr 25, 2017 · 9 comments

Comments

@lvsjack
Copy link

lvsjack commented Apr 25, 2017

Provide Your Network Information

  1. Where is the location of your server? (i.e. City, or In/Out China)
  2. Which cloud platform(AliYun/Qcloud/DigitalOcean/etc) are you using?

localhost in China

Run npm run doctor or wechaty run doctor(for docker user), paste output here

...
Starting Wechaty ... NodeJS Version=v7.9.0v0.7.62
...

Expected behavior

const target = keyroom.member({alias: targetName}) || keyroom.member({name: targetName});
console.log(target);

get contact in room

Actual behavior

always return null , which is incorrect, because if I use room.memberList() method, it can return right contact info in the list.

Steps to reproduce the behavior (and fixes, if any)

fixed as below

function getTarget(){
            const nameMap = keyroom.obj.nameMap;
            const roomAliasMap = keyroom.obj.roomAliasMap;
            const contactAliasMap = keyroom.obj.contactAliasMap;
            const memberList = keyroom.obj.memberList;

            const targetKey = parseMap(nameMap) || parseMap(roomAliasMap) || parseMap(contactAliasMap);
            
            
            if(targetKey){
                for(let i=0; i<memberList.length; i  ){
                    if(memberList[i].id === targetKey){
                        return memberList[i];
                    }
                }
            }else{
                return null
            }
            function parseMap(map){
                for(let key in map){
                    if(map[key].trim() == targetName.trim()) {
                        return key;
                    }
                }
                return null
            }
        }

Paste the full output logs here with WECHATY_LOG=silly set

@lijiarui
Copy link
Member

lijiarui commented Apr 25, 2017

try

await keyroom.ready()

before

const target = keyroom.member({alias: targetName}) || keyroom.member({name: targetName});
console.log(target);

it may fix.

@lvsjack
Copy link
Author

lvsjack commented Apr 26, 2017

await keyroom.refresh();
await keyroom.ready();
const target = keyroom.member({name: targetName}) || keyroom.member({alias: targetName});
console.log(target);
        

no, not working, the result shows null, instead of 'Contact'.

@lijiarui
Copy link
Member

lijiarui commented Apr 26, 2017

please paste log and let me try to resolve...

both console.log(room) and console.log(target) log

@huan
Copy link
Member

huan commented Apr 26, 2017

@lvsjack I suggest you just use keyroom.member(targetName) for convenience.

@lvsjack
Copy link
Author

lvsjack commented Apr 26, 2017

console.log(keyroom)

Room {
  domain: null,
  _events: {},
  _eventsCount: 0,
  _maxListeners: undefined,
  id: '@@6ebabcea6af4ea365ac8c9e44a60dcc8d491d7925c57c2028607a62afddcec0d',
  rawObj:
   { Alias: '',
     AppAccountFlag: 0,
     AttrStatus: 0,
     ChatRoomId: 0,
     ChatRoomOwner: '@ac1fb2b1fcc424a00376c9939a42a7d364a83d2eb020954c6987b91afddb0328',
     City: '',
     ContactFlag: 2,
     DisplayName: '',
     EncryChatRoomId: '@9a9a79a3ceb5cde028e1548196bf3987',
     HeadImgUpdateFlag: 1,
     HeadImgUrl: '/cgi-bin/mmwebwx-bin/webwxgetheadimg?seq=0&username=@@6ebabcea6af4ea365ac8c9e44a60dcc8d491d7925c57c2028607a62afddcec0d&skey=@crypt_d03fd9d9_3cfd07801bfab5357ed4a16e5dac967a',
     HideInputBarFlag: 0,
     IsOwner: 1,
     KeyWord: '',
     MMFromBatchGet: true,
     MMFromBatchget: true,
     MMInChatroom: true,
     MMOrderSymbol: '~',
     MemberCount: 3,
     MemberList: [ [Object], [Object], [Object] ],
     NickName: '测试',
     OwnerUin: 0,
     PYInitial: 'BYD1ABZ',
     PYQuanPin: 'beiyaode1aibangzhu',
     Province: '',
     RemarkName: '',
     RemarkPYInitial: '',
     RemarkPYQuanPin: '',
     Sex: 0,
     Signature: '',
     SnsFlag: 0,
     StarFriend: 0,
     Statues: 1,
     Uin: 0,
     UniFriend: 0,
     UserName: '@@6ebabcea6af4ea365ac8c9e44a60dcc8d491d7925c57c2028607a62afddcec0d',
     VerifyFlag: 0,
     stranger: true },
  obj:
   { id: '@@6ebabcea6af4ea365ac8c9e44a60dcc8d491d7925c57c2028607a62afddcec0d',
     encryId: '@9a9a79a3ceb5cde028e1548196bf3987',
     topic: '测试',
     ownerUin: 0,
     memberList: [ [Object], [Object], [Object] ],
     nameMap:
      Map {
        '@ac1fb2b1fcc424a00376c9939a42a7d364a83d2eb020954c6987b91afddb0328': '爱帮助-助手',
        '@a16a2b59ce63aef85657e10225e48cf6': '123',
        '@f11869123319f881d427d391b3cba04acb69fe93fb56fd2d982152566a7625e1': '明天🌞' },
     roomAliasMap:
      Map {
        '@ac1fb2b1fcc424a00376c9939a42a7d364a83d2eb020954c6987b91afddb0328': '爱帮助(测试)-助手',
        '@a16a2b59ce63aef85657e10225e48cf6': '',
        '@f11869123319f881d427d391b3cba04acb69fe93fb56fd2d982152566a7625e1': '' },
     contactAliasMap:
      Map {
        '@ac1fb2b1fcc424a00376c9939a42a7d364a83d2eb020954c6987b91afddb0328': '',
        '@a16a2b59ce63aef85657e10225e48cf6': '',
        '@f11869123319f881d427d391b3cba04acb69fe93fb56fd2d982152566a7625e1': '' } },
  dirtyObj:
   { id: '@@6ebabcea6af4ea365ac8c9e44a60dcc8d491d7925c57c2028607a62afddcec0d',
     encryId: '@9a9a79a3ceb5cde028e1548196bf3987',
     topic: '测试',
     ownerUin: 0,
     memberList: [ [Object], [Object], [Object] ],
     nameMap:
      Map {
        '@ac1fb2b1fcc424a00376c9939a42a7d364a83d2eb020954c6987b91afddb0328': '爱帮助-助手',
        '@a16a2b59ce63aef85657e10225e48cf6': '123',
        '@f11869123319f881d427d391b3cba04acb69fe93fb56fd2d982152566a7625e1': '明天🌞' },
     roomAliasMap:
      Map {
        '@ac1fb2b1fcc424a00376c9939a42a7d364a83d2eb020954c6987b91afddb0328': '爱帮助(测试)-助手',
        '@a16a2b59ce63aef85657e10225e48cf6': '',
        '@f11869123319f881d427d391b3cba04acb69fe93fb56fd2d982152566a7625e1': '' },
     contactAliasMap:
      Map {
        '@ac1fb2b1fcc424a00376c9939a42a7d364a83d2eb020954c6987b91afddb0328': '',
        '@a16a2b59ce63aef85657e10225e48cf6': '',
        '@f11869123319f881d427d391b3cba04acb69fe93fb56fd2d982152566a7625e1': '' } } }

const target = keyroom.member({name: "爱帮助(测试)-助手"}) || keyroom.member({alias: "爱帮助(测试)-助手"});
console.log(target) // null

const target = keyroom.member("爱帮助(测试)-助手"); 
console.log(target) // null

@huan
Copy link
Member

huan commented Apr 28, 2017

What's the output of your targetName?

console.log(targetName)

@lvsjack
Copy link
Author

lvsjack commented Apr 29, 2017

const target = keyroom.member({name: "爱帮助(测试)-助手"}) || keyroom.member({alias: "爱帮助(测试)-助手"});
const target = keyroom.member("爱帮助(测试)-助手"); 

@huan
Copy link
Member

huan commented Apr 29, 2017

It's wired.

Could you run your code by set WECHATY_LOG=silly and post the full output log for us to have a look?

export WECHATY_LOG=silly

@huan
Copy link
Member

huan commented Jul 6, 2017

Close this issue due to inactivity for more than two months.

@huan huan closed this as completed Jul 6, 2017
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

No branches or pull requests

3 participants