feat(xep): XEP-0045 cache fixes.
Signed-off-by: Ikjot Singh Dhody <ikjotsd@gmail.com>
This commit is contained in:
parent
8728166a4d
commit
51bca6c25d
@ -83,8 +83,6 @@ class _MyHomePageState extends State<MyHomePage> {
|
|||||||
),
|
),
|
||||||
MessageManager(),
|
MessageManager(),
|
||||||
PresenceManager(),
|
PresenceManager(),
|
||||||
OccupantIdManager(),
|
|
||||||
MUCManager()
|
|
||||||
])
|
])
|
||||||
..registerFeatureNegotiators([
|
..registerFeatureNegotiators([
|
||||||
ResourceBindingNegotiator(),
|
ResourceBindingNegotiator(),
|
||||||
@ -160,47 +158,6 @@ class _MyHomePageState extends State<MyHomePage> {
|
|||||||
),
|
),
|
||||||
obscureText: true,
|
obscureText: true,
|
||||||
),
|
),
|
||||||
TextButton(
|
|
||||||
onPressed: () async {
|
|
||||||
// final muc = connection.getManagerById<MUCManager>(mucManager);
|
|
||||||
// final roomInformationResult = await muc!.queryRoomInformation(
|
|
||||||
// JID.fromString('moxxmpp-muc-test@muc.moxxy.org'));
|
|
||||||
// if (roomInformationResult.isType<RoomInformation>()) {
|
|
||||||
// print('Room information received');
|
|
||||||
// print(roomInformationResult.get<RoomInformation>().jid);
|
|
||||||
// print(roomInformationResult.get<RoomInformation>().name);
|
|
||||||
// print(roomInformationResult.get<RoomInformation>().features);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// final muc = connection.getManagerById<MUCManager>(mucManager);
|
|
||||||
// print('joining room');
|
|
||||||
// final roomInformationResult = await muc!.joinRoom(
|
|
||||||
// JID.fromString('moxxmpp-muc-test@muc.moxxy.org/test_1'));
|
|
||||||
// if (roomInformationResult.isType<MUCError>()) {
|
|
||||||
// print(roomInformationResult.get());
|
|
||||||
// } else {
|
|
||||||
// print(roomInformationResult.get());
|
|
||||||
// }
|
|
||||||
|
|
||||||
print('HERE IS YOUR JID');
|
|
||||||
print(connection.resource);
|
|
||||||
final sid = connection.generateId();
|
|
||||||
final originId = connection.generateId();
|
|
||||||
final message =
|
|
||||||
connection.getManagerById<MessageManager>(messageManager);
|
|
||||||
message!.sendMessage(
|
|
||||||
JID.fromString('moxxmpp-muc-test@muc.moxxy.org/ISD'),
|
|
||||||
TypedMap<StanzaHandlerExtension>.fromList([
|
|
||||||
const MessageBodyData('Testing'),
|
|
||||||
const MarkableData(true),
|
|
||||||
MessageIdData(sid),
|
|
||||||
StableIdData(originId, null),
|
|
||||||
ConversationTypeData(ConversationType.groupchatprivate)
|
|
||||||
]),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
child: const Text('Test'),
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
@ -23,7 +23,7 @@ class RoomInformation {
|
|||||||
.name!,
|
.name!,
|
||||||
);
|
);
|
||||||
|
|
||||||
/// The JID (Jabber ID) of the Multi-User Chat (MUC) room.
|
/// The JID of the Multi-User Chat (MUC) room.
|
||||||
final JID jid;
|
final JID jid;
|
||||||
|
|
||||||
/// A list of features supported by the Multi-User Chat (MUC) room.
|
/// A list of features supported by the Multi-User Chat (MUC) room.
|
||||||
@ -36,10 +36,8 @@ class RoomInformation {
|
|||||||
class RoomState {
|
class RoomState {
|
||||||
RoomState({
|
RoomState({
|
||||||
required this.roomJid,
|
required this.roomJid,
|
||||||
required this.roomInformation,
|
|
||||||
this.nick,
|
this.nick,
|
||||||
});
|
});
|
||||||
final JID roomJid;
|
final JID roomJid;
|
||||||
final RoomInformation roomInformation;
|
|
||||||
String? nick;
|
String? nick;
|
||||||
}
|
}
|
||||||
|
@ -13,13 +13,6 @@ import 'package:moxxmpp/src/xeps/xep_0045/errors.dart';
|
|||||||
import 'package:moxxmpp/src/xeps/xep_0045/types.dart';
|
import 'package:moxxmpp/src/xeps/xep_0045/types.dart';
|
||||||
import 'package:synchronized/synchronized.dart';
|
import 'package:synchronized/synchronized.dart';
|
||||||
|
|
||||||
enum ConversationType { chat, groupchat, groupchatprivate }
|
|
||||||
|
|
||||||
class ConversationTypeData extends StanzaHandlerExtension {
|
|
||||||
ConversationTypeData(this.conversationType);
|
|
||||||
final ConversationType conversationType;
|
|
||||||
}
|
|
||||||
|
|
||||||
class MUCManager extends XmppManagerBase {
|
class MUCManager extends XmppManagerBase {
|
||||||
MUCManager() : super(mucManager);
|
MUCManager() : super(mucManager);
|
||||||
|
|
||||||
@ -45,14 +38,6 @@ class MUCManager extends XmppManagerBase {
|
|||||||
final roomInformation = RoomInformation.fromDiscoInfo(
|
final roomInformation = RoomInformation.fromDiscoInfo(
|
||||||
discoInfo: result.get<DiscoInfo>(),
|
discoInfo: result.get<DiscoInfo>(),
|
||||||
);
|
);
|
||||||
await _cacheLock.synchronized(
|
|
||||||
() async {
|
|
||||||
_mucRoomCache[roomJID] = RoomState(
|
|
||||||
roomJid: roomJID,
|
|
||||||
roomInformation: roomInformation,
|
|
||||||
);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
return Result(roomInformation);
|
return Result(roomInformation);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return Result(InvalidDiscoInfoResponse);
|
return Result(InvalidDiscoInfoResponse);
|
||||||
@ -80,7 +65,7 @@ class MUCManager extends XmppManagerBase {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
await _cacheLock.synchronized(
|
await _cacheLock.synchronized(
|
||||||
() async {
|
() {
|
||||||
_mucRoomCache[roomJID]!.nick = nick;
|
_mucRoomCache[roomJID]!.nick = nick;
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
@ -90,15 +75,8 @@ class MUCManager extends XmppManagerBase {
|
|||||||
Future<Result<bool, MUCError>> leaveRoom(
|
Future<Result<bool, MUCError>> leaveRoom(
|
||||||
JID roomJID,
|
JID roomJID,
|
||||||
) async {
|
) async {
|
||||||
String? nick;
|
final nick =
|
||||||
await _cacheLock.synchronized(
|
await _cacheLock.synchronized(() => _mucRoomCache[roomJID]!.nick);
|
||||||
() async {
|
|
||||||
nick = _mucRoomCache[roomJID]!.nick;
|
|
||||||
},
|
|
||||||
);
|
|
||||||
if (nick!.isEmpty) {
|
|
||||||
return Result(NoNicknameSpecified());
|
|
||||||
}
|
|
||||||
await getAttributes().sendStanza(
|
await getAttributes().sendStanza(
|
||||||
StanzaDetails(
|
StanzaDetails(
|
||||||
Stanza.presence(
|
Stanza.presence(
|
||||||
@ -108,7 +86,7 @@ class MUCManager extends XmppManagerBase {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
await _cacheLock.synchronized(
|
await _cacheLock.synchronized(
|
||||||
() async {
|
() {
|
||||||
_mucRoomCache.remove(roomJID);
|
_mucRoomCache.remove(roomJID);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user