Update

Update the specific post by creating a new post with the postType amend and the original post item_hash as the ref along with the new content.

Usage

Create a Post

import { ItemType } from 'aleph-sdk-ts/dist/messages/message';
import { Publish as publishPost } from 'aleph-sdk-ts/dist/messages/post';

(async () => {
    await publishPost({
        account: account,
        postType: 'mytype',
        content: {'body': 'first content'},
        channel: 'TEST',
	})
})();

The message result is here Item hash: 919939843673b380b5ed5fa5a863768f948041c48ff9c8840a740b385d1058a3

Update the Post

With the same account, send another post message that refers to the original item hash:

import { ItemType } from 'aleph-sdk-ts/dist/messages/message';
import { Publish as publishPost } from 'aleph-sdk-ts/dist/messages/post';

(async () => {
    await publishPost({
        account: account, // The same account that created the message
        postType: 'amend', //Must be amend
        ref: '919939843673b380b5ed5fa5a863768f948041c48ff9c8840a740b385d1058a3', // Item Hash of the original post
        content: {'body': 'first content updated'},
        channel: 'TEST',
	})
})();

The message result is here

Checking the result

import { ItemType } from 'aleph-sdk-ts/dist/messages/message';
import { Get as getPost } from 'aleph-sdk-ts/dist/messages/post';

(async () => {
    await getPost({
            types: 'mytype',
            hashes: [res.item_hash],
	})
})();

The content return is : "content":{"body":"first content updated"}.

The original value of the message can be retrieved when you are fetching a message that have been amended:

{
    original_item_hash: '27f5bccbde6d41f3460c68d32083429a098d5d78a16539303670c6cdf71cbfc0',
    original_signature: '0x1f575376780c3b11e31bee349a587a251d7a3bbef2bc6a884246992c02ba19972db2cda27b415d434bcdf76b726448ee2f870c13100eaf2808939426df85775e1b',
    original_type: 'mytype',
    ...
}

Last updated