Skip to content

Commit

Permalink
add messaging demonstration to example
Browse files Browse the repository at this point in the history
  • Loading branch information
vsevex committed Sep 2, 2024
1 parent 9cc9fc6 commit 34d898b
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions example/message.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import 'package:whixp/whixp.dart';

void main() {
final whixp = Whixp(
jabberID: 'vsevex@localhost',
password: 'passwd',
logger: Log(enableWarning: true, enableError: true, includeTimestamp: true),
internalDatabasePath: 'whixp',
reconnectionPolicy: RandomBackoffReconnectionPolicy(1, 3),
);

whixp
..addEventHandler('streamNegotiated', (_) {
whixp.sendPresence();

/// Sending sample message.
whixp.sendMessage(JabberID('alyosha@localhost'), body: 'First message');

/// Sending marked message.
const id = StanzaID('random-id');
whixp.sendMessage(
JabberID('alyosha@localhost'),
body: 'Second message requesting displayed marker',
requestDisplayedInformation: true,
payloads: [id],
);
})
..addEventHandler<Message>('message', (message) {
if (message == null) return;
if (message.isMarked) {
final messageIDs = message.get<StanzaID>();
if (messageIDs.isNotEmpty && message.from != null) {
final id = messageIDs.first.id;
whixp.sendDisplayedMessage(message.from!, messageID: id);
}
}
});
whixp.connect();
}

0 comments on commit 34d898b

Please sign in to comment.