Notification: Set a new Friendship and Accepted Friendship
This commit is contained in:
@@ -30,6 +30,8 @@ const download = require('image-downloader');
|
||||
// SETTINGS WebPush Configuration
|
||||
const webpush = require('web-push');
|
||||
|
||||
const i18n = require('i18n');
|
||||
|
||||
const FILELOG = 'filelog.txt';
|
||||
const FILEEVENTS = 'logevents.txt';
|
||||
const FILEMANAGERS = 'logmanagers.txt';
|
||||
@@ -578,6 +580,7 @@ module.exports = {
|
||||
'typeid',
|
||||
'dest',
|
||||
'descr',
|
||||
'title',
|
||||
'openUrl',
|
||||
'datenotif',
|
||||
'read',
|
||||
@@ -852,9 +855,21 @@ module.exports = {
|
||||
|
||||
},
|
||||
|
||||
getReqByPar(idapp, usernameOrig) {
|
||||
return {
|
||||
body: {
|
||||
idapp: idapp,
|
||||
},
|
||||
user: {
|
||||
username: usernameOrig,
|
||||
}
|
||||
};
|
||||
},
|
||||
|
||||
sendNotificationByUsername: async function(idapp, username, cmd, telegram, usernameOrig) {
|
||||
|
||||
var {User} = require('../models/user');
|
||||
const {SendNotif} = require('../models/sendnotif');
|
||||
|
||||
const telegrambot = require('../telegram/telegrambot');
|
||||
|
||||
@@ -865,7 +880,7 @@ module.exports = {
|
||||
let userId = user._id;
|
||||
let lang = user.lang;
|
||||
|
||||
let sendnotif = true;
|
||||
let sendmynotif = true;
|
||||
|
||||
let title = this.getNomeAppByIdApp(idapp);
|
||||
let descr = '';
|
||||
@@ -880,19 +895,26 @@ module.exports = {
|
||||
|
||||
const userrecDest = await User.getUserShortDataByUsername(idapp, usernameOrig);
|
||||
|
||||
const req = this.getReqByPar(idapp, usernameOrig);
|
||||
|
||||
// CREATE NOTIFICATION IN TABLE SENDNOTIF
|
||||
SendNotif.createNewNotifToSingleUser(req, null, username, true, shared_consts.TypeNotifs.TYPEDIR_FRIENDS, shared_consts.TypeNotifs.ID_FRIENDS_NEW_REC);
|
||||
|
||||
if (userrecDest) {
|
||||
sendnotif = false; // non lo rimandare 2 volte !
|
||||
sendmynotif = false; // non lo rimandare 2 volte !
|
||||
// SEND TELEGRAM NOTIFICATION
|
||||
telegrambot.askConfirmationUserFriend(idapp, shared_consts.CallFunz.RICHIESTA_AMICIZIA, userrecDest, username, usernameOrig);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (userId) {
|
||||
this.sendNotificationToUser(userId, title, descr, openUrl, '', tag,
|
||||
actions);
|
||||
// SEND PUSH NOTIFICATION
|
||||
this.sendNotificationToUser(userId, title, descr, openUrl, '', tag, actions);
|
||||
}
|
||||
|
||||
if (telegram && sendnotif) {
|
||||
if (telegram && sendmynotif) {
|
||||
|
||||
const idtelegram = await User.TelegIdByUsername(idapp, username);
|
||||
|
||||
@@ -1105,11 +1127,18 @@ module.exports = {
|
||||
if (String(userpassed) !== String(userauth)) {
|
||||
// I'm trying to write something not mine!
|
||||
this.mylog('userId = ', userpassed, 'req.user._id', userauth);
|
||||
return {
|
||||
exit: true,
|
||||
ret: res.status(404).
|
||||
send({code: server_constants.RIS_CODE_TODO_CREATING_NOTMYUSER}),
|
||||
};
|
||||
if (!res) {
|
||||
return {
|
||||
exit: true,
|
||||
ret: false,
|
||||
}
|
||||
} else {
|
||||
return {
|
||||
exit: true,
|
||||
ret: res.status(404).
|
||||
send({code: server_constants.RIS_CODE_TODO_CREATING_NOTMYUSER}),
|
||||
};
|
||||
}
|
||||
} else {
|
||||
return {exit: false, ret: false};
|
||||
}
|
||||
@@ -2754,7 +2783,7 @@ module.exports = {
|
||||
async loadApps() {
|
||||
try {
|
||||
this.MYAPPS = await Site.findAll(0);
|
||||
console.log('this.MYAPPS', this.MYAPPS);
|
||||
// console.log('this.MYAPPS', this.MYAPPS);
|
||||
}catch (e) {
|
||||
console.error('loadApps', e);
|
||||
}
|
||||
@@ -2933,6 +2962,27 @@ module.exports = {
|
||||
});
|
||||
},
|
||||
|
||||
capitalize(value) {
|
||||
if (!value) {
|
||||
return ''
|
||||
}
|
||||
const myval = value.toString()
|
||||
return myval.charAt(0).toUpperCase() + myval.slice(1)
|
||||
},
|
||||
|
||||
firstchars(value, numchars = 200) {
|
||||
if (!value) {
|
||||
return ''
|
||||
}
|
||||
try {
|
||||
let mycar = value.substring(0, numchars)
|
||||
if (value.length > numchars) mycar += '...'
|
||||
return mycar
|
||||
} catch (e) {
|
||||
return value
|
||||
}
|
||||
},
|
||||
|
||||
removeAtChar(mystr) {
|
||||
if (mystr && mystr[0] === '@'){
|
||||
return mystr = mystr.substring(1);
|
||||
@@ -2961,4 +3011,16 @@ module.exports = {
|
||||
|
||||
},
|
||||
|
||||
getContentNotifByParams(params, content, typesend) {
|
||||
if (typesend === shared_consts.TypeSend.TELEGRAM) {
|
||||
|
||||
let myhost = this.getHostByIdApp(params.idapp);
|
||||
|
||||
if (params.openUrl)
|
||||
content = content + '\n' + '<a href="' + myhost + params.openUrl + '">' + i18n.__('OPEN PAGE') + '</a>';
|
||||
}
|
||||
|
||||
return content;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user