feat(xep): Allow adding MUCs to join later
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
This commit is contained in:
parent
afa3927720
commit
76a9f7be7a
@ -16,6 +16,9 @@ import 'package:moxxmpp/src/xeps/xep_0359.dart';
|
|||||||
import 'package:synchronized/extension.dart';
|
import 'package:synchronized/extension.dart';
|
||||||
import 'package:synchronized/synchronized.dart';
|
import 'package:synchronized/synchronized.dart';
|
||||||
|
|
||||||
|
/// (Room JID, nickname)
|
||||||
|
typedef MUCRoomJoin = (JID, String);
|
||||||
|
|
||||||
class MUCManager extends XmppManagerBase {
|
class MUCManager extends XmppManagerBase {
|
||||||
MUCManager() : super(mucManager);
|
MUCManager() : super(mucManager);
|
||||||
|
|
||||||
@ -28,6 +31,10 @@ class MUCManager extends XmppManagerBase {
|
|||||||
/// Cache lock
|
/// Cache lock
|
||||||
final Lock _cacheLock = Lock();
|
final Lock _cacheLock = Lock();
|
||||||
|
|
||||||
|
/// Flag indicating whether we joined the rooms added to the room list with
|
||||||
|
/// [prepareRoomList].
|
||||||
|
bool _joinedPreparedRooms = true;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<StanzaHandler> getIncomingStanzaHandlers() => [
|
List<StanzaHandler> getIncomingStanzaHandlers() => [
|
||||||
StanzaHandler(
|
StanzaHandler(
|
||||||
@ -52,8 +59,9 @@ class MUCManager extends XmppManagerBase {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only attempt rejoining if we did not resume the stream.
|
// Only attempt rejoining if we did not resume the stream and all
|
||||||
if (event.resumed) {
|
// prepared rooms are already joined.
|
||||||
|
if (event.resumed && _joinedPreparedRooms) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -70,6 +78,28 @@ class MUCManager extends XmppManagerBase {
|
|||||||
0,
|
0,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
_joinedPreparedRooms = true;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Prepares the internal room list to ensure that the rooms
|
||||||
|
/// [rooms] are joined once we are connected.
|
||||||
|
Future<void> prepareRoomList(List<MUCRoomJoin> rooms) async {
|
||||||
|
assert(
|
||||||
|
rooms.isNotEmpty,
|
||||||
|
'The room list should not be empty',
|
||||||
|
);
|
||||||
|
|
||||||
|
await _cacheLock.synchronized(() {
|
||||||
|
_joinedPreparedRooms = false;
|
||||||
|
for (final room in rooms) {
|
||||||
|
final (roomJid, nick) = room;
|
||||||
|
_mucRoomCache[roomJid] = RoomState(
|
||||||
|
roomJid: roomJid,
|
||||||
|
nick: nick,
|
||||||
|
joined: false,
|
||||||
|
);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user