Добавлена поддержка вывода имени пользователя в уведомлениях
This commit is contained in:
@@ -110,15 +110,29 @@ public class FirebaseDispatcher {
|
||||
* @param title заголовок уведомления
|
||||
* @param messageText текст уведомления
|
||||
*/
|
||||
public void sendPushNotification(List<String> publicKeys, String title, String messageText) {
|
||||
public void sendPushNotification(List<String> publicKeys, String title, String messageText, String senderPublicKey) {
|
||||
executor.submit(() -> {
|
||||
for (String publicKey : publicKeys) {
|
||||
sendPushNotificationSync(publicKey, title, messageText);
|
||||
sendPushNotificationSync(publicKey, title, messageText, senderPublicKey);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void sendPushNotificationSync(String publicKey, String title, String messageText) {
|
||||
/**
|
||||
* Отправляет push-уведомление нескольким пользователям (асинхронно)
|
||||
* @param publicKeys список публичных ключей пользователей
|
||||
* @param title заголовок уведомления
|
||||
* @param messageText текст уведомления
|
||||
*/
|
||||
public void sendPushNotification(List<String> publicKeys, String title, String messageText) {
|
||||
executor.submit(() -> {
|
||||
for (String publicKey : publicKeys) {
|
||||
sendPushNotificationSync(publicKey, title, messageText, null);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void sendPushNotificationSync(String publicKey, String title, String messageText, String senderPublicKey) {
|
||||
try {
|
||||
List<String> tokens = userService.getNotificationsTokens(publicKey);
|
||||
if (tokens == null || tokens.isEmpty()) {
|
||||
|
||||
@@ -4,13 +4,15 @@ import java.util.List;
|
||||
|
||||
import im.rosetta.client.ClientManager;
|
||||
import im.rosetta.client.tags.ECIAuthentificate;
|
||||
import im.rosetta.database.entity.User;
|
||||
import im.rosetta.database.repository.BufferRepository;
|
||||
import im.rosetta.database.repository.GroupRepository;
|
||||
import im.rosetta.database.repository.UserRepository;
|
||||
import im.rosetta.packet.Packet11Typeing;
|
||||
import im.rosetta.packet.Packet7Read;
|
||||
import im.rosetta.packet.base.PacketBaseDialog;
|
||||
import im.rosetta.service.services.BufferService;
|
||||
|
||||
import im.rosetta.service.services.UserService;
|
||||
import io.orprotocol.ProtocolException;
|
||||
import io.orprotocol.client.Client;
|
||||
import io.orprotocol.packet.PacketManager;
|
||||
@@ -29,6 +31,8 @@ public class MessageDispatcher {
|
||||
private final BufferRepository bufferRepository = new BufferRepository();
|
||||
private final BufferService bufferService;
|
||||
private final FirebaseDispatcher firebaseDispatcher = new FirebaseDispatcher();
|
||||
private final UserRepository userRepository = new UserRepository();
|
||||
private final UserService userService = new UserService(userRepository);
|
||||
|
||||
public MessageDispatcher(ClientManager clientManager, PacketManager packetManager) {
|
||||
this.clientManager = clientManager;
|
||||
@@ -101,7 +105,7 @@ public class MessageDispatcher {
|
||||
/**
|
||||
* Отправляем PUSH уведомление
|
||||
*/
|
||||
this.firebaseDispatcher.sendPushNotification(groupMembersPublicKeys, "Rosetta", "New message in group");
|
||||
this.firebaseDispatcher.sendPushNotification(groupMembersPublicKeys, "Rosetta", "New message in group", toPublicKey.replace("#group:", ""));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -115,7 +119,13 @@ public class MessageDispatcher {
|
||||
public void sendPeer(PacketBaseDialog packet, Client client, boolean bufferizationNeed) throws ProtocolException {
|
||||
String fromPublicKey = packet.getFromPublicKey();
|
||||
String toPublicKey = packet.getToPublicKey();
|
||||
|
||||
User user = this.userService.fromClient(client);
|
||||
if(user == null){
|
||||
/**
|
||||
* Если пользователь не найден, то не отправляем сообщение, так как у нас нет информации о том, кто отправляет сообщение
|
||||
*/
|
||||
return;
|
||||
}
|
||||
/**
|
||||
* Ретранслируем сообщение ВСЕМ авторизованным сессиям отправителя КРОМЕ текущей,
|
||||
* чтобы синхронизировать отправленные сообщения
|
||||
@@ -154,7 +164,7 @@ public class MessageDispatcher {
|
||||
/**
|
||||
* Отправляем PUSH уведомление получателю
|
||||
*/
|
||||
this.firebaseDispatcher.sendPushNotification(toPublicKey, "Rosetta", "New message");
|
||||
this.firebaseDispatcher.sendPushNotification(toPublicKey, user.getTitle(), "New message");
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user