feat(all): Migrate to the new StanzaDetails API
This commit is contained in:
parent
bd4e1d28ea
commit
3163101f82
2
.gitlint
2
.gitlint
@ -7,7 +7,7 @@ line-length=72
|
|||||||
[title-trailing-punctuation]
|
[title-trailing-punctuation]
|
||||||
[title-hard-tab]
|
[title-hard-tab]
|
||||||
[title-match-regex]
|
[title-match-regex]
|
||||||
regex=^((feat|fix|chore|refactor|docs|release|test)\((meta|tests|style|docs|xep|core|example)+(,(meta|tests|style|docs|xep|core|example))*\)|release): [A-Z0-9].*$
|
regex=^((feat|fix|chore|refactor|docs|release|test)\((meta|tests|style|docs|xep|core|example|all)+(,(meta|tests|style|docs|xep|core|example|all))*\)|release): [A-Z0-9].*$
|
||||||
|
|
||||||
|
|
||||||
[body-trailing-whitespace]
|
[body-trailing-whitespace]
|
||||||
|
@ -9,6 +9,8 @@
|
|||||||
- **BREAKING**: Remove `DiscoManager.discoInfoCapHashQuery`.
|
- **BREAKING**: Remove `DiscoManager.discoInfoCapHashQuery`.
|
||||||
- **BREAKING**: The entity argument of `DiscoManager.discoInfoQuery` and `DiscoManager.discoItemsQuery` are now `JID` instead of `String`.
|
- **BREAKING**: The entity argument of `DiscoManager.discoInfoQuery` and `DiscoManager.discoItemsQuery` are now `JID` instead of `String`.
|
||||||
- **BREAKING**: `PubSubManager` and `UserAvatarManager` now use `JID` instead of `String`.
|
- **BREAKING**: `PubSubManager` and `UserAvatarManager` now use `JID` instead of `String`.
|
||||||
|
- **BREAKING**: `XmppConnection.sendStanza` not only takes a `StanzaDetails` argument.
|
||||||
|
- Sent stanzas are not kept in a queue until sent.
|
||||||
|
|
||||||
## 0.3.1
|
## 0.3.1
|
||||||
|
|
||||||
|
@ -420,12 +420,17 @@ class XmppConnection {
|
|||||||
.contains(await getConnectionState());
|
.contains(await getConnectionState());
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<Future<XMLNode>?> sendStanza2(StanzaDetails details) async {
|
/// Sends a stanza described by [details] to the server. Until sent, the stanza is
|
||||||
|
/// kept in a queue, that is flushed after going online again. If Stream Management
|
||||||
|
/// is active, stanza's acknowledgement is tracked.
|
||||||
|
// TODO(Unknown): if addId = false, the function crashes.
|
||||||
|
Future<XMLNode?> sendStanza(StanzaDetails details) async {
|
||||||
assert(
|
assert(
|
||||||
implies(
|
implies(
|
||||||
details.awaitable,
|
details.awaitable,
|
||||||
details.stanza.id != null && details.stanza.id!.isNotEmpty ||
|
details.stanza.id != null && details.stanza.id!.isNotEmpty ||
|
||||||
details.addId),
|
details.addId,
|
||||||
|
),
|
||||||
'An awaitable stanza must have an id',
|
'An awaitable stanza must have an id',
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -550,131 +555,6 @@ class XmppConnection {
|
|||||||
_log.fine('Done');
|
_log.fine('Done');
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sends a [stanza] to the server. If stream management is enabled, then keeping track
|
|
||||||
/// of the stanza is taken care of. Returns a Future that resolves when we receive a
|
|
||||||
/// response to the stanza.
|
|
||||||
///
|
|
||||||
/// If addFrom is true, then a 'from' attribute will be added to the stanza if
|
|
||||||
/// [stanza] has none.
|
|
||||||
/// If addId is true, then an 'id' attribute will be added to the stanza if [stanza] has
|
|
||||||
/// none.
|
|
||||||
// TODO(Unknown): if addId = false, the function crashes.
|
|
||||||
Future<XMLNode> sendStanza(
|
|
||||||
Stanza stanza, {
|
|
||||||
StanzaFromType addFrom = StanzaFromType.full,
|
|
||||||
bool addId = true,
|
|
||||||
bool awaitable = true,
|
|
||||||
bool encrypted = false,
|
|
||||||
bool forceEncryption = false,
|
|
||||||
}) async {
|
|
||||||
assert(
|
|
||||||
implies(addId == false && stanza.id == null, !awaitable),
|
|
||||||
'Cannot await a stanza with no id',
|
|
||||||
);
|
|
||||||
|
|
||||||
// Add extra data in case it was not set
|
|
||||||
var stanza_ = stanza;
|
|
||||||
if (addId && (stanza_.id == null || stanza_.id == '')) {
|
|
||||||
stanza_ = stanza.copyWith(id: generateId());
|
|
||||||
}
|
|
||||||
if (addFrom != StanzaFromType.none &&
|
|
||||||
(stanza_.from == null || stanza_.from == '')) {
|
|
||||||
switch (addFrom) {
|
|
||||||
case StanzaFromType.full:
|
|
||||||
{
|
|
||||||
stanza_ = stanza_.copyWith(
|
|
||||||
from: _getJidWithResource().toString(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case StanzaFromType.bare:
|
|
||||||
{
|
|
||||||
stanza_ = stanza_.copyWith(
|
|
||||||
from: connectionSettings.jid.toBare().toString(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case StanzaFromType.none:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
stanza_ = stanza_.copyWith(
|
|
||||||
xmlns: _negotiationsHandler.getStanzaNamespace(),
|
|
||||||
);
|
|
||||||
|
|
||||||
_log.fine('Running pre stanza handlers..');
|
|
||||||
final data = await _runOutgoingPreStanzaHandlers(
|
|
||||||
stanza_,
|
|
||||||
initial: StanzaHandlerData(
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
null,
|
|
||||||
stanza_,
|
|
||||||
encrypted: encrypted,
|
|
||||||
forceEncryption: forceEncryption,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
_log.fine('Done');
|
|
||||||
|
|
||||||
if (data.cancel) {
|
|
||||||
_log.fine('A stanza handler indicated that it wants to cancel sending.');
|
|
||||||
await _sendEvent(StanzaSendingCancelledEvent(data));
|
|
||||||
return Stanza(
|
|
||||||
tag: data.stanza.tag,
|
|
||||||
to: data.stanza.from,
|
|
||||||
from: data.stanza.to,
|
|
||||||
attributes: <String, String>{
|
|
||||||
'type': 'error',
|
|
||||||
if (data.stanza.id != null) 'id': data.stanza.id!,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
final prefix = data.encrypted ? '(Encrypted) ' : '';
|
|
||||||
_log.finest('==> $prefix${stanza_.toXml()}');
|
|
||||||
|
|
||||||
final stanzaString = data.stanza.toXml();
|
|
||||||
|
|
||||||
// ignore: cascade_invocations
|
|
||||||
_log.fine('Attempting to acquire lock for ${data.stanza.id}...');
|
|
||||||
// TODO(PapaTutuWawa): Handle this much more graceful
|
|
||||||
var future = Future.value(XMLNode(tag: 'not-used'));
|
|
||||||
if (awaitable) {
|
|
||||||
future = await _stanzaAwaiter.addPending(
|
|
||||||
// A stanza with no to attribute is for direct processing by the server. As such,
|
|
||||||
// we can correlate it by just *assuming* we have that attribute
|
|
||||||
// (RFC 6120 Section 8.1.1.1)
|
|
||||||
data.stanza.to ?? connectionSettings.jid.toBare().toString(),
|
|
||||||
data.stanza.id!,
|
|
||||||
data.stanza.tag,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// This uses the StreamManager to behave like a send queue
|
|
||||||
if (await _canSendData()) {
|
|
||||||
_socket.write(stanzaString);
|
|
||||||
|
|
||||||
// Try to ack every stanza
|
|
||||||
// NOTE: Here we have send an Ack request nonza. This is now done by StreamManagementManager when receiving the StanzaSentEvent
|
|
||||||
} else {
|
|
||||||
_log.fine('_canSendData() returned false.');
|
|
||||||
}
|
|
||||||
|
|
||||||
_log.fine('Running post stanza handlers..');
|
|
||||||
await _runOutgoingPostStanzaHandlers(
|
|
||||||
stanza_,
|
|
||||||
initial: StanzaHandlerData(
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
null,
|
|
||||||
stanza_,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
_log.fine('Done');
|
|
||||||
|
|
||||||
return future;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Called when we timeout during connecting
|
/// Called when we timeout during connecting
|
||||||
Future<void> _onConnectingTimeout() async {
|
Future<void> _onConnectingTimeout() async {
|
||||||
_log.severe('Connection stuck in "connecting". Causing a reconnection...');
|
_log.severe('Connection stuck in "connecting". Causing a reconnection...');
|
||||||
@ -696,18 +576,11 @@ class XmppConnection {
|
|||||||
// Set the new routing state
|
// Set the new routing state
|
||||||
_updateRoutingState(RoutingState.handleStanzas);
|
_updateRoutingState(RoutingState.handleStanzas);
|
||||||
|
|
||||||
// Set the connection state
|
|
||||||
await _setConnectionState(XmppConnectionState.connected);
|
|
||||||
|
|
||||||
// Enable reconnections
|
// Enable reconnections
|
||||||
if (_enableReconnectOnSuccess) {
|
if (_enableReconnectOnSuccess) {
|
||||||
await _reconnectionPolicy.setShouldReconnect(true);
|
await _reconnectionPolicy.setShouldReconnect(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Resolve the connection completion future
|
|
||||||
_connectionCompleter?.complete(const Result(true));
|
|
||||||
_connectionCompleter = null;
|
|
||||||
|
|
||||||
// Tell consumers of the event stream that we're done with stream feature
|
// Tell consumers of the event stream that we're done with stream feature
|
||||||
// negotiations
|
// negotiations
|
||||||
await _sendEvent(
|
await _sendEvent(
|
||||||
@ -716,6 +589,16 @@ class XmppConnection {
|
|||||||
false,
|
false,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Set the connection state
|
||||||
|
await _setConnectionState(XmppConnectionState.connected);
|
||||||
|
|
||||||
|
// Resolve the connection completion future
|
||||||
|
_connectionCompleter?.complete(const Result(true));
|
||||||
|
_connectionCompleter = null;
|
||||||
|
|
||||||
|
// Flush the stanza send queue
|
||||||
|
await _stanzaQueue.restart();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the connection state to [state] and triggers an event of type
|
/// Sets the connection state to [state] and triggers an event of type
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import 'package:moxxmpp/src/connection.dart';
|
import 'package:moxxmpp/src/connection.dart';
|
||||||
import 'package:moxxmpp/src/managers/data.dart';
|
import 'package:moxxmpp/src/managers/data.dart';
|
||||||
import 'package:moxxmpp/src/stanza.dart';
|
import 'package:moxxmpp/src/stanza.dart';
|
||||||
|
import 'package:moxxmpp/src/util/queue.dart';
|
||||||
|
|
||||||
/// Bounce a stanza if it was not handled by any manager. [conn] is the connection object
|
/// Bounce a stanza if it was not handled by any manager. [conn] is the connection object
|
||||||
/// to use for sending the stanza. [data] is the StanzaHandlerData of the unhandled
|
/// to use for sending the stanza. [data] is the StanzaHandlerData of the unhandled
|
||||||
@ -23,9 +24,11 @@ Future<void> handleUnhandledStanza(
|
|||||||
);
|
);
|
||||||
|
|
||||||
await conn.sendStanza(
|
await conn.sendStanza(
|
||||||
|
StanzaDetails(
|
||||||
stanza,
|
stanza,
|
||||||
awaitable: false,
|
awaitable: false,
|
||||||
forceEncryption: data.encrypted,
|
forceEncryption: data.encrypted,
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,8 +6,8 @@ import 'package:moxxmpp/src/managers/base.dart';
|
|||||||
import 'package:moxxmpp/src/negotiators/negotiator.dart';
|
import 'package:moxxmpp/src/negotiators/negotiator.dart';
|
||||||
import 'package:moxxmpp/src/settings.dart';
|
import 'package:moxxmpp/src/settings.dart';
|
||||||
import 'package:moxxmpp/src/socket.dart';
|
import 'package:moxxmpp/src/socket.dart';
|
||||||
import 'package:moxxmpp/src/stanza.dart';
|
|
||||||
import 'package:moxxmpp/src/stringxml.dart';
|
import 'package:moxxmpp/src/stringxml.dart';
|
||||||
|
import 'package:moxxmpp/src/util/queue.dart';
|
||||||
|
|
||||||
class XmppManagerAttributes {
|
class XmppManagerAttributes {
|
||||||
XmppManagerAttributes({
|
XmppManagerAttributes({
|
||||||
@ -23,14 +23,7 @@ class XmppManagerAttributes {
|
|||||||
});
|
});
|
||||||
|
|
||||||
/// Send a stanza whose response can be awaited.
|
/// Send a stanza whose response can be awaited.
|
||||||
final Future<XMLNode> Function(
|
final Future<XMLNode?> Function(StanzaDetails) sendStanza;
|
||||||
Stanza stanza, {
|
|
||||||
StanzaFromType addFrom,
|
|
||||||
bool addId,
|
|
||||||
bool awaitable,
|
|
||||||
bool encrypted,
|
|
||||||
bool forceEncryption,
|
|
||||||
}) sendStanza;
|
|
||||||
|
|
||||||
/// Send a nonza.
|
/// Send a nonza.
|
||||||
final void Function(XMLNode) sendNonza;
|
final void Function(XMLNode) sendNonza;
|
||||||
|
@ -6,6 +6,7 @@ import 'package:moxxmpp/src/managers/data.dart';
|
|||||||
import 'package:moxxmpp/src/managers/handlers.dart';
|
import 'package:moxxmpp/src/managers/handlers.dart';
|
||||||
import 'package:moxxmpp/src/managers/namespaces.dart';
|
import 'package:moxxmpp/src/managers/namespaces.dart';
|
||||||
import 'package:moxxmpp/src/stringxml.dart';
|
import 'package:moxxmpp/src/stringxml.dart';
|
||||||
|
import 'package:moxxmpp/src/util/queue.dart';
|
||||||
import 'package:moxxmpp/src/xeps/xep_0030/errors.dart';
|
import 'package:moxxmpp/src/xeps/xep_0030/errors.dart';
|
||||||
import 'package:moxxmpp/src/xeps/xep_0030/types.dart';
|
import 'package:moxxmpp/src/xeps/xep_0030/types.dart';
|
||||||
import 'package:moxxmpp/src/xeps/xep_0030/xep_0030.dart';
|
import 'package:moxxmpp/src/xeps/xep_0030/xep_0030.dart';
|
||||||
@ -165,9 +166,11 @@ abstract class XmppManagerBase {
|
|||||||
);
|
);
|
||||||
|
|
||||||
await getAttributes().sendStanza(
|
await getAttributes().sendStanza(
|
||||||
|
StanzaDetails(
|
||||||
stanza,
|
stanza,
|
||||||
awaitable: false,
|
awaitable: false,
|
||||||
forceEncryption: data.encrypted,
|
forceEncryption: data.encrypted,
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,7 @@ import 'package:moxxmpp/src/managers/namespaces.dart';
|
|||||||
import 'package:moxxmpp/src/namespaces.dart';
|
import 'package:moxxmpp/src/namespaces.dart';
|
||||||
import 'package:moxxmpp/src/stanza.dart';
|
import 'package:moxxmpp/src/stanza.dart';
|
||||||
import 'package:moxxmpp/src/stringxml.dart';
|
import 'package:moxxmpp/src/stringxml.dart';
|
||||||
|
import 'package:moxxmpp/src/util/queue.dart';
|
||||||
import 'package:moxxmpp/src/xeps/staging/file_upload_notification.dart';
|
import 'package:moxxmpp/src/xeps/staging/file_upload_notification.dart';
|
||||||
import 'package:moxxmpp/src/xeps/xep_0066.dart';
|
import 'package:moxxmpp/src/xeps/xep_0066.dart';
|
||||||
import 'package:moxxmpp/src/xeps/xep_0085.dart';
|
import 'package:moxxmpp/src/xeps/xep_0085.dart';
|
||||||
@ -320,6 +321,11 @@ class MessageManager extends XmppManagerBase {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
getAttributes().sendStanza(stanza, awaitable: false);
|
getAttributes().sendStanza(
|
||||||
|
StanzaDetails(
|
||||||
|
stanza,
|
||||||
|
awaitable: false,
|
||||||
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,10 +7,9 @@ import 'package:moxxmpp/src/managers/data.dart';
|
|||||||
import 'package:moxxmpp/src/managers/handlers.dart';
|
import 'package:moxxmpp/src/managers/handlers.dart';
|
||||||
import 'package:moxxmpp/src/managers/namespaces.dart';
|
import 'package:moxxmpp/src/managers/namespaces.dart';
|
||||||
import 'package:moxxmpp/src/namespaces.dart';
|
import 'package:moxxmpp/src/namespaces.dart';
|
||||||
import 'package:moxxmpp/src/negotiators/namespaces.dart';
|
|
||||||
import 'package:moxxmpp/src/stanza.dart';
|
import 'package:moxxmpp/src/stanza.dart';
|
||||||
import 'package:moxxmpp/src/stringxml.dart';
|
import 'package:moxxmpp/src/stringxml.dart';
|
||||||
import 'package:moxxmpp/src/xeps/xep_0198/negotiator.dart';
|
import 'package:moxxmpp/src/util/queue.dart';
|
||||||
|
|
||||||
/// A function that will be called when presence, outside of subscription request
|
/// A function that will be called when presence, outside of subscription request
|
||||||
/// management, will be sent. Useful for managers that want to add [XMLNode]s to said
|
/// management, will be sent. Useful for managers that want to add [XMLNode]s to said
|
||||||
@ -49,12 +48,8 @@ class PresenceManager extends XmppManagerBase {
|
|||||||
Future<void> onXmppEvent(XmppEvent event) async {
|
Future<void> onXmppEvent(XmppEvent event) async {
|
||||||
if (event is StreamNegotiationsDoneEvent) {
|
if (event is StreamNegotiationsDoneEvent) {
|
||||||
// Send initial presence only when we have not resumed the stream
|
// Send initial presence only when we have not resumed the stream
|
||||||
final sm = getAttributes().getNegotiatorById<StreamManagementNegotiator>(
|
if (!event.resumed) {
|
||||||
streamManagementNegotiator,
|
await sendInitialPresence();
|
||||||
);
|
|
||||||
final isResumed = sm?.isResumed ?? false;
|
|
||||||
if (!isResumed) {
|
|
||||||
unawaited(sendInitialPresence());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -108,66 +103,82 @@ class PresenceManager extends XmppManagerBase {
|
|||||||
|
|
||||||
final attrs = getAttributes();
|
final attrs = getAttributes();
|
||||||
await attrs.sendStanza(
|
await attrs.sendStanza(
|
||||||
|
StanzaDetails(
|
||||||
Stanza.presence(
|
Stanza.presence(
|
||||||
from: attrs.getFullJID().toString(),
|
from: attrs.getFullJID().toString(),
|
||||||
children: children,
|
children: children,
|
||||||
),
|
),
|
||||||
awaitable: false,
|
awaitable: false,
|
||||||
addId: false,
|
addId: false,
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Send an unavailable presence with no 'to' attribute.
|
/// Send an unavailable presence with no 'to' attribute.
|
||||||
void sendUnavailablePresence() {
|
void sendUnavailablePresence() {
|
||||||
getAttributes().sendStanza(
|
getAttributes().sendStanza(
|
||||||
|
StanzaDetails(
|
||||||
Stanza.presence(
|
Stanza.presence(
|
||||||
type: 'unavailable',
|
type: 'unavailable',
|
||||||
),
|
),
|
||||||
addFrom: StanzaFromType.full,
|
awaitable: false,
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sends a subscription request to [to].
|
/// Sends a subscription request to [to].
|
||||||
void sendSubscriptionRequest(String to) {
|
void sendSubscriptionRequest(String to) {
|
||||||
getAttributes().sendStanza(
|
getAttributes().sendStanza(
|
||||||
|
StanzaDetails(
|
||||||
Stanza.presence(
|
Stanza.presence(
|
||||||
type: 'subscribe',
|
type: 'subscribe',
|
||||||
to: to,
|
to: to,
|
||||||
),
|
),
|
||||||
addFrom: StanzaFromType.none,
|
addFrom: StanzaFromType.none,
|
||||||
|
awaitable: false,
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sends an unsubscription request to [to].
|
/// Sends an unsubscription request to [to].
|
||||||
void sendUnsubscriptionRequest(String to) {
|
void sendUnsubscriptionRequest(String to) {
|
||||||
getAttributes().sendStanza(
|
getAttributes().sendStanza(
|
||||||
|
StanzaDetails(
|
||||||
Stanza.presence(
|
Stanza.presence(
|
||||||
type: 'unsubscribe',
|
type: 'unsubscribe',
|
||||||
to: to,
|
to: to,
|
||||||
),
|
),
|
||||||
addFrom: StanzaFromType.none,
|
addFrom: StanzaFromType.none,
|
||||||
|
awaitable: false,
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Accept a presence subscription request for [to].
|
/// Accept a presence subscription request for [to].
|
||||||
void sendSubscriptionRequestApproval(String to) {
|
void sendSubscriptionRequestApproval(String to) {
|
||||||
getAttributes().sendStanza(
|
getAttributes().sendStanza(
|
||||||
|
StanzaDetails(
|
||||||
Stanza.presence(
|
Stanza.presence(
|
||||||
type: 'subscribed',
|
type: 'subscribed',
|
||||||
to: to,
|
to: to,
|
||||||
),
|
),
|
||||||
addFrom: StanzaFromType.none,
|
addFrom: StanzaFromType.none,
|
||||||
|
awaitable: false,
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Reject a presence subscription request for [to].
|
/// Reject a presence subscription request for [to].
|
||||||
void sendSubscriptionRequestRejection(String to) {
|
void sendSubscriptionRequestRejection(String to) {
|
||||||
getAttributes().sendStanza(
|
getAttributes().sendStanza(
|
||||||
|
StanzaDetails(
|
||||||
Stanza.presence(
|
Stanza.presence(
|
||||||
type: 'unsubscribed',
|
type: 'unsubscribed',
|
||||||
to: to,
|
to: to,
|
||||||
),
|
),
|
||||||
addFrom: StanzaFromType.none,
|
addFrom: StanzaFromType.none,
|
||||||
|
awaitable: false,
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,7 @@ import 'package:moxxmpp/src/roster/state.dart';
|
|||||||
import 'package:moxxmpp/src/stanza.dart';
|
import 'package:moxxmpp/src/stanza.dart';
|
||||||
import 'package:moxxmpp/src/stringxml.dart';
|
import 'package:moxxmpp/src/stringxml.dart';
|
||||||
import 'package:moxxmpp/src/types/result.dart';
|
import 'package:moxxmpp/src/types/result.dart';
|
||||||
|
import 'package:moxxmpp/src/util/queue.dart';
|
||||||
|
|
||||||
@immutable
|
@immutable
|
||||||
class XmppRosterItem {
|
class XmppRosterItem {
|
||||||
@ -235,14 +236,16 @@ class RosterManager extends XmppManagerBase {
|
|||||||
query.attributes['ver'] = rosterVersion;
|
query.attributes['ver'] = rosterVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
final response = await attrs.sendStanza(
|
final response = (await attrs.sendStanza(
|
||||||
|
StanzaDetails(
|
||||||
Stanza.iq(
|
Stanza.iq(
|
||||||
type: 'get',
|
type: 'get',
|
||||||
children: [
|
children: [
|
||||||
query,
|
query,
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
),
|
||||||
|
))!;
|
||||||
|
|
||||||
if (response.attributes['type'] != 'result') {
|
if (response.attributes['type'] != 'result') {
|
||||||
logger.warning('Error requesting roster: ${response.toXml()}');
|
logger.warning('Error requesting roster: ${response.toXml()}');
|
||||||
@ -258,7 +261,8 @@ class RosterManager extends XmppManagerBase {
|
|||||||
Future<Result<RosterRequestResult?, RosterError>>
|
Future<Result<RosterRequestResult?, RosterError>>
|
||||||
requestRosterPushes() async {
|
requestRosterPushes() async {
|
||||||
final attrs = getAttributes();
|
final attrs = getAttributes();
|
||||||
final result = await attrs.sendStanza(
|
final result = (await attrs.sendStanza(
|
||||||
|
StanzaDetails(
|
||||||
Stanza.iq(
|
Stanza.iq(
|
||||||
type: 'get',
|
type: 'get',
|
||||||
children: [
|
children: [
|
||||||
@ -271,7 +275,8 @@ class RosterManager extends XmppManagerBase {
|
|||||||
)
|
)
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
),
|
||||||
|
))!;
|
||||||
|
|
||||||
if (result.attributes['type'] != 'result') {
|
if (result.attributes['type'] != 'result') {
|
||||||
logger.warning('Requesting roster pushes failed: ${result.toXml()}');
|
logger.warning('Requesting roster pushes failed: ${result.toXml()}');
|
||||||
@ -296,7 +301,8 @@ class RosterManager extends XmppManagerBase {
|
|||||||
List<String>? groups,
|
List<String>? groups,
|
||||||
}) async {
|
}) async {
|
||||||
final attrs = getAttributes();
|
final attrs = getAttributes();
|
||||||
final response = await attrs.sendStanza(
|
final response = (await attrs.sendStanza(
|
||||||
|
StanzaDetails(
|
||||||
Stanza.iq(
|
Stanza.iq(
|
||||||
type: 'set',
|
type: 'set',
|
||||||
children: [
|
children: [
|
||||||
@ -317,10 +323,11 @@ class RosterManager extends XmppManagerBase {
|
|||||||
.toList(),
|
.toList(),
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
)
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
),
|
||||||
|
))!;
|
||||||
|
|
||||||
if (response.attributes['type'] != 'result') {
|
if (response.attributes['type'] != 'result') {
|
||||||
logger.severe('Error adding $jid to roster: $response');
|
logger.severe('Error adding $jid to roster: $response');
|
||||||
@ -334,7 +341,8 @@ class RosterManager extends XmppManagerBase {
|
|||||||
/// false otherwise.
|
/// false otherwise.
|
||||||
Future<RosterRemovalResult> removeFromRoster(String jid) async {
|
Future<RosterRemovalResult> removeFromRoster(String jid) async {
|
||||||
final attrs = getAttributes();
|
final attrs = getAttributes();
|
||||||
final response = await attrs.sendStanza(
|
final response = (await attrs.sendStanza(
|
||||||
|
StanzaDetails(
|
||||||
Stanza.iq(
|
Stanza.iq(
|
||||||
type: 'set',
|
type: 'set',
|
||||||
children: [
|
children: [
|
||||||
@ -353,7 +361,8 @@ class RosterManager extends XmppManagerBase {
|
|||||||
)
|
)
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
),
|
||||||
|
))!;
|
||||||
|
|
||||||
if (response.attributes['type'] != 'result') {
|
if (response.attributes['type'] != 'result') {
|
||||||
logger.severe('Failed to remove roster item: ${response.toXml()}');
|
logger.severe('Failed to remove roster item: ${response.toXml()}');
|
||||||
|
@ -10,6 +10,7 @@ import 'package:moxxmpp/src/namespaces.dart';
|
|||||||
import 'package:moxxmpp/src/stanza.dart';
|
import 'package:moxxmpp/src/stanza.dart';
|
||||||
import 'package:moxxmpp/src/stringxml.dart';
|
import 'package:moxxmpp/src/stringxml.dart';
|
||||||
import 'package:moxxmpp/src/types/result.dart';
|
import 'package:moxxmpp/src/types/result.dart';
|
||||||
|
import 'package:moxxmpp/src/util/queue.dart';
|
||||||
import 'package:moxxmpp/src/util/wait.dart';
|
import 'package:moxxmpp/src/util/wait.dart';
|
||||||
import 'package:moxxmpp/src/xeps/xep_0030/cache.dart';
|
import 'package:moxxmpp/src/xeps/xep_0030/cache.dart';
|
||||||
import 'package:moxxmpp/src/xeps/xep_0030/errors.dart';
|
import 'package:moxxmpp/src/xeps/xep_0030/errors.dart';
|
||||||
@ -291,10 +292,12 @@ class DiscoManager extends XmppManagerBase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final stanza = await getAttributes().sendStanza(
|
final stanza = (await getAttributes().sendStanza(
|
||||||
|
StanzaDetails(
|
||||||
buildDiscoInfoQueryStanza(entity, node),
|
buildDiscoInfoQueryStanza(entity, node),
|
||||||
encrypted: !shouldEncrypt,
|
encrypted: !shouldEncrypt,
|
||||||
);
|
),
|
||||||
|
))!;
|
||||||
final query = stanza.firstTag('query');
|
final query = stanza.firstTag('query');
|
||||||
if (query == null) {
|
if (query == null) {
|
||||||
final result = Result<DiscoError, DiscoInfo>(InvalidResponseDiscoError());
|
final result = Result<DiscoError, DiscoInfo>(InvalidResponseDiscoError());
|
||||||
@ -331,10 +334,12 @@ class DiscoManager extends XmppManagerBase {
|
|||||||
return future;
|
return future;
|
||||||
}
|
}
|
||||||
|
|
||||||
final stanza = await getAttributes().sendStanza(
|
final stanza = (await getAttributes().sendStanza(
|
||||||
|
StanzaDetails(
|
||||||
buildDiscoItemsQueryStanza(entity, node: node),
|
buildDiscoItemsQueryStanza(entity, node: node),
|
||||||
encrypted: !shouldEncrypt,
|
encrypted: !shouldEncrypt,
|
||||||
) as Stanza;
|
),
|
||||||
|
))!;
|
||||||
|
|
||||||
final query = stanza.firstTag('query');
|
final query = stanza.firstTag('query');
|
||||||
if (query == null) {
|
if (query == null) {
|
||||||
@ -344,7 +349,7 @@ class DiscoManager extends XmppManagerBase {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (stanza.type == 'error') {
|
if (stanza.attributes['type'] == 'error') {
|
||||||
//final error = stanza.firstTag('error');
|
//final error = stanza.firstTag('error');
|
||||||
//print("Disco Items error: " + error.toXml());
|
//print("Disco Items error: " + error.toXml());
|
||||||
final result =
|
final result =
|
||||||
|
@ -8,6 +8,7 @@ import 'package:moxxmpp/src/namespaces.dart';
|
|||||||
import 'package:moxxmpp/src/stanza.dart';
|
import 'package:moxxmpp/src/stanza.dart';
|
||||||
import 'package:moxxmpp/src/stringxml.dart';
|
import 'package:moxxmpp/src/stringxml.dart';
|
||||||
import 'package:moxxmpp/src/types/result.dart';
|
import 'package:moxxmpp/src/types/result.dart';
|
||||||
|
import 'package:moxxmpp/src/util/queue.dart';
|
||||||
|
|
||||||
abstract class VCardError {}
|
abstract class VCardError {}
|
||||||
|
|
||||||
@ -103,7 +104,8 @@ class VCardManager extends XmppManagerBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<Result<VCardError, VCard>> requestVCard(String jid) async {
|
Future<Result<VCardError, VCard>> requestVCard(String jid) async {
|
||||||
final result = await getAttributes().sendStanza(
|
final result = (await getAttributes().sendStanza(
|
||||||
|
StanzaDetails(
|
||||||
Stanza.iq(
|
Stanza.iq(
|
||||||
to: jid,
|
to: jid,
|
||||||
type: 'get',
|
type: 'get',
|
||||||
@ -115,7 +117,8 @@ class VCardManager extends XmppManagerBase {
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
encrypted: true,
|
encrypted: true,
|
||||||
);
|
),
|
||||||
|
))!;
|
||||||
|
|
||||||
if (result.attributes['type'] != 'result') {
|
if (result.attributes['type'] != 'result') {
|
||||||
return Result(UnknownVCardError());
|
return Result(UnknownVCardError());
|
||||||
|
@ -10,6 +10,7 @@ import 'package:moxxmpp/src/namespaces.dart';
|
|||||||
import 'package:moxxmpp/src/stanza.dart';
|
import 'package:moxxmpp/src/stanza.dart';
|
||||||
import 'package:moxxmpp/src/stringxml.dart';
|
import 'package:moxxmpp/src/stringxml.dart';
|
||||||
import 'package:moxxmpp/src/types/result.dart';
|
import 'package:moxxmpp/src/types/result.dart';
|
||||||
|
import 'package:moxxmpp/src/util/queue.dart';
|
||||||
import 'package:moxxmpp/src/xeps/xep_0004.dart';
|
import 'package:moxxmpp/src/xeps/xep_0004.dart';
|
||||||
import 'package:moxxmpp/src/xeps/xep_0030/errors.dart';
|
import 'package:moxxmpp/src/xeps/xep_0030/errors.dart';
|
||||||
import 'package:moxxmpp/src/xeps/xep_0030/types.dart';
|
import 'package:moxxmpp/src/xeps/xep_0030/types.dart';
|
||||||
@ -181,7 +182,8 @@ class PubSubManager extends XmppManagerBase {
|
|||||||
|
|
||||||
Future<Result<PubSubError, bool>> subscribe(String jid, String node) async {
|
Future<Result<PubSubError, bool>> subscribe(String jid, String node) async {
|
||||||
final attrs = getAttributes();
|
final attrs = getAttributes();
|
||||||
final result = await attrs.sendStanza(
|
final result = (await attrs.sendStanza(
|
||||||
|
StanzaDetails(
|
||||||
Stanza.iq(
|
Stanza.iq(
|
||||||
type: 'set',
|
type: 'set',
|
||||||
to: jid,
|
to: jid,
|
||||||
@ -201,7 +203,8 @@ class PubSubManager extends XmppManagerBase {
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
),
|
||||||
|
))!;
|
||||||
|
|
||||||
if (result.attributes['type'] != 'result') {
|
if (result.attributes['type'] != 'result') {
|
||||||
return Result(UnknownPubSubError());
|
return Result(UnknownPubSubError());
|
||||||
@ -222,7 +225,8 @@ class PubSubManager extends XmppManagerBase {
|
|||||||
|
|
||||||
Future<Result<PubSubError, bool>> unsubscribe(String jid, String node) async {
|
Future<Result<PubSubError, bool>> unsubscribe(String jid, String node) async {
|
||||||
final attrs = getAttributes();
|
final attrs = getAttributes();
|
||||||
final result = await attrs.sendStanza(
|
final result = (await attrs.sendStanza(
|
||||||
|
StanzaDetails(
|
||||||
Stanza.iq(
|
Stanza.iq(
|
||||||
type: 'set',
|
type: 'set',
|
||||||
to: jid,
|
to: jid,
|
||||||
@ -242,7 +246,8 @@ class PubSubManager extends XmppManagerBase {
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
),
|
||||||
|
))!;
|
||||||
|
|
||||||
if (result.attributes['type'] != 'result') {
|
if (result.attributes['type'] != 'result') {
|
||||||
return Result(UnknownPubSubError());
|
return Result(UnknownPubSubError());
|
||||||
@ -293,7 +298,8 @@ class PubSubManager extends XmppManagerBase {
|
|||||||
pubOptions = await preprocessPublishOptions(jid, node, options);
|
pubOptions = await preprocessPublishOptions(jid, node, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
final result = await getAttributes().sendStanza(
|
final result = (await getAttributes().sendStanza(
|
||||||
|
StanzaDetails(
|
||||||
Stanza.iq(
|
Stanza.iq(
|
||||||
type: 'set',
|
type: 'set',
|
||||||
to: jid.toString(),
|
to: jid.toString(),
|
||||||
@ -324,7 +330,8 @@ class PubSubManager extends XmppManagerBase {
|
|||||||
)
|
)
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
),
|
||||||
|
))!;
|
||||||
if (result.attributes['type'] != 'result') {
|
if (result.attributes['type'] != 'result') {
|
||||||
final error = getPubSubError(result);
|
final error = getPubSubError(result);
|
||||||
|
|
||||||
@ -395,7 +402,8 @@ class PubSubManager extends XmppManagerBase {
|
|||||||
String jid,
|
String jid,
|
||||||
String node,
|
String node,
|
||||||
) async {
|
) async {
|
||||||
final result = await getAttributes().sendStanza(
|
final result = (await getAttributes().sendStanza(
|
||||||
|
StanzaDetails(
|
||||||
Stanza.iq(
|
Stanza.iq(
|
||||||
type: 'get',
|
type: 'get',
|
||||||
to: jid,
|
to: jid,
|
||||||
@ -404,12 +412,16 @@ class PubSubManager extends XmppManagerBase {
|
|||||||
tag: 'pubsub',
|
tag: 'pubsub',
|
||||||
xmlns: pubsubXmlns,
|
xmlns: pubsubXmlns,
|
||||||
children: [
|
children: [
|
||||||
XMLNode(tag: 'items', attributes: <String, String>{'node': node}),
|
XMLNode(
|
||||||
|
tag: 'items',
|
||||||
|
attributes: <String, String>{'node': node},
|
||||||
|
),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
),
|
||||||
|
))!;
|
||||||
|
|
||||||
if (result.attributes['type'] != 'result') {
|
if (result.attributes['type'] != 'result') {
|
||||||
return Result(getPubSubError(result));
|
return Result(getPubSubError(result));
|
||||||
@ -436,7 +448,8 @@ class PubSubManager extends XmppManagerBase {
|
|||||||
String node,
|
String node,
|
||||||
String id,
|
String id,
|
||||||
) async {
|
) async {
|
||||||
final result = await getAttributes().sendStanza(
|
final result = (await getAttributes().sendStanza(
|
||||||
|
StanzaDetails(
|
||||||
Stanza.iq(
|
Stanza.iq(
|
||||||
type: 'get',
|
type: 'get',
|
||||||
to: jid,
|
to: jid,
|
||||||
@ -459,7 +472,8 @@ class PubSubManager extends XmppManagerBase {
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
),
|
||||||
|
))!;
|
||||||
|
|
||||||
if (result.attributes['type'] != 'result') {
|
if (result.attributes['type'] != 'result') {
|
||||||
return Result(getPubSubError(result));
|
return Result(getPubSubError(result));
|
||||||
@ -488,7 +502,8 @@ class PubSubManager extends XmppManagerBase {
|
|||||||
final attrs = getAttributes();
|
final attrs = getAttributes();
|
||||||
|
|
||||||
// Request the form
|
// Request the form
|
||||||
final form = await attrs.sendStanza(
|
final form = (await attrs.sendStanza(
|
||||||
|
StanzaDetails(
|
||||||
Stanza.iq(
|
Stanza.iq(
|
||||||
type: 'get',
|
type: 'get',
|
||||||
to: jid.toString(),
|
to: jid.toString(),
|
||||||
@ -507,12 +522,14 @@ class PubSubManager extends XmppManagerBase {
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
),
|
||||||
|
))!;
|
||||||
if (form.attributes['type'] != 'result') {
|
if (form.attributes['type'] != 'result') {
|
||||||
return Result(getPubSubError(form));
|
return Result(getPubSubError(form));
|
||||||
}
|
}
|
||||||
|
|
||||||
final submit = await attrs.sendStanza(
|
final submit = (await attrs.sendStanza(
|
||||||
|
StanzaDetails(
|
||||||
Stanza.iq(
|
Stanza.iq(
|
||||||
type: 'set',
|
type: 'set',
|
||||||
to: jid.toString(),
|
to: jid.toString(),
|
||||||
@ -534,7 +551,8 @@ class PubSubManager extends XmppManagerBase {
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
),
|
||||||
|
))!;
|
||||||
if (submit.attributes['type'] != 'result') {
|
if (submit.attributes['type'] != 'result') {
|
||||||
return Result(getPubSubError(form));
|
return Result(getPubSubError(form));
|
||||||
}
|
}
|
||||||
@ -543,7 +561,8 @@ class PubSubManager extends XmppManagerBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<Result<PubSubError, bool>> delete(JID host, String node) async {
|
Future<Result<PubSubError, bool>> delete(JID host, String node) async {
|
||||||
final request = await getAttributes().sendStanza(
|
final request = (await getAttributes().sendStanza(
|
||||||
|
StanzaDetails(
|
||||||
Stanza.iq(
|
Stanza.iq(
|
||||||
type: 'set',
|
type: 'set',
|
||||||
to: host.toString(),
|
to: host.toString(),
|
||||||
@ -562,9 +581,10 @@ class PubSubManager extends XmppManagerBase {
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
) as Stanza;
|
),
|
||||||
|
))!;
|
||||||
|
|
||||||
if (request.type != 'result') {
|
if (request.attributes['type'] != 'result') {
|
||||||
// TODO(Unknown): Be more specific
|
// TODO(Unknown): Be more specific
|
||||||
return Result(UnknownPubSubError());
|
return Result(UnknownPubSubError());
|
||||||
}
|
}
|
||||||
@ -577,7 +597,8 @@ class PubSubManager extends XmppManagerBase {
|
|||||||
String node,
|
String node,
|
||||||
String itemId,
|
String itemId,
|
||||||
) async {
|
) async {
|
||||||
final request = await getAttributes().sendStanza(
|
final request = (await getAttributes().sendStanza(
|
||||||
|
StanzaDetails(
|
||||||
Stanza.iq(
|
Stanza.iq(
|
||||||
type: 'set',
|
type: 'set',
|
||||||
to: host.toString(),
|
to: host.toString(),
|
||||||
@ -604,9 +625,10 @@ class PubSubManager extends XmppManagerBase {
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
) as Stanza;
|
),
|
||||||
|
))!;
|
||||||
|
|
||||||
if (request.type != 'result') {
|
if (request.attributes['type'] != 'result') {
|
||||||
// TODO(Unknown): Be more specific
|
// TODO(Unknown): Be more specific
|
||||||
return Result(UnknownPubSubError());
|
return Result(UnknownPubSubError());
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ import 'package:moxxmpp/src/managers/namespaces.dart';
|
|||||||
import 'package:moxxmpp/src/namespaces.dart';
|
import 'package:moxxmpp/src/namespaces.dart';
|
||||||
import 'package:moxxmpp/src/stanza.dart';
|
import 'package:moxxmpp/src/stanza.dart';
|
||||||
import 'package:moxxmpp/src/stringxml.dart';
|
import 'package:moxxmpp/src/stringxml.dart';
|
||||||
|
import 'package:moxxmpp/src/util/queue.dart';
|
||||||
|
|
||||||
enum ChatState { active, composing, paused, inactive, gone }
|
enum ChatState { active, composing, paused, inactive, gone }
|
||||||
|
|
||||||
@ -111,10 +112,14 @@ class ChatStateManager extends XmppManagerBase {
|
|||||||
final tagName = state.toString().split('.').last;
|
final tagName = state.toString().split('.').last;
|
||||||
|
|
||||||
getAttributes().sendStanza(
|
getAttributes().sendStanza(
|
||||||
|
StanzaDetails(
|
||||||
Stanza.message(
|
Stanza.message(
|
||||||
to: to,
|
to: to,
|
||||||
type: messageType,
|
type: messageType,
|
||||||
children: [XMLNode.xmlns(tag: tagName, xmlns: chatStateXmlns)],
|
children: [
|
||||||
|
XMLNode.xmlns(tag: tagName, xmlns: chatStateXmlns),
|
||||||
|
],
|
||||||
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@ import 'package:moxxmpp/src/managers/namespaces.dart';
|
|||||||
import 'package:moxxmpp/src/namespaces.dart';
|
import 'package:moxxmpp/src/namespaces.dart';
|
||||||
import 'package:moxxmpp/src/stanza.dart';
|
import 'package:moxxmpp/src/stanza.dart';
|
||||||
import 'package:moxxmpp/src/stringxml.dart';
|
import 'package:moxxmpp/src/stringxml.dart';
|
||||||
|
import 'package:moxxmpp/src/util/queue.dart';
|
||||||
import 'package:moxxmpp/src/xeps/xep_0030/xep_0030.dart';
|
import 'package:moxxmpp/src/xeps/xep_0030/xep_0030.dart';
|
||||||
|
|
||||||
class BlockingManager extends XmppManagerBase {
|
class BlockingManager extends XmppManagerBase {
|
||||||
@ -96,7 +97,8 @@ class BlockingManager extends XmppManagerBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<bool> block(List<String> items) async {
|
Future<bool> block(List<String> items) async {
|
||||||
final result = await getAttributes().sendStanza(
|
final result = (await getAttributes().sendStanza(
|
||||||
|
StanzaDetails(
|
||||||
Stanza.iq(
|
Stanza.iq(
|
||||||
type: 'set',
|
type: 'set',
|
||||||
children: [
|
children: [
|
||||||
@ -112,13 +114,15 @@ class BlockingManager extends XmppManagerBase {
|
|||||||
)
|
)
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
),
|
||||||
|
))!;
|
||||||
|
|
||||||
return result.attributes['type'] == 'result';
|
return result.attributes['type'] == 'result';
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<bool> unblockAll() async {
|
Future<bool> unblockAll() async {
|
||||||
final result = await getAttributes().sendStanza(
|
final result = (await getAttributes().sendStanza(
|
||||||
|
StanzaDetails(
|
||||||
Stanza.iq(
|
Stanza.iq(
|
||||||
type: 'set',
|
type: 'set',
|
||||||
children: [
|
children: [
|
||||||
@ -128,7 +132,8 @@ class BlockingManager extends XmppManagerBase {
|
|||||||
)
|
)
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
),
|
||||||
|
))!;
|
||||||
|
|
||||||
return result.attributes['type'] == 'result';
|
return result.attributes['type'] == 'result';
|
||||||
}
|
}
|
||||||
@ -136,7 +141,8 @@ class BlockingManager extends XmppManagerBase {
|
|||||||
Future<bool> unblock(List<String> items) async {
|
Future<bool> unblock(List<String> items) async {
|
||||||
assert(items.isNotEmpty, 'The list of items to unblock must be non-empty');
|
assert(items.isNotEmpty, 'The list of items to unblock must be non-empty');
|
||||||
|
|
||||||
final result = await getAttributes().sendStanza(
|
final result = (await getAttributes().sendStanza(
|
||||||
|
StanzaDetails(
|
||||||
Stanza.iq(
|
Stanza.iq(
|
||||||
type: 'set',
|
type: 'set',
|
||||||
children: [
|
children: [
|
||||||
@ -154,13 +160,15 @@ class BlockingManager extends XmppManagerBase {
|
|||||||
)
|
)
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
),
|
||||||
|
))!;
|
||||||
|
|
||||||
return result.attributes['type'] == 'result';
|
return result.attributes['type'] == 'result';
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<List<String>> getBlocklist() async {
|
Future<List<String>> getBlocklist() async {
|
||||||
final result = await getAttributes().sendStanza(
|
final result = (await getAttributes().sendStanza(
|
||||||
|
StanzaDetails(
|
||||||
Stanza.iq(
|
Stanza.iq(
|
||||||
type: 'get',
|
type: 'get',
|
||||||
children: [
|
children: [
|
||||||
@ -170,7 +178,8 @@ class BlockingManager extends XmppManagerBase {
|
|||||||
)
|
)
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
),
|
||||||
|
))!;
|
||||||
|
|
||||||
final blocklist = result.firstTag('blocklist', xmlns: blockingXmlns)!;
|
final blocklist = result.firstTag('blocklist', xmlns: blockingXmlns)!;
|
||||||
return blocklist
|
return blocklist
|
||||||
|
@ -11,6 +11,7 @@ import 'package:moxxmpp/src/namespaces.dart';
|
|||||||
import 'package:moxxmpp/src/negotiators/namespaces.dart';
|
import 'package:moxxmpp/src/negotiators/namespaces.dart';
|
||||||
import 'package:moxxmpp/src/stanza.dart';
|
import 'package:moxxmpp/src/stanza.dart';
|
||||||
import 'package:moxxmpp/src/stringxml.dart';
|
import 'package:moxxmpp/src/stringxml.dart';
|
||||||
|
import 'package:moxxmpp/src/util/queue.dart';
|
||||||
import 'package:moxxmpp/src/xeps/xep_0198/errors.dart';
|
import 'package:moxxmpp/src/xeps/xep_0198/errors.dart';
|
||||||
import 'package:moxxmpp/src/xeps/xep_0198/negotiator.dart';
|
import 'package:moxxmpp/src/xeps/xep_0198/negotiator.dart';
|
||||||
import 'package:moxxmpp/src/xeps/xep_0198/nonzas.dart';
|
import 'package:moxxmpp/src/xeps/xep_0198/nonzas.dart';
|
||||||
@ -414,7 +415,12 @@ class StreamManagementManager extends XmppManagerBase {
|
|||||||
_unackedStanzas.clear();
|
_unackedStanzas.clear();
|
||||||
|
|
||||||
for (final stanza in stanzas) {
|
for (final stanza in stanzas) {
|
||||||
await getAttributes().sendStanza(stanza, awaitable: false);
|
await getAttributes().sendStanza(
|
||||||
|
StanzaDetails(
|
||||||
|
stanza,
|
||||||
|
awaitable: false,
|
||||||
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
import 'package:logging/logging.dart';
|
import 'package:logging/logging.dart';
|
||||||
import 'package:meta/meta.dart';
|
import 'package:meta/meta.dart';
|
||||||
import 'package:moxxmpp/src/connection.dart';
|
|
||||||
import 'package:moxxmpp/src/events.dart';
|
import 'package:moxxmpp/src/events.dart';
|
||||||
import 'package:moxxmpp/src/jid.dart';
|
import 'package:moxxmpp/src/jid.dart';
|
||||||
import 'package:moxxmpp/src/managers/base.dart';
|
import 'package:moxxmpp/src/managers/base.dart';
|
||||||
@ -11,6 +10,7 @@ import 'package:moxxmpp/src/namespaces.dart';
|
|||||||
import 'package:moxxmpp/src/negotiators/namespaces.dart';
|
import 'package:moxxmpp/src/negotiators/namespaces.dart';
|
||||||
import 'package:moxxmpp/src/stanza.dart';
|
import 'package:moxxmpp/src/stanza.dart';
|
||||||
import 'package:moxxmpp/src/stringxml.dart';
|
import 'package:moxxmpp/src/stringxml.dart';
|
||||||
|
import 'package:moxxmpp/src/util/queue.dart';
|
||||||
import 'package:moxxmpp/src/xeps/xep_0030/xep_0030.dart';
|
import 'package:moxxmpp/src/xeps/xep_0030/xep_0030.dart';
|
||||||
import 'package:moxxmpp/src/xeps/xep_0297.dart';
|
import 'package:moxxmpp/src/xeps/xep_0297.dart';
|
||||||
import 'package:moxxmpp/src/xeps/xep_0386.dart';
|
import 'package:moxxmpp/src/xeps/xep_0386.dart';
|
||||||
@ -111,7 +111,8 @@ class CarbonsManager extends XmppManagerBase {
|
|||||||
/// Returns true if carbons were enabled. False, if not.
|
/// Returns true if carbons were enabled. False, if not.
|
||||||
Future<bool> enableCarbons() async {
|
Future<bool> enableCarbons() async {
|
||||||
final attrs = getAttributes();
|
final attrs = getAttributes();
|
||||||
final result = await attrs.sendStanza(
|
final result = (await attrs.sendStanza(
|
||||||
|
StanzaDetails(
|
||||||
Stanza.iq(
|
Stanza.iq(
|
||||||
to: attrs.getFullJID().toBare().toString(),
|
to: attrs.getFullJID().toBare().toString(),
|
||||||
type: 'set',
|
type: 'set',
|
||||||
@ -122,9 +123,8 @@ class CarbonsManager extends XmppManagerBase {
|
|||||||
)
|
)
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
addFrom: StanzaFromType.full,
|
),
|
||||||
addId: true,
|
))!;
|
||||||
);
|
|
||||||
|
|
||||||
if (result.attributes['type'] != 'result') {
|
if (result.attributes['type'] != 'result') {
|
||||||
logger.warning('Failed to enable message carbons');
|
logger.warning('Failed to enable message carbons');
|
||||||
@ -142,7 +142,8 @@ class CarbonsManager extends XmppManagerBase {
|
|||||||
///
|
///
|
||||||
/// Returns true if carbons were disabled. False, if not.
|
/// Returns true if carbons were disabled. False, if not.
|
||||||
Future<bool> disableCarbons() async {
|
Future<bool> disableCarbons() async {
|
||||||
final result = await getAttributes().sendStanza(
|
final result = (await getAttributes().sendStanza(
|
||||||
|
StanzaDetails(
|
||||||
Stanza.iq(
|
Stanza.iq(
|
||||||
type: 'set',
|
type: 'set',
|
||||||
children: [
|
children: [
|
||||||
@ -152,9 +153,8 @@ class CarbonsManager extends XmppManagerBase {
|
|||||||
)
|
)
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
addFrom: StanzaFromType.full,
|
),
|
||||||
addId: true,
|
))!;
|
||||||
);
|
|
||||||
|
|
||||||
if (result.attributes['type'] != 'result') {
|
if (result.attributes['type'] != 'result') {
|
||||||
logger.warning('Failed to disable message carbons');
|
logger.warning('Failed to disable message carbons');
|
||||||
|
@ -8,6 +8,7 @@ import 'package:moxxmpp/src/namespaces.dart';
|
|||||||
import 'package:moxxmpp/src/stanza.dart';
|
import 'package:moxxmpp/src/stanza.dart';
|
||||||
import 'package:moxxmpp/src/stringxml.dart';
|
import 'package:moxxmpp/src/stringxml.dart';
|
||||||
import 'package:moxxmpp/src/types/result.dart';
|
import 'package:moxxmpp/src/types/result.dart';
|
||||||
|
import 'package:moxxmpp/src/util/queue.dart';
|
||||||
import 'package:moxxmpp/src/xeps/xep_0030/errors.dart';
|
import 'package:moxxmpp/src/xeps/xep_0030/errors.dart';
|
||||||
import 'package:moxxmpp/src/xeps/xep_0030/types.dart';
|
import 'package:moxxmpp/src/xeps/xep_0030/types.dart';
|
||||||
import 'package:moxxmpp/src/xeps/xep_0030/xep_0030.dart';
|
import 'package:moxxmpp/src/xeps/xep_0030/xep_0030.dart';
|
||||||
@ -149,7 +150,8 @@ class HttpFileUploadManager extends XmppManagerBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
final attrs = getAttributes();
|
final attrs = getAttributes();
|
||||||
final response = await attrs.sendStanza(
|
final response = (await attrs.sendStanza(
|
||||||
|
StanzaDetails(
|
||||||
Stanza.iq(
|
Stanza.iq(
|
||||||
to: _entityJid.toString(),
|
to: _entityJid.toString(),
|
||||||
type: 'get',
|
type: 'get',
|
||||||
@ -165,7 +167,8 @@ class HttpFileUploadManager extends XmppManagerBase {
|
|||||||
)
|
)
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
),
|
||||||
|
))!;
|
||||||
|
|
||||||
if (response.attributes['type']! != 'result') {
|
if (response.attributes['type']! != 'result') {
|
||||||
logger.severe('Failed to request HTTP File Upload slot.');
|
logger.severe('Failed to request HTTP File Upload slot.');
|
||||||
|
@ -11,6 +11,7 @@ import 'package:moxxmpp/src/namespaces.dart';
|
|||||||
import 'package:moxxmpp/src/stanza.dart';
|
import 'package:moxxmpp/src/stanza.dart';
|
||||||
import 'package:moxxmpp/src/stringxml.dart';
|
import 'package:moxxmpp/src/stringxml.dart';
|
||||||
import 'package:moxxmpp/src/types/result.dart';
|
import 'package:moxxmpp/src/types/result.dart';
|
||||||
|
import 'package:moxxmpp/src/util/queue.dart';
|
||||||
import 'package:moxxmpp/src/xeps/xep_0030/errors.dart';
|
import 'package:moxxmpp/src/xeps/xep_0030/errors.dart';
|
||||||
import 'package:moxxmpp/src/xeps/xep_0030/types.dart';
|
import 'package:moxxmpp/src/xeps/xep_0030/types.dart';
|
||||||
import 'package:moxxmpp/src/xeps/xep_0030/xep_0030.dart';
|
import 'package:moxxmpp/src/xeps/xep_0030/xep_0030.dart';
|
||||||
@ -262,6 +263,7 @@ abstract class BaseOmemoManager extends XmppManagerBase {
|
|||||||
String toJid,
|
String toJid,
|
||||||
) async {
|
) async {
|
||||||
await getAttributes().sendStanza(
|
await getAttributes().sendStanza(
|
||||||
|
StanzaDetails(
|
||||||
Stanza.message(
|
Stanza.message(
|
||||||
to: toJid,
|
to: toJid,
|
||||||
type: 'chat',
|
type: 'chat',
|
||||||
@ -280,6 +282,7 @@ abstract class BaseOmemoManager extends XmppManagerBase {
|
|||||||
),
|
),
|
||||||
awaitable: false,
|
awaitable: false,
|
||||||
encrypted: true,
|
encrypted: true,
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'package:moxxmpp/moxxmpp.dart';
|
import 'package:moxxmpp/moxxmpp.dart';
|
||||||
|
import 'package:moxxmpp/src/util/queue.dart';
|
||||||
import 'package:test/test.dart';
|
import 'package:test/test.dart';
|
||||||
import '../helpers/logging.dart';
|
import '../helpers/logging.dart';
|
||||||
import '../helpers/xmpp.dart';
|
import '../helpers/xmpp.dart';
|
||||||
@ -44,15 +45,8 @@ Future<void> runOutgoingStanzaHandlers(
|
|||||||
|
|
||||||
XmppManagerAttributes mkAttributes(void Function(Stanza) callback) {
|
XmppManagerAttributes mkAttributes(void Function(Stanza) callback) {
|
||||||
return XmppManagerAttributes(
|
return XmppManagerAttributes(
|
||||||
sendStanza: (
|
sendStanza: (StanzaDetails details) async {
|
||||||
stanza, {
|
callback(details.stanza);
|
||||||
StanzaFromType addFrom = StanzaFromType.full,
|
|
||||||
bool addId = true,
|
|
||||||
bool awaitable = true,
|
|
||||||
bool encrypted = false,
|
|
||||||
bool forceEncryption = false,
|
|
||||||
}) async {
|
|
||||||
callback(stanza);
|
|
||||||
|
|
||||||
return Stanza.message();
|
return Stanza.message();
|
||||||
},
|
},
|
||||||
@ -290,12 +284,8 @@ void main() {
|
|||||||
);
|
);
|
||||||
final sm = StreamManagementManager();
|
final sm = StreamManagementManager();
|
||||||
await conn.registerManagers([
|
await conn.registerManagers([
|
||||||
PresenceManager(),
|
|
||||||
RosterManager(TestingRosterStateManager('', [])),
|
|
||||||
DiscoManager([]),
|
|
||||||
sm,
|
sm,
|
||||||
CarbonsManager()..forceEnable(),
|
CarbonsManager()..forceEnable(),
|
||||||
EntityCapabilitiesManager('http://moxxmpp.example'),
|
|
||||||
]);
|
]);
|
||||||
await conn.registerFeatureNegotiators([
|
await conn.registerFeatureNegotiators([
|
||||||
SaslPlainNegotiator(),
|
SaslPlainNegotiator(),
|
||||||
@ -776,7 +766,11 @@ void main() {
|
|||||||
|
|
||||||
// Send a bogus stanza
|
// Send a bogus stanza
|
||||||
unawaited(
|
unawaited(
|
||||||
conn.sendStanza(Stanza.iq(to: 'localhost', type: 'get')),
|
conn.sendStanza(
|
||||||
|
StanzaDetails(
|
||||||
|
Stanza.iq(to: 'localhost', type: 'get'),
|
||||||
|
),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
await Future<void>.delayed(const Duration(seconds: 5));
|
await Future<void>.delayed(const Duration(seconds: 5));
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import 'package:moxxmpp/moxxmpp.dart';
|
import 'package:moxxmpp/moxxmpp.dart';
|
||||||
|
import 'package:moxxmpp/src/util/queue.dart';
|
||||||
import 'package:test/test.dart';
|
import 'package:test/test.dart';
|
||||||
import '../helpers/logging.dart';
|
import '../helpers/logging.dart';
|
||||||
import '../helpers/xmpp.dart';
|
import '../helpers/xmpp.dart';
|
||||||
@ -9,17 +10,9 @@ void main() {
|
|||||||
test("Test if we're vulnerable against CVE-2020-26547 style vulnerabilities",
|
test("Test if we're vulnerable against CVE-2020-26547 style vulnerabilities",
|
||||||
() async {
|
() async {
|
||||||
final attributes = XmppManagerAttributes(
|
final attributes = XmppManagerAttributes(
|
||||||
sendStanza: (
|
sendStanza: (StanzaDetails details) async {
|
||||||
stanza, {
|
|
||||||
StanzaFromType addFrom = StanzaFromType.full,
|
|
||||||
bool addId = true,
|
|
||||||
bool retransmitted = false,
|
|
||||||
bool awaitable = true,
|
|
||||||
bool encrypted = false,
|
|
||||||
bool forceEncryption = false,
|
|
||||||
}) async {
|
|
||||||
// ignore: avoid_print
|
// ignore: avoid_print
|
||||||
print('==> ${stanza.toXml()}');
|
print('==> ${details.stanza.toXml()}');
|
||||||
return XMLNode(tag: 'iq', attributes: {'type': 'result'});
|
return XMLNode(tag: 'iq', attributes: {'type': 'result'});
|
||||||
},
|
},
|
||||||
sendNonza: (nonza) {},
|
sendNonza: (nonza) {},
|
||||||
|
@ -131,11 +131,7 @@ void main() {
|
|||||||
password: 'aaaa',
|
password: 'aaaa',
|
||||||
);
|
);
|
||||||
await conn.registerManagers([
|
await conn.registerManagers([
|
||||||
PresenceManager(),
|
|
||||||
RosterManager(TestingRosterStateManager('', [])),
|
|
||||||
DiscoManager([]),
|
|
||||||
StreamManagementManager(),
|
StreamManagementManager(),
|
||||||
EntityCapabilitiesManager('http://moxxmpp.example'),
|
|
||||||
]);
|
]);
|
||||||
await conn.registerFeatureNegotiators([
|
await conn.registerFeatureNegotiators([
|
||||||
SaslPlainNegotiator(),
|
SaslPlainNegotiator(),
|
||||||
|
Loading…
Reference in New Issue
Block a user