Coder Social home page Coder Social logo

Comments (14)

tschellenbach avatar tschellenbach commented on July 17, 2024 1

see #107

from stream-chat-android.

tschellenbach avatar tschellenbach commented on July 17, 2024

from stream-chat-android.

luknow93 avatar luknow93 commented on July 17, 2024

Yeah I think adding only that extraData field would be enough as long as anything custom will end up there :)

from stream-chat-android.

luknow93 avatar luknow93 commented on July 17, 2024

While we're at it, similar thing could be added to Message object. I see iOS already has it, and we're using it there

from stream-chat-android.

tschellenbach avatar tschellenbach commented on July 17, 2024

Yeah, it's private on the message object atm. Will update once this is resolved.

from stream-chat-android.

tschellenbach avatar tschellenbach commented on July 17, 2024
// message and channel have extra data getters and setters
message.setExtraData
channel.setExtraData

@tbarbugli we currently don't have this on the attachment, can you have a look?

from stream-chat-android.

luknow93 avatar luknow93 commented on July 17, 2024

I tried to send some extraData attached to Message. But it seems like its not being sent?
In Channel.java extraDtya is not passed to SendMessageRequest at all. Unless I'm missing something?

public void sendMessage(Message message,
                            MessageCallback callback) {
        List<String> mentionedUserIDs = Utils.getMentionedUserIDs(channelState, message.getText());
        SendMessageRequest request;
        if (message.getId() != null) {
            request = new SendMessageRequest(message.getId(), message.getText(), message.getAttachments(), message.getParentId(), false, mentionedUserIDs);
        } else {
            request = new SendMessageRequest(message.getText(), message.getAttachments(), message.getParentId(), false, mentionedUserIDs);
        }

        client.sendMessage(this, request, new MessageCallback() {
            @Override
            public void onSuccess(MessageResponse response) {
                if (callback != null)
                    callback.onSuccess(response);
            }

            @Override
            public void onError(String errMsg, int errCode) {
                if (callback != null)
                    callback.onError(errMsg, errCode);
            }
        });
    }

I tried to add extra data while intercepting the message being sent by MessageInputView, and then passing it to ChannelViewModel as MessageInputView would do by default.
Is this the correct approach?

val viewModel = ViewModelProviders.of(this@MyFragment, ChannelViewModelFactory(activity!!.application, channel)) 
                    .get(ChannelViewModel::class.java)
ready__message_input.setViewModel(viewModel, this)

//...

ready__message_input.setOnSendMessageListener(object : MessageInputView.SendMessageListener {
                override fun onSendMessage(message: Message, callback: MessageCallback?) {
                    val extra = message.extraData ?: HashMap<String, Any>()
                    extra["testkey"] = "testvalue"
                    message.extraData = extra

                    viewModel.onSendMessage(message, callback) //ChannelViewModel
                }
            })

from stream-chat-android.

tschellenbach avatar tschellenbach commented on July 17, 2024

from stream-chat-android.

luknow93 avatar luknow93 commented on July 17, 2024

Awesome, can't wait 🤓

from stream-chat-android.

adrian09h avatar adrian09h commented on July 17, 2024

master supports it now.

If message has extradata, all key&values of extradata are set on SendMessageRequest by MessageGsonAdapter.

public class MessageGsonAdapter extends TypeAdapter<Message> {
    private static final String TAG = MessageGsonAdapter.class.getSimpleName();

    @Override
    public void write(JsonWriter writer, Message message) throws IOException {
        HashMap<String, Object> data = new HashMap<>();

        if (message.getExtraData() != null && !message.getExtraData().isEmpty())
            for (Map.Entry<String, Object> set : message.getExtraData().entrySet())
                data.put(set.getKey(), set.getValue());
...

Extradata of Channel, User and Attachment same as Message.

from stream-chat-android.

luknow93 avatar luknow93 commented on July 17, 2024

Hey!
just tried master and can confirm that the data is coming down in Attachment.extraData and Message.extraData.

One question tho, at what point can I edit the extraData of the message thats about to be send from my end(I need to attach some extras for every message I send)?
Previously it was possible through MessageInputView.SendMessageListener but now it's only returning the send result/error. I tried to walk through the whole send sequence, from hitting the button to building request, but couldn't find a place I could plug myself in.

from stream-chat-android.

tschellenbach avatar tschellenbach commented on July 17, 2024

At the moment you need your own custom message input component, going to make this easy to change this in the future though

from stream-chat-android.

luknow93 avatar luknow93 commented on July 17, 2024

Hm, I really hoped to avoid that at this point, especially that nothing important can be extended from yours and we need to battle test the whole GetStream before the end of October when Layer goes down :/

Any chance, even temporarily, you could simply add one method to SendMessageListener

public interface SendMessageListener {
        void onBeforeSendMessage(Message message); // <--- new callback
        void onSendMessageSuccess(Message message);
        void onSendMessageError(String errMsg);
    }

And then call it right before the Message is handed over to viewModel?

private void onSendMessage(String input, boolean isEdit) {
        binding.ivSend.setEnabled(false);

        if (isEdit) {
            getEditMessage().setText(input);
            getEditMessage().setAttachments(messageInputClient.getSelectedAttachments());
            viewModel.getChannel().updateMessage(getEditMessage(),  new MessageCallback() {
                @Override
                public void onSuccess(MessageResponse response) {
                    initSendMessage();
                    binding.ivSend.setEnabled(true);
                    clearFocus();
                }

                @Override
                public void onError(String errMsg, int errCode) {
                    initSendMessage();
                    binding.ivSend.setEnabled(true);
                    clearFocus();
                }
            });
        } else {
            Message m = new Message();
            m.setStatus(null);
            m.setText(input);
            m.setAttachments(messageInputClient.getSelectedAttachments());
                                                            //<-- new line
            if (sendMessageListener != null)                //<-- new line    
                sendMessageListener.onBeforeSendMessage(m); //<-- new line
                                                            //<-- new line
            viewModel.sendMessage(m, new MessageCallback() {
                @Override
                public void onSuccess(MessageResponse response) {
                    binding.ivSend.setEnabled(true);
                    initSendMessage();
                    if (sendMessageListener != null)
                        sendMessageListener.onSendMessageSuccess(response.getMessage());
                }

                @Override
                public void onError(String errMsg, int errCode) {
                    initSendMessage();
                    binding.ivSend.setEnabled(true);
                    if (sendMessageListener != null) {
                        sendMessageListener.onSendMessageError(errMsg);
                    } else {
                        Utils.showMessage(getContext(), errMsg);
                    }
                }
            });
        }
    }

If not(or maybe I'm missing something else?) then I'm just gonna fork the repo for now and tweak it myself.

from stream-chat-android.

luknow93 avatar luknow93 commented on July 17, 2024

You guys are the BEST!! 👏👏👏

from stream-chat-android.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.