async getMessages()

in src/chat.js [145:191]


  async getMessages() {
    let Messages = this.state.messageList;
    const user = await Auth.currentAuthenticatedUser();
    const authId = user.attributes.sub;
    const userName = user.username;
    console.log(user);
    console.log("NAME!!!!: " + userName);
    this.setState({
      isLoading: true,
    })
    console.log("GET MESSAGE!!!")
    try {
      console.log(this.state);
      let messageList = await chimeApi.listChannelMessages(this.state.chatChannel, authId, this.nextToken);
      console.log("messages: ");
      console.log(messageList);
      messageList.Messages.map((msg, index) => {
        let variant = "incoming";
        if (msg.Sender.Name === userName) {
          variant = "outgoing"
        }
        console.log(variant);
        Messages.push(
          <ChatBubbleContainer
                timestamp={formatTime(msg.CreatedTimestamp)}
                css="margin: 1rem;"
                key={`message${index.toString()}`}
              >
                <ChatBubble
                    variant={variant}
                    senderName={msg.Sender.Name}
                    showName={true}
                    showTail={true}
                > {msg.Content} </ChatBubble>
            </ChatBubbleContainer>
        );
      });
    }
    catch (e) {
      console.log("ERROR!!! GET MESSAGE!!");
      console.log(e);
    }
    this.setState({
      isLoading: false,
    })
    return Messages;
  }