SlideShare a Scribd company logo
1 of 16
Download to read offline
Creating a WhatsApp Clone - Part XII
Lets continue with the other entities. I’ll skip media as it’s just a copy and paste of the facebook media class and partially implemented to boot.
@Entity
@Indexed
public class ChatGroup {
@Id
private String id;
@Field
private String name;
@Field
private String tagline;
@Temporal(TemporalType.DATE)
private Date creationDate;
@ManyToOne
private Media avatar;
@ManyToOne
ChatGroup
ChatGroup is an entity that wraps the concept of a group. In a sense it’s similar to the User entity but has no phone
@Entity
@Indexed
public class ChatGroup {
@Id
private String id;
@Field
private String name;
@Field
private String tagline;
@Temporal(TemporalType.DATE)
private Date creationDate;
@ManyToOne
private Media avatar;
@ManyToOne
ChatGroup
All of these properties, the id, name, tagline, creation date and even avatar are a part of a group.
@Temporal(TemporalType.DATE)
private Date creationDate;
@ManyToOne
private Media avatar;
@ManyToOne
private User createdBy;
@OneToMany
@OrderBy("name ASC")
private Set<User> admins;
@OneToMany
@OrderBy("name ASC")
private Set<User> members;
public ChatGroup() {
id = UUID.randomUUID().toString();
}
ChatGroup
However, unlike a regular user a group is effectively created by a user
@Temporal(TemporalType.DATE)
private Date creationDate;
@ManyToOne
private Media avatar;
@ManyToOne
private User createdBy;
@OneToMany
@OrderBy("name ASC")
private Set<User> admins;
@OneToMany
@OrderBy("name ASC")
private Set<User> members;
public ChatGroup() {
id = UUID.randomUUID().toString();
}
ChatGroup
A group also has two lists of group administrators and group members
package com.codename1.whatsapp.server.entities;
import org.springframework.data.repository.CrudRepository;
public interface ChatGroupRepository extends
CrudRepository<ChatGroup, String> {
}
ChatGroupRepository
The chat group repository is empty as this is a feature we didn’t finish
@Entity
@Indexed
public class ChatMessage {
@Id
private String id;
@ManyToOne
private User author;
@ManyToOne
private User sentTo;
@ManyToOne
private ChatGroup sentToGroup;
@Temporal(TemporalType.TIMESTAMP)
private Date messageTime;
private String body;
ChatMessage
A chat message must be stored on servers for a while. If your device isn’t connected at this moment (e.g. flight) the server would need to keep the message until you’re
available again. It can then be purged. If we wish to be very secure we can encrypt the message based on a client public key, that way no one in the middle could “peek”
into the message. This should be easy enough to implement but I didn’t get around to do it, this would mostly be client side work. Here we store messages so they can
be fetched by the app.

Like everything else we have a unique string id per message
@Entity
@Indexed
public class ChatMessage {
@Id
private String id;
@ManyToOne
private User author;
@ManyToOne
private User sentTo;
@ManyToOne
private ChatGroup sentToGroup;
@Temporal(TemporalType.TIMESTAMP)
private Date messageTime;
private String body;
ChatMessage
Every message naturally has an author of that message
@Entity
@Indexed
public class ChatMessage {
@Id
private String id;
@ManyToOne
private User author;
@ManyToOne
private User sentTo;
@ManyToOne
private ChatGroup sentToGroup;
@Temporal(TemporalType.TIMESTAMP)
private Date messageTime;
private String body;
ChatGroupRepository
But more importantly a destination which can be either a different user or a group. Not both…
private User author;
@ManyToOne
private User sentTo;
@ManyToOne
private ChatGroup sentToGroup;
@Temporal(TemporalType.TIMESTAMP)
private Date messageTime;
private String body;
private boolean ack;
@OneToMany
@OrderBy("date ASC")
private Set<Media> attachments;
public ChatMessage() {
id = UUID.randomUUID().toString();
}
ChatMessage
Every message has a date time stamp for when it was sent
private User author;
@ManyToOne
private User sentTo;
@ManyToOne
private ChatGroup sentToGroup;
@Temporal(TemporalType.TIMESTAMP)
private Date messageTime;
private String body;
private boolean ack;
@OneToMany
@OrderBy("date ASC")
private Set<Media> attachments;
public ChatMessage() {
id = UUID.randomUUID().toString();
}
ChatMessage
The message has a text body alway, it can be null though
private User author;
@ManyToOne
private User sentTo;
@ManyToOne
private ChatGroup sentToGroup;
@Temporal(TemporalType.TIMESTAMP)
private Date messageTime;
private String body;
private boolean ack;
@OneToMany
@OrderBy("date ASC")
private Set<Media> attachments;
public ChatMessage() {
id = UUID.randomUUID().toString();
}
ChatMessage
If we have media attachments to the message
private User author;
@ManyToOne
private User sentTo;
@ManyToOne
private ChatGroup sentToGroup;
@Temporal(TemporalType.TIMESTAMP)
private Date messageTime;
private String body;
private boolean ack;
@OneToMany
@OrderBy("date ASC")
private Set<Media> attachments;
public ChatMessage() {
id = UUID.randomUUID().toString();
}
ChatMessage
The ack flag indicates whether the client acknowledged receiving the message. This works great for one-to-one messages but a message sent to a group would probably
need a more elaborate ack implementation.
@OneToMany
@OrderBy("date ASC")
private Set<Media> attachments;
public ChatMessage() {
id = UUID.randomUUID().toString();
}
public MessageDAO getDAO() {
String[] a;
if(attachments != null && !attachments.isEmpty()) {
a = new String[attachments.size()];
Iterator<Media> i = attachments.iterator();
for(int iter = 0 ; iter < a.length ; iter++) {
a[iter] = i.next().getId();
}
} else {
a = new String[0];
}
return new MessageDAO(id, author.getId(),
sentTo != null ? sentTo.getId() : sentToGroup.getId(),
messageTime, body, a);
}
ChatMessage
The DAO is again practically copied from the facebook app, we can include the id’s for the attachments as part of the message
package com.codename1.whatsapp.server.entities;
import java.util.List;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
public interface ChatMessageRepository extends
CrudRepository<ChatMessage, String> {
@Query("select n from ChatMessage n where n.ack = false and "
+ "n.sentTo.id = ?1 order by messageTime asc")
public List<ChatMessage> findByUnAcked(String sentTo);
}
ChatMessageRepository
The chat message repository includes one find method which helps us find messages that we didn’t acknowledge yet. If a specific user has pending messages this
finder is used to locate such messages and send them again.
import com.fasterxml.jackson.annotation.JsonFormat;
import java.util.Date;
public class MessageDAO {
private String id;
private String authorId;
private String sentTo;
@JsonFormat(pattern="yyyy-MM-dd'T'HH:mm:ss.SSS")
private Date time;
private String body;
private String[] attachments;
public MessageDAO() {
}
public MessageDAO(String id, String authorId, String sentTo,
Date time, String body, String[] attachments) {
this.id = id;
this.authorId = authorId;
this.sentTo = sentTo;
this.time = time;
this.body = body;
MessageDAO
The MessageDAO entry represents the current message. It maps pretty accurately to the entity object.

With that we are effectively done with the entity and DAO layers. There is still an ErrorDAO but it’s effectively identical to what we had in the facebook app and is totally
trivial so I’ll skip that.

More Related Content

Similar to Creating a Whatsapp Clone - Part XII - Transcript.pdf

Creating a Whatsapp Clone - Part XI.pdf
Creating a Whatsapp Clone - Part XI.pdfCreating a Whatsapp Clone - Part XI.pdf
Creating a Whatsapp Clone - Part XI.pdfShaiAlmog1
 
WhatsApp Chat Hacking/Stealing POC
WhatsApp Chat Hacking/Stealing POCWhatsApp Chat Hacking/Stealing POC
WhatsApp Chat Hacking/Stealing POCE Hacking
 
Creating a Facebook Clone - Part XVIII.pdf
Creating a Facebook Clone - Part XVIII.pdfCreating a Facebook Clone - Part XVIII.pdf
Creating a Facebook Clone - Part XVIII.pdfShaiAlmog1
 
Creating a Facebook Clone - Part XX.pdf
Creating a Facebook Clone - Part XX.pdfCreating a Facebook Clone - Part XX.pdf
Creating a Facebook Clone - Part XX.pdfShaiAlmog1
 
Beyond Logging: Using MongoDB to Power a Private Social Network (Oh, and log ...
Beyond Logging: Using MongoDB to Power a Private Social Network (Oh, and log ...Beyond Logging: Using MongoDB to Power a Private Social Network (Oh, and log ...
Beyond Logging: Using MongoDB to Power a Private Social Network (Oh, and log ...justinjenkins
 
Creating a Facebook Clone - Part XXXI - Transcript.pdf
Creating a Facebook Clone - Part XXXI - Transcript.pdfCreating a Facebook Clone - Part XXXI - Transcript.pdf
Creating a Facebook Clone - Part XXXI - Transcript.pdfShaiAlmog1
 
Creating a Whatsapp Clone - Part III - Transcript.pdf
Creating a Whatsapp Clone - Part III - Transcript.pdfCreating a Whatsapp Clone - Part III - Transcript.pdf
Creating a Whatsapp Clone - Part III - Transcript.pdfShaiAlmog1
 
Development of Twitter Application #4 - Timeline and Tweet
Development of Twitter Application #4 - Timeline and TweetDevelopment of Twitter Application #4 - Timeline and Tweet
Development of Twitter Application #4 - Timeline and TweetMyungjin Lee
 
Creating a Facebook Clone - Part XIX.pdf
Creating a Facebook Clone - Part XIX.pdfCreating a Facebook Clone - Part XIX.pdf
Creating a Facebook Clone - Part XIX.pdfShaiAlmog1
 
Creating a Facebook Clone - Part XXXVIII.pdf
Creating a Facebook Clone - Part XXXVIII.pdfCreating a Facebook Clone - Part XXXVIII.pdf
Creating a Facebook Clone - Part XXXVIII.pdfShaiAlmog1
 
Project: Call Center Management
Project: Call Center ManagementProject: Call Center Management
Project: Call Center Managementpritamkumar
 
Creating an Uber Clone - Part XI.pdf
Creating an Uber Clone - Part XI.pdfCreating an Uber Clone - Part XI.pdf
Creating an Uber Clone - Part XI.pdfShaiAlmog1
 
Creating a Whatsapp Clone - Part III.pdf
Creating a Whatsapp Clone - Part III.pdfCreating a Whatsapp Clone - Part III.pdf
Creating a Whatsapp Clone - Part III.pdfShaiAlmog1
 
Naming Standards, Clean Code
Naming Standards, Clean CodeNaming Standards, Clean Code
Naming Standards, Clean CodeCleanestCode
 
Social data analysis using apache flume, hdfs, hive
Social data analysis using apache flume, hdfs, hiveSocial data analysis using apache flume, hdfs, hive
Social data analysis using apache flume, hdfs, hiveijctet
 
Creating a Facebook Clone - Part XVII.pdf
Creating a Facebook Clone - Part XVII.pdfCreating a Facebook Clone - Part XVII.pdf
Creating a Facebook Clone - Part XVII.pdfShaiAlmog1
 

Similar to Creating a Whatsapp Clone - Part XII - Transcript.pdf (20)

Creating a Whatsapp Clone - Part XI.pdf
Creating a Whatsapp Clone - Part XI.pdfCreating a Whatsapp Clone - Part XI.pdf
Creating a Whatsapp Clone - Part XI.pdf
 
WhatsApp Chat Hacking/Stealing POC
WhatsApp Chat Hacking/Stealing POCWhatsApp Chat Hacking/Stealing POC
WhatsApp Chat Hacking/Stealing POC
 
Creating a Facebook Clone - Part XVIII.pdf
Creating a Facebook Clone - Part XVIII.pdfCreating a Facebook Clone - Part XVIII.pdf
Creating a Facebook Clone - Part XVIII.pdf
 
Creating a Facebook Clone - Part XX.pdf
Creating a Facebook Clone - Part XX.pdfCreating a Facebook Clone - Part XX.pdf
Creating a Facebook Clone - Part XX.pdf
 
Beyond Logging: Using MongoDB to Power a Private Social Network (Oh, and log ...
Beyond Logging: Using MongoDB to Power a Private Social Network (Oh, and log ...Beyond Logging: Using MongoDB to Power a Private Social Network (Oh, and log ...
Beyond Logging: Using MongoDB to Power a Private Social Network (Oh, and log ...
 
Social Aggregator Paper
Social Aggregator PaperSocial Aggregator Paper
Social Aggregator Paper
 
Creating a Facebook Clone - Part XXXI - Transcript.pdf
Creating a Facebook Clone - Part XXXI - Transcript.pdfCreating a Facebook Clone - Part XXXI - Transcript.pdf
Creating a Facebook Clone - Part XXXI - Transcript.pdf
 
Creating a Whatsapp Clone - Part III - Transcript.pdf
Creating a Whatsapp Clone - Part III - Transcript.pdfCreating a Whatsapp Clone - Part III - Transcript.pdf
Creating a Whatsapp Clone - Part III - Transcript.pdf
 
Java Persistence API
Java Persistence APIJava Persistence API
Java Persistence API
 
Android
AndroidAndroid
Android
 
Development of Twitter Application #4 - Timeline and Tweet
Development of Twitter Application #4 - Timeline and TweetDevelopment of Twitter Application #4 - Timeline and Tweet
Development of Twitter Application #4 - Timeline and Tweet
 
Creating a Facebook Clone - Part XIX.pdf
Creating a Facebook Clone - Part XIX.pdfCreating a Facebook Clone - Part XIX.pdf
Creating a Facebook Clone - Part XIX.pdf
 
Creating a Facebook Clone - Part XXXVIII.pdf
Creating a Facebook Clone - Part XXXVIII.pdfCreating a Facebook Clone - Part XXXVIII.pdf
Creating a Facebook Clone - Part XXXVIII.pdf
 
Project: Call Center Management
Project: Call Center ManagementProject: Call Center Management
Project: Call Center Management
 
Creating an Uber Clone - Part XI.pdf
Creating an Uber Clone - Part XI.pdfCreating an Uber Clone - Part XI.pdf
Creating an Uber Clone - Part XI.pdf
 
Creating a Whatsapp Clone - Part III.pdf
Creating a Whatsapp Clone - Part III.pdfCreating a Whatsapp Clone - Part III.pdf
Creating a Whatsapp Clone - Part III.pdf
 
Naming Standards, Clean Code
Naming Standards, Clean CodeNaming Standards, Clean Code
Naming Standards, Clean Code
 
Social data analysis using apache flume, hdfs, hive
Social data analysis using apache flume, hdfs, hiveSocial data analysis using apache flume, hdfs, hive
Social data analysis using apache flume, hdfs, hive
 
Green dao 3.0
Green dao 3.0Green dao 3.0
Green dao 3.0
 
Creating a Facebook Clone - Part XVII.pdf
Creating a Facebook Clone - Part XVII.pdfCreating a Facebook Clone - Part XVII.pdf
Creating a Facebook Clone - Part XVII.pdf
 

More from ShaiAlmog1

The Duck Teaches Learn to debug from the masters. Local to production- kill ...
The Duck Teaches  Learn to debug from the masters. Local to production- kill ...The Duck Teaches  Learn to debug from the masters. Local to production- kill ...
The Duck Teaches Learn to debug from the masters. Local to production- kill ...ShaiAlmog1
 
create-netflix-clone-06-client-ui.pdf
create-netflix-clone-06-client-ui.pdfcreate-netflix-clone-06-client-ui.pdf
create-netflix-clone-06-client-ui.pdfShaiAlmog1
 
create-netflix-clone-01-introduction_transcript.pdf
create-netflix-clone-01-introduction_transcript.pdfcreate-netflix-clone-01-introduction_transcript.pdf
create-netflix-clone-01-introduction_transcript.pdfShaiAlmog1
 
create-netflix-clone-02-server_transcript.pdf
create-netflix-clone-02-server_transcript.pdfcreate-netflix-clone-02-server_transcript.pdf
create-netflix-clone-02-server_transcript.pdfShaiAlmog1
 
create-netflix-clone-04-server-continued_transcript.pdf
create-netflix-clone-04-server-continued_transcript.pdfcreate-netflix-clone-04-server-continued_transcript.pdf
create-netflix-clone-04-server-continued_transcript.pdfShaiAlmog1
 
create-netflix-clone-01-introduction.pdf
create-netflix-clone-01-introduction.pdfcreate-netflix-clone-01-introduction.pdf
create-netflix-clone-01-introduction.pdfShaiAlmog1
 
create-netflix-clone-06-client-ui_transcript.pdf
create-netflix-clone-06-client-ui_transcript.pdfcreate-netflix-clone-06-client-ui_transcript.pdf
create-netflix-clone-06-client-ui_transcript.pdfShaiAlmog1
 
create-netflix-clone-03-server.pdf
create-netflix-clone-03-server.pdfcreate-netflix-clone-03-server.pdf
create-netflix-clone-03-server.pdfShaiAlmog1
 
create-netflix-clone-04-server-continued.pdf
create-netflix-clone-04-server-continued.pdfcreate-netflix-clone-04-server-continued.pdf
create-netflix-clone-04-server-continued.pdfShaiAlmog1
 
create-netflix-clone-05-client-model_transcript.pdf
create-netflix-clone-05-client-model_transcript.pdfcreate-netflix-clone-05-client-model_transcript.pdf
create-netflix-clone-05-client-model_transcript.pdfShaiAlmog1
 
create-netflix-clone-02-server.pdf
create-netflix-clone-02-server.pdfcreate-netflix-clone-02-server.pdf
create-netflix-clone-02-server.pdfShaiAlmog1
 
create-netflix-clone-05-client-model.pdf
create-netflix-clone-05-client-model.pdfcreate-netflix-clone-05-client-model.pdf
create-netflix-clone-05-client-model.pdfShaiAlmog1
 
Creating a Whatsapp Clone - Part II.pdf
Creating a Whatsapp Clone - Part II.pdfCreating a Whatsapp Clone - Part II.pdf
Creating a Whatsapp Clone - Part II.pdfShaiAlmog1
 
Creating a Whatsapp Clone - Part IX - Transcript.pdf
Creating a Whatsapp Clone - Part IX - Transcript.pdfCreating a Whatsapp Clone - Part IX - Transcript.pdf
Creating a Whatsapp Clone - Part IX - Transcript.pdfShaiAlmog1
 
Creating a Whatsapp Clone - Part II - Transcript.pdf
Creating a Whatsapp Clone - Part II - Transcript.pdfCreating a Whatsapp Clone - Part II - Transcript.pdf
Creating a Whatsapp Clone - Part II - Transcript.pdfShaiAlmog1
 
Creating a Whatsapp Clone - Part V - Transcript.pdf
Creating a Whatsapp Clone - Part V - Transcript.pdfCreating a Whatsapp Clone - Part V - Transcript.pdf
Creating a Whatsapp Clone - Part V - Transcript.pdfShaiAlmog1
 
Creating a Whatsapp Clone - Part IV.pdf
Creating a Whatsapp Clone - Part IV.pdfCreating a Whatsapp Clone - Part IV.pdf
Creating a Whatsapp Clone - Part IV.pdfShaiAlmog1
 
Creating a Whatsapp Clone - Part I - Transcript.pdf
Creating a Whatsapp Clone - Part I - Transcript.pdfCreating a Whatsapp Clone - Part I - Transcript.pdf
Creating a Whatsapp Clone - Part I - Transcript.pdfShaiAlmog1
 
Creating a Whatsapp Clone - Part IX.pdf
Creating a Whatsapp Clone - Part IX.pdfCreating a Whatsapp Clone - Part IX.pdf
Creating a Whatsapp Clone - Part IX.pdfShaiAlmog1
 
Creating a Whatsapp Clone - Part VI.pdf
Creating a Whatsapp Clone - Part VI.pdfCreating a Whatsapp Clone - Part VI.pdf
Creating a Whatsapp Clone - Part VI.pdfShaiAlmog1
 

More from ShaiAlmog1 (20)

The Duck Teaches Learn to debug from the masters. Local to production- kill ...
The Duck Teaches  Learn to debug from the masters. Local to production- kill ...The Duck Teaches  Learn to debug from the masters. Local to production- kill ...
The Duck Teaches Learn to debug from the masters. Local to production- kill ...
 
create-netflix-clone-06-client-ui.pdf
create-netflix-clone-06-client-ui.pdfcreate-netflix-clone-06-client-ui.pdf
create-netflix-clone-06-client-ui.pdf
 
create-netflix-clone-01-introduction_transcript.pdf
create-netflix-clone-01-introduction_transcript.pdfcreate-netflix-clone-01-introduction_transcript.pdf
create-netflix-clone-01-introduction_transcript.pdf
 
create-netflix-clone-02-server_transcript.pdf
create-netflix-clone-02-server_transcript.pdfcreate-netflix-clone-02-server_transcript.pdf
create-netflix-clone-02-server_transcript.pdf
 
create-netflix-clone-04-server-continued_transcript.pdf
create-netflix-clone-04-server-continued_transcript.pdfcreate-netflix-clone-04-server-continued_transcript.pdf
create-netflix-clone-04-server-continued_transcript.pdf
 
create-netflix-clone-01-introduction.pdf
create-netflix-clone-01-introduction.pdfcreate-netflix-clone-01-introduction.pdf
create-netflix-clone-01-introduction.pdf
 
create-netflix-clone-06-client-ui_transcript.pdf
create-netflix-clone-06-client-ui_transcript.pdfcreate-netflix-clone-06-client-ui_transcript.pdf
create-netflix-clone-06-client-ui_transcript.pdf
 
create-netflix-clone-03-server.pdf
create-netflix-clone-03-server.pdfcreate-netflix-clone-03-server.pdf
create-netflix-clone-03-server.pdf
 
create-netflix-clone-04-server-continued.pdf
create-netflix-clone-04-server-continued.pdfcreate-netflix-clone-04-server-continued.pdf
create-netflix-clone-04-server-continued.pdf
 
create-netflix-clone-05-client-model_transcript.pdf
create-netflix-clone-05-client-model_transcript.pdfcreate-netflix-clone-05-client-model_transcript.pdf
create-netflix-clone-05-client-model_transcript.pdf
 
create-netflix-clone-02-server.pdf
create-netflix-clone-02-server.pdfcreate-netflix-clone-02-server.pdf
create-netflix-clone-02-server.pdf
 
create-netflix-clone-05-client-model.pdf
create-netflix-clone-05-client-model.pdfcreate-netflix-clone-05-client-model.pdf
create-netflix-clone-05-client-model.pdf
 
Creating a Whatsapp Clone - Part II.pdf
Creating a Whatsapp Clone - Part II.pdfCreating a Whatsapp Clone - Part II.pdf
Creating a Whatsapp Clone - Part II.pdf
 
Creating a Whatsapp Clone - Part IX - Transcript.pdf
Creating a Whatsapp Clone - Part IX - Transcript.pdfCreating a Whatsapp Clone - Part IX - Transcript.pdf
Creating a Whatsapp Clone - Part IX - Transcript.pdf
 
Creating a Whatsapp Clone - Part II - Transcript.pdf
Creating a Whatsapp Clone - Part II - Transcript.pdfCreating a Whatsapp Clone - Part II - Transcript.pdf
Creating a Whatsapp Clone - Part II - Transcript.pdf
 
Creating a Whatsapp Clone - Part V - Transcript.pdf
Creating a Whatsapp Clone - Part V - Transcript.pdfCreating a Whatsapp Clone - Part V - Transcript.pdf
Creating a Whatsapp Clone - Part V - Transcript.pdf
 
Creating a Whatsapp Clone - Part IV.pdf
Creating a Whatsapp Clone - Part IV.pdfCreating a Whatsapp Clone - Part IV.pdf
Creating a Whatsapp Clone - Part IV.pdf
 
Creating a Whatsapp Clone - Part I - Transcript.pdf
Creating a Whatsapp Clone - Part I - Transcript.pdfCreating a Whatsapp Clone - Part I - Transcript.pdf
Creating a Whatsapp Clone - Part I - Transcript.pdf
 
Creating a Whatsapp Clone - Part IX.pdf
Creating a Whatsapp Clone - Part IX.pdfCreating a Whatsapp Clone - Part IX.pdf
Creating a Whatsapp Clone - Part IX.pdf
 
Creating a Whatsapp Clone - Part VI.pdf
Creating a Whatsapp Clone - Part VI.pdfCreating a Whatsapp Clone - Part VI.pdf
Creating a Whatsapp Clone - Part VI.pdf
 

Recently uploaded

Structuring Teams and Portfolios for Success
Structuring Teams and Portfolios for SuccessStructuring Teams and Portfolios for Success
Structuring Teams and Portfolios for SuccessUXDXConf
 
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)Julian Hyde
 
Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya Halder
Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya HalderCustom Approval Process: A New Perspective, Pavel Hrbacek & Anindya Halder
Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya HalderCzechDreamin
 
Speed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in MinutesSpeed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in Minutesconfluent
 
Demystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John StaveleyDemystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John StaveleyJohn Staveley
 
How we scaled to 80K users by doing nothing!.pdf
How we scaled to 80K users by doing nothing!.pdfHow we scaled to 80K users by doing nothing!.pdf
How we scaled to 80K users by doing nothing!.pdfSrushith Repakula
 
AI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří KarpíšekAI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří KarpíšekCzechDreamin
 
WSO2CONMay2024OpenSourceConferenceDebrief.pptx
WSO2CONMay2024OpenSourceConferenceDebrief.pptxWSO2CONMay2024OpenSourceConferenceDebrief.pptx
WSO2CONMay2024OpenSourceConferenceDebrief.pptxJennifer Lim
 
Salesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
Salesforce Adoption – Metrics, Methods, and Motivation, Antone KomSalesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
Salesforce Adoption – Metrics, Methods, and Motivation, Antone KomCzechDreamin
 
Where to Learn More About FDO _ Richard at FIDO Alliance.pdf
Where to Learn More About FDO _ Richard at FIDO Alliance.pdfWhere to Learn More About FDO _ Richard at FIDO Alliance.pdf
Where to Learn More About FDO _ Richard at FIDO Alliance.pdfFIDO Alliance
 
Powerful Start- the Key to Project Success, Barbara Laskowska
Powerful Start- the Key to Project Success, Barbara LaskowskaPowerful Start- the Key to Project Success, Barbara Laskowska
Powerful Start- the Key to Project Success, Barbara LaskowskaCzechDreamin
 
WebAssembly is Key to Better LLM Performance
WebAssembly is Key to Better LLM PerformanceWebAssembly is Key to Better LLM Performance
WebAssembly is Key to Better LLM PerformanceSamy Fodil
 
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo DiehlFuture Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo DiehlPeter Udo Diehl
 
IoT Analytics Company Presentation May 2024
IoT Analytics Company Presentation May 2024IoT Analytics Company Presentation May 2024
IoT Analytics Company Presentation May 2024IoTAnalytics
 
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...CzechDreamin
 
Intro in Product Management - Коротко про професію продакт менеджера
Intro in Product Management - Коротко про професію продакт менеджераIntro in Product Management - Коротко про професію продакт менеджера
Intro in Product Management - Коротко про професію продакт менеджераMark Opanasiuk
 
TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...
TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...
TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...marcuskenyatta275
 
AI presentation and introduction - Retrieval Augmented Generation RAG 101
AI presentation and introduction - Retrieval Augmented Generation RAG 101AI presentation and introduction - Retrieval Augmented Generation RAG 101
AI presentation and introduction - Retrieval Augmented Generation RAG 101vincent683379
 
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...FIDO Alliance
 
Free and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
Free and Effective: Making Flows Publicly Accessible, Yumi IbrahimzadeFree and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
Free and Effective: Making Flows Publicly Accessible, Yumi IbrahimzadeCzechDreamin
 

Recently uploaded (20)

Structuring Teams and Portfolios for Success
Structuring Teams and Portfolios for SuccessStructuring Teams and Portfolios for Success
Structuring Teams and Portfolios for Success
 
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
 
Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya Halder
Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya HalderCustom Approval Process: A New Perspective, Pavel Hrbacek & Anindya Halder
Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya Halder
 
Speed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in MinutesSpeed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in Minutes
 
Demystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John StaveleyDemystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John Staveley
 
How we scaled to 80K users by doing nothing!.pdf
How we scaled to 80K users by doing nothing!.pdfHow we scaled to 80K users by doing nothing!.pdf
How we scaled to 80K users by doing nothing!.pdf
 
AI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří KarpíšekAI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří Karpíšek
 
WSO2CONMay2024OpenSourceConferenceDebrief.pptx
WSO2CONMay2024OpenSourceConferenceDebrief.pptxWSO2CONMay2024OpenSourceConferenceDebrief.pptx
WSO2CONMay2024OpenSourceConferenceDebrief.pptx
 
Salesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
Salesforce Adoption – Metrics, Methods, and Motivation, Antone KomSalesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
Salesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
 
Where to Learn More About FDO _ Richard at FIDO Alliance.pdf
Where to Learn More About FDO _ Richard at FIDO Alliance.pdfWhere to Learn More About FDO _ Richard at FIDO Alliance.pdf
Where to Learn More About FDO _ Richard at FIDO Alliance.pdf
 
Powerful Start- the Key to Project Success, Barbara Laskowska
Powerful Start- the Key to Project Success, Barbara LaskowskaPowerful Start- the Key to Project Success, Barbara Laskowska
Powerful Start- the Key to Project Success, Barbara Laskowska
 
WebAssembly is Key to Better LLM Performance
WebAssembly is Key to Better LLM PerformanceWebAssembly is Key to Better LLM Performance
WebAssembly is Key to Better LLM Performance
 
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo DiehlFuture Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
 
IoT Analytics Company Presentation May 2024
IoT Analytics Company Presentation May 2024IoT Analytics Company Presentation May 2024
IoT Analytics Company Presentation May 2024
 
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
 
Intro in Product Management - Коротко про професію продакт менеджера
Intro in Product Management - Коротко про професію продакт менеджераIntro in Product Management - Коротко про професію продакт менеджера
Intro in Product Management - Коротко про професію продакт менеджера
 
TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...
TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...
TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...
 
AI presentation and introduction - Retrieval Augmented Generation RAG 101
AI presentation and introduction - Retrieval Augmented Generation RAG 101AI presentation and introduction - Retrieval Augmented Generation RAG 101
AI presentation and introduction - Retrieval Augmented Generation RAG 101
 
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
 
Free and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
Free and Effective: Making Flows Publicly Accessible, Yumi IbrahimzadeFree and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
Free and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
 

Creating a Whatsapp Clone - Part XII - Transcript.pdf

  • 1. Creating a WhatsApp Clone - Part XII Lets continue with the other entities. I’ll skip media as it’s just a copy and paste of the facebook media class and partially implemented to boot.
  • 2. @Entity @Indexed public class ChatGroup { @Id private String id; @Field private String name; @Field private String tagline; @Temporal(TemporalType.DATE) private Date creationDate; @ManyToOne private Media avatar; @ManyToOne ChatGroup ChatGroup is an entity that wraps the concept of a group. In a sense it’s similar to the User entity but has no phone
  • 3. @Entity @Indexed public class ChatGroup { @Id private String id; @Field private String name; @Field private String tagline; @Temporal(TemporalType.DATE) private Date creationDate; @ManyToOne private Media avatar; @ManyToOne ChatGroup All of these properties, the id, name, tagline, creation date and even avatar are a part of a group.
  • 4. @Temporal(TemporalType.DATE) private Date creationDate; @ManyToOne private Media avatar; @ManyToOne private User createdBy; @OneToMany @OrderBy("name ASC") private Set<User> admins; @OneToMany @OrderBy("name ASC") private Set<User> members; public ChatGroup() { id = UUID.randomUUID().toString(); } ChatGroup However, unlike a regular user a group is effectively created by a user
  • 5. @Temporal(TemporalType.DATE) private Date creationDate; @ManyToOne private Media avatar; @ManyToOne private User createdBy; @OneToMany @OrderBy("name ASC") private Set<User> admins; @OneToMany @OrderBy("name ASC") private Set<User> members; public ChatGroup() { id = UUID.randomUUID().toString(); } ChatGroup A group also has two lists of group administrators and group members
  • 6. package com.codename1.whatsapp.server.entities; import org.springframework.data.repository.CrudRepository; public interface ChatGroupRepository extends CrudRepository<ChatGroup, String> { } ChatGroupRepository The chat group repository is empty as this is a feature we didn’t finish
  • 7. @Entity @Indexed public class ChatMessage { @Id private String id; @ManyToOne private User author; @ManyToOne private User sentTo; @ManyToOne private ChatGroup sentToGroup; @Temporal(TemporalType.TIMESTAMP) private Date messageTime; private String body; ChatMessage A chat message must be stored on servers for a while. If your device isn’t connected at this moment (e.g. flight) the server would need to keep the message until you’re available again. It can then be purged. If we wish to be very secure we can encrypt the message based on a client public key, that way no one in the middle could “peek” into the message. This should be easy enough to implement but I didn’t get around to do it, this would mostly be client side work. Here we store messages so they can be fetched by the app. Like everything else we have a unique string id per message
  • 8. @Entity @Indexed public class ChatMessage { @Id private String id; @ManyToOne private User author; @ManyToOne private User sentTo; @ManyToOne private ChatGroup sentToGroup; @Temporal(TemporalType.TIMESTAMP) private Date messageTime; private String body; ChatMessage Every message naturally has an author of that message
  • 9. @Entity @Indexed public class ChatMessage { @Id private String id; @ManyToOne private User author; @ManyToOne private User sentTo; @ManyToOne private ChatGroup sentToGroup; @Temporal(TemporalType.TIMESTAMP) private Date messageTime; private String body; ChatGroupRepository But more importantly a destination which can be either a different user or a group. Not both…
  • 10. private User author; @ManyToOne private User sentTo; @ManyToOne private ChatGroup sentToGroup; @Temporal(TemporalType.TIMESTAMP) private Date messageTime; private String body; private boolean ack; @OneToMany @OrderBy("date ASC") private Set<Media> attachments; public ChatMessage() { id = UUID.randomUUID().toString(); } ChatMessage Every message has a date time stamp for when it was sent
  • 11. private User author; @ManyToOne private User sentTo; @ManyToOne private ChatGroup sentToGroup; @Temporal(TemporalType.TIMESTAMP) private Date messageTime; private String body; private boolean ack; @OneToMany @OrderBy("date ASC") private Set<Media> attachments; public ChatMessage() { id = UUID.randomUUID().toString(); } ChatMessage The message has a text body alway, it can be null though
  • 12. private User author; @ManyToOne private User sentTo; @ManyToOne private ChatGroup sentToGroup; @Temporal(TemporalType.TIMESTAMP) private Date messageTime; private String body; private boolean ack; @OneToMany @OrderBy("date ASC") private Set<Media> attachments; public ChatMessage() { id = UUID.randomUUID().toString(); } ChatMessage If we have media attachments to the message
  • 13. private User author; @ManyToOne private User sentTo; @ManyToOne private ChatGroup sentToGroup; @Temporal(TemporalType.TIMESTAMP) private Date messageTime; private String body; private boolean ack; @OneToMany @OrderBy("date ASC") private Set<Media> attachments; public ChatMessage() { id = UUID.randomUUID().toString(); } ChatMessage The ack flag indicates whether the client acknowledged receiving the message. This works great for one-to-one messages but a message sent to a group would probably need a more elaborate ack implementation.
  • 14. @OneToMany @OrderBy("date ASC") private Set<Media> attachments; public ChatMessage() { id = UUID.randomUUID().toString(); } public MessageDAO getDAO() { String[] a; if(attachments != null && !attachments.isEmpty()) { a = new String[attachments.size()]; Iterator<Media> i = attachments.iterator(); for(int iter = 0 ; iter < a.length ; iter++) { a[iter] = i.next().getId(); } } else { a = new String[0]; } return new MessageDAO(id, author.getId(), sentTo != null ? sentTo.getId() : sentToGroup.getId(), messageTime, body, a); } ChatMessage The DAO is again practically copied from the facebook app, we can include the id’s for the attachments as part of the message
  • 15. package com.codename1.whatsapp.server.entities; import java.util.List; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.CrudRepository; public interface ChatMessageRepository extends CrudRepository<ChatMessage, String> { @Query("select n from ChatMessage n where n.ack = false and " + "n.sentTo.id = ?1 order by messageTime asc") public List<ChatMessage> findByUnAcked(String sentTo); } ChatMessageRepository The chat message repository includes one find method which helps us find messages that we didn’t acknowledge yet. If a specific user has pending messages this finder is used to locate such messages and send them again.
  • 16. import com.fasterxml.jackson.annotation.JsonFormat; import java.util.Date; public class MessageDAO { private String id; private String authorId; private String sentTo; @JsonFormat(pattern="yyyy-MM-dd'T'HH:mm:ss.SSS") private Date time; private String body; private String[] attachments; public MessageDAO() { } public MessageDAO(String id, String authorId, String sentTo, Date time, String body, String[] attachments) { this.id = id; this.authorId = authorId; this.sentTo = sentTo; this.time = time; this.body = body; MessageDAO The MessageDAO entry represents the current message. It maps pretty accurately to the entity object.
 With that we are effectively done with the entity and DAO layers. There is still an ErrorDAO but it’s effectively identical to what we had in the facebook app and is totally trivial so I’ll skip that.