diff --git a/packages/moxxmpp/lib/src/connection.dart b/packages/moxxmpp/lib/src/connection.dart index 6333961..af00139 100644 --- a/packages/moxxmpp/lib/src/connection.dart +++ b/packages/moxxmpp/lib/src/connection.dart @@ -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 + // > () determined by the server for + // > the connected resource that generated the stanza (see + // > Section 4.3.6), or the bare JID () 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( diff --git a/packages/moxxmpp/lib/src/presence.dart b/packages/moxxmpp/lib/src/presence.dart index 0fd8dff..211b049 100644 --- a/packages/moxxmpp/lib/src/presence.dart +++ b/packages/moxxmpp/lib/src/presence.dart @@ -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, ), ); diff --git a/packages/moxxmpp/lib/src/util/queue.dart b/packages/moxxmpp/lib/src/util/queue.dart index b483ae9..90845be 100644 --- a/packages/moxxmpp/lib/src/util/queue.dart +++ b/packages/moxxmpp/lib/src/util/queue.dart @@ -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; diff --git a/packages/moxxmpp/test/helpers/manager.dart b/packages/moxxmpp/test/helpers/manager.dart index 6813271..af64e56 100644 --- a/packages/moxxmpp/test/helpers/manager.dart +++ b/packages/moxxmpp/test/helpers/manager.dart @@ -33,7 +33,6 @@ class TestingManagerHolder { Future _sendStanza( stanza, { - StanzaFromType addFrom = StanzaFromType.full, bool addId = true, bool awaitable = true, bool encrypted = false, diff --git a/packages/moxxmpp/test/helpers/xmpp.dart b/packages/moxxmpp/test/helpers/xmpp.dart index b6686d1..4ad38fd 100644 --- a/packages/moxxmpp/test/helpers/xmpp.dart +++ b/packages/moxxmpp/test/helpers/xmpp.dart @@ -98,7 +98,7 @@ List buildAuthenticatedPlay(ConnectionSettings settings) { ignoreId: true, ), StanzaExpectation( - "chat", + "chat", '', ), ]; diff --git a/packages/moxxmpp/test/xeps/xep_0030_test.dart b/packages/moxxmpp/test/xeps/xep_0030_test.dart index f38255f..134d9e6 100644 --- a/packages/moxxmpp/test/xeps/xep_0030_test.dart +++ b/packages/moxxmpp/test/xeps/xep_0030_test.dart @@ -58,11 +58,11 @@ void main() { ignoreId: true, ), StanzaExpectation( - "chat", + "chat", '', ), StanzaExpectation( - "", + "", '', ignoreId: true, ), diff --git a/packages/moxxmpp/test/xeps/xep_0060_test.dart b/packages/moxxmpp/test/xeps/xep_0060_test.dart index e559dbc..0f1795b 100644 --- a/packages/moxxmpp/test/xeps/xep_0060_test.dart +++ b/packages/moxxmpp/test/xeps/xep_0060_test.dart @@ -92,7 +92,7 @@ void main() { [ StanzaExpectation( ''' - + ''', @@ -110,7 +110,7 @@ void main() { ), StanzaExpectation( ''' - + ''', @@ -124,7 +124,7 @@ void main() { ), StanzaExpectation( ''' - + diff --git a/packages/moxxmpp/test/xeps/xep_0198_test.dart b/packages/moxxmpp/test/xeps/xep_0198_test.dart index 89cd0eb..ec67d19 100644 --- a/packages/moxxmpp/test/xeps/xep_0198_test.dart +++ b/packages/moxxmpp/test/xeps/xep_0198_test.dart @@ -381,7 +381,7 @@ void main() { '', ), StanzaExpectation( - "chat", + "chat", '', ), StringExpectation( @@ -671,7 +671,7 @@ void main() { "", ), StanzaExpectation( - "", + "", '', ignoreId: true, ), @@ -724,7 +724,7 @@ void main() { "", ), StanzaExpectation( - "", + "", '', ignoreId: true, ), diff --git a/packages/moxxmpp/test/xeps/xep_0352_test.dart b/packages/moxxmpp/test/xeps/xep_0352_test.dart index fb252b4..a823faa 100644 --- a/packages/moxxmpp/test/xeps/xep_0352_test.dart +++ b/packages/moxxmpp/test/xeps/xep_0352_test.dart @@ -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, diff --git a/packages/moxxmpp/test/xmpp_test.dart b/packages/moxxmpp/test/xmpp_test.dart index cbe157b..1f2277e 100644 --- a/packages/moxxmpp/test/xmpp_test.dart +++ b/packages/moxxmpp/test/xmpp_test.dart @@ -16,7 +16,6 @@ Future 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,