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.fresh()not work; Room.alias()returns null #391

Closed
lvsjack opened this issue Apr 5, 2017 · 5 comments
Closed

Room.fresh()not work; Room.alias()returns null #391

lvsjack opened this issue Apr 5, 2017 · 5 comments

Comments

@lvsjack
Copy link

lvsjack commented Apr 5, 2017

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

npm ERR! Darwin 16.5.0
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "doctor"
npm ERR! node v7.8.0
npm ERR! npm v4.2.0

npm ERR! missing script: doctor
npm ERR!
npm ERR! If you need help, you may report this error at:
npm ERR! https://github.com/npm/npm/issues

npm ERR! Please include the following file with any support request:
npm ERR! /Users/Jack/.npm/_logs/2017-04-05T09_51_44_417Z-debug.log

Expected behavior

  1. after refresh the group data with Room.fresh(), the data should update as document say.

Room.alias (contact: Contact): string

Get the contact's alias in the room, if the contact doesn't set its roomAlias in the room, it return name.

Actual behavior

  1. still the same as before modify.
  2. Room.alias (contact: Contact): string returns null

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

import {greetingsMsg, hsyGroupClearMsg} from "../global";

const ONEDAY: number = 1000 * 60 * 60 * 24;
const FIVEMINS:number = 1000 * 60 * 5;

exports = module.exports = async function roomJoin(room, inviteeList, inviter) {
    room.say(greetingsMsg(room.topic()));

    // 如果群人数数量是5的倍数的时候,删除未按格式命名用户
    if (room.memberList().length % 2 === 0) {
        room.say(hsyGroupClearMsg);
        await timeout(1000);
        await delRandomMember(room);
    }
};

async function delRandomMember(room) {
    let list = room.memberList();
    let clearList = [];
    list.map((contact) => {
        let name = (room.alias(contact) === null) ? contact.name() : room.alias(contact); // 这里有个bug,room.alias(contact)在没有昵称的情况下,没有返回name,返回了null
        if (/-/.test(name) === false) {
            clearList.push(contact);
        }
    });

    if (clearList.length === 0) {
        return;
    } else {
        let warningMemberString = "为了方便交流,请修改群昵称,系统会在5分钟后自动删除未按规则命名用户";
        room.say(warningMemberString, clearList);

        // TODO 这里可能用户修改昵称 需要刷新群内用户信息,并删除没有按照格式修改的用户,但是没有效果
        await room.refresh();
        await timeout(10000); // 在这10秒内,我修改用户昵称

        list = room.memberList();
        list.map((contact) => {
            let name = (room.alias(contact) === null) ? contact.name() : room.alias(contact);
            if (/-/.test(name) === false) {
                clearList.push(contact);
            }
            console.log(name); // 但是显示的还是修改前的用户昵称
        });
        if (clearList.length === 0) {
            return;
        }
        const randomIndex = Math.floor(Math.random() * clearList.length);
        room.del(clearList[randomIndex]); // 这里还是删除了已经修改过昵称的用户
    }
}
function timeout(ms) {
    return new Promise((resolve) => {
        setTimeout(resolve, ms);
    });
}

Paste the full output logs here with WECHATY_LOG=silly set

@lijiarui
Copy link
Member

lijiarui commented Apr 5, 2017

  1. how about adding await room.ready() after await @room.refresh()
  2. see more about Room.alias() should return null if we have not set the alias in the room  #283 . If the contact doesn't set its roomAlias in the room, return null.

Btw, you should add more logs here as issue template showed, or I cannot give the more useful suggestion.
Thanks

@lvsjack
Copy link
Author

lvsjack commented Apr 6, 2017

...
await timeout(20000); // 在这段时间内,我修改群用户昵称
await room.refresh();
await room.ready();

list = room.memberList();
list.map((contact) => {
    let name = (room.alias(contact) === null) ? contact.name() : room.alias(contact);
    console.log(name); // 但是显示的还是修改前的用户昵称
    });
...

if I modify the alias, then refresh the room, the alias data not updated, but if I submit a new message, then get alias data, the data updated.

@lvsjack
Copy link
Author

lvsjack commented Apr 6, 2017

have to submit the message by hand to let data refresh, the bot say is not working.

Btw, about Room.say(content, replayTo), When I try to replayTo someone, the message format is right as @Someone something, but the app not really mention someone.

@lijiarui
Copy link
Member

lijiarui commented Apr 6, 2017

Btw, about Room.say(content, replayTo), When I try to replayTo someone, the message format is right as @Someone something, but the app not really mention someone.

yes, this is not a bug, because this it the most wechaty can do now, you can contribute more on this if you really need more.

About other questions, because of no more log or information, I cannot give the more useful suggestion.

@lvsjack
Copy link
Author

lvsjack commented Apr 12, 2017

OK, I see. Thanks you for your time.

@lvsjack lvsjack closed this as completed Apr 12, 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

2 participants