xmpp: RECEIVE MESSAGES!
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
import "package:moxxyv2/xmpp/jid.dart";
|
||||
|
||||
abstract class XmppEvent {}
|
||||
|
||||
class MessageEvent extends XmppEvent {
|
||||
final String body;
|
||||
final String fromJid;
|
||||
final FullJID fromJid;
|
||||
final String sid;
|
||||
|
||||
MessageEvent({ required this.body, required this.fromJid, required this.sid });
|
||||
|
||||
@@ -30,7 +30,17 @@ class BareJID extends JID {
|
||||
|
||||
class FullJID extends JID {
|
||||
FullJID({ required String local, required String domain, required String resource }) : super(local: local, domain: domain, resource: resource);
|
||||
|
||||
BareJID toBare() {
|
||||
return BareJID(local: this.local, domain: this.domain);
|
||||
}
|
||||
|
||||
static FullJID fromString(String fullJid) {
|
||||
final jidParts = fullJid.split("@");
|
||||
final other = jidParts[1].split("/");
|
||||
return FullJID(local: jidParts[0], domain: other[0], resource: other[1]);
|
||||
}
|
||||
|
||||
String toString() {
|
||||
return "${this.local}@${this.domain}/${this.resource}";
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import "package:moxxyv2/xmpp/stanzas/stanza.dart";
|
||||
import "package:moxxyv2/xmpp/connection.dart";
|
||||
import "package:moxxyv2/xmpp/events.dart";
|
||||
import "package:moxxyv2/xmpp/jid.dart";
|
||||
|
||||
bool handleMessageStanza(XmppConnection conn, Stanza stanza) {
|
||||
final body = stanza.firstTag("body");
|
||||
@@ -8,7 +9,7 @@ bool handleMessageStanza(XmppConnection conn, Stanza stanza) {
|
||||
|
||||
conn.sendEvent(MessageEvent(
|
||||
body: body.innerText(),
|
||||
fromJid: stanza.attributes["from"]!,
|
||||
fromJid: FullJID.fromString(stanza.attributes["from"]!),
|
||||
sid: stanza.attributes["id"]!
|
||||
));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user