feat(core): Remove getter and setter for connectionSettings

This commit is contained in:
PapaTutuWawa 2023-04-03 17:56:31 +02:00
parent 47d821c02e
commit 3e43ac22d7
12 changed files with 121 additions and 188 deletions

View File

@ -108,12 +108,10 @@ class _MyHomePageState extends State<MyHomePage> {
setState(() { setState(() {
loading = true; loading = true;
}); });
connection.setConnectionSettings( connection.connectionSettings = ConnectionSettings(
ConnectionSettings(
jid: JID.fromString(jidController.text), jid: JID.fromString(jidController.text),
password: passwordController.text, password: passwordController.text,
useDirectTLS: true, useDirectTLS: true,
),
); );
final result = await connection.connect(waitUntilLogin: true); final result = await connection.connect(waitUntilLogin: true);
setState(() { setState(() {

View File

@ -6,6 +6,7 @@
- Renamed `ResourceBindingSuccessEvent` to `ResourceBoundEvent` - Renamed `ResourceBindingSuccessEvent` to `ResourceBoundEvent`
- **BREAKING**: Removed `isFeatureSupported` from the manager attributes. The managers now all have a method `isFeatureSupported` that works the same - **BREAKING**: Removed `isFeatureSupported` from the manager attributes. The managers now all have a method `isFeatureSupported` that works the same
- The `PresenceManager` is now optional - The `PresenceManager` is now optional
- **BREAKING**: Removed `setConnectionSettings` and `getConnectionSettings`. Just directly acces the `connectionSettings` field.
## 0.1.6+1 ## 0.1.6+1

View File

@ -119,7 +119,7 @@ class XmppConnection {
late final Stream<String> _socketStream; late final Stream<String> _socketStream;
/// Connection settings /// Connection settings
late ConnectionSettings _connectionSettings; late ConnectionSettings connectionSettings;
/// A policy on how to reconnect /// A policy on how to reconnect
final ReconnectionPolicy _reconnectionPolicy; final ReconnectionPolicy _reconnectionPolicy;
@ -197,9 +197,9 @@ class XmppConnection {
sendStanza: sendStanza, sendStanza: sendStanza,
sendNonza: sendRawXML, sendNonza: sendRawXML,
sendEvent: _sendEvent, sendEvent: _sendEvent,
getConnectionSettings: () => _connectionSettings, getConnectionSettings: () => connectionSettings,
getManagerById: getManagerById, getManagerById: getManagerById,
getFullJID: () => _connectionSettings.jid.withResource(_resource), getFullJID: () => connectionSettings.jid.withResource(_resource),
getSocket: () => _socket, getSocket: () => _socket,
getConnection: () => this, getConnection: () => this,
getNegotiatorById: _negotiationsHandler.getNegotiatorById, getNegotiatorById: _negotiationsHandler.getNegotiatorById,
@ -246,11 +246,11 @@ class XmppConnection {
NegotiatorAttributes( NegotiatorAttributes(
sendRawXML, sendRawXML,
() => this, () => this,
() => _connectionSettings, () => connectionSettings,
_sendEvent, _sendEvent,
_negotiationsHandler.getNegotiatorById, _negotiationsHandler.getNegotiatorById,
getManagerById, getManagerById,
() => _connectionSettings.jid.withResource(_resource), () => connectionSettings.jid.withResource(_resource),
() => _socket, () => _socket,
() => _isAuthenticated, () => _isAuthenticated,
_setAuthenticated, _setAuthenticated,
@ -312,16 +312,6 @@ class XmppConnection {
return getManagerById(csiManager); return getManagerById(csiManager);
} }
/// Set the connection settings of this connection.
void setConnectionSettings(ConnectionSettings settings) {
_connectionSettings = settings;
}
/// Returns the connection settings of this connection.
ConnectionSettings getConnectionSettings() {
return _connectionSettings;
}
/// Attempts to reconnect to the server by following an exponential backoff. /// Attempts to reconnect to the server by following an exponential backoff.
Future<void> _attemptReconnection() async { Future<void> _attemptReconnection() async {
_log.finest('_attemptReconnection: Setting state to notConnected'); _log.finest('_attemptReconnection: Setting state to notConnected');
@ -471,14 +461,14 @@ class XmppConnection {
case StanzaFromType.full: case StanzaFromType.full:
{ {
stanza_ = stanza_.copyWith( stanza_ = stanza_.copyWith(
from: _connectionSettings.jid.withResource(_resource).toString(), from: connectionSettings.jid.withResource(_resource).toString(),
); );
} }
break; break;
case StanzaFromType.bare: case StanzaFromType.bare:
{ {
stanza_ = stanza_.copyWith( stanza_ = stanza_.copyWith(
from: _connectionSettings.jid.toBare().toString(), from: connectionSettings.jid.toBare().toString(),
); );
} }
break; break;
@ -533,7 +523,7 @@ class XmppConnection {
// A stanza with no to attribute is for direct processing by the server. As such, // 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 // we can correlate it by just *assuming* we have that attribute
// (RFC 6120 Section 8.1.1.1) // (RFC 6120 Section 8.1.1.1)
data.stanza.to ?? _connectionSettings.jid.toBare().toString(), data.stanza.to ?? connectionSettings.jid.toBare().toString(),
data.stanza.id!, data.stanza.id!,
data.stanza.tag, data.stanza.tag,
); );
@ -752,7 +742,7 @@ class XmppConnection {
final awaited = await _stanzaAwaiter.onData( final awaited = await _stanzaAwaiter.onData(
incomingPreHandlers.stanza, incomingPreHandlers.stanza,
_connectionSettings.jid.toBare(), connectionSettings.jid.toBare(),
); );
if (awaited) { if (awaited) {
return; return;
@ -841,7 +831,7 @@ class XmppConnection {
closeTag: false, closeTag: false,
isDeclaration: true, isDeclaration: true,
children: [ children: [
StreamHeaderNonza(_connectionSettings.jid), StreamHeaderNonza(connectionSettings.jid),
], ],
).toXml(), ).toXml(),
); );
@ -929,20 +919,17 @@ class XmppConnection {
} }
final smManager = getStreamManagementManager(); final smManager = getStreamManagementManager();
var host = _connectionSettings.host; var host = connectionSettings.host;
var port = _connectionSettings.port; var port = connectionSettings.port;
if (smManager?.state.streamResumptionLocation != null) { if (smManager?.state.streamResumptionLocation != null) {
// TODO(Unknown): Maybe wrap this in a try catch? // TODO(Unknown): Maybe wrap this in a try catch?
final parsed = Uri.parse(smManager!.state.streamResumptionLocation!); final parsed = Uri.parse(smManager!.state.streamResumptionLocation!);
host = parsed.host; host = parsed.host;
port = parsed.port; port = parsed.port;
} else {
host = _connectionSettings.host;
port = _connectionSettings.port;
} }
final result = await _socket.connect( final result = await _socket.connect(
_connectionSettings.jid.domain, connectionSettings.jid.domain,
host: host, host: host,
port: port, port: port,
); );

View File

@ -72,12 +72,10 @@ void main() {
AlwaysConnectedConnectivityManager(), AlwaysConnectedConnectivityManager(),
ClientToServerNegotiator(), ClientToServerNegotiator(),
fakeSocket, fakeSocket,
)..setConnectionSettings( )..connectionSettings = ConnectionSettings(
ConnectionSettings(
jid: JID.fromString('polynomdivision@test.server'), jid: JID.fromString('polynomdivision@test.server'),
password: 'aaaa', password: 'aaaa',
useDirectTLS: true, useDirectTLS: true,
),
); );
await conn.registerManagers([ await conn.registerManagers([
PresenceManager(), PresenceManager(),

View File

@ -161,7 +161,7 @@ void main() {
AlwaysConnectedConnectivityManager(), AlwaysConnectedConnectivityManager(),
ClientToServerNegotiator(), ClientToServerNegotiator(),
socket, socket,
); )..connectionSettings = TestingManagerHolder.settings;
await connection.registerManagers([ await connection.registerManagers([
PubSubManager(), PubSubManager(),
@ -174,7 +174,6 @@ void main() {
SaslPlainNegotiator(), SaslPlainNegotiator(),
ResourceBindingNegotiator(), ResourceBindingNegotiator(),
]); ]);
connection.setConnectionSettings(TestingManagerHolder.settings);
await connection.connect( await connection.connect(
waitUntilLogin: true, waitUntilLogin: true,
); );

View File

@ -283,12 +283,10 @@ void main() {
AlwaysConnectedConnectivityManager(), AlwaysConnectedConnectivityManager(),
ClientToServerNegotiator(), ClientToServerNegotiator(),
fakeSocket, fakeSocket,
)..setConnectionSettings( )..connectionSettings = ConnectionSettings(
ConnectionSettings(
jid: JID.fromString('polynomdivision@test.server'), jid: JID.fromString('polynomdivision@test.server'),
password: 'aaaa', password: 'aaaa',
useDirectTLS: true, useDirectTLS: true,
),
); );
final sm = StreamManagementManager(); final sm = StreamManagementManager();
await conn.registerManagers([ await conn.registerManagers([
@ -409,12 +407,10 @@ void main() {
AlwaysConnectedConnectivityManager(), AlwaysConnectedConnectivityManager(),
ClientToServerNegotiator(), ClientToServerNegotiator(),
fakeSocket, fakeSocket,
)..setConnectionSettings( )..connectionSettings = ConnectionSettings(
ConnectionSettings(
jid: JID.fromString('polynomdivision@test.server'), jid: JID.fromString('polynomdivision@test.server'),
password: 'aaaa', password: 'aaaa',
useDirectTLS: true, useDirectTLS: true,
),
); );
final sm = StreamManagementManager(); final sm = StreamManagementManager();
await conn.registerManagers([ await conn.registerManagers([
@ -570,12 +566,10 @@ void main() {
AlwaysConnectedConnectivityManager(), AlwaysConnectedConnectivityManager(),
ClientToServerNegotiator(), ClientToServerNegotiator(),
fakeSocket, fakeSocket,
)..setConnectionSettings( )..connectionSettings = ConnectionSettings(
ConnectionSettings(
jid: JID.fromString('polynomdivision@test.server'), jid: JID.fromString('polynomdivision@test.server'),
password: 'aaaa', password: 'aaaa',
useDirectTLS: true, useDirectTLS: true,
),
); );
await conn.registerManagers([ await conn.registerManagers([
PresenceManager(), PresenceManager(),
@ -665,12 +659,10 @@ void main() {
AlwaysConnectedConnectivityManager(), AlwaysConnectedConnectivityManager(),
ClientToServerNegotiator(), ClientToServerNegotiator(),
fakeSocket, fakeSocket,
)..setConnectionSettings( )..connectionSettings = ConnectionSettings(
ConnectionSettings(
jid: JID.fromString('polynomdivision@test.server'), jid: JID.fromString('polynomdivision@test.server'),
password: 'aaaa', password: 'aaaa',
useDirectTLS: true, useDirectTLS: true,
),
); );
await conn.registerManagers([ await conn.registerManagers([
PresenceManager(), PresenceManager(),
@ -757,12 +749,10 @@ void main() {
AlwaysConnectedConnectivityManager(), AlwaysConnectedConnectivityManager(),
ClientToServerNegotiator(), ClientToServerNegotiator(),
fakeSocket, fakeSocket,
)..setConnectionSettings( )..connectionSettings = ConnectionSettings(
ConnectionSettings(
jid: JID.fromString('polynomdivision@test.server'), jid: JID.fromString('polynomdivision@test.server'),
password: 'aaaa', password: 'aaaa',
useDirectTLS: true, useDirectTLS: true,
),
); );
await conn.registerManagers([ await conn.registerManagers([
PresenceManager(), PresenceManager(),
@ -846,12 +836,10 @@ void main() {
ClientToServerNegotiator(), ClientToServerNegotiator(),
fakeSocket, fakeSocket,
) )
..setConnectionSettings( ..connectionSettings = ConnectionSettings(
ConnectionSettings(
jid: JID.fromString('polynomdivision@test.server'), jid: JID.fromString('polynomdivision@test.server'),
password: 'aaaa', password: 'aaaa',
useDirectTLS: true, useDirectTLS: true,
),
) )
..setResource('test-resource', triggerEvent: false); ..setResource('test-resource', triggerEvent: false);
await conn.registerManagers([ await conn.registerManagers([
@ -946,12 +934,10 @@ void main() {
ClientToServerNegotiator(), ClientToServerNegotiator(),
fakeSocket, fakeSocket,
) )
..setConnectionSettings( ..connectionSettings = ConnectionSettings(
ConnectionSettings(
jid: JID.fromString('polynomdivision@test.server'), jid: JID.fromString('polynomdivision@test.server'),
password: 'aaaa', password: 'aaaa',
useDirectTLS: true, useDirectTLS: true,
),
) )
..setResource('test-resource', triggerEvent: false); ..setResource('test-resource', triggerEvent: false);
await conn.registerManagers([ await conn.registerManagers([
@ -1050,12 +1036,10 @@ void main() {
ClientToServerNegotiator(), ClientToServerNegotiator(),
fakeSocket, fakeSocket,
) )
..setConnectionSettings( ..connectionSettings = ConnectionSettings(
ConnectionSettings(
jid: JID.fromString('polynomdivision@test.server'), jid: JID.fromString('polynomdivision@test.server'),
password: 'aaaa', password: 'aaaa',
useDirectTLS: true, useDirectTLS: true,
),
) )
..setResource('test-resource', triggerEvent: false); ..setResource('test-resource', triggerEvent: false);
await conn.registerManagers([ await conn.registerManagers([

View File

@ -107,12 +107,10 @@ void main() {
ClientToServerNegotiator(), ClientToServerNegotiator(),
fakeSocket, fakeSocket,
) )
..setConnectionSettings( ..connectionSettings = ConnectionSettings(
ConnectionSettings(
jid: JID.fromString('polynomdivision@test.server'), jid: JID.fromString('polynomdivision@test.server'),
password: 'aaaa', password: 'aaaa',
useDirectTLS: true, useDirectTLS: true,
),
) )
..setResource('test-resource', triggerEvent: false); ..setResource('test-resource', triggerEvent: false);
await conn.registerManagers([ await conn.registerManagers([

View File

@ -171,12 +171,10 @@ void main() {
AlwaysConnectedConnectivityManager(), AlwaysConnectedConnectivityManager(),
ClientToServerNegotiator(), ClientToServerNegotiator(),
fakeSocket, fakeSocket,
)..setConnectionSettings( )..connectionSettings = ConnectionSettings(
ConnectionSettings(
jid: JID.fromString('polynomdivision@test.server'), jid: JID.fromString('polynomdivision@test.server'),
password: 'aaaa', password: 'aaaa',
useDirectTLS: true, useDirectTLS: true,
),
); );
final csi = CSIManager(); final csi = CSIManager();
await csi.setInactive(sendNonza: false); await csi.setInactive(sendNonza: false);

View File

@ -46,12 +46,10 @@ void main() {
AlwaysConnectedConnectivityManager(), AlwaysConnectedConnectivityManager(),
ClientToServerNegotiator(), ClientToServerNegotiator(),
fakeSocket, fakeSocket,
)..setConnectionSettings( )..connectionSettings = ConnectionSettings(
ConnectionSettings(
jid: JID.fromString('polynomdivision@test.server'), jid: JID.fromString('polynomdivision@test.server'),
password: 'aaaa', password: 'aaaa',
useDirectTLS: true, useDirectTLS: true,
),
); );
await conn.registerManagers([ await conn.registerManagers([
PresenceManager(), PresenceManager(),
@ -120,12 +118,10 @@ void main() {
AlwaysConnectedConnectivityManager(), AlwaysConnectedConnectivityManager(),
ClientToServerNegotiator(), ClientToServerNegotiator(),
fakeSocket, fakeSocket,
)..setConnectionSettings( )..connectionSettings = ConnectionSettings(
ConnectionSettings(
jid: JID.fromString('polynomdivision@test.server'), jid: JID.fromString('polynomdivision@test.server'),
password: 'aaaa', password: 'aaaa',
useDirectTLS: true, useDirectTLS: true,
),
); );
await conn.registerManagers([ await conn.registerManagers([
RosterManager(TestingRosterStateManager('', [])), RosterManager(TestingRosterStateManager('', [])),

View File

@ -103,12 +103,10 @@ void main() {
AlwaysConnectedConnectivityManager(), AlwaysConnectedConnectivityManager(),
ClientToServerNegotiator(), ClientToServerNegotiator(),
fakeSocket, fakeSocket,
)..setConnectionSettings( )..connectionSettings = ConnectionSettings(
ConnectionSettings(
jid: JID.fromString('polynomdivision@test.server'), jid: JID.fromString('polynomdivision@test.server'),
password: 'aaaa', password: 'aaaa',
useDirectTLS: true, useDirectTLS: true,
),
); );
await conn.registerManagers([ await conn.registerManagers([
PresenceManager(), PresenceManager(),
@ -184,12 +182,10 @@ void main() {
AlwaysConnectedConnectivityManager(), AlwaysConnectedConnectivityManager(),
ClientToServerNegotiator(), ClientToServerNegotiator(),
fakeSocket, fakeSocket,
)..setConnectionSettings( )..connectionSettings = ConnectionSettings(
ConnectionSettings(
jid: JID.fromString('user@server'), jid: JID.fromString('user@server'),
password: 'pencil', password: 'pencil',
useDirectTLS: true, useDirectTLS: true,
),
); );
await conn.registerManagers([ await conn.registerManagers([
PresenceManager(), PresenceManager(),
@ -264,12 +260,10 @@ void main() {
AlwaysConnectedConnectivityManager(), AlwaysConnectedConnectivityManager(),
ClientToServerNegotiator(), ClientToServerNegotiator(),
fakeSocket, fakeSocket,
)..setConnectionSettings( )..connectionSettings = ConnectionSettings(
ConnectionSettings(
jid: JID.fromString('user@server'), jid: JID.fromString('user@server'),
password: 'pencil', password: 'pencil',
useDirectTLS: true, useDirectTLS: true,
),
); );
await conn.registerManagers([ await conn.registerManagers([
PresenceManager(), PresenceManager(),
@ -352,12 +346,10 @@ void main() {
AlwaysConnectedConnectivityManager(), AlwaysConnectedConnectivityManager(),
ClientToServerNegotiator(), ClientToServerNegotiator(),
fakeSocket, fakeSocket,
)..setConnectionSettings( )..connectionSettings = ConnectionSettings(
ConnectionSettings(
jid: JID.fromString('polynomdivision@test.server'), jid: JID.fromString('polynomdivision@test.server'),
password: 'aaaa', password: 'aaaa',
useDirectTLS: true, useDirectTLS: true,
),
); );
await conn.registerManagers([ await conn.registerManagers([
PresenceManager(), PresenceManager(),
@ -438,12 +430,10 @@ void main() {
AlwaysConnectedConnectivityManager(), AlwaysConnectedConnectivityManager(),
ClientToServerNegotiator(), ClientToServerNegotiator(),
fakeSocket, fakeSocket,
)..setConnectionSettings( )..connectionSettings = ConnectionSettings(
ConnectionSettings(
jid: JID.fromString('polynomdivision@test.server'), jid: JID.fromString('polynomdivision@test.server'),
password: 'aaaa', password: 'aaaa',
useDirectTLS: true, useDirectTLS: true,
),
); );
await conn.registerManagers([ await conn.registerManagers([
PresenceManager(), PresenceManager(),

View File

@ -109,12 +109,10 @@ void main() {
AlwaysConnectedConnectivityManager(), AlwaysConnectedConnectivityManager(),
ClientToServerNegotiator(), ClientToServerNegotiator(),
fakeSocket, fakeSocket,
)..setConnectionSettings( )..connectionSettings = ConnectionSettings(
ConnectionSettings(
jid: JID.fromString('polynomdivision@test.server'), jid: JID.fromString('polynomdivision@test.server'),
password: 'aaaa', password: 'aaaa',
useDirectTLS: true, useDirectTLS: true,
),
); );
await conn.registerManagers([ await conn.registerManagers([
RosterManager(TestingRosterStateManager('', [])), RosterManager(TestingRosterStateManager('', [])),
@ -225,12 +223,10 @@ void main() {
AlwaysConnectedConnectivityManager(), AlwaysConnectedConnectivityManager(),
ClientToServerNegotiator(), ClientToServerNegotiator(),
fakeSocket, fakeSocket,
)..setConnectionSettings( )..connectionSettings = ConnectionSettings(
ConnectionSettings(
jid: JID.fromString('polynomdivision@test.server'), jid: JID.fromString('polynomdivision@test.server'),
password: 'aaaa', password: 'aaaa',
useDirectTLS: true, useDirectTLS: true,
),
); );
await conn.registerManagers([ await conn.registerManagers([
RosterManager(TestingRosterStateManager('', [])), RosterManager(TestingRosterStateManager('', [])),

View File

@ -127,12 +127,10 @@ void main() {
AlwaysConnectedConnectivityManager(), AlwaysConnectedConnectivityManager(),
ClientToServerNegotiator(), ClientToServerNegotiator(),
fakeSocket, fakeSocket,
)..setConnectionSettings( )..connectionSettings = ConnectionSettings(
ConnectionSettings(
jid: JID.fromString('polynomdivision@test.server'), jid: JID.fromString('polynomdivision@test.server'),
password: 'aaaa', password: 'aaaa',
useDirectTLS: true, useDirectTLS: true,
),
); );
await conn.registerManagers([ await conn.registerManagers([
PresenceManager(), PresenceManager(),
@ -185,12 +183,10 @@ void main() {
AlwaysConnectedConnectivityManager(), AlwaysConnectedConnectivityManager(),
ClientToServerNegotiator(), ClientToServerNegotiator(),
fakeSocket, fakeSocket,
)..setConnectionSettings( )..connectionSettings = ConnectionSettings(
ConnectionSettings(
jid: JID.fromString('polynomdivision@test.server'), jid: JID.fromString('polynomdivision@test.server'),
password: 'aaaa', password: 'aaaa',
useDirectTLS: true, useDirectTLS: true,
),
); );
await conn.registerManagers([ await conn.registerManagers([
PresenceManager(), PresenceManager(),
@ -245,12 +241,10 @@ void main() {
AlwaysConnectedConnectivityManager(), AlwaysConnectedConnectivityManager(),
ClientToServerNegotiator(), ClientToServerNegotiator(),
fakeSocket, fakeSocket,
)..setConnectionSettings( )..connectionSettings = ConnectionSettings(
ConnectionSettings(
jid: JID.fromString('polynomdivision@test.server'), jid: JID.fromString('polynomdivision@test.server'),
password: 'aaaa', password: 'aaaa',
useDirectTLS: true, useDirectTLS: true,
),
); );
await conn.registerManagers([ await conn.registerManagers([
PresenceManager(), PresenceManager(),
@ -406,6 +400,10 @@ void main() {
AlwaysConnectedConnectivityManager(), AlwaysConnectedConnectivityManager(),
ClientToServerNegotiator(), ClientToServerNegotiator(),
fakeSocket, fakeSocket,
)..connectionSettings = ConnectionSettings(
jid: JID.fromString('testuser@example.org'),
password: 'abc123',
useDirectTLS: false,
); );
await conn.registerManagers([ await conn.registerManagers([
PresenceManager(), PresenceManager(),
@ -416,13 +414,6 @@ void main() {
// SaslPlainNegotiator(), // SaslPlainNegotiator(),
ResourceBindingNegotiator(), ResourceBindingNegotiator(),
]); ]);
conn.setConnectionSettings(
ConnectionSettings(
jid: JID.fromString('testuser@example.org'),
password: 'abc123',
useDirectTLS: false,
),
);
final result = await conn.connect( final result = await conn.connect(
waitUntilLogin: true, waitUntilLogin: true,
@ -503,6 +494,10 @@ void main() {
AlwaysConnectedConnectivityManager(), AlwaysConnectedConnectivityManager(),
ClientToServerNegotiator(), ClientToServerNegotiator(),
fakeSocket, fakeSocket,
)..connectionSettings = ConnectionSettings(
jid: JID.fromString('testuser@example.org'),
password: 'abc123',
useDirectTLS: false,
); );
await conn.registerManagers([ await conn.registerManagers([
RosterManager(TestingRosterStateManager('', [])), RosterManager(TestingRosterStateManager('', [])),
@ -512,13 +507,6 @@ void main() {
SaslPlainNegotiator(), SaslPlainNegotiator(),
ResourceBindingNegotiator(), ResourceBindingNegotiator(),
]); ]);
conn.setConnectionSettings(
ConnectionSettings(
jid: JID.fromString('testuser@example.org'),
password: 'abc123',
useDirectTLS: false,
),
);
final result1 = conn.connect( final result1 = conn.connect(
waitUntilLogin: true, waitUntilLogin: true,