Manage data after login
This commit is contained in:
@@ -21,6 +21,10 @@ public class Channel {
|
||||
this.created_at = created_at;
|
||||
}
|
||||
|
||||
public Channel() {
|
||||
|
||||
}
|
||||
|
||||
public void setChannel_id(String Channel_id){this.channel_id = Channel_id;}
|
||||
public void setCreator_id(UUID creator_id){this.creator_id = creator_id;}
|
||||
public void setChannel_name(String channel_name){this.channel_name = channel_name;}
|
||||
@@ -40,4 +44,6 @@ public class Channel {
|
||||
return this.internal_uuid;
|
||||
}
|
||||
|
||||
public void setInternal_uuid(UUID internalUuid) { this.internal_uuid = internalUuid;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,27 +3,27 @@ package org.to.telegramfinalproject.Models;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.UUID;
|
||||
|
||||
public class ChannelSubscribe {
|
||||
public class ChannelSubscribe{
|
||||
private UUID channel_id;
|
||||
private UUID user_id;
|
||||
private LocalDateTime join_at;
|
||||
private LocalDateTime Subscribed_at;
|
||||
|
||||
|
||||
public ChannelSubscribe(UUID channel_id, UUID user_id, String role){
|
||||
this.channel_id = channel_id;
|
||||
this.user_id = user_id;
|
||||
this.join_at = LocalDateTime.now();
|
||||
this.Subscribed_at = LocalDateTime.now();
|
||||
}
|
||||
|
||||
public void setChannel_id(UUID group_id){this.channel_id = group_id;}
|
||||
public void setUser_id(UUID user_id){this.user_id = user_id;}
|
||||
public void setJoin_at(LocalDateTime join_at){this.join_at = join_at;}
|
||||
public void setJoin_at(LocalDateTime join_at){this.Subscribed_at = join_at;}
|
||||
|
||||
|
||||
|
||||
public UUID getChannel_id(){return this.channel_id;}
|
||||
public UUID getUser_id(){return this.user_id;}
|
||||
public LocalDateTime getJoin_at(){return this.join_at;}
|
||||
public LocalDateTime getJoin_at(){return this.Subscribed_at;}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
package org.to.telegramfinalproject.Models;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
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;
|
||||
|
||||
public ChatEntry(String name, String id, String imageUrl, String type, LocalDateTime lastMessageTime) {
|
||||
this.name = name;
|
||||
this.id = id;
|
||||
this.imageUrl = imageUrl;
|
||||
this.type = type;
|
||||
this.lastMessageTime = lastMessageTime;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getImageUrl() {
|
||||
return imageUrl;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public LocalDateTime getLastMessageTime() {
|
||||
return lastMessageTime;
|
||||
}
|
||||
}
|
||||
@@ -1,23 +1,27 @@
|
||||
package org.to.telegramfinalproject.Models;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class Contact {
|
||||
private UUID user_id;
|
||||
private UUID contact_id;
|
||||
private LocalDateTime add_at;
|
||||
private LocalDateTime added_at;
|
||||
private Boolean is_blocked;
|
||||
|
||||
public Contact(UUID user_id, UUID contact_id){
|
||||
this.user_id = user_id;
|
||||
this.contact_id = contact_id;
|
||||
this.add_at = LocalDateTime.now();
|
||||
this.added_at = LocalDateTime.now();
|
||||
}
|
||||
|
||||
public void setUser_id(UUID user_id){this.user_id = user_id;}
|
||||
public void setContact_id(UUID contact_id){this.contact_id = contact_id;}
|
||||
public void setAdd_at(LocalDateTime add_at){this.add_at =add_at;}
|
||||
public void setAdd_at(LocalDateTime add_at){this.added_at =add_at;}
|
||||
public void setIs_blocked(Boolean is_blocked){this.is_blocked =is_blocked;}
|
||||
|
||||
public UUID getUser_id(){
|
||||
@@ -27,9 +31,14 @@ public class Contact {
|
||||
public UUID getContact_id(){return this.contact_id;}
|
||||
|
||||
public LocalDateTime getAdd_at() {
|
||||
return add_at;
|
||||
return added_at;
|
||||
}
|
||||
public Boolean getIs_blocked(){
|
||||
return is_blocked;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -21,6 +21,10 @@ public class Group {
|
||||
this.created_at = created_at;
|
||||
}
|
||||
|
||||
public Group() {
|
||||
|
||||
}
|
||||
|
||||
public void setGroup_id(String group_id){this.group_id = group_id;}
|
||||
public void setCreator_id(UUID creator_id){this.creator_id = creator_id;}
|
||||
public void setGroup_name(String group_name){this.group_name = group_name;}
|
||||
@@ -40,4 +44,6 @@ public class Group {
|
||||
return this.internal_uuid;
|
||||
}
|
||||
|
||||
public void setInternal_uuid(UUID internalUuid) { this.internal_uuid = internalUuid;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,157 @@
|
||||
package org.to.telegramfinalproject.Models;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class JsonUtil {
|
||||
public static JSONArray contactListToJson(List<Contact> contacts) {
|
||||
|
||||
|
||||
JSONArray array = new JSONArray();
|
||||
for (Contact contact : contacts) {
|
||||
JSONObject obj = new JSONObject();
|
||||
obj.put("user_id", contact.getUser_id().toString());
|
||||
obj.put("contact_id", contact.getContact_id().toString());
|
||||
obj.put("is_blocked", contact.getIs_blocked());
|
||||
obj.put("added_at", contact.getAdd_at().toString());
|
||||
array.put(obj);
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public static JSONObject userToJson(User user) {
|
||||
JSONObject obj = new JSONObject();
|
||||
obj.put("internalUUID", 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());
|
||||
obj.put("bio", user.getBio()!= null ?user.getBio().toString() :JSONObject.NULL);
|
||||
obj.put("image_url", user.getImage_url() != null ?user.getImage_url().toString() :JSONObject.NULL);
|
||||
obj.put("status", user.getStatus());
|
||||
obj.put("last_seen", user.getLast_seen() != null ? user.getLast_seen().toString() : JSONObject.NULL);
|
||||
obj.put("contactList", JsonUtil.contactListToJson(user.getContactList()));
|
||||
obj.put("channelList", JsonUtil.channelListToJson(user.getChannelList()));
|
||||
obj.put("groupList", JsonUtil.groupListToJson(user.getGroupList()));
|
||||
obj.put("unreadMessages", JsonUtil.messageListToJson(user.getUnreadMessages()));
|
||||
return obj;
|
||||
}
|
||||
|
||||
|
||||
public static JSONArray messageListToJson(List<Message> messages) {
|
||||
JSONArray array = new JSONArray();
|
||||
for (Message message : messages) {
|
||||
JSONObject obj = new JSONObject();
|
||||
obj.put("message_id", message.getMessage_id().toString());
|
||||
obj.put("sender_id", message.getSender_id() != null ? message.getSender_id().toString() : JSONObject.NULL);
|
||||
obj.put("receiver_type", message.getReceiver_type());
|
||||
obj.put("receiver_id", message.getReceiver_id().toString());
|
||||
obj.put("content", message.getContent());
|
||||
obj.put("message_type", message.getMessage_type());
|
||||
obj.put("file_url", message.getFile_url());
|
||||
obj.put("send_at", message.getSend_at().toString());
|
||||
obj.put("status", message.getStatus());
|
||||
obj.put("reply_to_id", message.getReply_to_id() != null ? message.getReply_to_id().toString() : JSONObject.NULL);
|
||||
obj.put("is_edited", message.isIs_edited());
|
||||
obj.put("original_message_id", message.getOriginal_message_id() != null ? message.getOriginal_message_id().toString() : JSONObject.NULL);
|
||||
obj.put("forwarded_by", message.getForwarded_by() != null ? message.getForwarded_by().toString() : JSONObject.NULL);
|
||||
obj.put("forwarded_from", message.getForwarded_from() != null ? message.getForwarded_from().toString() : JSONObject.NULL);
|
||||
array.put(obj);
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public static JSONArray groupListToJson(List<Group> groups) {
|
||||
JSONArray array = new JSONArray();
|
||||
for (Group group : groups) {
|
||||
JSONObject obj = new JSONObject();
|
||||
obj.put("internal_uuid", group.getInternal_uuid().toString());
|
||||
obj.put("group_id", group.getGroup_id() != null ?group.getGroup_id().toString() :JSONObject.NULL);
|
||||
obj.put("group_name", group.getGroup_name());
|
||||
obj.put("creator_id", group.getCreator_id().toString());
|
||||
obj.put("image_url",group.getImage_url()!= null ?group.getImage_url().toString() : JSONObject.NULL );
|
||||
obj.put("description", group.getDescription() != null ?group.getDescription().toString() : JSONObject.NULL );
|
||||
obj.put("created_at", group.getCreated_at().toString());
|
||||
obj.put("members", JsonUtil.groupMemberListToJson(group.getMembers()));
|
||||
array.put(obj);
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public static JSONArray channelListToJson(List<Channel> channels) {
|
||||
JSONArray array = new JSONArray();
|
||||
for (Channel channel : channels) {
|
||||
JSONObject obj = new JSONObject();
|
||||
obj.put("internal_uuid",channel.getInternal_uuid().toString());
|
||||
obj.put("channel_id", channel.getChannel_id() != null ?channel.getChannel_id().toString() :JSONObject.NULL);
|
||||
obj.put("channel_name", channel.getChannel_name());
|
||||
obj.put("creator_id", channel.getCreator_id().toString());
|
||||
obj.put("image_url",channel.getImage_url()!= null ?channel.getImage_url().toString() : JSONObject.NULL );
|
||||
obj.put("description",channel.getDescription() != null ?channel.getDescription().toString() : JSONObject.NULL );
|
||||
obj.put("created_at",channel.getCreated_at().toString());
|
||||
obj.put("members", JsonUtil.channelSubscribeToJson(channel.getMembers()));
|
||||
array.put(obj);
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public static JSONArray groupMemberListToJson(List<GroupMember> members) {
|
||||
JSONArray array = new JSONArray();
|
||||
for (GroupMember m : members) {
|
||||
JSONObject obj = new JSONObject();
|
||||
obj.put("group_id", m.getGroup_id().toString());
|
||||
obj.put("user_id", m.getUser_id().toString());
|
||||
obj.put("joined_at", m.getJoin_at().toString());
|
||||
obj.put("role", m.getRole());
|
||||
array.put(obj);
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
public static JSONArray channelSubscribeToJson(List<ChannelSubscribe> subscribes){
|
||||
JSONArray array = new JSONArray();
|
||||
for(ChannelSubscribe s :subscribes ){
|
||||
JSONObject obj = new JSONObject();
|
||||
obj.put("channel_id",s.getChannel_id().toString());
|
||||
obj.put("user_id", s.getUser_id().toString());
|
||||
obj.put("Subscribed_at", s.getJoin_at().toString());
|
||||
}
|
||||
|
||||
return array;
|
||||
}
|
||||
|
||||
|
||||
public static JSONArray chatListToJson(List<ChatEntry> chatList) {
|
||||
JSONArray jsonArray = new JSONArray();
|
||||
|
||||
for (ChatEntry entry : chatList) {
|
||||
JSONObject obj = new JSONObject();
|
||||
obj.put("id", entry.getId() != null ?entry.getId() :JSONObject.NULL);
|
||||
obj.put("name", entry.getName());
|
||||
obj.put("image_url", entry.getImageUrl() != null ?entry.getImageUrl() :JSONObject.NULL);
|
||||
obj.put("type", entry.getType());
|
||||
obj.put("last_message_time", entry.getLastMessageTime() != null ? entry.getLastMessageTime().toString() : JSONObject.NULL);
|
||||
|
||||
jsonArray.put(obj);
|
||||
}
|
||||
|
||||
return jsonArray;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package org.to.telegramfinalproject.Models;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class LoginBootstrapData {
|
||||
private User user;
|
||||
private List<Contact> contacts;
|
||||
private List<Group> groups;
|
||||
private List<Channel> channels;
|
||||
private List<Message> unreadMessages;
|
||||
|
||||
public LoginBootstrapData(User user, List<Contact> contacts, List<Group> groups,
|
||||
List<Channel> channels, List<Message> unreadMessages) {
|
||||
this.user = user;
|
||||
this.contacts = contacts;
|
||||
this.groups = groups;
|
||||
this.channels = channels;
|
||||
this.unreadMessages = unreadMessages;
|
||||
}
|
||||
|
||||
public void setUnreadMessages(List<Message> unreadMessages){this.unreadMessages = unreadMessages;}
|
||||
public void setContacts(List<Contact> contacts){this.contacts =contacts;}
|
||||
public void setGroups(List<Group> groups){this.groups = groups;}
|
||||
public void setChannels(List<Channel> channels){this.channels = channels;}
|
||||
public void setUser(User user){this.user = user;}
|
||||
|
||||
public List<Message> getUnreadMessages(){return unreadMessages;}
|
||||
public List<Group> getGroups(){return groups;}
|
||||
public List<Contact> getContacts(){return contacts;}
|
||||
public List<Channel> getChannels(){return channels;}
|
||||
public User getUser(User user){return user;}
|
||||
}
|
||||
@@ -1,12 +1,23 @@
|
||||
package org.to.telegramfinalproject.Models;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
public class ResponseModel {
|
||||
private String status;
|
||||
private String message;
|
||||
private JSONObject data;
|
||||
|
||||
|
||||
public ResponseModel(String status, String message) {
|
||||
this.status = status;
|
||||
this.message = message;
|
||||
this.data = null;
|
||||
}
|
||||
|
||||
public ResponseModel(String status, String message, JSONObject data) {
|
||||
this.status = status;
|
||||
this.message = message;
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public String getStatus() {
|
||||
@@ -16,4 +27,6 @@ public class ResponseModel {
|
||||
public String getMessage() {
|
||||
return this.message;
|
||||
}
|
||||
|
||||
public JSONObject getData() {return this.data;}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package org.to.telegramfinalproject.Models;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
@@ -17,6 +19,8 @@ public class User {
|
||||
private List<Contact> contactList;
|
||||
private List<Group> groupList;
|
||||
private List<Channel> channelList;
|
||||
private List<Message> unreadMessages;
|
||||
private List<ChatEntry> chatList;
|
||||
|
||||
public User(String user_id, UUID internal_uuid, String username, String password, String profile_name) {
|
||||
this.user_id = user_id;
|
||||
@@ -64,6 +68,10 @@ public class User {
|
||||
|
||||
public void setGroupList(List<Group> groupList){this.groupList = groupList;}
|
||||
|
||||
public void setUnreadMessages(List<Message> unreadMessages){this.unreadMessages = unreadMessages;}
|
||||
|
||||
public void setChatList(List<ChatEntry> chatList){this.chatList = chatList;}
|
||||
|
||||
public UUID getInternal_uuid() {
|
||||
return this.internal_uuid;
|
||||
}
|
||||
@@ -105,5 +113,13 @@ public class User {
|
||||
public List<Channel> getChannelList(){return this.channelList;}
|
||||
|
||||
public List<Group> getGroupList(){return this.groupList;}
|
||||
|
||||
public List<Message> getUnreadMessages(){return this.unreadMessages;}
|
||||
|
||||
public List<ChatEntry> getChatList(){return this.chatList;}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user