简体   繁体   English

如何编辑 PubNub 消息并添加对单个消息的反应

[英]How do I edit PubNub Message and Add reaction to individual message

I have been working with PubNub, I tried storage and playback to update ( edit ) message, but failed.我一直在使用 PubNub,我尝试存储和播放以更新(编辑)消息,但失败了。 Kindly make me understand with code example, how to do it.请通过代码示例让我理解,如何做到这一点。

Can you provide some examples of your code?你能提供一些你的代码示例吗? You can find the docs for storage and playback at: https://www.pubnub.com/docs/web-javascript/api-reference-storage-and-playback您可以在以下位置找到用于存储和播放的文档: https://www.pubnub.com/docs/web-javascript/api-reference-storage-and-playback

1st thing you need to do is create a PubNub Client:您需要做的第一件事是创建一个 PubNub 客户端:

var pubnub = new PubNub({
    subscribeKey: "mySubscribeKey",
    publishKey: "myPublishKey",
    cipherKey: "myCipherKey",
    authKey: "myAuthKey",
    logVerbosity: true,
    uuid: "myUniqueUUID",
    ssl: true,
});

Then you can make a history call to a specific channel you want messages for:然后,您可以对您想要消息的特定频道进行历史调用:

pubnub.history(
    {
        channel: 'channel ID you want history for',
        count: 100, // how many items to fetch
        stringifiedTimeToken: true, // false is the default
    },
    function (status, response) {
        // handle status, response
    }
);

After that you can just load the JSON into your UI之后,您可以将 JSON 加载到您的 UI 中

Docs on editing a message: https://www.pubnub.com/docs/web-javascript/message-update-delete编辑消息的文档: https://www.pubnub.com/docs/web-javascript/message-update-delete

To edit a message编辑消息

Using the Interleaving pattern, you publish new versions of the same message to the same channel just like normal publishes.使用交错模式,您可以像正常发布一样将同一消息的新版本发布到同一频道。 The subsequent messages must use the same message_id as the original message...后续消息必须使用与原始消息相同的 message_id...

Let me know if this helps!让我知道这是否有帮助! Mathew马修

thanks I found the solution: just using pubnub.addMessageAction() and pubnub.removeMessageAction() like this:谢谢我找到了解决方案:只需像这样使用 pubnub.addMessageAction() 和 pubnub.removeMessageAction() :

pubnub.addMessageAction(
{
    channel: 'channel1'
    messageTimetoken: '15610547826970040',
    action: {
        type: 'reaction',
        value: 'smiley_face',
    },
},
function(status, response) {

});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM