Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions contracts/Web3EntryBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,16 @@ contract Web3EntryBase is
_createThenLinkCharacter(vars.fromCharacterId, vars.to, vars.linkType, "0x");
}

/**
* @notice linkNote creates a link between a character and a note, which can be used to indicate liking or
disagreeing for notes by assigning different linkTypes .
* @param vars The linkNoteData struct containing the following parameters:
* * fromCharacterId: The character id of the linker.
* * toCharacterId: The character id of the note owner.
* * toNoteId: The note id of the note to link.
* * linkType: The link type to use, for example, `LikeLinkType`.
* * data: The data input for link module, if any.
*/
function linkNote(DataTypes.linkNoteData calldata vars) external override {
_validateCallerPermission(vars.fromCharacterId, OP.LINK_NOTE);
_validateNoteExists(vars.toCharacterId, vars.toNoteId);
Expand All @@ -186,6 +196,35 @@ contract Web3EntryBase is
);
}

/**
* @notice linkNoteWithUri creates a link between a character and a note, and at the same
time attaches a uri to the link.
* @param vars The linkNoteData struct containing the following parameters:
* * fromCharacterId: The character id of the linker.
* * toCharacterId: The character id of the note owner.
* * toNoteId: The note id of the note to link.
* * linkType: The link type to use, for example, `LikeLinkType`.
* * data: The data input for link module, if any.
* @param uri The uri attached to the link, which can contain anything depending on how
you want to use it.
*/
function linkNoteWithUri(DataTypes.linkNoteData calldata vars, string calldata uri)
external
override
{
_validateCallerPermission(vars.fromCharacterId, OP.LINK_NOTE);
_validateNoteExists(vars.toCharacterId, vars.toNoteId);

LinkLogic.linkNoteWithUri(
vars,
uri,
IERC721Enumerable(this).ownerOf(vars.fromCharacterId),
_linklist,
_noteByIdByCharacter,
_attachedLinklists
);
}

function unlinkNote(DataTypes.unlinkNoteData calldata vars) external override {
_validateCallerPermission(vars.fromCharacterId, OP.UNLINK_NOTE);

Expand Down
2 changes: 2 additions & 0 deletions contracts/interfaces/IWeb3Entry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ interface IWeb3Entry {

function linkNote(DataTypes.linkNoteData calldata vars) external;

function linkNoteWithUri(DataTypes.linkNoteData calldata vars, string calldata uri) external;

function unlinkNote(DataTypes.unlinkNoteData calldata vars) external;

function linkERC721(DataTypes.linkERC721Data calldata vars) external;
Expand Down
9 changes: 9 additions & 0 deletions contracts/libraries/Events.sol
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,15 @@ library Events {
uint256 linklistId
);

event LinkNoteWithUri(
uint256 indexed fromCharacterId,
uint256 indexed toCharacterId,
uint256 indexed toNoteId,
bytes32 linkType,
string uri,
uint256 linklistId
);

event UnlinkNote(
uint256 indexed fromCharacterId,
uint256 indexed toCharacterId,
Expand Down
79 changes: 61 additions & 18 deletions contracts/libraries/LinkLogic.sol
Original file line number Diff line number Diff line change
Expand Up @@ -62,34 +62,45 @@ library LinkLogic {
mapping(uint256 => mapping(uint256 => DataTypes.Note)) storage _noteByIdByCharacter,
mapping(uint256 => mapping(bytes32 => uint256)) storage _attachedLinklists
) external {
uint256 linklistId = _mintLinklist(
vars.fromCharacterId,
vars.linkType,
uint256 linklistId = _processLinkNote(
vars,
linker,
linklist,
_noteByIdByCharacter,
_attachedLinklists
);

// add to link list
ILinklist(linklist).addLinkingNote(linklistId, vars.toCharacterId, vars.toNoteId);
emit Events.LinkNote(
vars.fromCharacterId,
vars.toCharacterId,
vars.toNoteId,
vars.linkType,
linklistId
);
}

// process link
address linkModule = _noteByIdByCharacter[vars.toCharacterId][vars.toNoteId].linkModule;
if (linkModule != address(0)) {
try
ILinkModule4Note(linkModule).processLink(
linker,
vars.toCharacterId,
vars.toNoteId,
vars.data
)
{} catch {} // solhint-disable-line no-empty-blocks
}
function linkNoteWithUri(
DataTypes.linkNoteData calldata vars,
string calldata uri,
address linker,
address linklist,
mapping(uint256 => mapping(uint256 => DataTypes.Note)) storage _noteByIdByCharacter,
mapping(uint256 => mapping(bytes32 => uint256)) storage _attachedLinklists
) external {
uint256 linklistId = _processLinkNote(
vars,
linker,
linklist,
_noteByIdByCharacter,
_attachedLinklists
);

emit Events.LinkNote(
emit Events.LinkNoteWithUri(
vars.fromCharacterId,
vars.toCharacterId,
vars.toNoteId,
vars.linkType,
uri,
linklistId
);
}
Expand Down Expand Up @@ -313,4 +324,36 @@ library LinkLogic {
emit Events.AttachLinklist(linklistId, fromCharacterId, linkType);
}
}

function _processLinkNote(
DataTypes.linkNoteData calldata vars,
address linker,
address linklist,
mapping(uint256 => mapping(uint256 => DataTypes.Note)) storage _noteByIdByCharacter,
mapping(uint256 => mapping(bytes32 => uint256)) storage _attachedLinklists
) internal returns (uint256) {
uint256 linklistId = _mintLinklist(
vars.fromCharacterId,
vars.linkType,
linklist,
_attachedLinklists
);

// add to link list
ILinklist(linklist).addLinkingNote(linklistId, vars.toCharacterId, vars.toNoteId);

// process link
address linkModule = _noteByIdByCharacter[vars.toCharacterId][vars.toNoteId].linkModule;
if (linkModule != address(0)) {
try
ILinkModule4Note(linkModule).processLink(
linker,
vars.toCharacterId,
vars.toNoteId,
vars.data
)
{} catch {} // solhint-disable-line no-empty-blocks
}
return linklistId;
}
}
6 changes: 6 additions & 0 deletions docs/Web3EntryBase.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ function createThenLinkCharacter(struct DataTypes.createThenLinkCharacterData va
function linkNote(struct DataTypes.linkNoteData vars) external
```

### linkNoteWithUri

```solidity
function linkNoteWithUri(struct DataTypes.linkNoteData vars, string uri) external
```

### unlinkNote

```solidity
Expand Down
6 changes: 6 additions & 0 deletions docs/interfaces/IWeb3Entry.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ function createThenLinkCharacter(struct DataTypes.createThenLinkCharacterData va
function linkNote(struct DataTypes.linkNoteData vars) external
```

### linkNoteWithUri

```solidity
function linkNoteWithUri(struct DataTypes.linkNoteData vars, string uri) external
```

### unlinkNote

```solidity
Expand Down
6 changes: 6 additions & 0 deletions docs/libraries/Events.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@ event UnlinkCharacter(address account, uint256 fromCharacterId, uint256 toCharac
event LinkNote(uint256 fromCharacterId, uint256 toCharacterId, uint256 toNoteId, bytes32 linkType, uint256 linklistId)
```

### LinkNoteWithUri

```solidity
event LinkNoteWithUri(uint256 fromCharacterId, uint256 toCharacterId, uint256 toNoteId, bytes32 linkType, string uri, uint256 linklistId)
```

### UnlinkNote

```solidity
Expand Down
12 changes: 12 additions & 0 deletions docs/libraries/LinkLogic.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,18 @@ function unlinkCharacter(struct DataTypes.unlinkCharacterData vars, address link
function linkNote(struct DataTypes.linkNoteData vars, address linker, address linklist, mapping(uint256 => mapping(uint256 => struct DataTypes.Note)) _noteByIdByCharacter, mapping(uint256 => mapping(bytes32 => uint256)) _attachedLinklists) external
```

### linkNoteWithUri

```solidity
function linkNoteWithUri(struct DataTypes.linkNoteData vars, string uri, address linker, address linklist, mapping(uint256 => mapping(uint256 => struct DataTypes.Note)) _noteByIdByCharacter, mapping(uint256 => mapping(bytes32 => uint256)) _attachedLinklists) external
```

### _processLinkNote

```solidity
function _processLinkNote(struct DataTypes.linkNoteData vars, address linker, address linklist, mapping(uint256 => mapping(uint256 => struct DataTypes.Note)) _noteByIdByCharacter, mapping(uint256 => mapping(bytes32 => uint256)) _attachedLinklists) internal returns (uint256)
```

### unlinkNote

```solidity
Expand Down
Loading