Skip to content

Commit

Permalink
allow setting new virgin contact names
Browse files Browse the repository at this point in the history
  • Loading branch information
bulk88 committed Oct 28, 2023
1 parent 82e5a2c commit 7bb4db7
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 28 deletions.
45 changes: 25 additions & 20 deletions client.js
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,7 @@ x.onreadystatechange=function(){if(x.readyState==4){
getAuthToken(function(tok) {mkContact_t(false,tok,name,num,finish)});
}
else if(x.status != 200) {alert("status: "+x.status+"\nresp:"+x.response);finish && finish(x.response||-1);}
else {finish && finish(false)};
else {finish && finish(false, JSON.parse(x.response))};
}};
x.send('{"name":{"display_name":'+JSON.stringify(name)+'},"phone":{"value":"+1'+num+'","type":""}}');
}
Expand Down Expand Up @@ -901,26 +901,31 @@ x.onreadystatechange=function(){
}
else if(x.status != 200) {alert("status: "+x.status+"\nresp:"+x.response);finish && finish(x.response||-1);}
else {
var body = JSON.parse(x.response).personResponse[0].person;
if(name != null) {
body.name[0].displayName = name;
}
if(url != null) {
obj = (body.website = body.website || []);
obj = (obj[0] = obj[0] || {});
obj.value = url;
obj.metadata = obj.metadata || {"container": "CONTACT"}; // or err 400
var body = JSON.parse(x.response).personResponse[0];
if(body.status == "SUCCESS") {
body = body.person;
if(name != null) {
body.name[0].displayName = name;
}
if(url != null) {
obj = (body.website = body.website || []);
obj = (obj[0] = obj[0] || {});
obj.value = url;
obj.metadata = obj.metadata || {"container": "CONTACT"}; // or err 400
}
x = new XMLHttpRequest;
/* from GV Web UI */
x.open("PUT", 'https://content-people-pa.googleapis.com/v2/people/'+pid+'?container=CONTACT&person_id='+pid+(name != null?'&field_mask=person.name':'')+(url != null?'&field_mask=person.website':'')+'&get_people_request.extension_set.extension_names=phone_canonicalization&get_people_request.merged_person_source_options.person_model_params.person_model=CONTACT_CENTRIC&get_people_request.request_mask.include_field.paths=person.name&get_people_request.request_mask.include_field.paths=person.website&get_people_request.request_mask.include_container=CONTACT&get_people_request.request_mask.include_container=PROFILE&get_people_request.request_mask.include_container=DOMAIN_CONTACT&get_people_request.request_mask.include_container=DOMAIN_PROFILE&get_people_request.request_mask.include_container=PLACE&get_people_request.context.migration_options.use_new_request_mask_behavior=true&prettyPrint=false&alt=json',1);
x.setRequestHeader("Content-Type", "application/json");
x.setRequestHeader("Authorization","Bearer "+tok);
x.onreadystatechange=function(){if(x.readyState==4){
if(x.status != 200) {alert("status: "+x.status+"\nresp:"+x.response);finish && finish(x.response||-1);}
else {finish && finish(false, JSON.parse(x.response))};
}};
x.send(JSON.stringify(body));
} else { //contact was deleted in another window
alert("status: "+x.status+"\nresp:"+x.response);finish && finish(x.response||-1);
}
x = new XMLHttpRequest;
/* from GV Web UI */
x.open("PUT", 'https://content-people-pa.googleapis.com/v2/people/'+pid+'?container=CONTACT&person_id='+pid+(name != null?'&field_mask=person.name':'')+(url != null?'&field_mask=person.website':'')+'&get_people_request.extension_set.extension_names=phone_canonicalization&get_people_request.merged_person_source_options.person_model_params.person_model=CONTACT_CENTRIC&get_people_request.request_mask.include_field.paths=person.name&get_people_request.request_mask.include_field.paths=person.website&get_people_request.request_mask.include_container=CONTACT&get_people_request.request_mask.include_container=PROFILE&get_people_request.request_mask.include_container=DOMAIN_CONTACT&get_people_request.request_mask.include_container=DOMAIN_PROFILE&get_people_request.request_mask.include_container=PLACE&get_people_request.context.migration_options.use_new_request_mask_behavior=true&prettyPrint=false&alt=json',1);
x.setRequestHeader("Content-Type", "application/json");
x.setRequestHeader("Authorization","Bearer "+tok);
x.onreadystatechange=function(){if(x.readyState==4){
if(x.status != 200) {alert("status: "+x.status+"\nresp:"+x.response);finish && finish(x.response||-1);}
else {finish && finish(false, JSON.parse(x.response))};
}};
x.send(JSON.stringify(body));
};
}};
x.send('');
Expand Down
2 changes: 1 addition & 1 deletion docs/ac.appcache
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
CACHE MANIFEST
# v Mon Oct 23 04:06:16 2023
# v Sat Oct 28 15:46:09 2023

CACHE:
index.html
Expand Down
2 changes: 1 addition & 1 deletion docs/client.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/thread.html

Large diffs are not rendered by default.

16 changes: 11 additions & 5 deletions thread.html
Original file line number Diff line number Diff line change
Expand Up @@ -287,10 +287,9 @@
//set save handler
this.onclick = function () {
var button = this,
input = button.previousElementSibling;
if(old_name !== input.value) {
button.textContent = "\u270F\uFE0F\u231B"; //hourglass mark
upContact(input.getAttribute("data-pid"), input.value, null, function (err,r) {
input = button.previousElementSibling,
pid,
xhrCB = function (err,r) {
if (err) {
button.textContent = "\u270F\uFE0F\u2718"; //X mark
} else {
Expand All @@ -303,7 +302,14 @@
}
button.onclick = old_onclick_evt;
button.parentNode.replaceChild(span,input);
}); //end xhr callback
};
if(old_name !== input.value) {
button.textContent = "\u270F\uFE0F\u231B"; //hourglass mark
if((pid = input.getAttribute("data-pid")) !== 'null') {
upContact(pid, input.value, null, xhrCB); //end xhr callback
} else {
mkContact(input.value, location.hash.substring(1), xhrCB);
}
} else { //no I/O name didn't change
button.parentNode.replaceChild(span,input);
button.onclick = old_onclick_evt;
Expand Down

0 comments on commit 7bb4db7

Please sign in to comment.