aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortomsmeding <tom.smeding@gmail.com>2017-05-24 21:04:16 +0200
committertomsmeding <tom.smeding@gmail.com>2017-05-24 21:04:16 +0200
commit096270b1d0ec09f0dbcfe8653957154a07a90de4 (patch)
treebbfaa58f0c2c83e9163bc9be01782f46bd5228a4
parent438254db34608808f7d521fe871e21393542c556 (diff)
server: Fix firebase notifications
-rwxr-xr-xfirebase-io/firebase-io.js13
-rw-r--r--firebase.c8
2 files changed, 15 insertions, 6 deletions
diff --git a/firebase-io/firebase-io.js b/firebase-io/firebase-io.js
index bfcca0f..e4e7305 100755
--- a/firebase-io/firebase-io.js
+++ b/firebase-io/firebase-io.js
@@ -10,6 +10,7 @@ firebase.initializeApp({
const fieldConverters=new Map([
["token",(b)=>b.toString()],
["user",(b)=>b.toString()],
+ ["to_user",(b)=>b.toString()],
["room",(b)=>b.toString()],
["message",(b)=>b.toString()],
["timestamp",(b)=>b.toString()], // Nanosecond timestamps are too close to 52-bit range
@@ -71,6 +72,7 @@ function processMessage(type,fields){
switch(type){
case "message":
const user=fields.get("user");
+ const to_user=fields.get("to_user");
const room=fields.get("room");
const token=fields.get("token");
const payload={
@@ -78,6 +80,10 @@ function processMessage(type,fields){
title: user+" ("+room+")",
body: fields.get("message"),
tag: room,
+ },
+ data: {
+ user: user,
+ room: room,
}
};
firebase.messaging().sendToDevice(token,payload)
@@ -85,10 +91,11 @@ function processMessage(type,fields){
const result=response.results[0];
const realToken=result.canonicalRegistrationToken;
if(result.error){
- console.error("JS: Send error:",result.error);
+ console.error("JS: Send error:",result.error.errorInfo);
+ console.log("delete_token "+to_user+" "+token);
} else if(realToken&&realToken!=token){
- console.log("delete_token "+user+" "+token);
- console.log("add_token "+user+" "+realToken);
+ console.log("delete_token "+to_user+" "+token);
+ console.log("add_token "+to_user+" "+realToken);
}
})
.catch((err)=>{
diff --git a/firebase.c b/firebase.c
index 6244882..5221af7 100644
--- a/firebase.c
+++ b/firebase.c
@@ -16,11 +16,13 @@ static void write_field(FILE *f,const char *key,const char *value){
fprintf(f," %s %zu %s",key,strlen(value),value);
}
-static void token_send(const char *token,const char *room,const char *user,const char *msg){
+static void token_send(const char *token,const char *to_user,const char *room,const char *user,const char *msg){
+ fprintf(stderr,"token_send(%s,%s,%s,%s,%s)\n",token,to_user,room,user,msg);
fprintf(js_write,"message");
write_field(js_write,"token",token);
write_field(js_write,"room",room);
write_field(js_write,"user",user);
+ write_field(js_write,"to_user",to_user);
write_field(js_write,"message",msg);
fprintf(js_write,"\n");
fflush(js_write);
@@ -67,7 +69,7 @@ static void script_output_listener(FILE *js_read){
continue;
invalid_line:
- fprintf(stderr,"firebase thread: Invalid line form js script: <%s>\n",line);
+ fprintf(stderr,"firebase thread: Invalid line from js script: <%s>\n",line);
}
}
@@ -130,7 +132,7 @@ void firebase_send_message(const char *room,i64 roomid,const char *user,const ch
if(userdata_is_active(members.list[i].id))continue;
struct db_strings_list tokens=db_user_tokens(members.list[i].id);
for(i64 j=0;j<tokens.count;j++){
- token_send(tokens.list[j],room,user,msg);
+ token_send(tokens.list[j],members.list[i].name,room,user,msg);
}
db_nullify_strings_list(tokens);
}