SlideShare a Scribd company logo
Creating a WhatsApp Clone - Part IV
public class ChatMessage implements PropertyBusinessObject {
public final Property<String, ChatMessage> id = new Property<>("id");
public final Property<String, ChatMessage> authorId =
new Property<>("authorId");
public final Property<String, ChatMessage> authorPhone =
new Property<>("authorPhone");
public final Property<String, ChatMessage> sentTo =
new Property<>("sentTo");
public final Property<Date, ChatMessage> time =
new Property<>("time", Date.class);
public final Property<String, ChatMessage> body =
new Property<>("body");
public final MapProperty<String, String, ChatMessage> attachments =
new MapProperty<>("media", String.class, String.class);
public final SetProperty<String, ChatMessage> viewedBy =
new SetProperty<>("viewedBy", String.class);
public final BooleanProperty<ChatMessage> typing =
new BooleanProperty<>("typing");
ChatMessage
public class ChatMessage implements PropertyBusinessObject {
public final Property<String, ChatMessage> id = new Property<>("id");
public final Property<String, ChatMessage> authorId =
new Property<>("authorId");
public final Property<String, ChatMessage> authorPhone =
new Property<>("authorPhone");
public final Property<String, ChatMessage> sentTo =
new Property<>("sentTo");
public final Property<Date, ChatMessage> time =
new Property<>("time", Date.class);
public final Property<String, ChatMessage> body =
new Property<>("body");
public final MapProperty<String, String, ChatMessage> attachments =
new MapProperty<>("media", String.class, String.class);
public final SetProperty<String, ChatMessage> viewedBy =
new SetProperty<>("viewedBy", String.class);
public final BooleanProperty<ChatMessage> typing =
new BooleanProperty<>("typing");
ChatMessage
public class ChatMessage implements PropertyBusinessObject {
public final Property<String, ChatMessage> id = new Property<>("id");
public final Property<String, ChatMessage> authorId =
new Property<>("authorId");
public final Property<String, ChatMessage> authorPhone =
new Property<>("authorPhone");
public final Property<String, ChatMessage> sentTo =
new Property<>("sentTo");
public final Property<Date, ChatMessage> time =
new Property<>("time", Date.class);
public final Property<String, ChatMessage> body =
new Property<>("body");
public final MapProperty<String, String, ChatMessage> attachments =
new MapProperty<>("media", String.class, String.class);
public final SetProperty<String, ChatMessage> viewedBy =
new SetProperty<>("viewedBy", String.class);
public final BooleanProperty<ChatMessage> typing =
new BooleanProperty<>("typing");
ChatMessage
public class ChatMessage implements PropertyBusinessObject {
public final Property<String, ChatMessage> id = new Property<>("id");
public final Property<String, ChatMessage> authorId =
new Property<>("authorId");
public final Property<String, ChatMessage> authorPhone =
new Property<>("authorPhone");
public final Property<String, ChatMessage> sentTo =
new Property<>("sentTo");
public final Property<Date, ChatMessage> time =
new Property<>("time", Date.class);
public final Property<String, ChatMessage> body =
new Property<>("body");
public final MapProperty<String, String, ChatMessage> attachments =
new MapProperty<>("media", String.class, String.class);
public final SetProperty<String, ChatMessage> viewedBy =
new SetProperty<>("viewedBy", String.class);
public final BooleanProperty<ChatMessage> typing =
new BooleanProperty<>("typing");
ChatMessage
public class ChatMessage implements PropertyBusinessObject {
public final Property<String, ChatMessage> id = new Property<>("id");
public final Property<String, ChatMessage> authorId =
new Property<>("authorId");
public final Property<String, ChatMessage> authorPhone =
new Property<>("authorPhone");
public final Property<String, ChatMessage> sentTo =
new Property<>("sentTo");
public final Property<Date, ChatMessage> time =
new Property<>("time", Date.class);
public final Property<String, ChatMessage> body =
new Property<>("body");
public final MapProperty<String, String, ChatMessage> attachments =
new MapProperty<>("media", String.class, String.class);
public final SetProperty<String, ChatMessage> viewedBy =
new SetProperty<>("viewedBy", String.class);
public final BooleanProperty<ChatMessage> typing =
new BooleanProperty<>("typing");
ChatMessage
public class ChatMessage implements PropertyBusinessObject {
public final Property<String, ChatMessage> id = new Property<>("id");
public final Property<String, ChatMessage> authorId =
new Property<>("authorId");
public final Property<String, ChatMessage> authorPhone =
new Property<>("authorPhone");
public final Property<String, ChatMessage> sentTo =
new Property<>("sentTo");
public final Property<Date, ChatMessage> time =
new Property<>("time", Date.class);
public final Property<String, ChatMessage> body =
new Property<>("body");
public final MapProperty<String, String, ChatMessage> attachments =
new MapProperty<>("media", String.class, String.class);
public final SetProperty<String, ChatMessage> viewedBy =
new SetProperty<>("viewedBy", String.class);
public final BooleanProperty<ChatMessage> typing =
new BooleanProperty<>("typing");
ChatMessage
new Property<>("authorPhone");
public final Property<String, ChatMessage> sentTo =
new Property<>("sentTo");
public final Property<Date, ChatMessage> time =
new Property<>("time", Date.class);
public final Property<String, ChatMessage> body =
new Property<>("body");
public final MapProperty<String, String, ChatMessage> attachments =
new MapProperty<>("media", String.class, String.class);
public final SetProperty<String, ChatMessage> viewedBy =
new SetProperty<>("viewedBy", String.class);
public final BooleanProperty<ChatMessage> typing =
new BooleanProperty<>("typing");
private final PropertyIndex idx = new PropertyIndex(this,
"ChatMessage", id, authorId, authorPhone, sentTo, time,
body, attachments, viewedBy, typing);
@Override
public PropertyIndex getPropertyIndex() {
return idx;
}
}
ChatMessage
public class WhatsAppClone implements PushCallback {
private Form current;
private Resources theme;
public void init(Object context) {
// use two network threads instead of one
updateNetworkThreadCount(2);
theme = UIManager.initFirstTheme("/theme");
// Enable Toolbar on all Forms by default
Toolbar.setGlobalToolbar(true);
// Pro only feature
Log.bindCrashProtection(true);
Server.init();
WhatsAppClone
public class WhatsAppClone implements PushCallback {
private Form current;
private Resources theme;
public void init(Object context) {
// use two network threads instead of one
updateNetworkThreadCount(2);
theme = UIManager.initFirstTheme("/theme");
// Enable Toolbar on all Forms by default
Toolbar.setGlobalToolbar(true);
// Pro only feature
Log.bindCrashProtection(true);
Server.init();
WhatsAppClone
// Pro only feature
Log.bindCrashProtection(true);
Server.init();
addNetworkErrorListener(err -> {
// prevent the event from propagating
err.consume();
if(err.getError() != null) {
Log.e(err.getError());
}
Log.sendLogAsync();
Dialog.show("Connection Error",
"There was a networking error in the connection to " +
err.getConnectionRequest().getUrl(), "OK", null);
});
}
@Override
public void push(String value) {
}
WhatsAppClone
err.getConnectionRequest().getUrl(), "OK", null);
});
}
@Override
public void push(String value) {
}
@Override
public void registeredForPush(String deviceId) {
Server.updatePushKey(Push.getPushKey());
}
@Override
public void pushRegistrationError(String error, int errorCode) {
}
static class SMSVerifyImpl extends SMSVerification {
@Override
public void sendSMSCode(String phone) {
Dialog d = new InfiniteProgress().showInfiniteBlocking();
Server.signup(new ChatContact().phone.set(phone),
c -> d.dispose());
WhatsAppClone
@Override
public void pushRegistrationError(String error, int errorCode) {
}
static class SMSVerifyImpl extends SMSVerification {
@Override
public void sendSMSCode(String phone) {
Dialog d = new InfiniteProgress().showInfiniteBlocking();
Server.signup(new ChatContact().phone.set(phone),
c -> d.dispose());
}
@Override
public void verifySmsCode(String code,
SuccessCallback<Boolean> s) {
Dialog d = new InfiniteProgress().showInfiniteBlocking();
boolean result = Server.verify(code);
d.dispose();
s.onSucess(result);
}
}
WhatsAppClone
@Override
public void pushRegistrationError(String error, int errorCode) {
}
static class SMSVerifyImpl extends SMSVerification {
@Override
public void sendSMSCode(String phone) {
Dialog d = new InfiniteProgress().showInfiniteBlocking();
Server.signup(new ChatContact().phone.set(phone),
c -> d.dispose());
}
@Override
public void verifySmsCode(String code,
SuccessCallback<Boolean> s) {
Dialog d = new InfiniteProgress().showInfiniteBlocking();
boolean result = Server.verify(code);
d.dispose();
s.onSucess(result);
}
}
WhatsAppClone
@Override
public void pushRegistrationError(String error, int errorCode) {
}
static class SMSVerifyImpl extends SMSVerification {
@Override
public void sendSMSCode(String phone) {
Dialog d = new InfiniteProgress().showInfiniteBlocking();
Server.signup(new ChatContact().phone.set(phone),
c -> d.dispose());
}
@Override
public void verifySmsCode(String code,
SuccessCallback<Boolean> s) {
Dialog d = new InfiniteProgress().showInfiniteBlocking();
boolean result = Server.verify(code);
d.dispose();
s.onSucess(result);
}
}
WhatsAppClone
Dialog d = new InfiniteProgress().showInfiniteBlocking();
boolean result = Server.verify(code);
d.dispose();
s.onSucess(result);
}
}
private void bindMessageListener() {
Server.bindMessageListener(new ServerMessages() {
@Override
public void connected() {
}
@Override
public void disconnected() {
}
@Override
public void messageReceived(ChatMessage m) {
Form f = getCurrentForm();
if(f instanceof ChatForm) {
ChatForm cf = (ChatForm)f;
if(cf.getContact().id.equals(m.authorId.get())) {
WhatsAppClone
@Override
public void disconnected() {
}
@Override
public void messageReceived(ChatMessage m) {
Form f = getCurrentForm();
if(f instanceof ChatForm) {
ChatForm cf = (ChatForm)f;
if(cf.getContact().id.equals(m.authorId.get())) {
cf.addMessageToUI(m);
}
}
MainForm.getInstance().refreshChatsContainer();
}
@Override
public void userTyping(String contactId) {
}
@Override
public void messageViewed(String msgId, List<String> userIds) {
WhatsAppClone
@Override
public void disconnected() {
}
@Override
public void messageReceived(ChatMessage m) {
Form f = getCurrentForm();
if(f instanceof ChatForm) {
ChatForm cf = (ChatForm)f;
if(cf.getContact().id.equals(m.authorId.get())) {
cf.addMessageToUI(m);
}
}
MainForm.getInstance().refreshChatsContainer();
}
@Override
public void userTyping(String contactId) {
}
@Override
public void messageViewed(String msgId, List<String> userIds) {
WhatsAppClone
@Override
public void disconnected() {
}
@Override
public void messageReceived(ChatMessage m) {
Form f = getCurrentForm();
if(f instanceof ChatForm) {
ChatForm cf = (ChatForm)f;
if(cf.getContact().id.equals(m.authorId.get())) {
cf.addMessageToUI(m);
}
}
MainForm.getInstance().refreshChatsContainer();
}
@Override
public void userTyping(String contactId) {
}
@Override
public void messageViewed(String msgId, List<String> userIds) {
WhatsAppClone
@Override
public void disconnected() {
}
@Override
public void messageReceived(ChatMessage m) {
Form f = getCurrentForm();
if(f instanceof ChatForm) {
ChatForm cf = (ChatForm)f;
if(cf.getContact().id.equals(m.authorId.get())) {
cf.addMessageToUI(m);
}
}
MainForm.getInstance().refreshChatsContainer();
}
@Override
public void userTyping(String contactId) {
}
@Override
public void messageViewed(String msgId, List<String> userIds) {
WhatsAppClone
}
@Override
public void userTyping(String contactId) {
}
@Override
public void messageViewed(String msgId, List<String> userIds) {
}
});
}
public void start() {
if(current != null){
current.show();
bindMessageListener();
return;
}
String phoneNumber = Preferences.get("PhoneNumber", null);
if(phoneNumber == null) {
ActivationForm.create("Signup").
codeDigits(6).
show(s -> {
WhatsAppClone
}
@Override
public void userTyping(String contactId) {
}
@Override
public void messageViewed(String msgId, List<String> userIds) {
}
});
}
public void start() {
if(current != null){
current.show();
bindMessageListener();
return;
}
String phoneNumber = Preferences.get("PhoneNumber", null);
if(phoneNumber == null) {
ActivationForm.create("Signup").
codeDigits(6).
show(s -> {
WhatsAppClone
public void start() {
if(current != null){
current.show();
bindMessageListener();
return;
}
String phoneNumber = Preferences.get("PhoneNumber", null);
if(phoneNumber == null) {
ActivationForm.create("Signup").
codeDigits(6).
show(s -> {
Log.p("SMS Activation returned " + s);
Preferences.set("PhoneNumber", s);
new MainForm().show();
}, new SMSVerifyImpl());
} else {
new MainForm().show();
}
bindMessageListener();
callSerially(() -> registerPush());
}
WhatsAppClone
public void start() {
if(current != null){
current.show();
bindMessageListener();
return;
}
String phoneNumber = Preferences.get("PhoneNumber", null);
if(phoneNumber == null) {
ActivationForm.create("Signup").
codeDigits(6).
show(s -> {
Log.p("SMS Activation returned " + s);
Preferences.set("PhoneNumber", s);
new MainForm().show();
}, new SMSVerifyImpl());
} else {
new MainForm().show();
}
bindMessageListener();
callSerially(() -> registerPush());
}
WhatsAppClone
public void start() {
if(current != null){
current.show();
bindMessageListener();
return;
}
String phoneNumber = Preferences.get("PhoneNumber", null);
if(phoneNumber == null) {
ActivationForm.create("Signup").
codeDigits(6).
show(s -> {
Log.p("SMS Activation returned " + s);
Preferences.set("PhoneNumber", s);
new MainForm().show();
}, new SMSVerifyImpl());
} else {
new MainForm().show();
}
bindMessageListener();
callSerially(() -> registerPush());
}
WhatsAppClone
public void start() {
if(current != null){
current.show();
bindMessageListener();
return;
}
String phoneNumber = Preferences.get("PhoneNumber", null);
if(phoneNumber == null) {
ActivationForm.create("Signup").
codeDigits(6).
show(s -> {
Log.p("SMS Activation returned " + s);
Preferences.set("PhoneNumber", s);
new MainForm().show();
}, new SMSVerifyImpl());
} else {
new MainForm().show();
}
bindMessageListener();
callSerially(() -> registerPush());
}
WhatsAppClone
public void start() {
if(current != null){
current.show();
bindMessageListener();
return;
}
String phoneNumber = Preferences.get("PhoneNumber", null);
if(phoneNumber == null) {
ActivationForm.create("Signup").
codeDigits(6).
show(s -> {
Log.p("SMS Activation returned " + s);
Preferences.set("PhoneNumber", s);
new MainForm().show();
}, new SMSVerifyImpl());
} else {
new MainForm().show();
}
bindMessageListener();
callSerially(() -> registerPush());
}
WhatsAppClone
public void start() {
if(current != null){
current.show();
bindMessageListener();
return;
}
String phoneNumber = Preferences.get("PhoneNumber", null);
if(phoneNumber == null) {
ActivationForm.create("Signup").
codeDigits(6).
show(s -> {
Log.p("SMS Activation returned " + s);
Preferences.set("PhoneNumber", s);
new MainForm().show();
}, new SMSVerifyImpl());
} else {
new MainForm().show();
}
bindMessageListener();
callSerially(() -> registerPush());
}
WhatsAppClone
public void start() {
if(current != null){
current.show();
bindMessageListener();
return;
}
String phoneNumber = Preferences.get("PhoneNumber", null);
if(phoneNumber == null) {
ActivationForm.create("Signup").
codeDigits(6).
show(s -> {
Log.p("SMS Activation returned " + s);
Preferences.set("PhoneNumber", s);
new MainForm().show();
}, new SMSVerifyImpl());
} else {
new MainForm().show();
}
bindMessageListener();
callSerially(() -> registerPush());
}
WhatsAppClone
public void start() {
if(current != null){
current.show();
bindMessageListener();
return;
}
String phoneNumber = Preferences.get("PhoneNumber", null);
if(phoneNumber == null) {
ActivationForm.create("Signup").
codeDigits(6).
show(s -> {
Log.p("SMS Activation returned " + s);
Preferences.set("PhoneNumber", s);
new MainForm().show();
}, new SMSVerifyImpl());
} else {
new MainForm().show();
}
bindMessageListener();
callSerially(() -> registerPush());
}
WhatsAppClone
public void start() {
if(current != null){
current.show();
bindMessageListener();
return;
}
String phoneNumber = Preferences.get("PhoneNumber", null);
if(phoneNumber == null) {
ActivationForm.create("Signup").
codeDigits(6).
show(s -> {
Log.p("SMS Activation returned " + s);
Preferences.set("PhoneNumber", s);
new MainForm().show();
}, new SMSVerifyImpl());
} else {
new MainForm().show();
}
bindMessageListener();
callSerially(() -> registerPush());
}
WhatsAppClone
public void start() {
if(current != null){
current.show();
bindMessageListener();
return;
}
String phoneNumber = Preferences.get("PhoneNumber", null);
if(phoneNumber == null) {
ActivationForm.create("Signup").
codeDigits(6).
show(s -> {
Log.p("SMS Activation returned " + s);
Preferences.set("PhoneNumber", s);
new MainForm().show();
}, new SMSVerifyImpl());
} else {
new MainForm().show();
}
bindMessageListener();
callSerially(() -> registerPush());
}
WhatsAppClone
Preferences.set("PhoneNumber", s);
new MainForm().show();
}, new SMSVerifyImpl());
} else {
new MainForm().show();
}
bindMessageListener();
callSerially(() -> registerPush());
}
public void stop() {
Server.closeWebsocketConnection();
current = getCurrentForm();
if(current instanceof Dialog) {
((Dialog)current).dispose();
current = getCurrentForm();
}
}
public void destroy() {
}
}
WhatsAppClone

More Related Content

PDF
Creating a Whatsapp Clone - Part IV - Transcript.pdf
PDF
Creating a Whatsapp Clone - Part III.pdf
PDF
Creating a Whatsapp Clone - Part III - Transcript.pdf
PDF
Creating a Facebook Clone - Part XL.pdf
PDF
Creating a Facebook Clone - Part XL - Transcript.pdf
PDF
Creating a Facebook Clone - Part XIV.pdf
PDF
Creating a Whatsapp Clone - Part XI.pdf
PDF
Creating a Facebook Clone - Part XXVIII - Transcript.pdf
Creating a Whatsapp Clone - Part IV - Transcript.pdf
Creating a Whatsapp Clone - Part III.pdf
Creating a Whatsapp Clone - Part III - Transcript.pdf
Creating a Facebook Clone - Part XL.pdf
Creating a Facebook Clone - Part XL - Transcript.pdf
Creating a Facebook Clone - Part XIV.pdf
Creating a Whatsapp Clone - Part XI.pdf
Creating a Facebook Clone - Part XXVIII - Transcript.pdf

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

PDF
Creating a Whatsapp Clone - Part II.pdf
PPTX
PDF
Creating a Facebook Clone - Part XIV - Transcript.pdf
DOCX
JavaExamples
PDF
Creating a Facebook Clone - Part XI.pdf
PDF
Creating a Facebook Clone - Part X.pdf
PDF
create-netflix-clone-04-server-continued.pdf
DOC
Id32
PPTX
Windows 8 metro applications
PDF
Creating a Whatsapp Clone - Part IX.pdf
PDF
create-netflix-clone-05-client-model.pdf
PDF
Speed up your Web applications with HTML5 WebSockets
DOCX
Laporan multi client
PDF
Bot builder v4 HOL
PDF
Creating an Uber Clone - Part XX - Transcript.pdf
PDF
final project for C#
PDF
Need help on creating code using cart. The output has to show multip.pdf
PPTX
A GWT Application with MVP Pattern Deploying to CloudFoundry using Spring Roo
PPTX
MVVM e Caliburn Micro for Windows Phone applications
PDF
creating dynamic web project in eclipse1.) create Survey servlet c.pdf
Creating a Whatsapp Clone - Part II.pdf
Creating a Facebook Clone - Part XIV - Transcript.pdf
JavaExamples
Creating a Facebook Clone - Part XI.pdf
Creating a Facebook Clone - Part X.pdf
create-netflix-clone-04-server-continued.pdf
Id32
Windows 8 metro applications
Creating a Whatsapp Clone - Part IX.pdf
create-netflix-clone-05-client-model.pdf
Speed up your Web applications with HTML5 WebSockets
Laporan multi client
Bot builder v4 HOL
Creating an Uber Clone - Part XX - Transcript.pdf
final project for C#
Need help on creating code using cart. The output has to show multip.pdf
A GWT Application with MVP Pattern Deploying to CloudFoundry using Spring Roo
MVVM e Caliburn Micro for Windows Phone applications
creating dynamic web project in eclipse1.) create Survey servlet c.pdf
Ad

More from ShaiAlmog1 (20)

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

Recently uploaded (20)

PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPTX
Big Data Technologies - Introduction.pptx
PDF
Electronic commerce courselecture one. Pdf
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPTX
sap open course for s4hana steps from ECC to s4
PDF
Unlocking AI with Model Context Protocol (MCP)
PPTX
Spectroscopy.pptx food analysis technology
PPT
Teaching material agriculture food technology
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Big Data Technologies - Introduction.pptx
Electronic commerce courselecture one. Pdf
20250228 LYD VKU AI Blended-Learning.pptx
Advanced methodologies resolving dimensionality complications for autism neur...
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
NewMind AI Weekly Chronicles - August'25 Week I
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Building Integrated photovoltaic BIPV_UPV.pdf
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Per capita expenditure prediction using model stacking based on satellite ima...
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
sap open course for s4hana steps from ECC to s4
Unlocking AI with Model Context Protocol (MCP)
Spectroscopy.pptx food analysis technology
Teaching material agriculture food technology
Reach Out and Touch Someone: Haptics and Empathic Computing
Dropbox Q2 2025 Financial Results & Investor Presentation

Creating a Whatsapp Clone - Part IV.pdf

  • 1. Creating a WhatsApp Clone - Part IV
  • 2. public class ChatMessage implements PropertyBusinessObject { public final Property<String, ChatMessage> id = new Property<>("id"); public final Property<String, ChatMessage> authorId = new Property<>("authorId"); public final Property<String, ChatMessage> authorPhone = new Property<>("authorPhone"); public final Property<String, ChatMessage> sentTo = new Property<>("sentTo"); public final Property<Date, ChatMessage> time = new Property<>("time", Date.class); public final Property<String, ChatMessage> body = new Property<>("body"); public final MapProperty<String, String, ChatMessage> attachments = new MapProperty<>("media", String.class, String.class); public final SetProperty<String, ChatMessage> viewedBy = new SetProperty<>("viewedBy", String.class); public final BooleanProperty<ChatMessage> typing = new BooleanProperty<>("typing"); ChatMessage
  • 3. public class ChatMessage implements PropertyBusinessObject { public final Property<String, ChatMessage> id = new Property<>("id"); public final Property<String, ChatMessage> authorId = new Property<>("authorId"); public final Property<String, ChatMessage> authorPhone = new Property<>("authorPhone"); public final Property<String, ChatMessage> sentTo = new Property<>("sentTo"); public final Property<Date, ChatMessage> time = new Property<>("time", Date.class); public final Property<String, ChatMessage> body = new Property<>("body"); public final MapProperty<String, String, ChatMessage> attachments = new MapProperty<>("media", String.class, String.class); public final SetProperty<String, ChatMessage> viewedBy = new SetProperty<>("viewedBy", String.class); public final BooleanProperty<ChatMessage> typing = new BooleanProperty<>("typing"); ChatMessage
  • 4. public class ChatMessage implements PropertyBusinessObject { public final Property<String, ChatMessage> id = new Property<>("id"); public final Property<String, ChatMessage> authorId = new Property<>("authorId"); public final Property<String, ChatMessage> authorPhone = new Property<>("authorPhone"); public final Property<String, ChatMessage> sentTo = new Property<>("sentTo"); public final Property<Date, ChatMessage> time = new Property<>("time", Date.class); public final Property<String, ChatMessage> body = new Property<>("body"); public final MapProperty<String, String, ChatMessage> attachments = new MapProperty<>("media", String.class, String.class); public final SetProperty<String, ChatMessage> viewedBy = new SetProperty<>("viewedBy", String.class); public final BooleanProperty<ChatMessage> typing = new BooleanProperty<>("typing"); ChatMessage
  • 5. public class ChatMessage implements PropertyBusinessObject { public final Property<String, ChatMessage> id = new Property<>("id"); public final Property<String, ChatMessage> authorId = new Property<>("authorId"); public final Property<String, ChatMessage> authorPhone = new Property<>("authorPhone"); public final Property<String, ChatMessage> sentTo = new Property<>("sentTo"); public final Property<Date, ChatMessage> time = new Property<>("time", Date.class); public final Property<String, ChatMessage> body = new Property<>("body"); public final MapProperty<String, String, ChatMessage> attachments = new MapProperty<>("media", String.class, String.class); public final SetProperty<String, ChatMessage> viewedBy = new SetProperty<>("viewedBy", String.class); public final BooleanProperty<ChatMessage> typing = new BooleanProperty<>("typing"); ChatMessage
  • 6. public class ChatMessage implements PropertyBusinessObject { public final Property<String, ChatMessage> id = new Property<>("id"); public final Property<String, ChatMessage> authorId = new Property<>("authorId"); public final Property<String, ChatMessage> authorPhone = new Property<>("authorPhone"); public final Property<String, ChatMessage> sentTo = new Property<>("sentTo"); public final Property<Date, ChatMessage> time = new Property<>("time", Date.class); public final Property<String, ChatMessage> body = new Property<>("body"); public final MapProperty<String, String, ChatMessage> attachments = new MapProperty<>("media", String.class, String.class); public final SetProperty<String, ChatMessage> viewedBy = new SetProperty<>("viewedBy", String.class); public final BooleanProperty<ChatMessage> typing = new BooleanProperty<>("typing"); ChatMessage
  • 7. public class ChatMessage implements PropertyBusinessObject { public final Property<String, ChatMessage> id = new Property<>("id"); public final Property<String, ChatMessage> authorId = new Property<>("authorId"); public final Property<String, ChatMessage> authorPhone = new Property<>("authorPhone"); public final Property<String, ChatMessage> sentTo = new Property<>("sentTo"); public final Property<Date, ChatMessage> time = new Property<>("time", Date.class); public final Property<String, ChatMessage> body = new Property<>("body"); public final MapProperty<String, String, ChatMessage> attachments = new MapProperty<>("media", String.class, String.class); public final SetProperty<String, ChatMessage> viewedBy = new SetProperty<>("viewedBy", String.class); public final BooleanProperty<ChatMessage> typing = new BooleanProperty<>("typing"); ChatMessage
  • 8. new Property<>("authorPhone"); public final Property<String, ChatMessage> sentTo = new Property<>("sentTo"); public final Property<Date, ChatMessage> time = new Property<>("time", Date.class); public final Property<String, ChatMessage> body = new Property<>("body"); public final MapProperty<String, String, ChatMessage> attachments = new MapProperty<>("media", String.class, String.class); public final SetProperty<String, ChatMessage> viewedBy = new SetProperty<>("viewedBy", String.class); public final BooleanProperty<ChatMessage> typing = new BooleanProperty<>("typing"); private final PropertyIndex idx = new PropertyIndex(this, "ChatMessage", id, authorId, authorPhone, sentTo, time, body, attachments, viewedBy, typing); @Override public PropertyIndex getPropertyIndex() { return idx; } } ChatMessage
  • 9. public class WhatsAppClone implements PushCallback { private Form current; private Resources theme; public void init(Object context) { // use two network threads instead of one updateNetworkThreadCount(2); theme = UIManager.initFirstTheme("/theme"); // Enable Toolbar on all Forms by default Toolbar.setGlobalToolbar(true); // Pro only feature Log.bindCrashProtection(true); Server.init(); WhatsAppClone
  • 10. public class WhatsAppClone implements PushCallback { private Form current; private Resources theme; public void init(Object context) { // use two network threads instead of one updateNetworkThreadCount(2); theme = UIManager.initFirstTheme("/theme"); // Enable Toolbar on all Forms by default Toolbar.setGlobalToolbar(true); // Pro only feature Log.bindCrashProtection(true); Server.init(); WhatsAppClone
  • 11. // Pro only feature Log.bindCrashProtection(true); Server.init(); addNetworkErrorListener(err -> { // prevent the event from propagating err.consume(); if(err.getError() != null) { Log.e(err.getError()); } Log.sendLogAsync(); Dialog.show("Connection Error", "There was a networking error in the connection to " + err.getConnectionRequest().getUrl(), "OK", null); }); } @Override public void push(String value) { } WhatsAppClone
  • 12. err.getConnectionRequest().getUrl(), "OK", null); }); } @Override public void push(String value) { } @Override public void registeredForPush(String deviceId) { Server.updatePushKey(Push.getPushKey()); } @Override public void pushRegistrationError(String error, int errorCode) { } static class SMSVerifyImpl extends SMSVerification { @Override public void sendSMSCode(String phone) { Dialog d = new InfiniteProgress().showInfiniteBlocking(); Server.signup(new ChatContact().phone.set(phone), c -> d.dispose()); WhatsAppClone
  • 13. @Override public void pushRegistrationError(String error, int errorCode) { } static class SMSVerifyImpl extends SMSVerification { @Override public void sendSMSCode(String phone) { Dialog d = new InfiniteProgress().showInfiniteBlocking(); Server.signup(new ChatContact().phone.set(phone), c -> d.dispose()); } @Override public void verifySmsCode(String code, SuccessCallback<Boolean> s) { Dialog d = new InfiniteProgress().showInfiniteBlocking(); boolean result = Server.verify(code); d.dispose(); s.onSucess(result); } } WhatsAppClone
  • 14. @Override public void pushRegistrationError(String error, int errorCode) { } static class SMSVerifyImpl extends SMSVerification { @Override public void sendSMSCode(String phone) { Dialog d = new InfiniteProgress().showInfiniteBlocking(); Server.signup(new ChatContact().phone.set(phone), c -> d.dispose()); } @Override public void verifySmsCode(String code, SuccessCallback<Boolean> s) { Dialog d = new InfiniteProgress().showInfiniteBlocking(); boolean result = Server.verify(code); d.dispose(); s.onSucess(result); } } WhatsAppClone
  • 15. @Override public void pushRegistrationError(String error, int errorCode) { } static class SMSVerifyImpl extends SMSVerification { @Override public void sendSMSCode(String phone) { Dialog d = new InfiniteProgress().showInfiniteBlocking(); Server.signup(new ChatContact().phone.set(phone), c -> d.dispose()); } @Override public void verifySmsCode(String code, SuccessCallback<Boolean> s) { Dialog d = new InfiniteProgress().showInfiniteBlocking(); boolean result = Server.verify(code); d.dispose(); s.onSucess(result); } } WhatsAppClone
  • 16. Dialog d = new InfiniteProgress().showInfiniteBlocking(); boolean result = Server.verify(code); d.dispose(); s.onSucess(result); } } private void bindMessageListener() { Server.bindMessageListener(new ServerMessages() { @Override public void connected() { } @Override public void disconnected() { } @Override public void messageReceived(ChatMessage m) { Form f = getCurrentForm(); if(f instanceof ChatForm) { ChatForm cf = (ChatForm)f; if(cf.getContact().id.equals(m.authorId.get())) { WhatsAppClone
  • 17. @Override public void disconnected() { } @Override public void messageReceived(ChatMessage m) { Form f = getCurrentForm(); if(f instanceof ChatForm) { ChatForm cf = (ChatForm)f; if(cf.getContact().id.equals(m.authorId.get())) { cf.addMessageToUI(m); } } MainForm.getInstance().refreshChatsContainer(); } @Override public void userTyping(String contactId) { } @Override public void messageViewed(String msgId, List<String> userIds) { WhatsAppClone
  • 18. @Override public void disconnected() { } @Override public void messageReceived(ChatMessage m) { Form f = getCurrentForm(); if(f instanceof ChatForm) { ChatForm cf = (ChatForm)f; if(cf.getContact().id.equals(m.authorId.get())) { cf.addMessageToUI(m); } } MainForm.getInstance().refreshChatsContainer(); } @Override public void userTyping(String contactId) { } @Override public void messageViewed(String msgId, List<String> userIds) { WhatsAppClone
  • 19. @Override public void disconnected() { } @Override public void messageReceived(ChatMessage m) { Form f = getCurrentForm(); if(f instanceof ChatForm) { ChatForm cf = (ChatForm)f; if(cf.getContact().id.equals(m.authorId.get())) { cf.addMessageToUI(m); } } MainForm.getInstance().refreshChatsContainer(); } @Override public void userTyping(String contactId) { } @Override public void messageViewed(String msgId, List<String> userIds) { WhatsAppClone
  • 20. @Override public void disconnected() { } @Override public void messageReceived(ChatMessage m) { Form f = getCurrentForm(); if(f instanceof ChatForm) { ChatForm cf = (ChatForm)f; if(cf.getContact().id.equals(m.authorId.get())) { cf.addMessageToUI(m); } } MainForm.getInstance().refreshChatsContainer(); } @Override public void userTyping(String contactId) { } @Override public void messageViewed(String msgId, List<String> userIds) { WhatsAppClone
  • 21. } @Override public void userTyping(String contactId) { } @Override public void messageViewed(String msgId, List<String> userIds) { } }); } public void start() { if(current != null){ current.show(); bindMessageListener(); return; } String phoneNumber = Preferences.get("PhoneNumber", null); if(phoneNumber == null) { ActivationForm.create("Signup"). codeDigits(6). show(s -> { WhatsAppClone
  • 22. } @Override public void userTyping(String contactId) { } @Override public void messageViewed(String msgId, List<String> userIds) { } }); } public void start() { if(current != null){ current.show(); bindMessageListener(); return; } String phoneNumber = Preferences.get("PhoneNumber", null); if(phoneNumber == null) { ActivationForm.create("Signup"). codeDigits(6). show(s -> { WhatsAppClone
  • 23. public void start() { if(current != null){ current.show(); bindMessageListener(); return; } String phoneNumber = Preferences.get("PhoneNumber", null); if(phoneNumber == null) { ActivationForm.create("Signup"). codeDigits(6). show(s -> { Log.p("SMS Activation returned " + s); Preferences.set("PhoneNumber", s); new MainForm().show(); }, new SMSVerifyImpl()); } else { new MainForm().show(); } bindMessageListener(); callSerially(() -> registerPush()); } WhatsAppClone
  • 24. public void start() { if(current != null){ current.show(); bindMessageListener(); return; } String phoneNumber = Preferences.get("PhoneNumber", null); if(phoneNumber == null) { ActivationForm.create("Signup"). codeDigits(6). show(s -> { Log.p("SMS Activation returned " + s); Preferences.set("PhoneNumber", s); new MainForm().show(); }, new SMSVerifyImpl()); } else { new MainForm().show(); } bindMessageListener(); callSerially(() -> registerPush()); } WhatsAppClone
  • 25. public void start() { if(current != null){ current.show(); bindMessageListener(); return; } String phoneNumber = Preferences.get("PhoneNumber", null); if(phoneNumber == null) { ActivationForm.create("Signup"). codeDigits(6). show(s -> { Log.p("SMS Activation returned " + s); Preferences.set("PhoneNumber", s); new MainForm().show(); }, new SMSVerifyImpl()); } else { new MainForm().show(); } bindMessageListener(); callSerially(() -> registerPush()); } WhatsAppClone
  • 26. public void start() { if(current != null){ current.show(); bindMessageListener(); return; } String phoneNumber = Preferences.get("PhoneNumber", null); if(phoneNumber == null) { ActivationForm.create("Signup"). codeDigits(6). show(s -> { Log.p("SMS Activation returned " + s); Preferences.set("PhoneNumber", s); new MainForm().show(); }, new SMSVerifyImpl()); } else { new MainForm().show(); } bindMessageListener(); callSerially(() -> registerPush()); } WhatsAppClone
  • 27. public void start() { if(current != null){ current.show(); bindMessageListener(); return; } String phoneNumber = Preferences.get("PhoneNumber", null); if(phoneNumber == null) { ActivationForm.create("Signup"). codeDigits(6). show(s -> { Log.p("SMS Activation returned " + s); Preferences.set("PhoneNumber", s); new MainForm().show(); }, new SMSVerifyImpl()); } else { new MainForm().show(); } bindMessageListener(); callSerially(() -> registerPush()); } WhatsAppClone
  • 28. public void start() { if(current != null){ current.show(); bindMessageListener(); return; } String phoneNumber = Preferences.get("PhoneNumber", null); if(phoneNumber == null) { ActivationForm.create("Signup"). codeDigits(6). show(s -> { Log.p("SMS Activation returned " + s); Preferences.set("PhoneNumber", s); new MainForm().show(); }, new SMSVerifyImpl()); } else { new MainForm().show(); } bindMessageListener(); callSerially(() -> registerPush()); } WhatsAppClone
  • 29. public void start() { if(current != null){ current.show(); bindMessageListener(); return; } String phoneNumber = Preferences.get("PhoneNumber", null); if(phoneNumber == null) { ActivationForm.create("Signup"). codeDigits(6). show(s -> { Log.p("SMS Activation returned " + s); Preferences.set("PhoneNumber", s); new MainForm().show(); }, new SMSVerifyImpl()); } else { new MainForm().show(); } bindMessageListener(); callSerially(() -> registerPush()); } WhatsAppClone
  • 30. public void start() { if(current != null){ current.show(); bindMessageListener(); return; } String phoneNumber = Preferences.get("PhoneNumber", null); if(phoneNumber == null) { ActivationForm.create("Signup"). codeDigits(6). show(s -> { Log.p("SMS Activation returned " + s); Preferences.set("PhoneNumber", s); new MainForm().show(); }, new SMSVerifyImpl()); } else { new MainForm().show(); } bindMessageListener(); callSerially(() -> registerPush()); } WhatsAppClone
  • 31. public void start() { if(current != null){ current.show(); bindMessageListener(); return; } String phoneNumber = Preferences.get("PhoneNumber", null); if(phoneNumber == null) { ActivationForm.create("Signup"). codeDigits(6). show(s -> { Log.p("SMS Activation returned " + s); Preferences.set("PhoneNumber", s); new MainForm().show(); }, new SMSVerifyImpl()); } else { new MainForm().show(); } bindMessageListener(); callSerially(() -> registerPush()); } WhatsAppClone
  • 32. public void start() { if(current != null){ current.show(); bindMessageListener(); return; } String phoneNumber = Preferences.get("PhoneNumber", null); if(phoneNumber == null) { ActivationForm.create("Signup"). codeDigits(6). show(s -> { Log.p("SMS Activation returned " + s); Preferences.set("PhoneNumber", s); new MainForm().show(); }, new SMSVerifyImpl()); } else { new MainForm().show(); } bindMessageListener(); callSerially(() -> registerPush()); } WhatsAppClone
  • 33. Preferences.set("PhoneNumber", s); new MainForm().show(); }, new SMSVerifyImpl()); } else { new MainForm().show(); } bindMessageListener(); callSerially(() -> registerPush()); } public void stop() { Server.closeWebsocketConnection(); current = getCurrentForm(); if(current instanceof Dialog) { ((Dialog)current).dispose(); current = getCurrentForm(); } } public void destroy() { } } WhatsAppClone