Skip to content

Commit 820c4ce

Browse files
Update README.md
1 parent 090d695 commit 820c4ce

File tree

1 file changed

+31
-24
lines changed

1 file changed

+31
-24
lines changed

README.md

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -92,37 +92,44 @@ try {
9292

9393
#### Subscribe to receive messages
9494

95-
QuickBlox provides message event handler allowing to notify client apps of events that happen on the chat. Thus, when a dialog has been created, a user can subscribe to receive notifications about new incoming messages. To subscribe to message events call `QB.chat.subscribeMessageEvents` method and pass `dialogId`, `eventName`, `data` parameters to it using the following code snippet. The `QB.chat.subscribeMessageEvents` method tells SDK to send events about new messages.
96-
`eventName` - provides some values:
95+
QuickBlox provides chat event handler allowing to notify client apps of events that happen on the chat. Thus, when a dialog has been created, a user can subscribe to receive notifications about new incoming messages. To subscribe to message events call `QB.chat.subscribeChatEvent` method and pass QBChatEvents.RECEIVED_NEW_MESSAGE as an event parameter to it using the following code snippet.
96+
97+
`event` - provides some values:
9798

9899
- `QBChatEvents.RECEIVED_NEW_MESSAGE` - subscribe to `new messages` event
100+
- `QBChatEvents.RECEIVED_SYSTEM_MESSAGE` - subsccribe to `system messages` event
101+
- `QBChatEvents.MESSAGE_DELIVERED` - subscribe to `message delivered` event
102+
- `QBChatEvents.MESSAGE_READ` - subscribe to `message read` event
99103

100104
```dart
101-
await QB.chat.subscribeMessageEvents(dialogId, eventName, (data) {
102-
//receive a new message
103-
104-
Map<String, Object> map = new Map<String, dynamic>.from(data);
105-
String messageType = map["type"];
106-
if (messageType == QBChatEvents.RECEIVED_NEW_MESSAGE) {
107-
Map<String, Object> payload = new Map<String, dynamic>.from(map["payload"]);
108-
String messageBody = payload["body"];
109-
String messageId = payload["id"];
110-
}
111-
} on PlatformException catch (e) {
112-
// Some error occured, look at the exception message for more details
113-
}
114-
```
115105
116-
- Unsubscribe to `new messages` event
106+
StreamSubscription? _someSubscription;
107+
108+
...
109+
110+
@override
111+
void dispose() {
112+
if(_someSubscription != null) {
113+
_someSubscription!.cancel();
114+
_someSubscription = null;
115+
}
116+
}
117+
118+
...
119+
120+
String event = QBChatEvents.RECEIVED_NEW_MESSAGE;
117121
118-
```dart
119-
// eventName - QBChatEvents.RECEIVED_NEW_MESSAGE
120122
try {
121-
await QB.chat.unsubscribeMessageEvents(dialogId, eventName);
122-
} on PlatformException catch (e) {
123-
// Some error occured, look at the exception message for more details
124-
}
125-
```
123+
_someSubscription = await QB.chat.subscribeChatEvent(event, (data) {
124+
Map<dynamic, dynamic> map = Map<dynamic, dynamic>.from(data);
125+
Map<dynamic, dynamic> payload = Map<dynamic, dynamic>.from(map["payload"]);
126+
String? messageId = payload["id"];
127+
}
128+
});
129+
} on PlatformException catch (e) {
130+
// Some error occurred, look at the exception message for more details
131+
}
132+
```
126133

127134
#### Send message
128135

0 commit comments

Comments
 (0)