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

[FEAT]get post sayable from server posts #2530

Closed
hcfw007 opened this issue May 3, 2023 · 2 comments
Closed

[FEAT]get post sayable from server posts #2530

hcfw007 opened this issue May 3, 2023 · 2 comments

Comments

@hcfw007
Copy link
Member

hcfw007 commented May 3, 2023

In wechaty post mixin:

if (PUPPET.payloads.isPostServer(this.payload)) {
for (const messageId of this.payload.sayableList) {
const message = await this.wechaty.Message.find({ id: messageId })
if (message) {
const sayable = await message.toSayable()
if (sayable) {
yield sayable
}
}
}

We get server post sayable by loading messages from the sayable id. This works for mixed messages (messages containing many sayables), however for moment and moment replies, it doesn't make no scence to convert them to messages.

So I say we create puppet method to get sayables with id, it should be somehting like this:

wechaty-puppet

    // get a sayable from server post (which comes with Id)
    abstract postPayloadSayable (postId: string, sayableId: string): Promise<SayablePayload>

wechaty:

  async * [Symbol.asyncIterator] (): AsyncIterableIterator<Sayable> {
    log.verbose('Post', '[Symbol.asyncIterator]()')

    const payloadToSayable = payloadToSayableWechaty(this.wechaty)

    if (PUPPET.payloads.isPostServer(this.payload)) {
      for (const sayableId of this.payload.sayableList) {
        const sayable = await this.getSayableWithId(sayableId)

        if (sayable) {
          yield sayable
        }
      }

    } else {  // client
      for (const sayablePayload of this.payload.sayableList) {
        const sayable = await payloadToSayable(sayablePayload)
        if (sayable) {
          yield sayable
        }
      }

    }
  }

  async getSayableWithIndex (sayableIndex: number) {
    log.verbose('Post', 'getSayableWithIndex(%s)', sayableIndex)

    const payloadToSayable = payloadToSayableWechaty(this.wechaty)

    if (PUPPET.payloads.isPostServer(this.payload)) {
      const sayablePayload = await this.wechaty.puppet.postPayloadSayable(this.id!, this.payload.sayableList[sayableIndex]!)
      const sayable = await payloadToSayable(sayablePayload)
      return sayable
    } else {
      const sayablePayload = this.payload.sayableList[sayableIndex]
      if (sayablePayload) {
        const sayable = await payloadToSayable(sayablePayload)
        return sayable
      } else {
        throw new Error(`post has no sayable with index ${sayableIndex}`)
      }
    }
  }

  async getSayableWithId (id: string) {
    log.verbose('Post', 'getSayableWithId(%s)', id)

    if (PUPPET.payloads.isPostServer(this.payload)) {
      const payloadToSayable = payloadToSayableWechaty(this.wechaty)
      const sayablePayload = await this.wechaty.puppet.postPayloadSayable(this.id!, id)
      const sayable = await payloadToSayable(sayablePayload)
      return sayable
    } else {
      throw new Error('client post sayable has no Id')
    }
  }
@hcfw007
Copy link
Member Author

hcfw007 commented May 5, 2023

After discussion in Wechaty Community Meeting (brief here)
Keys:

  1. Any sayable in Moment can be parsed as a message.
  2. The message's talker and listener should be bot self.
  3. As we mentioned in quote message issue, all messages should be able to be parsed as Post in puppet implementation. So you should be able to call postRawPayload with a valid message id and get a valid response.

Copy link

dosubot bot commented Nov 19, 2023

Hi, @hcfw007! I'm Dosu, and I'm here to help the wechaty team manage their backlog. I wanted to let you know that we are marking this issue as stale.

From what I understand, you opened this issue suggesting the addition of a new method called postPayloadSayable to the wechaty-puppet library. The proposal was discussed in the Wechaty Community Meeting, and it was determined that any sayable in Moment can be parsed as a message, and all messages should be able to be parsed as a Post in the puppet implementation.

I wanted to check with you if this issue is still relevant to the latest version of the wechaty repository. If it is, please let the wechaty team know by commenting on the issue. Otherwise, feel free to close the issue yourself, or it will be automatically closed in 7 days.

Thank you for your contribution, and please let us know if you have any further questions or concerns!

@dosubot dosubot bot added the stale Issue has not had recent activity or appears to be solved. Stale issues will be automatically closed label Nov 19, 2023
@dosubot dosubot bot closed this as not planned Won't fix, can't repro, duplicate, stale Nov 26, 2023
@dosubot dosubot bot removed the stale Issue has not had recent activity or appears to be solved. Stale issues will be automatically closed label Nov 26, 2023
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

1 participant