Compare commits
6 Commits
moxxmpp-v0
...
09696c1c4d
| Author | SHA1 | Date | |
|---|---|---|---|
| 09696c1c4d | |||
| 298a8342b8 | |||
| d64220426b | |||
| 88efdc361c | |||
| cc1b371198 | |||
| d9e4a3c1d4 |
1
.github/FUNDING.yml
vendored
Normal file
1
.github/FUNDING.yml
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
ko_fi: papatutuwawa
|
||||||
@@ -25,3 +25,9 @@ the development shell provided by the NixOS Flake, ensure that `ANDROID_HOME` an
|
|||||||
## License
|
## License
|
||||||
|
|
||||||
See `./LICENSE`.
|
See `./LICENSE`.
|
||||||
|
|
||||||
|
## Support
|
||||||
|
|
||||||
|
If you like what I do and you want to support me, feel free to donate to me on Ko-Fi.
|
||||||
|
|
||||||
|
[<img src="https://codeberg.org/moxxy/moxxyv2/raw/branch/master/assets/repo/kofi.png" height="36" style="height: 36px; border: 0px;"></img>](https://ko-fi.com/papatutuwawa)
|
||||||
|
|||||||
@@ -5,3 +5,9 @@ A pure-Dart XMPP library written for Moxxy.
|
|||||||
## License
|
## License
|
||||||
|
|
||||||
See `./LICENSE`.
|
See `./LICENSE`.
|
||||||
|
|
||||||
|
## Support
|
||||||
|
|
||||||
|
If you like what I do and you want to support me, feel free to donate to me on Ko-Fi.
|
||||||
|
|
||||||
|
[<img src="https://codeberg.org/moxxy/moxxyv2/raw/branch/master/assets/repo/kofi.png" height="36" style="height: 36px; border: 0px;"></img>](https://ko-fi.com/papatutuwawa)
|
||||||
|
|||||||
@@ -75,7 +75,9 @@ export 'package:moxxmpp/src/xeps/xep_0384/xep_0384.dart';
|
|||||||
export 'package:moxxmpp/src/xeps/xep_0385.dart';
|
export 'package:moxxmpp/src/xeps/xep_0385.dart';
|
||||||
export 'package:moxxmpp/src/xeps/xep_0414.dart';
|
export 'package:moxxmpp/src/xeps/xep_0414.dart';
|
||||||
export 'package:moxxmpp/src/xeps/xep_0424.dart';
|
export 'package:moxxmpp/src/xeps/xep_0424.dart';
|
||||||
|
export 'package:moxxmpp/src/xeps/xep_0444.dart';
|
||||||
export 'package:moxxmpp/src/xeps/xep_0446.dart';
|
export 'package:moxxmpp/src/xeps/xep_0446.dart';
|
||||||
export 'package:moxxmpp/src/xeps/xep_0447.dart';
|
export 'package:moxxmpp/src/xeps/xep_0447.dart';
|
||||||
export 'package:moxxmpp/src/xeps/xep_0448.dart';
|
export 'package:moxxmpp/src/xeps/xep_0448.dart';
|
||||||
|
export 'package:moxxmpp/src/xeps/xep_0449.dart';
|
||||||
export 'package:moxxmpp/src/xeps/xep_0461.dart';
|
export 'package:moxxmpp/src/xeps/xep_0461.dart';
|
||||||
|
|||||||
@@ -6,9 +6,11 @@ import 'package:moxxmpp/src/xeps/xep_0030/types.dart';
|
|||||||
import 'package:moxxmpp/src/xeps/xep_0060/xep_0060.dart';
|
import 'package:moxxmpp/src/xeps/xep_0060/xep_0060.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';
|
||||||
|
import 'package:moxxmpp/src/xeps/xep_0334.dart';
|
||||||
import 'package:moxxmpp/src/xeps/xep_0359.dart';
|
import 'package:moxxmpp/src/xeps/xep_0359.dart';
|
||||||
import 'package:moxxmpp/src/xeps/xep_0385.dart';
|
import 'package:moxxmpp/src/xeps/xep_0385.dart';
|
||||||
import 'package:moxxmpp/src/xeps/xep_0424.dart';
|
import 'package:moxxmpp/src/xeps/xep_0424.dart';
|
||||||
|
import 'package:moxxmpp/src/xeps/xep_0444.dart';
|
||||||
import 'package:moxxmpp/src/xeps/xep_0446.dart';
|
import 'package:moxxmpp/src/xeps/xep_0446.dart';
|
||||||
import 'package:moxxmpp/src/xeps/xep_0447.dart';
|
import 'package:moxxmpp/src/xeps/xep_0447.dart';
|
||||||
import 'package:moxxmpp/src/xeps/xep_0461.dart';
|
import 'package:moxxmpp/src/xeps/xep_0461.dart';
|
||||||
@@ -75,6 +77,9 @@ class MessageEvent extends XmppEvent {
|
|||||||
this.funCancellation,
|
this.funCancellation,
|
||||||
this.messageRetraction,
|
this.messageRetraction,
|
||||||
this.messageCorrectionId,
|
this.messageCorrectionId,
|
||||||
|
this.messageReactions,
|
||||||
|
this.messageProcessingHints,
|
||||||
|
this.stickerPackId,
|
||||||
});
|
});
|
||||||
final StanzaError? error;
|
final StanzaError? error;
|
||||||
final String body;
|
final String body;
|
||||||
@@ -97,6 +102,9 @@ class MessageEvent extends XmppEvent {
|
|||||||
final bool encrypted;
|
final bool encrypted;
|
||||||
final MessageRetractionData? messageRetraction;
|
final MessageRetractionData? messageRetraction;
|
||||||
final String? messageCorrectionId;
|
final String? messageCorrectionId;
|
||||||
|
final MessageReactions? messageReactions;
|
||||||
|
final List<MessageProcessingHint>? messageProcessingHints;
|
||||||
|
final String? stickerPackId;
|
||||||
final Map<String, dynamic> other;
|
final Map<String, dynamic> other;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
|
||||||
import 'package:moxxmpp/src/connection.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';
|
||||||
@@ -11,7 +10,6 @@ import 'package:moxxmpp/src/stanza.dart';
|
|||||||
import 'package:moxxmpp/src/stringxml.dart';
|
import 'package:moxxmpp/src/stringxml.dart';
|
||||||
|
|
||||||
class XmppManagerAttributes {
|
class XmppManagerAttributes {
|
||||||
|
|
||||||
XmppManagerAttributes({
|
XmppManagerAttributes({
|
||||||
required this.sendStanza,
|
required this.sendStanza,
|
||||||
required this.sendNonza,
|
required this.sendNonza,
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import 'package:moxxmpp/src/xeps/xep_0359.dart';
|
|||||||
import 'package:moxxmpp/src/xeps/xep_0380.dart';
|
import 'package:moxxmpp/src/xeps/xep_0380.dart';
|
||||||
import 'package:moxxmpp/src/xeps/xep_0385.dart';
|
import 'package:moxxmpp/src/xeps/xep_0385.dart';
|
||||||
import 'package:moxxmpp/src/xeps/xep_0424.dart';
|
import 'package:moxxmpp/src/xeps/xep_0424.dart';
|
||||||
|
import 'package:moxxmpp/src/xeps/xep_0444.dart';
|
||||||
import 'package:moxxmpp/src/xeps/xep_0446.dart';
|
import 'package:moxxmpp/src/xeps/xep_0446.dart';
|
||||||
import 'package:moxxmpp/src/xeps/xep_0447.dart';
|
import 'package:moxxmpp/src/xeps/xep_0447.dart';
|
||||||
import 'package:moxxmpp/src/xeps/xep_0461.dart';
|
import 'package:moxxmpp/src/xeps/xep_0461.dart';
|
||||||
@@ -61,6 +62,10 @@ class StanzaHandlerData with _$StanzaHandlerData {
|
|||||||
MessageRetractionData? messageRetraction,
|
MessageRetractionData? messageRetraction,
|
||||||
// If non-null, then the message is a correction for the specified stanza Id
|
// If non-null, then the message is a correction for the specified stanza Id
|
||||||
String? lastMessageCorrectionSid,
|
String? lastMessageCorrectionSid,
|
||||||
|
// Reactions data
|
||||||
|
MessageReactions? messageReactions,
|
||||||
|
// The Id of the sticker pack this sticker belongs to
|
||||||
|
String? stickerPackId,
|
||||||
}
|
}
|
||||||
) = _StanzaHandlerData;
|
) = _StanzaHandlerData;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,7 +59,11 @@ mixin _$StanzaHandlerData {
|
|||||||
// retracted
|
// retracted
|
||||||
MessageRetractionData? get messageRetraction =>
|
MessageRetractionData? get messageRetraction =>
|
||||||
throw _privateConstructorUsedError; // If non-null, then the message is a correction for the specified stanza Id
|
throw _privateConstructorUsedError; // If non-null, then the message is a correction for the specified stanza Id
|
||||||
String? get lastMessageCorrectionSid => throw _privateConstructorUsedError;
|
String? get lastMessageCorrectionSid =>
|
||||||
|
throw _privateConstructorUsedError; // Reactions data
|
||||||
|
MessageReactions? get messageReactions =>
|
||||||
|
throw _privateConstructorUsedError; // The Id of the sticker pack this sticker belongs to
|
||||||
|
String? get stickerPackId => throw _privateConstructorUsedError;
|
||||||
|
|
||||||
@JsonKey(ignore: true)
|
@JsonKey(ignore: true)
|
||||||
$StanzaHandlerDataCopyWith<StanzaHandlerData> get copyWith =>
|
$StanzaHandlerDataCopyWith<StanzaHandlerData> get copyWith =>
|
||||||
@@ -94,7 +98,9 @@ abstract class $StanzaHandlerDataCopyWith<$Res> {
|
|||||||
DelayedDelivery? delayedDelivery,
|
DelayedDelivery? delayedDelivery,
|
||||||
Map<String, dynamic> other,
|
Map<String, dynamic> other,
|
||||||
MessageRetractionData? messageRetraction,
|
MessageRetractionData? messageRetraction,
|
||||||
String? lastMessageCorrectionSid});
|
String? lastMessageCorrectionSid,
|
||||||
|
MessageReactions? messageReactions,
|
||||||
|
String? stickerPackId});
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @nodoc
|
/// @nodoc
|
||||||
@@ -131,6 +137,8 @@ class _$StanzaHandlerDataCopyWithImpl<$Res>
|
|||||||
Object? other = freezed,
|
Object? other = freezed,
|
||||||
Object? messageRetraction = freezed,
|
Object? messageRetraction = freezed,
|
||||||
Object? lastMessageCorrectionSid = freezed,
|
Object? lastMessageCorrectionSid = freezed,
|
||||||
|
Object? messageReactions = freezed,
|
||||||
|
Object? stickerPackId = freezed,
|
||||||
}) {
|
}) {
|
||||||
return _then(_value.copyWith(
|
return _then(_value.copyWith(
|
||||||
done: done == freezed
|
done: done == freezed
|
||||||
@@ -225,6 +233,14 @@ class _$StanzaHandlerDataCopyWithImpl<$Res>
|
|||||||
? _value.lastMessageCorrectionSid
|
? _value.lastMessageCorrectionSid
|
||||||
: lastMessageCorrectionSid // ignore: cast_nullable_to_non_nullable
|
: lastMessageCorrectionSid // ignore: cast_nullable_to_non_nullable
|
||||||
as String?,
|
as String?,
|
||||||
|
messageReactions: messageReactions == freezed
|
||||||
|
? _value.messageReactions
|
||||||
|
: messageReactions // ignore: cast_nullable_to_non_nullable
|
||||||
|
as MessageReactions?,
|
||||||
|
stickerPackId: stickerPackId == freezed
|
||||||
|
? _value.stickerPackId
|
||||||
|
: stickerPackId // ignore: cast_nullable_to_non_nullable
|
||||||
|
as String?,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -259,7 +275,9 @@ abstract class _$$_StanzaHandlerDataCopyWith<$Res>
|
|||||||
DelayedDelivery? delayedDelivery,
|
DelayedDelivery? delayedDelivery,
|
||||||
Map<String, dynamic> other,
|
Map<String, dynamic> other,
|
||||||
MessageRetractionData? messageRetraction,
|
MessageRetractionData? messageRetraction,
|
||||||
String? lastMessageCorrectionSid});
|
String? lastMessageCorrectionSid,
|
||||||
|
MessageReactions? messageReactions,
|
||||||
|
String? stickerPackId});
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @nodoc
|
/// @nodoc
|
||||||
@@ -298,6 +316,8 @@ class __$$_StanzaHandlerDataCopyWithImpl<$Res>
|
|||||||
Object? other = freezed,
|
Object? other = freezed,
|
||||||
Object? messageRetraction = freezed,
|
Object? messageRetraction = freezed,
|
||||||
Object? lastMessageCorrectionSid = freezed,
|
Object? lastMessageCorrectionSid = freezed,
|
||||||
|
Object? messageReactions = freezed,
|
||||||
|
Object? stickerPackId = freezed,
|
||||||
}) {
|
}) {
|
||||||
return _then(_$_StanzaHandlerData(
|
return _then(_$_StanzaHandlerData(
|
||||||
done == freezed
|
done == freezed
|
||||||
@@ -392,6 +412,14 @@ class __$$_StanzaHandlerDataCopyWithImpl<$Res>
|
|||||||
? _value.lastMessageCorrectionSid
|
? _value.lastMessageCorrectionSid
|
||||||
: lastMessageCorrectionSid // ignore: cast_nullable_to_non_nullable
|
: lastMessageCorrectionSid // ignore: cast_nullable_to_non_nullable
|
||||||
as String?,
|
as String?,
|
||||||
|
messageReactions: messageReactions == freezed
|
||||||
|
? _value.messageReactions
|
||||||
|
: messageReactions // ignore: cast_nullable_to_non_nullable
|
||||||
|
as MessageReactions?,
|
||||||
|
stickerPackId: stickerPackId == freezed
|
||||||
|
? _value.stickerPackId
|
||||||
|
: stickerPackId // ignore: cast_nullable_to_non_nullable
|
||||||
|
as String?,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -418,7 +446,9 @@ class _$_StanzaHandlerData implements _StanzaHandlerData {
|
|||||||
this.delayedDelivery,
|
this.delayedDelivery,
|
||||||
final Map<String, dynamic> other = const <String, dynamic>{},
|
final Map<String, dynamic> other = const <String, dynamic>{},
|
||||||
this.messageRetraction,
|
this.messageRetraction,
|
||||||
this.lastMessageCorrectionSid})
|
this.lastMessageCorrectionSid,
|
||||||
|
this.messageReactions,
|
||||||
|
this.stickerPackId})
|
||||||
: _other = other;
|
: _other = other;
|
||||||
|
|
||||||
// Indicates to the runner that processing is now done. This means that all
|
// Indicates to the runner that processing is now done. This means that all
|
||||||
@@ -501,10 +531,16 @@ class _$_StanzaHandlerData implements _StanzaHandlerData {
|
|||||||
// If non-null, then the message is a correction for the specified stanza Id
|
// If non-null, then the message is a correction for the specified stanza Id
|
||||||
@override
|
@override
|
||||||
final String? lastMessageCorrectionSid;
|
final String? lastMessageCorrectionSid;
|
||||||
|
// Reactions data
|
||||||
|
@override
|
||||||
|
final MessageReactions? messageReactions;
|
||||||
|
// The Id of the sticker pack this sticker belongs to
|
||||||
|
@override
|
||||||
|
final String? stickerPackId;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String toString() {
|
String toString() {
|
||||||
return 'StanzaHandlerData(done: $done, cancel: $cancel, cancelReason: $cancelReason, stanza: $stanza, retransmitted: $retransmitted, sims: $sims, sfs: $sfs, oob: $oob, stableId: $stableId, reply: $reply, chatState: $chatState, isCarbon: $isCarbon, deliveryReceiptRequested: $deliveryReceiptRequested, isMarkable: $isMarkable, fun: $fun, funReplacement: $funReplacement, funCancellation: $funCancellation, encrypted: $encrypted, encryptionType: $encryptionType, delayedDelivery: $delayedDelivery, other: $other, messageRetraction: $messageRetraction, lastMessageCorrectionSid: $lastMessageCorrectionSid)';
|
return 'StanzaHandlerData(done: $done, cancel: $cancel, cancelReason: $cancelReason, stanza: $stanza, retransmitted: $retransmitted, sims: $sims, sfs: $sfs, oob: $oob, stableId: $stableId, reply: $reply, chatState: $chatState, isCarbon: $isCarbon, deliveryReceiptRequested: $deliveryReceiptRequested, isMarkable: $isMarkable, fun: $fun, funReplacement: $funReplacement, funCancellation: $funCancellation, encrypted: $encrypted, encryptionType: $encryptionType, delayedDelivery: $delayedDelivery, other: $other, messageRetraction: $messageRetraction, lastMessageCorrectionSid: $lastMessageCorrectionSid, messageReactions: $messageReactions, stickerPackId: $stickerPackId)';
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -544,7 +580,11 @@ class _$_StanzaHandlerData implements _StanzaHandlerData {
|
|||||||
const DeepCollectionEquality()
|
const DeepCollectionEquality()
|
||||||
.equals(other.messageRetraction, messageRetraction) &&
|
.equals(other.messageRetraction, messageRetraction) &&
|
||||||
const DeepCollectionEquality().equals(
|
const DeepCollectionEquality().equals(
|
||||||
other.lastMessageCorrectionSid, lastMessageCorrectionSid));
|
other.lastMessageCorrectionSid, lastMessageCorrectionSid) &&
|
||||||
|
const DeepCollectionEquality()
|
||||||
|
.equals(other.messageReactions, messageReactions) &&
|
||||||
|
const DeepCollectionEquality()
|
||||||
|
.equals(other.stickerPackId, stickerPackId));
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -572,7 +612,9 @@ class _$_StanzaHandlerData implements _StanzaHandlerData {
|
|||||||
const DeepCollectionEquality().hash(delayedDelivery),
|
const DeepCollectionEquality().hash(delayedDelivery),
|
||||||
const DeepCollectionEquality().hash(_other),
|
const DeepCollectionEquality().hash(_other),
|
||||||
const DeepCollectionEquality().hash(messageRetraction),
|
const DeepCollectionEquality().hash(messageRetraction),
|
||||||
const DeepCollectionEquality().hash(lastMessageCorrectionSid)
|
const DeepCollectionEquality().hash(lastMessageCorrectionSid),
|
||||||
|
const DeepCollectionEquality().hash(messageReactions),
|
||||||
|
const DeepCollectionEquality().hash(stickerPackId)
|
||||||
]);
|
]);
|
||||||
|
|
||||||
@JsonKey(ignore: true)
|
@JsonKey(ignore: true)
|
||||||
@@ -603,7 +645,9 @@ abstract class _StanzaHandlerData implements StanzaHandlerData {
|
|||||||
final DelayedDelivery? delayedDelivery,
|
final DelayedDelivery? delayedDelivery,
|
||||||
final Map<String, dynamic> other,
|
final Map<String, dynamic> other,
|
||||||
final MessageRetractionData? messageRetraction,
|
final MessageRetractionData? messageRetraction,
|
||||||
final String? lastMessageCorrectionSid}) = _$_StanzaHandlerData;
|
final String? lastMessageCorrectionSid,
|
||||||
|
final MessageReactions? messageReactions,
|
||||||
|
final String? stickerPackId}) = _$_StanzaHandlerData;
|
||||||
|
|
||||||
@override // Indicates to the runner that processing is now done. This means that all
|
@override // Indicates to the runner that processing is now done. This means that all
|
||||||
// pre-processing is done and no other handlers should be consulted.
|
// pre-processing is done and no other handlers should be consulted.
|
||||||
@@ -658,6 +702,10 @@ abstract class _StanzaHandlerData implements StanzaHandlerData {
|
|||||||
MessageRetractionData? get messageRetraction;
|
MessageRetractionData? get messageRetraction;
|
||||||
@override // If non-null, then the message is a correction for the specified stanza Id
|
@override // If non-null, then the message is a correction for the specified stanza Id
|
||||||
String? get lastMessageCorrectionSid;
|
String? get lastMessageCorrectionSid;
|
||||||
|
@override // Reactions data
|
||||||
|
MessageReactions? get messageReactions;
|
||||||
|
@override // The Id of the sticker pack this sticker belongs to
|
||||||
|
String? get stickerPackId;
|
||||||
@override
|
@override
|
||||||
@JsonKey(ignore: true)
|
@JsonKey(ignore: true)
|
||||||
_$$_StanzaHandlerDataCopyWith<_$_StanzaHandlerData> get copyWith =>
|
_$$_StanzaHandlerDataCopyWith<_$_StanzaHandlerData> get copyWith =>
|
||||||
|
|||||||
@@ -26,3 +26,5 @@ const cryptographicHashManager = 'org.moxxmpp.cryptographichashmanager';
|
|||||||
const delayedDeliveryManager = 'org.moxxmpp.delayeddeliverymanager';
|
const delayedDeliveryManager = 'org.moxxmpp.delayeddeliverymanager';
|
||||||
const messageRetractionManager = 'org.moxxmpp.messageretractionmanager';
|
const messageRetractionManager = 'org.moxxmpp.messageretractionmanager';
|
||||||
const lastMessageCorrectionManager = 'org.moxxmpp.lastmessagecorrectionmanager';
|
const lastMessageCorrectionManager = 'org.moxxmpp.lastmessagecorrectionmanager';
|
||||||
|
const messageReactionsManager = 'org.moxxmpp.messagereactionsmanager';
|
||||||
|
const stickersManager = 'org.moxxmpp.stickersmanager';
|
||||||
|
|||||||
@@ -13,12 +13,19 @@ import 'package:moxxmpp/src/xeps/xep_0085.dart';
|
|||||||
import 'package:moxxmpp/src/xeps/xep_0184.dart';
|
import 'package:moxxmpp/src/xeps/xep_0184.dart';
|
||||||
import 'package:moxxmpp/src/xeps/xep_0308.dart';
|
import 'package:moxxmpp/src/xeps/xep_0308.dart';
|
||||||
import 'package:moxxmpp/src/xeps/xep_0333.dart';
|
import 'package:moxxmpp/src/xeps/xep_0333.dart';
|
||||||
|
import 'package:moxxmpp/src/xeps/xep_0334.dart';
|
||||||
import 'package:moxxmpp/src/xeps/xep_0359.dart';
|
import 'package:moxxmpp/src/xeps/xep_0359.dart';
|
||||||
import 'package:moxxmpp/src/xeps/xep_0424.dart';
|
import 'package:moxxmpp/src/xeps/xep_0424.dart';
|
||||||
|
import 'package:moxxmpp/src/xeps/xep_0444.dart';
|
||||||
import 'package:moxxmpp/src/xeps/xep_0446.dart';
|
import 'package:moxxmpp/src/xeps/xep_0446.dart';
|
||||||
import 'package:moxxmpp/src/xeps/xep_0447.dart';
|
import 'package:moxxmpp/src/xeps/xep_0447.dart';
|
||||||
import 'package:moxxmpp/src/xeps/xep_0448.dart';
|
import 'package:moxxmpp/src/xeps/xep_0448.dart';
|
||||||
|
|
||||||
|
/// Data used to build a message stanza.
|
||||||
|
///
|
||||||
|
/// [setOOBFallbackBody] indicates, when using SFS, whether a OOB fallback should be
|
||||||
|
/// added. This is recommended when sharing files but may cause issues when the message
|
||||||
|
/// stanza should include a SFS element without any fallbacks.
|
||||||
class MessageDetails {
|
class MessageDetails {
|
||||||
const MessageDetails({
|
const MessageDetails({
|
||||||
required this.to,
|
required this.to,
|
||||||
@@ -38,6 +45,10 @@ class MessageDetails {
|
|||||||
this.shouldEncrypt = false,
|
this.shouldEncrypt = false,
|
||||||
this.messageRetraction,
|
this.messageRetraction,
|
||||||
this.lastMessageCorrectionId,
|
this.lastMessageCorrectionId,
|
||||||
|
this.messageReactions,
|
||||||
|
this.messageProcessingHints,
|
||||||
|
this.stickerPackId,
|
||||||
|
this.setOOBFallbackBody = true,
|
||||||
});
|
});
|
||||||
final String to;
|
final String to;
|
||||||
final String? body;
|
final String? body;
|
||||||
@@ -56,6 +67,10 @@ class MessageDetails {
|
|||||||
final bool shouldEncrypt;
|
final bool shouldEncrypt;
|
||||||
final MessageRetractionData? messageRetraction;
|
final MessageRetractionData? messageRetraction;
|
||||||
final String? lastMessageCorrectionId;
|
final String? lastMessageCorrectionId;
|
||||||
|
final MessageReactions? messageReactions;
|
||||||
|
final String? stickerPackId;
|
||||||
|
final List<MessageProcessingHint>? messageProcessingHints;
|
||||||
|
final bool setOOBFallbackBody;
|
||||||
}
|
}
|
||||||
|
|
||||||
class MessageManager extends XmppManagerBase {
|
class MessageManager extends XmppManagerBase {
|
||||||
@@ -81,6 +96,11 @@ class MessageManager extends XmppManagerBase {
|
|||||||
final message = state.stanza;
|
final message = state.stanza;
|
||||||
final body = message.firstTag('body');
|
final body = message.firstTag('body');
|
||||||
|
|
||||||
|
final hints = List<MessageProcessingHint>.empty(growable: true);
|
||||||
|
for (final element in message.findTagsByXmlns(messageProcessingHintsXmlns)) {
|
||||||
|
hints.add(messageProcessingHintFromXml(element));
|
||||||
|
}
|
||||||
|
|
||||||
getAttributes().sendEvent(MessageEvent(
|
getAttributes().sendEvent(MessageEvent(
|
||||||
body: body != null ? body.innerText() : '',
|
body: body != null ? body.innerText() : '',
|
||||||
fromJid: JID.fromString(message.attributes['from']! as String),
|
fromJid: JID.fromString(message.attributes['from']! as String),
|
||||||
@@ -102,6 +122,11 @@ class MessageManager extends XmppManagerBase {
|
|||||||
encrypted: state.encrypted,
|
encrypted: state.encrypted,
|
||||||
messageRetraction: state.messageRetraction,
|
messageRetraction: state.messageRetraction,
|
||||||
messageCorrectionId: state.lastMessageCorrectionSid,
|
messageCorrectionId: state.lastMessageCorrectionSid,
|
||||||
|
messageReactions: state.messageReactions,
|
||||||
|
messageProcessingHints: hints.isEmpty ?
|
||||||
|
null :
|
||||||
|
hints,
|
||||||
|
stickerPackId: state.stickerPackId,
|
||||||
other: state.other,
|
other: state.other,
|
||||||
error: StanzaError.fromStanza(message),
|
error: StanzaError.fromStanza(message),
|
||||||
),);
|
),);
|
||||||
@@ -159,7 +184,7 @@ class MessageManager extends XmppManagerBase {
|
|||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
var body = details.body;
|
var body = details.body;
|
||||||
if (details.sfs != null) {
|
if (details.sfs != null && details.setOOBFallbackBody) {
|
||||||
// TODO(Unknown): Maybe find a better solution
|
// TODO(Unknown): Maybe find a better solution
|
||||||
final firstSource = details.sfs!.sources.first;
|
final firstSource = details.sfs!.sources.first;
|
||||||
if (firstSource is StatelessFileSharingUrlSource) {
|
if (firstSource is StatelessFileSharingUrlSource) {
|
||||||
@@ -171,9 +196,11 @@ class MessageManager extends XmppManagerBase {
|
|||||||
body = details.messageRetraction!.fallback;
|
body = details.messageRetraction!.fallback;
|
||||||
}
|
}
|
||||||
|
|
||||||
stanza.addChild(
|
if (body != null) {
|
||||||
XMLNode(tag: 'body', text: body),
|
stanza.addChild(
|
||||||
);
|
XMLNode(tag: 'body', text: body),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (details.requestDeliveryReceipt) {
|
if (details.requestDeliveryReceipt) {
|
||||||
@@ -190,7 +217,7 @@ class MessageManager extends XmppManagerBase {
|
|||||||
stanza.addChild(details.sfs!.toXML());
|
stanza.addChild(details.sfs!.toXML());
|
||||||
|
|
||||||
final source = details.sfs!.sources.first;
|
final source = details.sfs!.sources.first;
|
||||||
if (source is StatelessFileSharingUrlSource) {
|
if (source is StatelessFileSharingUrlSource && details.setOOBFallbackBody) {
|
||||||
// SFS recommends OOB as a fallback
|
// SFS recommends OOB as a fallback
|
||||||
stanza.addChild(constructOOBNode(OOBData(url: source.url)));
|
stanza.addChild(constructOOBNode(OOBData(url: source.url)));
|
||||||
}
|
}
|
||||||
@@ -261,6 +288,28 @@ class MessageManager extends XmppManagerBase {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (details.messageReactions != null) {
|
||||||
|
stanza.addChild(details.messageReactions!.toXml());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (details.messageProcessingHints != null) {
|
||||||
|
for (final hint in details.messageProcessingHints!) {
|
||||||
|
stanza.addChild(hint.toXml());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (details.stickerPackId != null) {
|
||||||
|
stanza.addChild(
|
||||||
|
XMLNode.xmlns(
|
||||||
|
tag: 'sticker',
|
||||||
|
xmlns: stickersXmlns,
|
||||||
|
attributes: {
|
||||||
|
'pack': details.stickerPackId!,
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
getAttributes().sendStanza(stanza, awaitable: false);
|
getAttributes().sendStanza(stanza, awaitable: false);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -123,9 +123,12 @@ const fasteningXmlns = 'urn:xmpp:fasten:0';
|
|||||||
// XEP-0424
|
// XEP-0424
|
||||||
const messageRetractionXmlns = 'urn:xmpp:message-retract:0';
|
const messageRetractionXmlns = 'urn:xmpp:message-retract:0';
|
||||||
|
|
||||||
// XEp-0428
|
// XEP-0428
|
||||||
const fallbackIndicationXmlns = 'urn:xmpp:fallback:0';
|
const fallbackIndicationXmlns = 'urn:xmpp:fallback:0';
|
||||||
|
|
||||||
|
// XEP-0444
|
||||||
|
const messageReactionsXmlns = 'urn:xmpp:reactions:0';
|
||||||
|
|
||||||
// XEP-0446
|
// XEP-0446
|
||||||
const fileMetadataXmlns = 'urn:xmpp:file:metadata:0';
|
const fileMetadataXmlns = 'urn:xmpp:file:metadata:0';
|
||||||
|
|
||||||
@@ -138,6 +141,9 @@ const sfsEncryptionAes128GcmNoPaddingXmlns = 'urn:xmpp:ciphers:aes-128-gcm-nopad
|
|||||||
const sfsEncryptionAes256GcmNoPaddingXmlns = 'urn:xmpp:ciphers:aes-256-gcm-nopadding:0';
|
const sfsEncryptionAes256GcmNoPaddingXmlns = 'urn:xmpp:ciphers:aes-256-gcm-nopadding:0';
|
||||||
const sfsEncryptionAes256CbcPkcs7Xmlns = 'urn:xmpp:ciphers:aes-256-cbc-pkcs7:0';
|
const sfsEncryptionAes256CbcPkcs7Xmlns = 'urn:xmpp:ciphers:aes-256-cbc-pkcs7:0';
|
||||||
|
|
||||||
|
// XEP-0449
|
||||||
|
const stickersXmlns = 'urn:xmpp:stickers:0';
|
||||||
|
|
||||||
// XEP-0461
|
// XEP-0461
|
||||||
const replyXmlns = 'urn:xmpp:reply:0';
|
const replyXmlns = 'urn:xmpp:reply:0';
|
||||||
const fallbackXmlns = 'urn:xmpp:feature-fallback:0';
|
const fallbackXmlns = 'urn:xmpp:feature-fallback:0';
|
||||||
|
|||||||
@@ -24,3 +24,28 @@ int ioctetSortComparator(String a, String b) {
|
|||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int ioctetSortComparatorRaw(List<int> a, List<int> b) {
|
||||||
|
if (a.isEmpty && b.isEmpty) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (a.isEmpty && b.isNotEmpty) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (a.isNotEmpty && b.isEmpty) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (a[0] == b[0]) {
|
||||||
|
return ioctetSortComparatorRaw(a.sublist(1), b.sublist(1));
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO(Unknown): Is this correct?
|
||||||
|
if (a[0] < b[0]) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|||||||
@@ -129,6 +129,12 @@ class XMLNode {
|
|||||||
}).toList();
|
}).toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
List<XMLNode> findTagsByXmlns(String xmlns) {
|
||||||
|
return children
|
||||||
|
.where((element) => element.attributes['xmlns'] == xmlns)
|
||||||
|
.toList();
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns the inner text of the node. If none is set, returns the "".
|
/// Returns the inner text of the node. If none is set, returns the "".
|
||||||
String innerText() {
|
String innerText() {
|
||||||
return text ?? '';
|
return text ?? '';
|
||||||
|
|||||||
@@ -289,7 +289,7 @@ class DiscoManager extends XmppManagerBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Sends a disco info query to the (full) jid [entity], optionally with node=[node].
|
/// Sends a disco info query to the (full) jid [entity], optionally with node=[node].
|
||||||
Future<Result<DiscoError, DiscoInfo>> discoInfoQuery(String entity, { String? node}) async {
|
Future<Result<DiscoError, DiscoInfo>> discoInfoQuery(String entity, { String? node, bool shouldEncrypt = true }) async {
|
||||||
final cacheKey = DiscoCacheKey(entity, node);
|
final cacheKey = DiscoCacheKey(entity, node);
|
||||||
DiscoInfo? info;
|
DiscoInfo? info;
|
||||||
Completer<Result<DiscoError, DiscoInfo>>? completer;
|
Completer<Result<DiscoError, DiscoInfo>>? completer;
|
||||||
@@ -316,6 +316,7 @@ class DiscoManager extends XmppManagerBase {
|
|||||||
|
|
||||||
final stanza = await getAttributes().sendStanza(
|
final stanza = await getAttributes().sendStanza(
|
||||||
buildDiscoInfoQueryStanza(entity, node),
|
buildDiscoInfoQueryStanza(entity, node),
|
||||||
|
encrypted: !shouldEncrypt,
|
||||||
);
|
);
|
||||||
final query = stanza.firstTag('query');
|
final query = stanza.firstTag('query');
|
||||||
if (query == null) {
|
if (query == null) {
|
||||||
@@ -359,9 +360,12 @@ class DiscoManager extends XmppManagerBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Sends a disco items query to the (full) jid [entity], optionally with node=[node].
|
/// Sends a disco items query to the (full) jid [entity], optionally with node=[node].
|
||||||
Future<Result<DiscoError, List<DiscoItem>>> discoItemsQuery(String entity, { String? node }) async {
|
Future<Result<DiscoError, List<DiscoItem>>> discoItemsQuery(String entity, { String? node, bool shouldEncrypt = true }) async {
|
||||||
final stanza = await getAttributes()
|
final stanza = await getAttributes()
|
||||||
.sendStanza(buildDiscoItemsQueryStanza(entity, node: node)) as Stanza;
|
.sendStanza(
|
||||||
|
buildDiscoItemsQueryStanza(entity, node: node),
|
||||||
|
encrypted: !shouldEncrypt,
|
||||||
|
) as Stanza;
|
||||||
|
|
||||||
final query = stanza.firstTag('query');
|
final query = stanza.firstTag('query');
|
||||||
if (query == null) return Result(InvalidResponseDiscoError());
|
if (query == null) return Result(InvalidResponseDiscoError());
|
||||||
|
|||||||
@@ -7,15 +7,20 @@ 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/types/result.dart';
|
||||||
|
|
||||||
|
abstract class VCardError {}
|
||||||
|
|
||||||
|
class UnknownVCardError extends VCardError {}
|
||||||
|
|
||||||
|
class InvalidVCardError extends VCardError {}
|
||||||
|
|
||||||
class VCardPhoto {
|
class VCardPhoto {
|
||||||
|
|
||||||
const VCardPhoto({ this.binval });
|
const VCardPhoto({ this.binval });
|
||||||
final String? binval;
|
final String? binval;
|
||||||
}
|
}
|
||||||
|
|
||||||
class VCard {
|
class VCard {
|
||||||
|
|
||||||
const VCard({ this.nickname, this.url, this.photo });
|
const VCard({ this.nickname, this.url, this.photo });
|
||||||
final String? nickname;
|
final String? nickname;
|
||||||
final String? url;
|
final String? url;
|
||||||
@@ -23,7 +28,6 @@ class VCard {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class VCardManager extends XmppManagerBase {
|
class VCardManager extends XmppManagerBase {
|
||||||
|
|
||||||
VCardManager() : _lastHash = {}, super();
|
VCardManager() : _lastHash = {}, super();
|
||||||
final Map<String, String> _lastHash;
|
final Map<String, String> _lastHash;
|
||||||
|
|
||||||
@@ -59,12 +63,18 @@ class VCardManager extends XmppManagerBase {
|
|||||||
final lastHash = _lastHash[from];
|
final lastHash = _lastHash[from];
|
||||||
if (lastHash != hash) {
|
if (lastHash != hash) {
|
||||||
_lastHash[from] = hash;
|
_lastHash[from] = hash;
|
||||||
final vcard = await requestVCard(from);
|
final vcardResult = await requestVCard(from);
|
||||||
|
|
||||||
if (vcard != null) {
|
if (vcardResult.isType<VCard>()) {
|
||||||
final binval = vcard.photo?.binval;
|
final binval = vcardResult.get<VCard>().photo?.binval;
|
||||||
if (binval != null) {
|
if (binval != null) {
|
||||||
getAttributes().sendEvent(AvatarUpdatedEvent(jid: from, base64: binval, hash: hash));
|
getAttributes().sendEvent(
|
||||||
|
AvatarUpdatedEvent(
|
||||||
|
jid: from,
|
||||||
|
base64: binval,
|
||||||
|
hash: hash,
|
||||||
|
),
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
logger.warning('No avatar data found');
|
logger.warning('No avatar data found');
|
||||||
}
|
}
|
||||||
@@ -95,7 +105,7 @@ class VCardManager extends XmppManagerBase {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<VCard?> requestVCard(String jid) async {
|
Future<Result<VCardError, VCard>> requestVCard(String jid) async {
|
||||||
final result = await getAttributes().sendStanza(
|
final result = await getAttributes().sendStanza(
|
||||||
Stanza.iq(
|
Stanza.iq(
|
||||||
to: jid,
|
to: jid,
|
||||||
@@ -107,12 +117,13 @@ class VCardManager extends XmppManagerBase {
|
|||||||
)
|
)
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
encrypted: true,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (result.attributes['type'] != 'result') return null;
|
if (result.attributes['type'] != 'result') return Result(UnknownVCardError());
|
||||||
final vcard = result.firstTag('vCard', xmlns: vCardTempXmlns);
|
final vcard = result.firstTag('vCard', xmlns: vCardTempXmlns);
|
||||||
if (vcard == null) return null;
|
if (vcard == null) return Result(UnknownVCardError());
|
||||||
|
|
||||||
return _parseVCard(vcard);
|
return Result(_parseVCard(vcard));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ import 'package:moxxmpp/src/xeps/xep_0060/errors.dart';
|
|||||||
import 'package:moxxmpp/src/xeps/xep_0060/helpers.dart';
|
import 'package:moxxmpp/src/xeps/xep_0060/helpers.dart';
|
||||||
|
|
||||||
class PubSubPublishOptions {
|
class PubSubPublishOptions {
|
||||||
|
|
||||||
const PubSubPublishOptions({
|
const PubSubPublishOptions({
|
||||||
this.accessModel,
|
this.accessModel,
|
||||||
this.maxItems,
|
this.maxItems,
|
||||||
@@ -60,7 +59,6 @@ class PubSubPublishOptions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class PubSubItem {
|
class PubSubItem {
|
||||||
|
|
||||||
const PubSubItem({ required this.id, required this.node, required this.payload });
|
const PubSubItem({ required this.id, required this.node, required this.payload });
|
||||||
final String id;
|
final String id;
|
||||||
final String node;
|
final String node;
|
||||||
|
|||||||
@@ -3,21 +3,24 @@ import 'package:moxxmpp/src/managers/base.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/stringxml.dart';
|
import 'package:moxxmpp/src/stringxml.dart';
|
||||||
|
import 'package:moxxmpp/src/types/result.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';
|
||||||
import 'package:moxxmpp/src/xeps/xep_0060/errors.dart';
|
import 'package:moxxmpp/src/xeps/xep_0060/errors.dart';
|
||||||
import 'package:moxxmpp/src/xeps/xep_0060/xep_0060.dart';
|
import 'package:moxxmpp/src/xeps/xep_0060/xep_0060.dart';
|
||||||
|
|
||||||
class UserAvatar {
|
abstract class AvatarError {}
|
||||||
|
|
||||||
|
class UnknownAvatarError extends AvatarError {}
|
||||||
|
|
||||||
|
class UserAvatar {
|
||||||
const UserAvatar({ required this.base64, required this.hash });
|
const UserAvatar({ required this.base64, required this.hash });
|
||||||
final String base64;
|
final String base64;
|
||||||
final String hash;
|
final String hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
class UserAvatarMetadata {
|
class UserAvatarMetadata {
|
||||||
|
|
||||||
const UserAvatarMetadata(
|
const UserAvatarMetadata(
|
||||||
this.id,
|
this.id,
|
||||||
this.length,
|
this.length,
|
||||||
@@ -62,30 +65,30 @@ class UserAvatarManager extends XmppManagerBase {
|
|||||||
// TODO(PapaTutuWawa): Check for PEP support
|
// TODO(PapaTutuWawa): Check for PEP support
|
||||||
@override
|
@override
|
||||||
Future<bool> isSupported() async => true;
|
Future<bool> isSupported() async => true;
|
||||||
|
|
||||||
/// Requests the avatar from [jid]. Returns the avatar data if the request was
|
/// Requests the avatar from [jid]. Returns the avatar data if the request was
|
||||||
/// successful. Null otherwise
|
/// successful. Null otherwise
|
||||||
// TODO(Unknown): Migrate to Resultsv2
|
Future<Result<AvatarError, UserAvatar>> getUserAvatar(String jid) async {
|
||||||
Future<UserAvatar?> getUserAvatar(String jid) async {
|
|
||||||
final pubsub = _getPubSubManager();
|
final pubsub = _getPubSubManager();
|
||||||
final resultsRaw = await pubsub.getItems(jid, userAvatarDataXmlns);
|
final resultsRaw = await pubsub.getItems(jid, userAvatarDataXmlns);
|
||||||
if (resultsRaw.isType<PubSubError>()) return null;
|
if (resultsRaw.isType<PubSubError>()) return Result(UnknownAvatarError());
|
||||||
|
|
||||||
final results = resultsRaw.get<List<PubSubItem>>();
|
final results = resultsRaw.get<List<PubSubItem>>();
|
||||||
if (results.isEmpty) return null;
|
if (results.isEmpty) return Result(UnknownAvatarError());
|
||||||
|
|
||||||
final item = results[0];
|
final item = results[0];
|
||||||
return UserAvatar(
|
return Result(
|
||||||
base64: item.payload.innerText(),
|
UserAvatar(
|
||||||
hash: item.id,
|
base64: item.payload.innerText(),
|
||||||
|
hash: item.id,
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Publish the avatar data, [base64], on the pubsub node using [hash] as
|
/// Publish the avatar data, [base64], on the pubsub node using [hash] as
|
||||||
/// the item id. [hash] must be the SHA-1 hash of the image data, while
|
/// the item id. [hash] must be the SHA-1 hash of the image data, while
|
||||||
/// [base64] must be the base64-encoded version of the image data.
|
/// [base64] must be the base64-encoded version of the image data.
|
||||||
// TODO(Unknown): Migrate to Resultsv2
|
Future<Result<AvatarError, bool>> publishUserAvatar(String base64, String hash, bool public) async {
|
||||||
Future<bool> publishUserAvatar(String base64, String hash, bool public) async {
|
|
||||||
final pubsub = _getPubSubManager();
|
final pubsub = _getPubSubManager();
|
||||||
final result = await pubsub.publish(
|
final result = await pubsub.publish(
|
||||||
getAttributes().getFullJID().toBare().toString(),
|
getAttributes().getFullJID().toBare().toString(),
|
||||||
@@ -101,14 +104,15 @@ class UserAvatarManager extends XmppManagerBase {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
return !result.isType<PubSubError>();
|
if (result.isType<PubSubError>()) return Result(UnknownAvatarError());
|
||||||
|
|
||||||
|
return const Result(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Publish avatar metadata [metadata] to the User Avatar's metadata node. If [public]
|
/// Publish avatar metadata [metadata] to the User Avatar's metadata node. If [public]
|
||||||
/// is true, then the node will be set to an 'open' access model. If [public] is false,
|
/// is true, then the node will be set to an 'open' access model. If [public] is false,
|
||||||
/// then the node will be set to an 'roster' access model.
|
/// then the node will be set to an 'roster' access model.
|
||||||
// TODO(Unknown): Migrate to Resultsv2
|
Future<Result<AvatarError, bool>> publishUserAvatarMetadata(UserAvatarMetadata metadata, bool public) async {
|
||||||
Future<bool> publishUserAvatarMetadata(UserAvatarMetadata metadata, bool public) async {
|
|
||||||
final pubsub = _getPubSubManager();
|
final pubsub = _getPubSubManager();
|
||||||
final result = await pubsub.publish(
|
final result = await pubsub.publish(
|
||||||
getAttributes().getFullJID().toBare().toString(),
|
getAttributes().getFullJID().toBare().toString(),
|
||||||
@@ -135,39 +139,37 @@ class UserAvatarManager extends XmppManagerBase {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
return result.isType<PubSubError>();
|
if (result.isType<PubSubError>()) return Result(UnknownAvatarError());
|
||||||
|
return const Result(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Subscribe the data and metadata node of [jid].
|
/// Subscribe the data and metadata node of [jid].
|
||||||
// TODO(Unknown): Migrate to Resultsv2
|
Future<Result<AvatarError, bool>> subscribe(String jid) async {
|
||||||
Future<bool> subscribe(String jid) async {
|
|
||||||
await _getPubSubManager().subscribe(jid, userAvatarDataXmlns);
|
await _getPubSubManager().subscribe(jid, userAvatarDataXmlns);
|
||||||
await _getPubSubManager().subscribe(jid, userAvatarMetadataXmlns);
|
await _getPubSubManager().subscribe(jid, userAvatarMetadataXmlns);
|
||||||
|
|
||||||
return true;
|
return const Result(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Unsubscribe the data and metadata node of [jid].
|
/// Unsubscribe the data and metadata node of [jid].
|
||||||
// TODO(Unknown): Migrate to Resultsv2
|
Future<Result<AvatarError, bool>> unsubscribe(String jid) async {
|
||||||
Future<bool> unsubscribe(String jid) async {
|
|
||||||
await _getPubSubManager().unsubscribe(jid, userAvatarDataXmlns);
|
await _getPubSubManager().unsubscribe(jid, userAvatarDataXmlns);
|
||||||
await _getPubSubManager().subscribe(jid, userAvatarMetadataXmlns);
|
await _getPubSubManager().subscribe(jid, userAvatarMetadataXmlns);
|
||||||
|
|
||||||
return true;
|
return const Result(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the PubSub Id of an avatar after doing a disco#items query.
|
/// Returns the PubSub Id of an avatar after doing a disco#items query.
|
||||||
/// Note that this assumes that there is only one (1) item published on
|
/// Note that this assumes that there is only one (1) item published on
|
||||||
/// the node.
|
/// the node.
|
||||||
// TODO(Unknown): Migrate to Resultsv2
|
Future<Result<AvatarError, String>> getAvatarId(String jid) async {
|
||||||
Future<String?> getAvatarId(String jid) async {
|
|
||||||
final disco = getAttributes().getManagerById(discoManager)! as DiscoManager;
|
final disco = getAttributes().getManagerById(discoManager)! as DiscoManager;
|
||||||
final response = await disco.discoItemsQuery(jid, node: userAvatarDataXmlns);
|
final response = await disco.discoItemsQuery(jid, node: userAvatarDataXmlns, shouldEncrypt: false);
|
||||||
if (response.isType<DiscoError>()) return null;
|
if (response.isType<DiscoError>()) return Result(UnknownAvatarError());
|
||||||
|
|
||||||
final items = response.get<List<DiscoItem>>();
|
final items = response.get<List<DiscoItem>>();
|
||||||
if (items.isEmpty) return null;
|
if (items.isEmpty) return Result(UnknownAvatarError());
|
||||||
|
|
||||||
return items.first.name;
|
return Result(items.first.name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,14 +8,12 @@ import 'package:moxxmpp/src/stanza.dart';
|
|||||||
|
|
||||||
@immutable
|
@immutable
|
||||||
class DelayedDelivery {
|
class DelayedDelivery {
|
||||||
|
|
||||||
const DelayedDelivery(this.from, this.timestamp);
|
const DelayedDelivery(this.from, this.timestamp);
|
||||||
final DateTime timestamp;
|
final DateTime timestamp;
|
||||||
final String from;
|
final String from;
|
||||||
}
|
}
|
||||||
|
|
||||||
class DelayedDeliveryManager extends XmppManagerBase {
|
class DelayedDeliveryManager extends XmppManagerBase {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String getId() => delayedDeliveryManager;
|
String getId() => delayedDeliveryManager;
|
||||||
|
|
||||||
|
|||||||
@@ -8,8 +8,18 @@ enum MessageProcessingHint {
|
|||||||
store,
|
store,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// NOTE: We do not define a function for turning a Message Processing Hint element into
|
MessageProcessingHint messageProcessingHintFromXml(XMLNode element) {
|
||||||
/// an enum value since the elements do not concern us as a client.
|
switch (element.tag) {
|
||||||
|
case 'no-permanent-store': return MessageProcessingHint.noPermanentStore;
|
||||||
|
case 'no-store': return MessageProcessingHint.noStore;
|
||||||
|
case 'no-copy': return MessageProcessingHint.noCopies;
|
||||||
|
case 'store': return MessageProcessingHint.store;
|
||||||
|
}
|
||||||
|
|
||||||
|
assert(false, 'Invalid Message Processing Hint: ${element.tag}');
|
||||||
|
return MessageProcessingHint.noStore;
|
||||||
|
}
|
||||||
|
|
||||||
extension XmlExtension on MessageProcessingHint {
|
extension XmlExtension on MessageProcessingHint {
|
||||||
XMLNode toXml() {
|
XMLNode toXml() {
|
||||||
String tag;
|
String tag;
|
||||||
|
|||||||
68
packages/moxxmpp/lib/src/xeps/xep_0444.dart
Normal file
68
packages/moxxmpp/lib/src/xeps/xep_0444.dart
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
import 'package:moxxmpp/src/managers/base.dart';
|
||||||
|
import 'package:moxxmpp/src/managers/data.dart';
|
||||||
|
import 'package:moxxmpp/src/managers/handlers.dart';
|
||||||
|
import 'package:moxxmpp/src/managers/namespaces.dart';
|
||||||
|
import 'package:moxxmpp/src/namespaces.dart';
|
||||||
|
import 'package:moxxmpp/src/stanza.dart';
|
||||||
|
import 'package:moxxmpp/src/stringxml.dart';
|
||||||
|
|
||||||
|
class MessageReactions {
|
||||||
|
const MessageReactions(this.messageId, this.emojis);
|
||||||
|
final String messageId;
|
||||||
|
final List<String> emojis;
|
||||||
|
|
||||||
|
XMLNode toXml() {
|
||||||
|
return XMLNode.xmlns(
|
||||||
|
tag: 'reactions',
|
||||||
|
xmlns: messageReactionsXmlns,
|
||||||
|
attributes: <String, String>{
|
||||||
|
'id': messageId,
|
||||||
|
},
|
||||||
|
children: emojis.map((emoji) {
|
||||||
|
return XMLNode(
|
||||||
|
tag: 'reaction',
|
||||||
|
text: emoji,
|
||||||
|
);
|
||||||
|
}).toList(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class MessageReactionsManager extends XmppManagerBase {
|
||||||
|
@override
|
||||||
|
List<String> getDiscoFeatures() => [ messageReactionsXmlns ];
|
||||||
|
|
||||||
|
@override
|
||||||
|
String getName() => 'MessageReactionsManager';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String getId() => messageReactionsManager;
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<StanzaHandler> getIncomingStanzaHandlers() => [
|
||||||
|
StanzaHandler(
|
||||||
|
stanzaTag: 'message',
|
||||||
|
tagName: 'reactions',
|
||||||
|
tagXmlns: messageReactionsXmlns,
|
||||||
|
callback: _onReactionsReceived,
|
||||||
|
// Before the message handler
|
||||||
|
priority: -99,
|
||||||
|
),
|
||||||
|
];
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<bool> isSupported() async => true;
|
||||||
|
|
||||||
|
Future<StanzaHandlerData> _onReactionsReceived(Stanza message, StanzaHandlerData state) async {
|
||||||
|
final reactionsElement = message.firstTag('reactions', xmlns: messageReactionsXmlns)!;
|
||||||
|
return state.copyWith(
|
||||||
|
messageReactions: MessageReactions(
|
||||||
|
reactionsElement.attributes['id']! as String,
|
||||||
|
reactionsElement.children
|
||||||
|
.where((c) => c.tag == 'reaction')
|
||||||
|
.map((c) => c.innerText())
|
||||||
|
.toList(),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,7 +4,6 @@ import 'package:moxxmpp/src/xeps/staging/extensible_file_thumbnails.dart';
|
|||||||
import 'package:moxxmpp/src/xeps/xep_0300.dart';
|
import 'package:moxxmpp/src/xeps/xep_0300.dart';
|
||||||
|
|
||||||
class FileMetadataData {
|
class FileMetadataData {
|
||||||
|
|
||||||
const FileMetadataData({
|
const FileMetadataData({
|
||||||
this.mediaType,
|
this.mediaType,
|
||||||
this.width,
|
this.width,
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ abstract class StatelessFileSharingSource {
|
|||||||
|
|
||||||
/// Implementation for url-data source elements.
|
/// Implementation for url-data source elements.
|
||||||
class StatelessFileSharingUrlSource extends StatelessFileSharingSource {
|
class StatelessFileSharingUrlSource extends StatelessFileSharingSource {
|
||||||
|
|
||||||
StatelessFileSharingUrlSource(this.url);
|
StatelessFileSharingUrlSource(this.url);
|
||||||
|
|
||||||
factory StatelessFileSharingUrlSource.fromXml(XMLNode element) {
|
factory StatelessFileSharingUrlSource.fromXml(XMLNode element) {
|
||||||
@@ -41,8 +40,29 @@ class StatelessFileSharingUrlSource extends StatelessFileSharingSource {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class StatelessFileSharingData {
|
/// Finds the <sources/> element in [node] and returns the list of
|
||||||
|
/// StatelessFileSharingSources contained with it.
|
||||||
|
/// If [checkXmlns] is true, then the sources element must also have an xmlns attribute
|
||||||
|
/// of "urn:xmpp:sfs:0".
|
||||||
|
List<StatelessFileSharingSource> processStatelessFileSharingSources(XMLNode node, { bool checkXmlns = true }) {
|
||||||
|
final sources = List<StatelessFileSharingSource>.empty(growable: true);
|
||||||
|
|
||||||
|
final sourcesElement = node.firstTag(
|
||||||
|
'sources',
|
||||||
|
xmlns: checkXmlns ? sfsXmlns : null,
|
||||||
|
)!;
|
||||||
|
for (final source in sourcesElement.children) {
|
||||||
|
if (source.attributes['xmlns'] == urlDataXmlns) {
|
||||||
|
sources.add(StatelessFileSharingUrlSource.fromXml(source));
|
||||||
|
} else if (source.attributes['xmlns'] == sfsEncryptionXmlns) {
|
||||||
|
sources.add(StatelessFileSharingEncryptedSource.fromXml(source));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return sources;
|
||||||
|
}
|
||||||
|
|
||||||
|
class StatelessFileSharingData {
|
||||||
const StatelessFileSharingData(this.metadata, this.sources);
|
const StatelessFileSharingData(this.metadata, this.sources);
|
||||||
|
|
||||||
/// Parse [node] as a StatelessFileSharingData element.
|
/// Parse [node] as a StatelessFileSharingData element.
|
||||||
@@ -50,20 +70,10 @@ class StatelessFileSharingData {
|
|||||||
assert(node.attributes['xmlns'] == sfsXmlns, 'Invalid element xmlns');
|
assert(node.attributes['xmlns'] == sfsXmlns, 'Invalid element xmlns');
|
||||||
assert(node.tag == 'file-sharing', 'Invalid element name');
|
assert(node.tag == 'file-sharing', 'Invalid element name');
|
||||||
|
|
||||||
final sources = List<StatelessFileSharingSource>.empty(growable: true);
|
|
||||||
|
|
||||||
final sourcesElement = node.firstTag('sources')!;
|
|
||||||
for (final source in sourcesElement.children) {
|
|
||||||
if (source.attributes['xmlns'] == urlDataXmlns) {
|
|
||||||
sources.add(StatelessFileSharingUrlSource.fromXml(source));
|
|
||||||
} else if (source.attributes['xmlns'] == sfsEncryptionXmlns) {
|
|
||||||
sources.add(StatelessFileSharingEncryptedSource.fromXml(source));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return StatelessFileSharingData(
|
return StatelessFileSharingData(
|
||||||
FileMetadataData.fromXML(node.firstTag('file')!),
|
FileMetadataData.fromXML(node.firstTag('file')!),
|
||||||
sources,
|
// TODO(PapaTutuWawa): This is a work around for Stickers where the source element has a XMLNS but SFS does not have one.
|
||||||
|
processStatelessFileSharingSources(node, checkXmlns: false),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -120,7 +130,7 @@ class SFSManager extends XmppManagerBase {
|
|||||||
final sfs = message.firstTag('file-sharing', xmlns: sfsXmlns)!;
|
final sfs = message.firstTag('file-sharing', xmlns: sfsXmlns)!;
|
||||||
|
|
||||||
return state.copyWith(
|
return state.copyWith(
|
||||||
sfs: StatelessFileSharingData.fromXML(sfs),
|
sfs: StatelessFileSharingData.fromXML(sfs, ),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
308
packages/moxxmpp/lib/src/xeps/xep_0449.dart
Normal file
308
packages/moxxmpp/lib/src/xeps/xep_0449.dart
Normal file
@@ -0,0 +1,308 @@
|
|||||||
|
import 'dart:convert';
|
||||||
|
import 'package:moxxmpp/src/jid.dart';
|
||||||
|
import 'package:moxxmpp/src/managers/base.dart';
|
||||||
|
import 'package:moxxmpp/src/managers/data.dart';
|
||||||
|
import 'package:moxxmpp/src/managers/handlers.dart';
|
||||||
|
import 'package:moxxmpp/src/managers/namespaces.dart';
|
||||||
|
import 'package:moxxmpp/src/namespaces.dart';
|
||||||
|
import 'package:moxxmpp/src/rfcs/rfc_4790.dart';
|
||||||
|
import 'package:moxxmpp/src/stanza.dart';
|
||||||
|
import 'package:moxxmpp/src/stringxml.dart';
|
||||||
|
import 'package:moxxmpp/src/types/result.dart';
|
||||||
|
import 'package:moxxmpp/src/xeps/xep_0060/errors.dart';
|
||||||
|
import 'package:moxxmpp/src/xeps/xep_0060/xep_0060.dart';
|
||||||
|
import 'package:moxxmpp/src/xeps/xep_0300.dart';
|
||||||
|
import 'package:moxxmpp/src/xeps/xep_0446.dart';
|
||||||
|
import 'package:moxxmpp/src/xeps/xep_0447.dart';
|
||||||
|
|
||||||
|
class Sticker {
|
||||||
|
const Sticker(this.metadata, this.sources, this.suggests);
|
||||||
|
|
||||||
|
factory Sticker.fromXML(XMLNode node) {
|
||||||
|
assert(node.tag == 'item', 'sticker has wrong tag');
|
||||||
|
|
||||||
|
return Sticker(
|
||||||
|
FileMetadataData.fromXML(node.firstTag('file', xmlns: fileMetadataXmlns)!),
|
||||||
|
processStatelessFileSharingSources(node, checkXmlns: false),
|
||||||
|
{},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
final FileMetadataData metadata;
|
||||||
|
final List<StatelessFileSharingSource> sources;
|
||||||
|
// Language -> suggestion
|
||||||
|
final Map<String, String> suggests;
|
||||||
|
|
||||||
|
XMLNode toPubSubXML() {
|
||||||
|
final suggestsElements = suggests.keys.map((suggest) {
|
||||||
|
Map<String, String> attrs;
|
||||||
|
if (suggest.isEmpty) {
|
||||||
|
attrs = {};
|
||||||
|
} else {
|
||||||
|
attrs = {
|
||||||
|
'xml:lang': suggest,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return XMLNode(
|
||||||
|
tag: 'suggest',
|
||||||
|
attributes: attrs,
|
||||||
|
text: suggests[suggest],
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
return XMLNode(
|
||||||
|
tag: 'item',
|
||||||
|
children: [
|
||||||
|
metadata.toXML(),
|
||||||
|
...sources.map((source) => source.toXml()),
|
||||||
|
...suggestsElements,
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class StickerPack {
|
||||||
|
const StickerPack(
|
||||||
|
this.id,
|
||||||
|
this.name,
|
||||||
|
this.summary,
|
||||||
|
this.hashAlgorithm,
|
||||||
|
this.hashValue,
|
||||||
|
this.stickers,
|
||||||
|
this.restricted,
|
||||||
|
);
|
||||||
|
|
||||||
|
factory StickerPack.fromXML(String id, XMLNode node, { bool hashAvailable = true }) {
|
||||||
|
assert(node.tag == 'pack', 'node has wrong tag');
|
||||||
|
assert(node.attributes['xmlns'] == stickersXmlns, 'node has wrong XMLNS');
|
||||||
|
|
||||||
|
var hashAlgorithm = HashFunction.sha256;
|
||||||
|
var hashValue = '';
|
||||||
|
if (hashAvailable) {
|
||||||
|
final hash = node.firstTag('hash', xmlns: hashXmlns)!;
|
||||||
|
hashAlgorithm = hashFunctionFromName(hash.attributes['algo']! as String);
|
||||||
|
hashValue = hash.innerText();
|
||||||
|
}
|
||||||
|
|
||||||
|
return StickerPack(
|
||||||
|
id,
|
||||||
|
node.firstTag('name')!.innerText(),
|
||||||
|
node.firstTag('summary')!.innerText(),
|
||||||
|
hashAlgorithm,
|
||||||
|
hashValue,
|
||||||
|
node.children
|
||||||
|
.where((e) => e.tag == 'item')
|
||||||
|
.map<Sticker>(Sticker.fromXML)
|
||||||
|
.toList(),
|
||||||
|
node.firstTag('restricted') != null,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
final String id;
|
||||||
|
// TODO(PapaTutuWawa): Turn name and summary into a Map as it may contain a xml:lang
|
||||||
|
final String name;
|
||||||
|
final String summary;
|
||||||
|
final HashFunction hashAlgorithm;
|
||||||
|
final String hashValue;
|
||||||
|
final List<Sticker> stickers;
|
||||||
|
final bool restricted;
|
||||||
|
|
||||||
|
/// When using the fromXML factory to parse a description of a sticker pack with a
|
||||||
|
/// yet unknown hash, then this function can be used in order to apply the freshly
|
||||||
|
/// calculated hash to the object.
|
||||||
|
StickerPack copyWithId(HashFunction newHashFunction, String newId) {
|
||||||
|
return StickerPack(
|
||||||
|
newId,
|
||||||
|
name,
|
||||||
|
summary,
|
||||||
|
newHashFunction,
|
||||||
|
newId,
|
||||||
|
stickers,
|
||||||
|
restricted,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
XMLNode toXML() {
|
||||||
|
return XMLNode.xmlns(
|
||||||
|
tag: 'pack',
|
||||||
|
xmlns: stickersXmlns,
|
||||||
|
children: [
|
||||||
|
// Pack metadata
|
||||||
|
XMLNode(
|
||||||
|
tag: 'name',
|
||||||
|
text: name,
|
||||||
|
),
|
||||||
|
XMLNode(
|
||||||
|
tag: 'summary',
|
||||||
|
text: summary,
|
||||||
|
),
|
||||||
|
constructHashElement(
|
||||||
|
hashAlgorithm.toName(),
|
||||||
|
hashValue,
|
||||||
|
),
|
||||||
|
|
||||||
|
...restricted ?
|
||||||
|
[XMLNode(tag: 'restricted')] :
|
||||||
|
[],
|
||||||
|
|
||||||
|
// Stickers
|
||||||
|
...stickers
|
||||||
|
.map((sticker) => sticker.toPubSubXML()),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Calculates the sticker pack's hash as specified by XEP-0449.
|
||||||
|
Future<String> getHash(HashFunction hashFunction) async {
|
||||||
|
// Build the meta string
|
||||||
|
final metaTmp = [
|
||||||
|
<int>[
|
||||||
|
...utf8.encode('name'),
|
||||||
|
0x1f,
|
||||||
|
0x1f,
|
||||||
|
...utf8.encode(name),
|
||||||
|
0x1f,
|
||||||
|
0x1e,
|
||||||
|
],
|
||||||
|
<int>[
|
||||||
|
...utf8.encode('summary'),
|
||||||
|
0x1f,
|
||||||
|
0x1f,
|
||||||
|
...utf8.encode(summary),
|
||||||
|
0x1f,
|
||||||
|
0x1e,
|
||||||
|
],
|
||||||
|
]..sort(ioctetSortComparatorRaw);
|
||||||
|
final metaString = List<int>.empty(growable: true);
|
||||||
|
for (final m in metaTmp) {
|
||||||
|
metaString.addAll(m);
|
||||||
|
}
|
||||||
|
metaString.add(0x1c);
|
||||||
|
|
||||||
|
// Build item hashes
|
||||||
|
final items = List<List<int>>.empty(growable: true);
|
||||||
|
for (final sticker in stickers) {
|
||||||
|
final tmp = List<int>.empty(growable: true)
|
||||||
|
..addAll(utf8.encode(sticker.metadata.desc!))
|
||||||
|
..add(0x1e);
|
||||||
|
|
||||||
|
final hashes = List<List<int>>.empty(growable: true);
|
||||||
|
for (final hash in sticker.metadata.hashes.keys) {
|
||||||
|
hashes.add([
|
||||||
|
...utf8.encode(hash),
|
||||||
|
0x1f,
|
||||||
|
...utf8.encode(sticker.metadata.hashes[hash]!),
|
||||||
|
0x1f,
|
||||||
|
0x1e,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
hashes.sort(ioctetSortComparatorRaw);
|
||||||
|
|
||||||
|
for (final hash in hashes) {
|
||||||
|
tmp.addAll(hash);
|
||||||
|
}
|
||||||
|
tmp.add(0x1d);
|
||||||
|
items.add(tmp);
|
||||||
|
}
|
||||||
|
items.sort(ioctetSortComparatorRaw);
|
||||||
|
final stickersString = List<int>.empty(growable: true);
|
||||||
|
for (final item in items) {
|
||||||
|
stickersString.addAll(item);
|
||||||
|
}
|
||||||
|
stickersString.add(0x1c);
|
||||||
|
|
||||||
|
// Calculate the hash
|
||||||
|
final rawHash = await CryptographicHashManager.hashFromData(
|
||||||
|
[
|
||||||
|
...metaString,
|
||||||
|
...stickersString,
|
||||||
|
],
|
||||||
|
hashFunction,
|
||||||
|
);
|
||||||
|
return base64.encode(rawHash).substring(0, 24);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class StickersManager extends XmppManagerBase {
|
||||||
|
@override
|
||||||
|
String getId() => stickersManager;
|
||||||
|
|
||||||
|
@override
|
||||||
|
String getName() => 'StickersManager';
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<bool> isSupported() async => true;
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<StanzaHandler> getIncomingStanzaHandlers() => [
|
||||||
|
StanzaHandler(
|
||||||
|
stanzaTag: 'message',
|
||||||
|
tagXmlns: stickersXmlns,
|
||||||
|
tagName: 'sticker',
|
||||||
|
callback: _onIncomingMessage,
|
||||||
|
priority: -99,
|
||||||
|
),
|
||||||
|
];
|
||||||
|
|
||||||
|
Future<StanzaHandlerData> _onIncomingMessage(Stanza stanza, StanzaHandlerData state) async {
|
||||||
|
final sticker = stanza.firstTag('sticker', xmlns: stickersXmlns)!;
|
||||||
|
return state.copyWith(
|
||||||
|
stickerPackId: sticker.attributes['pack']! as String,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Publishes the StickerPack [pack] to the PubSub node of [jid].
|
||||||
|
///
|
||||||
|
/// On success, returns true. On failure, returns a PubSubError.
|
||||||
|
Future<Result<PubSubError, bool>> publishStickerPack(JID jid, StickerPack pack) async {
|
||||||
|
assert(pack.id != '', 'The sticker pack must have an id');
|
||||||
|
final pm = getAttributes().getManagerById<PubSubManager>(pubsubManager)!;
|
||||||
|
|
||||||
|
return pm.publish(
|
||||||
|
jid.toBare().toString(),
|
||||||
|
stickersXmlns,
|
||||||
|
pack.toXML(),
|
||||||
|
id: pack.id,
|
||||||
|
options: const PubSubPublishOptions(
|
||||||
|
maxItems: 'max',
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Removes the sticker pack with id [id] from the PubSub node of [jid].
|
||||||
|
///
|
||||||
|
/// On success, returns the true. On failure, returns a PubSubError.
|
||||||
|
Future<Result<PubSubError, bool>> retractStickerPack(JID jid, String id) async {
|
||||||
|
final pm = getAttributes().getManagerById<PubSubManager>(pubsubManager)!;
|
||||||
|
|
||||||
|
return pm.retract(
|
||||||
|
jid,
|
||||||
|
stickersXmlns,
|
||||||
|
id,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Fetches the sticker pack with id [id] from [jid].
|
||||||
|
///
|
||||||
|
/// On success, returns the StickerPack. On failure, returns a PubSubError.
|
||||||
|
Future<Result<PubSubError, StickerPack>> fetchStickerPack(JID jid, String id) async {
|
||||||
|
final pm = getAttributes().getManagerById<PubSubManager>(pubsubManager)!;
|
||||||
|
final stickerPackDataRaw = await pm.getItem(
|
||||||
|
jid.toBare().toString(),
|
||||||
|
stickersXmlns,
|
||||||
|
id,
|
||||||
|
);
|
||||||
|
if (stickerPackDataRaw.isType<PubSubError>()) {
|
||||||
|
return Result(stickerPackDataRaw.get<PubSubError>());
|
||||||
|
}
|
||||||
|
|
||||||
|
final stickerPackData = stickerPackDataRaw.get<PubSubItem>();
|
||||||
|
final stickerPack = StickerPack.fromXML(
|
||||||
|
stickerPackData.id,
|
||||||
|
stickerPackData.payload,
|
||||||
|
);
|
||||||
|
|
||||||
|
return Result(stickerPack);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -14,3 +14,9 @@ is, for example, [moxdns](https://codeberg.org/moxxy/moxdns).
|
|||||||
## License
|
## License
|
||||||
|
|
||||||
See `./LICENSE`.
|
See `./LICENSE`.
|
||||||
|
|
||||||
|
## Support
|
||||||
|
|
||||||
|
If you like what I do and you want to support me, feel free to donate to me on Ko-Fi.
|
||||||
|
|
||||||
|
[<img src="https://codeberg.org/moxxy/moxxyv2/raw/branch/master/assets/repo/kofi.png" height="36" style="height: 36px; border: 0px;"></img>](https://ko-fi.com/papatutuwawa)
|
||||||
|
|||||||
Reference in New Issue
Block a user