RealTime and openChat
This commit is contained in:
@@ -1,28 +1,70 @@
|
||||
package org.to.telegramfinalproject.Models;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.UUID;
|
||||
|
||||
public class ChatEntry {
|
||||
private final String name;
|
||||
private final String id;
|
||||
private final String imageUrl;
|
||||
private final String type; // "private", "group", "channel"
|
||||
private final LocalDateTime lastMessageTime;
|
||||
private UUID internalId;
|
||||
private String displayId;
|
||||
private String name;
|
||||
private String imageUrl;
|
||||
private String type;
|
||||
private LocalDateTime lastMessageTime;
|
||||
|
||||
public ChatEntry(String name, String id, String imageUrl, String type, LocalDateTime lastMessageTime) {
|
||||
// 🔹 نقشها
|
||||
private boolean isOwner = false;
|
||||
private boolean isAdmin = false;
|
||||
private JSONObject permissions;
|
||||
|
||||
|
||||
public ChatEntry(UUID internalId, String displayId, String name, String imageUrl, String type, LocalDateTime lastMessageTime) {
|
||||
this.internalId = internalId;
|
||||
this.displayId = displayId;
|
||||
this.name = name;
|
||||
this.id = id;
|
||||
this.imageUrl = imageUrl;
|
||||
this.type = type;
|
||||
this.lastMessageTime = lastMessageTime;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
// ✅ کانستراکتور اضافهشده برای پشتیبانی از نقشها (اختیاری، برای استفادههای جدید)
|
||||
public ChatEntry(UUID internalId, String displayId, String name, String imageUrl, String type, LocalDateTime lastMessageTime, boolean isOwner, boolean isAdmin) {
|
||||
this(internalId, displayId, name, imageUrl, type, lastMessageTime);
|
||||
this.isOwner = isOwner;
|
||||
this.isAdmin = isAdmin;
|
||||
this.permissions = permissions;
|
||||
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
// 🟩 گتر و ستر جدید
|
||||
public boolean isOwner() {
|
||||
return isOwner;
|
||||
}
|
||||
|
||||
public void setOwner(boolean owner) {
|
||||
isOwner = owner;
|
||||
}
|
||||
|
||||
public boolean isAdmin() {
|
||||
return isAdmin;
|
||||
}
|
||||
|
||||
public void setAdmin(boolean admin) {
|
||||
isAdmin = admin;
|
||||
}
|
||||
|
||||
// سایر گترها
|
||||
public UUID getId() {
|
||||
return internalId;
|
||||
}
|
||||
|
||||
public String getDisplayId() {
|
||||
return displayId;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getImageUrl() {
|
||||
@@ -36,4 +78,13 @@ public class ChatEntry {
|
||||
public LocalDateTime getLastMessageTime() {
|
||||
return lastMessageTime;
|
||||
}
|
||||
|
||||
|
||||
public JSONObject getPermissions() {
|
||||
return permissions;
|
||||
}
|
||||
|
||||
public void setPermissions(JSONObject permissions) {
|
||||
this.permissions = permissions;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ public class JsonUtil {
|
||||
|
||||
public static JSONObject userToJson(User user) {
|
||||
JSONObject obj = new JSONObject();
|
||||
obj.put("internalUUID", user.getInternal_uuid().toString());
|
||||
obj.put("internal_uuid", user.getInternal_uuid().toString());
|
||||
obj.put("user_id", user.getUser_id() != null ?user.getUser_id().toString() :JSONObject.NULL);
|
||||
obj.put("username", user.getUsername());
|
||||
obj.put("profile_name", user.getProfile_name());
|
||||
@@ -154,11 +154,15 @@ public class JsonUtil {
|
||||
|
||||
for (ChatEntry entry : chatList) {
|
||||
JSONObject obj = new JSONObject();
|
||||
obj.put("id", entry.getId() != null ?entry.getId() :JSONObject.NULL);
|
||||
obj.put("internal_id", entry.getId().toString());
|
||||
obj.put("id", entry.getDisplayId());
|
||||
obj.put("name", entry.getName());
|
||||
obj.put("image_url", entry.getImageUrl() != null ?entry.getImageUrl() :JSONObject.NULL);
|
||||
obj.put("image_url", entry.getImageUrl());
|
||||
obj.put("type", entry.getType());
|
||||
obj.put("last_message_time", entry.getLastMessageTime() != null ? entry.getLastMessageTime().toString() : JSONObject.NULL);
|
||||
obj.put("last_message_time", entry.getLastMessageTime() == null ? JSONObject.NULL : entry.getLastMessageTime().toString());
|
||||
obj.put("is_owner", entry.isOwner());
|
||||
obj.put("is_admin", entry.isAdmin());
|
||||
|
||||
|
||||
jsonArray.put(obj);
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import java.time.LocalDateTime;
|
||||
import java.util.UUID;
|
||||
|
||||
public class PrivateChat {
|
||||
private UUID chat_id;
|
||||
private final UUID chat_id;
|
||||
private UUID user1_id;
|
||||
private UUID user2_id;
|
||||
private LocalDateTime created_at;
|
||||
|
||||
Reference in New Issue
Block a user