mirror of
https://gitlab.com/famedly/fluffychat.git
synced 2024-11-19 10:39:26 +01:00
Merge branch 'krille/fix-push' into 'main'
chore: Follow up fix push See merge request famedly/fluffychat!828
This commit is contained in:
commit
3e260a0d07
@ -1,8 +1,6 @@
|
|||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
import 'dart:ui';
|
import 'dart:ui';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
|
|
||||||
import 'package:flutter_cache_manager/flutter_cache_manager.dart';
|
import 'package:flutter_cache_manager/flutter_cache_manager.dart';
|
||||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||||
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
|
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
|
||||||
@ -63,50 +61,53 @@ Future<void> pushHelper(
|
|||||||
l10n ??= await L10n.delegate.load(window.locale);
|
l10n ??= await L10n.delegate.load(window.locale);
|
||||||
final matrixLocals = MatrixLocals(l10n);
|
final matrixLocals = MatrixLocals(l10n);
|
||||||
|
|
||||||
// Display notification// Calculate title
|
|
||||||
final title = l10n.unreadMessages(notification.counts?.unread ?? 1);
|
|
||||||
|
|
||||||
// Calculate the body
|
// Calculate the body
|
||||||
final body = event.getLocalizedBody(
|
final body = event.getLocalizedBody(
|
||||||
matrixLocals,
|
matrixLocals,
|
||||||
plaintextBody: true,
|
plaintextBody: true,
|
||||||
|
withSenderNamePrefix: !event.room.isDirectChat,
|
||||||
hideReply: true,
|
hideReply: true,
|
||||||
hideEdit: true,
|
hideEdit: true,
|
||||||
removeMarkdown: true,
|
removeMarkdown: true,
|
||||||
);
|
);
|
||||||
|
|
||||||
// The person object for the android message style notification
|
// The person object for the android message style notification
|
||||||
if (isBackgroundMessage) WidgetsFlutterBinding.ensureInitialized();
|
final avatar = event.room.avatar
|
||||||
final avatar = event.room.avatar?.toString();
|
?.getThumbnail(
|
||||||
|
client,
|
||||||
|
width: 126,
|
||||||
|
height: 126,
|
||||||
|
)
|
||||||
|
.toString();
|
||||||
final avatarFile =
|
final avatarFile =
|
||||||
avatar == null ? null : await DefaultCacheManager().getSingleFile(avatar);
|
avatar == null ? null : await DefaultCacheManager().getSingleFile(avatar);
|
||||||
|
|
||||||
final person = Person(
|
|
||||||
name: event.room.getLocalizedDisplayname(matrixLocals),
|
|
||||||
icon:
|
|
||||||
avatarFile == null ? null : BitmapFilePathAndroidIcon(avatarFile.path),
|
|
||||||
);
|
|
||||||
|
|
||||||
// Show notification
|
// Show notification
|
||||||
final androidPlatformChannelSpecifics = AndroidNotificationDetails(
|
final androidPlatformChannelSpecifics = AndroidNotificationDetails(
|
||||||
AppConfig.pushNotificationsChannelId,
|
AppConfig.pushNotificationsChannelId,
|
||||||
AppConfig.pushNotificationsChannelName,
|
AppConfig.pushNotificationsChannelName,
|
||||||
channelDescription: AppConfig.pushNotificationsChannelDescription,
|
channelDescription: AppConfig.pushNotificationsChannelDescription,
|
||||||
styleInformation: MessagingStyleInformation(
|
styleInformation: MessagingStyleInformation(
|
||||||
person,
|
Person(name: event.room.client.userID),
|
||||||
conversationTitle: title,
|
conversationTitle: event.room.displayname,
|
||||||
groupConversation: !event.room.isDirectChat,
|
groupConversation: !event.room.isDirectChat,
|
||||||
messages: [
|
messages: [
|
||||||
Message(
|
Message(
|
||||||
body,
|
body,
|
||||||
event.originServerTs,
|
event.originServerTs,
|
||||||
person,
|
Person(
|
||||||
|
name: event.room.displayname,
|
||||||
|
icon: avatarFile == null
|
||||||
|
? null
|
||||||
|
: BitmapFilePathAndroidIcon(avatarFile.path),
|
||||||
|
),
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
ticker: l10n.newMessageInFluffyChat,
|
ticker: l10n.unreadChats(notification.counts?.unread ?? 1),
|
||||||
importance: Importance.max,
|
importance: Importance.max,
|
||||||
priority: Priority.high,
|
priority: Priority.high,
|
||||||
|
groupKey: event.room.id,
|
||||||
);
|
);
|
||||||
const iOSPlatformChannelSpecifics = IOSNotificationDetails();
|
const iOSPlatformChannelSpecifics = IOSNotificationDetails();
|
||||||
final platformChannelSpecifics = NotificationDetails(
|
final platformChannelSpecifics = NotificationDetails(
|
||||||
@ -128,8 +129,8 @@ Future<void> pushHelper(
|
|||||||
/// IDs we map the [roomId] to a number and store this number.
|
/// IDs we map the [roomId] to a number and store this number.
|
||||||
Future<int> mapRoomIdToInt(String roomId) async {
|
Future<int> mapRoomIdToInt(String roomId) async {
|
||||||
final store = await SharedPreferences.getInstance();
|
final store = await SharedPreferences.getInstance();
|
||||||
final idMap = Map<String, int>.from(jsonDecode(
|
final idMap = Map<String, int>.from(
|
||||||
(store.getString(SettingKeys.notificationCurrentIds)) ?? '{}'));
|
jsonDecode(store.getString(SettingKeys.notificationCurrentIds) ?? '{}'));
|
||||||
int? currentInt;
|
int? currentInt;
|
||||||
try {
|
try {
|
||||||
currentInt = idMap[roomId];
|
currentInt = idMap[roomId];
|
||||||
@ -140,7 +141,7 @@ Future<int> mapRoomIdToInt(String roomId) async {
|
|||||||
return currentInt;
|
return currentInt;
|
||||||
}
|
}
|
||||||
var nCurrentInt = 0;
|
var nCurrentInt = 0;
|
||||||
while (idMap.values.contains(currentInt)) {
|
while (idMap.values.contains(nCurrentInt)) {
|
||||||
nCurrentInt++;
|
nCurrentInt++;
|
||||||
}
|
}
|
||||||
idMap[roomId] = nCurrentInt;
|
idMap[roomId] = nCurrentInt;
|
||||||
|
Loading…
Reference in New Issue
Block a user