ansible-role-varnish
ansible-role-varnish copied to clipboard
[Private Chat] [Multi-Device] `chatMessagesStream` does not fire for our own sent messages
Hi @TatankaConCube ,
First I want to ask if this was a design choice or are we missing implementation on our side.
We have no problem in Group Chats. We can get all the messages sent to a specific dialogId using chatMessagesStream
. Even our own messages fall to the listener as expected.
But while the user is sending a message to a Private Chat dialog, their messages are not received from chatMessagesStream
.
If this is by design, it should definitely be written in the documentation that our own messages are not received from the stream for private chats.
I think this is a very bad design choice in the architecture. What if my same CC user is logged in from multiple devices. Then how will we able to show the message they sent from their iOS device along with their Android device for instance? It will not be shown until app restarts and history is received! addMessageToListView
used in the sample app is a local device specific code. It can't support multi device scenarios.
The implementation of Group Chat makes more sense. Why is the implementation of the chatMessagesStream
different in Private Chat?
I looked at the example code and I have some questions:
- If
onReceiveMessage
does not catch our own messages in the first place, why do we check if(message.senderId == _cubeUser.id) return;
- What does
_cubeDialog.deliverMessage(message);
do exactly? - What can we do show our sent message in multiple devices when they are inside the chat pages? Can we use
deliveredStream
to catch our delivered messages and display them from all of our devices safely? Edit: i checked and this subcription only gives us a simpleMessageStatus
object. Not the actual message. - What does
message.markable = true;
accomplish? The docs were not very informative. - As a last resort, is there any other listener/subcription we can use to get the singular chat dialog messages including ours? This way, we can open the listener when the user is in that specific private chat page. And we can display our own messages safely.
_initChatListeners() {
msgSubscription = CubeChatConnection
.instance.chatMessagesManager!.chatMessagesStream
.listen(onReceiveMessage);
deliveredSubscription = CubeChatConnection
.instance.messagesStatusesManager!.deliveredStream
.listen(onDeliveredMessage);
readSubscription = CubeChatConnection
.instance.messagesStatusesManager!.readStream
.listen(onReadMessage);
typingSubscription = CubeChatConnection
.instance.typingStatusesManager!.isTypingStream
.listen(onTypingMessage);
}
void onReceiveMessage(CubeMessage message) {
log("onReceiveMessage message= $message");
if (message.dialogId != _cubeDialog.dialogId ||
message.senderId == _cubeUser.id) return; //Why do we omit our own messages here if we can't even receive them??
_cubeDialog.deliverMessage(message); //What does this do exactly?
addMessageToListView(message); //We add the received message to the list
}
https://github.com/ConnectyCube/connectycube-flutter-samples/blob/29c2675934d299cca094bfd104c6a0c07f5f6e30/chat_sample/lib/src/chat_dialog_screen.dart#L234
void onSendMessage(CubeMessage message) async {
log("onSendMessage message= $message");
textEditingController.clear();
await _cubeDialog.sendMessage(message);
message.senderId = _cubeUser.id;
addMessageToListView(message); //We add the sent message to the UI list directly and unconditionally (maybe network is down?)
listScrollController.animateTo(0.0,
duration: Duration(milliseconds: 300), curve: Curves.easeOut);
}
hi @aytunch and @erkansahin
The implementation of Group Chat makes more sense. Why is the implementation of the chatMessagesStream different in Private Chat?
There is the feature of MUC specification, the server sends messages to all group chat members including the current user. About using the chat feature on multiple devices - the same user should receive his own messages sent from other devices because the Carbons feature is enabled by default.
1
We do it to ignore our own messages in group chats. The Chat sample is a simple app for demonstrating Connectycube API, we haven't complicated it for use on multiple devices. If customers need this feature they can easily do it by themselves.
2
Since version 2.1.0 we do it on the SDK side automatically by default in the first place where we receive the incoming message, more there.
3
Yes, your user will receive status messages on all logged-in devices. The MessageStatus
model contains the id of the user who has marked the message, the id of the original message, and the id of the dialog the message is related to.
4
See the answer to the second question.
5
The msgSubscription
is the right way to listen to the incoming messages. You can apply the where
operator to filter messages related to the specific dialog only.
@TatankaConCube thank you very much for the responses. Other than this question, I have have answers:
What can we do show our sent message in multiple devices when they are inside the chat pages? Can we use deliveredStream to catch our delivered messages and display them from all of our devices safely? Edit: i checked and this subcription only gives us a simple MessageStatus object. Not the actual message.
What I mean here is that let's say my user is logged in with the same account from 2 devices. iPhone(A1) and Android(A2) and both are in the same private chat page actively with a 2nd person B
When A1 sends a mesaage, B receives it from msgSubscription
A1 knows that he sent the message so A1 can display the sent message.
What about A2? How can the android device display A1's message?
Can you please help because we rely on multi device users.
@aytunch sorry, we missed your last reply((( The feature for multidevice messaging was improved in version 2.5.5 and now you can use only one statement for filtering the messages list
if (message.dialogId != _cubeDialog.dialogId) return;