Last active
January 24, 2022 20:30
-
-
Save MCarlomagno/a083d7bccfb320c4138b61f4e44838f8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity >=0.7.0 <0.9.0; | |
contract Chat { | |
// the list of old messages in the chat | |
mapping(uint => Message) public messagesList; | |
function listMessages() public constant returns (uint[]){ | |
// if the chat is empty | |
if(lastMessageId == 0) { | |
return new uint[](0); | |
} | |
// give me the ids. | |
uint[] memory ids = new uint[](lastMessageId); | |
// loads all the message ids on 'ids' list. | |
for (uint i = 1; i <= lastMessageId; i++) { | |
// if the sender is different than me. | |
if(messages[i].sender != msg.sender) { | |
ids[numOfMessages] = messagesList[i].id; | |
} | |
} | |
return ids; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment