feat(all): Remove StanzaAddFrom

This commit is contained in:
PapaTutuWawa 2023-05-24 20:27:01 +02:00
parent 3163101f82
commit b95e75329d
10 changed files with 24 additions and 56 deletions

View File

@ -49,18 +49,6 @@ enum XmppConnectionState {
error
}
/// Metadata for [XmppConnection.sendStanza].
enum StanzaFromType {
/// Add the full JID to the stanza as the from attribute
full,
/// Add the bare JID to the stanza as the from attribute
bare,
/// Add no JID as the from attribute
none,
}
/// This class is a connection to the server.
class XmppConnection {
XmppConnection(
@ -454,25 +442,21 @@ class XmppConnection {
newStanza = newStanza.copyWith(id: generateId());
}
// Add a from type, if requested
if (details.addFrom != StanzaFromType.none &&
(newStanza.from == null || newStanza.from == '')) {
switch (details.addFrom) {
case StanzaFromType.full:
newStanza = newStanza.copyWith(
from: _getJidWithResource().toString(),
);
break;
case StanzaFromType.bare:
newStanza = newStanza.copyWith(
from: connectionSettings.jid.toBare().toString(),
);
break;
case StanzaFromType.none:
// NOOP
break;
}
}
// NOTE: Originally, we handled adding a "from" attribute to the stanza here.
// However, this is not neccessary as RFC 6120 states:
//
// > When a server receives an XML stanza from a connected client, the
// > server MUST add a 'from' attribute to the stanza or override the
// > 'from' attribute specified by the client, where the value of the
// > 'from' attribute MUST be the full JID
// > (<localpart@domainpart/resource>) determined by the server for
// > the connected resource that generated the stanza (see
// > Section 4.3.6), or the bare JID (<localpart@domainpart>) in the
// > case of subscription-related presence stanzas (see [XMPP-IM]).
//
// This means that even if we add a "from" attribute, the server will discard
// it. If we don't specify it, then the server will add the correct value
// itself.
// Add the correct stanza namespace
newStanza = newStanza.copyWith(

View File

@ -1,5 +1,4 @@
import 'dart:async';
import 'package:moxxmpp/src/connection.dart';
import 'package:moxxmpp/src/events.dart';
import 'package:moxxmpp/src/jid.dart';
import 'package:moxxmpp/src/managers/base.dart';
@ -105,7 +104,6 @@ class PresenceManager extends XmppManagerBase {
await attrs.sendStanza(
StanzaDetails(
Stanza.presence(
from: attrs.getFullJID().toString(),
children: children,
),
awaitable: false,
@ -134,7 +132,6 @@ class PresenceManager extends XmppManagerBase {
type: 'subscribe',
to: to,
),
addFrom: StanzaFromType.none,
awaitable: false,
),
);
@ -148,7 +145,6 @@ class PresenceManager extends XmppManagerBase {
type: 'unsubscribe',
to: to,
),
addFrom: StanzaFromType.none,
awaitable: false,
),
);
@ -162,7 +158,6 @@ class PresenceManager extends XmppManagerBase {
type: 'subscribed',
to: to,
),
addFrom: StanzaFromType.none,
awaitable: false,
),
);
@ -176,7 +171,6 @@ class PresenceManager extends XmppManagerBase {
type: 'unsubscribed',
to: to,
),
addFrom: StanzaFromType.none,
awaitable: false,
),
);

View File

@ -1,7 +1,6 @@
import 'dart:async';
import 'dart:collection';
import 'package:meta/meta.dart';
import 'package:moxxmpp/src/connection.dart';
import 'package:moxxmpp/src/stanza.dart';
import 'package:moxxmpp/src/stringxml.dart';
import 'package:synchronized/synchronized.dart';
@ -9,7 +8,6 @@ import 'package:synchronized/synchronized.dart';
class StanzaDetails {
const StanzaDetails(
this.stanza, {
this.addFrom = StanzaFromType.full,
this.addId = true,
this.awaitable = true,
this.encrypted = false,
@ -19,9 +17,6 @@ class StanzaDetails {
/// The stanza to send.
final Stanza stanza;
/// How to set the "from" attribute of the stanza.
final StanzaFromType addFrom;
/// Flag indicating whether a stanza id should be added before sending.
final bool addId;

View File

@ -33,7 +33,6 @@ class TestingManagerHolder {
Future<XMLNode> _sendStanza(
stanza, {
StanzaFromType addFrom = StanzaFromType.full,
bool addId = true,
bool awaitable = true,
bool encrypted = false,

View File

@ -98,7 +98,7 @@ List<ExpectationBase> buildAuthenticatedPlay(ConnectionSettings settings) {
ignoreId: true,
),
StanzaExpectation(
"<presence xmlns='jabber:client' from='${settings.jid.toBare()}/MU29eEZn'><show>chat</show></presence>",
"<presence xmlns='jabber:client'><show>chat</show></presence>",
'',
),
];

View File

@ -58,11 +58,11 @@ void main() {
ignoreId: true,
),
StanzaExpectation(
"<presence xmlns='jabber:client' from='polynomdivision@test.server/MU29eEZn'><show>chat</show><c xmlns='http://jabber.org/protocol/caps' hash='sha-1' node='http://moxxmpp.example' ver='3QvQ2RAy45XBDhArjxy/vEWMl+E=' /></presence>",
"<presence xmlns='jabber:client'><show>chat</show><c xmlns='http://jabber.org/protocol/caps' hash='sha-1' node='http://moxxmpp.example' ver='3QvQ2RAy45XBDhArjxy/vEWMl+E=' /></presence>",
'',
),
StanzaExpectation(
"<iq type='get' id='ec325efc-9924-4c48-93f8-ed34a2b0e5fc' to='romeo@montague.lit/orchard' from='polynomdivision@test.server/MU29eEZn' xmlns='jabber:client'><query xmlns='http://jabber.org/protocol/disco#info' /></iq>",
"<iq type='get' id='ec325efc-9924-4c48-93f8-ed34a2b0e5fc' to='romeo@montague.lit/orchard' xmlns='jabber:client'><query xmlns='http://jabber.org/protocol/disco#info' /></iq>",
'',
ignoreId: true,
),

View File

@ -92,7 +92,7 @@ void main() {
[
StanzaExpectation(
'''
<iq type="get" to="pubsub.server.example.org" id="a" from="testuser@example.org/MU29eEZn" xmlns="jabber:client">
<iq type="get" to="pubsub.server.example.org" id="a" xmlns="jabber:client">
<query xmlns="http://jabber.org/protocol/disco#info" />
</iq>
''',
@ -110,7 +110,7 @@ void main() {
),
StanzaExpectation(
'''
<iq type="get" to="pubsub.server.example.org" id="a" from="testuser@example.org/MU29eEZn" xmlns="jabber:client">
<iq type="get" to="pubsub.server.example.org" id="a" xmlns="jabber:client">
<query xmlns="http://jabber.org/protocol/disco#items" node="princely_musings" />
</iq>
''',
@ -124,7 +124,7 @@ void main() {
),
StanzaExpectation(
'''
<iq type="set" to="pubsub.server.example.org" id="a" from="testuser@example.org/MU29eEZn" xmlns="jabber:client">
<iq type="set" to="pubsub.server.example.org" id="a" xmlns="jabber:client">
<pubsub xmlns='http://jabber.org/protocol/pubsub'>
<publish node='princely_musings'>
<item id="current">

View File

@ -381,7 +381,7 @@ void main() {
'<enabled xmlns="urn:xmpp:sm:3" id="some-long-sm-id" resume="true" />',
),
StanzaExpectation(
"<presence xmlns='jabber:client' from='polynomdivision@test.server/MU29eEZn'><show>chat</show></presence>",
"<presence xmlns='jabber:client'><show>chat</show></presence>",
'<iq type="result" />',
),
StringExpectation(
@ -671,7 +671,7 @@ void main() {
"<resumed xmlns='urn:xmpp:sm:3' h='id-1' h='12' />",
),
StanzaExpectation(
"<iq to='localhost' type='get' from='polynomdivision@test.server/abc123' xmlns='jabber:client' />",
"<iq to='localhost' type='get' xmlns='jabber:client' />",
'',
ignoreId: true,
),
@ -724,7 +724,7 @@ void main() {
"<resumed xmlns='urn:xmpp:sm:3' h='id-1' h='12' />",
),
StanzaExpectation(
"<iq to='localhost' type='get' from='polynomdivision@test.server/abc123' xmlns='jabber:client' />",
"<iq to='localhost' type='get' xmlns='jabber:client' />",
'',
ignoreId: true,
),

View File

@ -39,7 +39,6 @@ void main() {
XmppManagerAttributes(
sendStanza: (
_, {
StanzaFromType addFrom = StanzaFromType.full,
bool addId = true,
bool retransmitted = false,
bool awaitable = true,
@ -78,7 +77,6 @@ void main() {
XmppManagerAttributes(
sendStanza: (
_, {
StanzaFromType addFrom = StanzaFromType.full,
bool addId = true,
bool retransmitted = false,
bool awaitable = true,

View File

@ -16,7 +16,6 @@ Future<bool> testRosterManager(
XmppManagerAttributes(
sendStanza: (
_, {
StanzaFromType addFrom = StanzaFromType.full,
bool addId = true,
bool retransmitted = false,
bool awaitable = true,
@ -267,7 +266,6 @@ void main() {
XmppManagerAttributes(
sendStanza: (
_, {
StanzaFromType addFrom = StanzaFromType.full,
bool addId = true,
bool retransmitted = false,
bool awaitable = true,