Comments (14)
see #107
from stream-chat-android.
from stream-chat-android.
Yeah I think adding only that extraData
field would be enough as long as anything custom will end up there :)
from stream-chat-android.
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.
Yeah, it's private on the message object atm. Will update once this is resolved.
from stream-chat-android.
// 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.
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.
from stream-chat-android.
Awesome, can't wait 🤓
from stream-chat-android.
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.
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.
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.
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.
You guys are the BEST!! 👏👏👏
from stream-chat-android.
Related Issues (20)
- The Android recipient user will be allowed to edit the sender's message. HOT 2
- Mention Search Customization Docs
- NullPointerException on MutableClientState.setUser HOT 1
- Unread Label
- Unable to input Japanese text using MessageComposer HOT 1
- Different Attachment Types within one Message cause invalid rendering (Compose UI) HOT 2
- Unable to Customise the AttachmentView / Gallery (Compose) HOT 1
- Crash issue with version 5.17.23
- Unable to use scrollToMessage when the message is not present in list HOT 1
- After reacting on message, message list scrolls down to bottom HOT 5
- Multiple ChatClient instances
- When the giphy is the first message of the channel, it won't disappear when the user click cancel HOT 3
- The API are sending correct response but Android SDK is failing to give in succes callback. HOT 11
- io.getstream.android.push.delegate.PushDelegateProvider obfuscated
- Issue in Compiling the Project HOT 1
- SDK crashing when switching User while observing channels
- Not able to create any new channels. HOT 3
- Highlighting and tapping on user mentions
- Sender does not always receive new message event when sending a PDF HOT 1
- Add a way to listen for clicks on individual messages and their avatars in Compose MessageScreen
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from stream-chat-android.