fixed real time bugs
This commit is contained in:
@@ -1143,10 +1143,16 @@ public class ClientHandler implements Runnable {
|
||||
//RealTime
|
||||
if (success) {
|
||||
List<UUID> members = GroupDatabase.getMemberUUIDs(groupId);
|
||||
|
||||
// 1. ارسال ownership_transferred فقط به owner جدید
|
||||
RealTimeEventDispatcher.sendOwnershipTransferred("group", groupId, groupId.toString(), List.of(newOwner.getInternal_uuid()));
|
||||
|
||||
// 2. ارسال update_group_or_channel برای همه اعضا
|
||||
RealTimeEventDispatcher.sendGroupOrChannelUpdate("group", groupId, groupId.toString(), "", "", members);
|
||||
}
|
||||
|
||||
|
||||
|
||||
response = success
|
||||
? new ResponseModel("success", "Ownership transferred.")
|
||||
: new ResponseModel("error", "Failed to transfer ownership.");
|
||||
@@ -1558,9 +1564,15 @@ public class ClientHandler implements Runnable {
|
||||
//RealTime
|
||||
if (success) {
|
||||
List<UUID> subscribers = ChannelDatabase.getChannelSubscriberUUIDs(channelId);
|
||||
|
||||
// 1. ارسال ownership_transferred فقط به owner جدید
|
||||
RealTimeEventDispatcher.sendOwnershipTransferred("channel", channelId, channelId.toString(), List.of(newOwner.getInternal_uuid()));
|
||||
|
||||
// 2. ارسال update_group_or_channel برای بروزرسانی UI تمام افراد
|
||||
RealTimeEventDispatcher.sendGroupOrChannelUpdate("channel", channelId, channelId.toString(), "", "", subscribers);
|
||||
}
|
||||
|
||||
|
||||
response = success
|
||||
|
||||
? new ResponseModel("success", "Ownership transferred successfully.")
|
||||
@@ -1586,7 +1598,7 @@ public class ClientHandler implements Runnable {
|
||||
if (requestJson.has("request_id")) {
|
||||
String requestId = requestJson.getString("request_id");
|
||||
response.setRequestId(requestId);
|
||||
responseJson.put("request_id", requestId); // ✅ بدون این، کلاینت قفل میشه
|
||||
responseJson.put("request_id", requestId);
|
||||
}
|
||||
|
||||
out.println(responseJson.toString());
|
||||
|
||||
@@ -264,7 +264,7 @@ public class RealTimeEventDispatcher {
|
||||
|
||||
public static void notifyBecameAdmin(String type, UUID chatId, String chatName, String imageUrl, UUID userId) {
|
||||
JSONObject data = new JSONObject();
|
||||
data.put("chat_type", type); // group یا channel
|
||||
data.put("chat_type", type); // group or channel
|
||||
data.put("chat_id", chatId.toString());
|
||||
data.put("chat_name", chatName);
|
||||
data.put("image_url", imageUrl);
|
||||
@@ -291,4 +291,18 @@ public class RealTimeEventDispatcher {
|
||||
sendToUser(userId, event);
|
||||
}
|
||||
|
||||
|
||||
public static void sendOwnershipTransferred(String type, UUID chatId, String chatName, List<UUID> affectedUsers) {
|
||||
JSONObject data = new JSONObject();
|
||||
data.put("chat_type", type); // "group" or "channel"
|
||||
data.put("chat_id", chatId.toString());
|
||||
data.put("chat_name", chatName);
|
||||
|
||||
JSONObject event = new JSONObject();
|
||||
event.put("action", "ownership_transferred");
|
||||
event.put("data", data);
|
||||
|
||||
broadcastToUsers(affectedUsers, event);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user