推送:保存用户个推cid

This commit is contained in:
qiaoxin
2021-07-05 19:15:40 +08:00
parent 33dcb728e2
commit 6492c8ce0d
5 changed files with 127 additions and 107 deletions

View File

@@ -13,7 +13,7 @@ var DUPLICATE_ERROR = "Please change your name to login.";
util = {
urlRE: /https?:\/\/([-\w\.]+)+(:\d+)?(\/([^\s]*(\?\S+)?)?)?/g,
// html sanitizer
toStaticHTML: function(inputHtml) {
toStaticHTML: function (inputHtml) {
inputHtml = inputHtml.toString();
return inputHtml.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
},
@@ -21,24 +21,24 @@ util = {
//digits is minimum length of output
//zeroPad(3, 5); returns "005"
//zeroPad(2, 500); returns "500"
zeroPad: function(digits, n) {
zeroPad: function (digits, n) {
n = n.toString();
while(n.length < digits)
n = '0' + n;
while (n.length < digits)
n = '0' + n;
return n;
},
//it is almost 8 o'clock PM here
//timeString(new Date); returns "19:49"
timeString: function(date) {
timeString: function (date) {
var minutes = date.getMinutes().toString();
var hours = date.getHours().toString();
return this.zeroPad(2, hours) + ":" + this.zeroPad(2, minutes);
},
//does the argument only contain whitespace?
isBlank: function(text) {
isBlank: function (text) {
var blank = /^\s*$/;
return(text.match(blank) !== null);
return (text.match(blank) !== null);
}
};
@@ -51,11 +51,11 @@ function scrollDown(base) {
// add message on board
function addMessage(from, target, text, time) {
var name = (target == '*' ? 'all' : target);
if(text === null) return;
if(time == null) {
if (text === null) return;
if (time == null) {
// if the time is null or undefined, use the current time.
time = new Date();
} else if((time instanceof Date) === false) {
} else if ((time instanceof Date) === false) {
// if it's a timestamp, interpret it
time = new Date(time);
}
@@ -77,8 +77,8 @@ function addMessage(from, target, text, time) {
// show tip
function tip(type, name) {
var tip,title;
switch(type){
var tip, title;
switch (type) {
case 'online':
tip = name + ' is online now.';
title = 'Online Notify';
@@ -92,13 +92,13 @@ function tip(type, name) {
title = 'Message Notify';
break;
}
var pop=new Pop(title, tip);
var pop = new Pop(title, tip);
};
// init user list
function initUserList(data) {
users = data.users;
for(var i = 0; i < users.length; i++) {
for (var i = 0; i < users.length; i++) {
var slElement = $(document.createElement("option"));
slElement.attr("value", users[i]);
slElement.text(users[i]);
@@ -117,9 +117,9 @@ function addUser(user) {
// remove user from user list
function removeUser(user) {
$("#usersList option").each(
function() {
if($(this).val() === user) $(this).remove();
});
function () {
if ($(this).val() === user) $(this).remove();
});
};
// set your name
@@ -142,13 +142,13 @@ function showError(content) {
function queryEntry(param, callback) {
var route = 'gate.gateHandler.queryEntry';
pomelo.init({
host: window.location.hostname,
host: '127.0.0.1',
port: 3014,
log: true
}, function() {
pomelo.request(route, param, function(data) {
}, function () {
pomelo.request(route, param, function (data) {
pomelo.disconnect();
if(data.code !== 0) {
if (data.code !== 0) {
showError(data.msg);
return;
}
@@ -161,25 +161,25 @@ function addToContent(text) {
$('#content').html(`<pre>${text}</pre>`);
}
$(document).ready(function() {
$(document).ready(function () {
//when first time into chat room.
//wait message from the server.
pomelo.on('onChat', function(data) {
pomelo.on('onChat', function (data) {
addMessage(data.from, data.target, data.msg);
$("#chatHistory").show();
if(data.from !== username)
if (data.from !== username)
tip('message', data.from);
});
//update user list
pomelo.on('onAdd', function(data) {
pomelo.on('onAdd', function (data) {
var user = data.user;
tip('online', user);
addUser(user);
});
//update user list
pomelo.on('onLeave', function(data) {
pomelo.on('onLeave', function (data) {
var user = data.user;
tip('offline', user);
removeUser(user);
@@ -187,7 +187,7 @@ $(document).ready(function() {
//handle disconect message, occours when the client is disconnect with servers
pomelo.on('disconnect', function(reason) {
pomelo.on('disconnect', function (reason) {
$("#add").show();
$('#remove').hide();
});
@@ -197,21 +197,21 @@ $(document).ready(function() {
var t = $('form').serializeArray();
//t的值为[{name: "a1", value: "xx"},
//{name: "a2", value: "xx"}...]
$.each(t, function() {
$.each(t, function () {
console.log(this.name, this.value, this.name == 'params' && this.value)
if(this.name == 'params' && this.value) {
if (this.name == 'params' && this.value) {
try {
var json = JSON.parse(this.value);
for(var key in json) {
for (var key in json) {
console.log(key, json[key])
d[key] = json[key];
}
} catch(e) {
} catch (e) {
alert('参数json格式错误');
return;
}
} else {
if(this.name == serverId) this.value = parseInt(this.value);
if (this.name == serverId) this.value = parseInt(this.value);
d[this.name] = this.value;
}
});
@@ -220,21 +220,21 @@ $(document).ready(function() {
}
//deal with login button click.
$("#add").click(function() {
$("#add").click(function () {
var d = getFormParam();
//query entry of connection
queryEntry(d, function(host, port) {
queryEntry(d, function (host, port) {
pomelo.init({
host: host,
port: port,
log: true
}, function() {
}, function () {
var route = "connector.entryHandler.enter";
pomelo.request(route, d, function(data) {
pomelo.request(route, d, function (data) {
console.log(data)
if(data.code != 0) {
if(data.msg) {
if (data.code != 0) {
if (data.msg) {
showError(data.msg);
} else {
showError(DUPLICATE_ERROR);
@@ -243,7 +243,7 @@ $(document).ready(function() {
}
$("#add").hide();
$('#remove').show();
addToContent(JSON.stringify(data, null,4));
addToContent(JSON.stringify(data, null, 4));
// setName();
// setRoom();
// showChat();
@@ -253,14 +253,14 @@ $(document).ready(function() {
});
});
$("#send").click(function() {
$("#send").click(function () {
var d = getFormParam();
//query entry of connection
var route = d.route;
pomelo.request(route, d, function(data) {
pomelo.request(route, d, function (data) {
console.log(data)
if(data.error) {
if(data.data) {
if (data.error) {
if (data.data) {
showError(data.data);
} else {
showError(DUPLICATE_ERROR);
@@ -277,47 +277,47 @@ $(document).ready(function() {
});
});
$('#confirm').click(function() {
$('#confirm').click(function () {
var value = $('#tuisong').val();
//update user list
pomelo.on(value, function(data) {
pomelo.on(value, function (data) {
$('#time').html(Date.now() + '');
$('#content2').html(`<pre>${JSON.stringify(data, null, 4)}</pre>`);
});
alert('OK')
})
$("#remove").click(function() {
$("#remove").click(function () {
pomelo.disconnect();
$("#add").show();
$('#remove').hide();
});
$("#errbtntest").click(()=>{
$("#errbtntest").click(() => {
var route = "chat.chatHandler.send";
pomelo.request(route,{
content:$("#entry").attr("value").replace("\n", ""),
rid:rid,
pomelo.request(route, {
content: $("#entry").attr("value").replace("\n", ""),
rid: rid,
// lost field
},data=>{
console.warn("!!?? ",data)
}, data => {
console.warn("!!?? ", data)
})
})
//deal with chat mode.
$("#entry").keypress(function(e) {
$("#entry").keypress(function (e) {
var route = "chat.chatHandler.send";
var target = $("#usersList").val();
if(e.keyCode != 13 /* Return */ ) return;
if (e.keyCode != 13 /* Return */) return;
var msg = $("#entry").attr("value").replace("\n", "");
if(!util.isBlank(msg)) {
if (!util.isBlank(msg)) {
pomelo.request(route, {
rid: rid,
content: msg,
from: username,
target: target
}, function(data) {
}, function (data) {
$("#entry").attr("value", ""); // clear the entry field.
if(target != '*' && target != username) {
if (target != '*' && target != username) {
addMessage(username, target, msg);
$("#chatHistory").show();
}