feat: join invite-from-knock rooms on launch app via notification, add custom invite reason for invite-on-knock to trigger custom content in background notifications (#5877)
This commit is contained in:
parent
65052de733
commit
a37bd658fc
3 changed files with 26 additions and 8 deletions
|
|
@ -14,6 +14,10 @@ extension KnockRoomExtension on Room {
|
|||
await join();
|
||||
await client.onJoinKnockedRoom(id);
|
||||
}
|
||||
|
||||
Future<void> acceptKnock(String userID) async {
|
||||
await invite(userID, reason: "invite_on_knock");
|
||||
}
|
||||
}
|
||||
|
||||
extension KnockClientExtension on Client {
|
||||
|
|
|
|||
|
|
@ -38,6 +38,7 @@ import 'package:fluffychat/l10n/l10n.dart';
|
|||
import 'package:fluffychat/main.dart';
|
||||
import 'package:fluffychat/pangea/common/utils/error_handler.dart';
|
||||
import 'package:fluffychat/pangea/common/utils/firebase_analytics.dart';
|
||||
import 'package:fluffychat/pangea/join_codes/knock_room_extension.dart';
|
||||
import 'package:fluffychat/pangea/languages/language_constants.dart';
|
||||
import 'package:fluffychat/utils/notification_background_handler.dart';
|
||||
import 'package:fluffychat/utils/push_helper.dart';
|
||||
|
|
@ -199,12 +200,12 @@ class BackgroundPush {
|
|||
|
||||
// #Pangea
|
||||
// Helper to ensure a room is loaded or synced.
|
||||
Future<Room?> _ensureRoomLoaded(String id) async {
|
||||
Future<Room?> _ensureRoomLoaded(String id, {Membership? membership}) async {
|
||||
await client.roomsLoading;
|
||||
await client.accountDataLoading;
|
||||
|
||||
var room = client.getRoomById(id);
|
||||
if (room == null) {
|
||||
if (room == null || (membership != null && room.membership != membership)) {
|
||||
await client.waitForRoomInSync(id).timeout(const Duration(seconds: 30));
|
||||
room = client.getRoomById(id);
|
||||
}
|
||||
|
|
@ -217,15 +218,14 @@ class BackgroundPush {
|
|||
String? sessionRoomId,
|
||||
String? activityId,
|
||||
}) async {
|
||||
Room? room = await _ensureRoomLoaded(roomId);
|
||||
// Handle session room if provided.
|
||||
if (sessionRoomId != null &&
|
||||
sessionRoomId.isNotEmpty &&
|
||||
activityId != null &&
|
||||
activityId.isNotEmpty) {
|
||||
try {
|
||||
final course = await _ensureRoomLoaded(roomId);
|
||||
if (course == null) return;
|
||||
|
||||
if (room == null) return;
|
||||
final session = client.getRoomById(sessionRoomId);
|
||||
if (session?.membership == Membership.join) {
|
||||
FluffyChatApp.router.go('/rooms/$sessionRoomId');
|
||||
|
|
@ -243,9 +243,19 @@ class BackgroundPush {
|
|||
|
||||
// Fallback: just open the original room.
|
||||
try {
|
||||
final room = await _ensureRoomLoaded(roomId);
|
||||
final hasKnocked = room?.hasKnocked;
|
||||
if (hasKnocked == true) {
|
||||
await room!.joinKnockedRoom();
|
||||
room = await _ensureRoomLoaded(roomId, membership: Membership.join);
|
||||
}
|
||||
|
||||
if (room == null || room.membership == Membership.invite) {
|
||||
FluffyChatApp.router.go('/rooms');
|
||||
return;
|
||||
}
|
||||
|
||||
FluffyChatApp.router.go(
|
||||
room?.membership == Membership.invite ? '/rooms' : '/rooms/$roomId',
|
||||
room.isSpace ? '/rooms/spaces/$roomId' : '/rooms/$roomId',
|
||||
);
|
||||
} catch (err, s) {
|
||||
ErrorHandler.logError(e: err, s: s, data: {"roomId": roomId});
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import 'package:fluffychat/pangea/analytics_misc/level_display_name.dart';
|
|||
import 'package:fluffychat/pangea/bot/utils/bot_name.dart';
|
||||
import 'package:fluffychat/pangea/bot/widgets/bot_chat_settings_dialog.dart';
|
||||
import 'package:fluffychat/pangea/extensions/pangea_room_extension.dart';
|
||||
import 'package:fluffychat/pangea/join_codes/knock_room_extension.dart';
|
||||
import 'package:fluffychat/pangea/user/about_me_display.dart';
|
||||
import 'package:fluffychat/widgets/avatar.dart';
|
||||
import 'package:fluffychat/widgets/permission_slider_dialog.dart';
|
||||
|
|
@ -316,7 +317,10 @@ void showMemberActionsPopupMenu({
|
|||
case _MemberActions.approve:
|
||||
await showFutureLoadingDialog(
|
||||
context: context,
|
||||
future: () => user.room.invite(user.id),
|
||||
// #Pangea
|
||||
// future: () => user.room.invite(user.id),
|
||||
future: () => user.room.acceptKnock(user.id),
|
||||
// Pangea#
|
||||
);
|
||||
return;
|
||||
case _MemberActions.kick:
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue