einfachIT / scratch3-messaging-extension

Apache License 2.0
1 stars 0 forks source link

Block to receive message - Part B #21

Open IsrarullahZaheer opened 6 months ago

IsrarullahZaheer commented 6 months ago

If a new message is received, this message needs to be accessible from the started code thread within scratch, we should not lose the message.

for example: User A: send three messages in order like: "Hallo 1", "Hallo 2", "Hallo 3" User B: should receive all three messages in the same order: "Hallo 1", "Hallo 2", "Hallo 3"

IsrarullahZaheer commented 4 months ago

Dear Mr. @Bassinator the code space is not working because the provided space is fulfil, I am working on this task on local machine and I will update the repo manually. Thanks

IsrarullahZaheer commented 4 months ago

Dear Mr. @Bassinator Dear Mr. @JoschaGreuel

After lots of try I couldn't find a good solution for it. If you have any good idea how can we achieve the goal.

I tried with the array but I couldn't achieve the goal.

Bassinator commented 4 months ago

Hello, I do not have very limited time, but took a short look in the code. So it is not sure if this works, but my idea would be:

  1. Here:

    this.client.on("message", (topic, message) => { // Store the latest message for the topic this.latestMessages[topic] = message.toString(); })

change this.latestMessages[topcic] from a simple string to a FIFO queue of strings.

new codeblock would then be:

  this.client.on("message", (topic, message) => {
    // Store the latest message for the topic
      this.latestMessages[topic].enqueue(message.toString());
  })
  1. The coldeblock to implement the hat block would then be changed from:

    newMessage({topic}){ return this.latestMessages[topic] || "" }

to

newMessage({topic}){ return this.latestMessages[topic].dequeue() || ""

}

kind regards,

Bastian

IsrarullahZaheer commented 4 months ago

Dear Mr. @Bassinator, Thanks for a valuable comments, I will try it and let you know today.

IsrarullahZaheer commented 4 months ago

Dear Mr. @Bassinator, I tried both solutions (npm package (queue-fifo)) and I implemented the queue myself both solutions are not working. the problem is: Cannot read properties of undefined (reading 'dequeue') Cannot read properties of undefined (reading 'enqueue')

but it's defined. I will continue working on this task.

you can continue with testing other tasks in the review this is something we can do by downloading the index file again at the end.

NOTE: When you are downloading index file from the repo in (rasbpi) system, make sure you have access to the repo othewise the empty file will download.

IsrarullahZaheer commented 3 months ago

Implement the queue structure, Checked the code with Mr. Faisal and will continue working tomorrow

IsrarullahZaheer commented 3 months ago

This task is done, I have implemented as queue structure if I have received Hallo 1 Hallo 2 Danke

output will be in the same order

Hallo 1 Hallo 2 Danke

in the screenshots it's showing only Danke but it executed Hallo1 and Hallo 2 before

Image

Image