Skip to content

Commit

Permalink
## v0.2.23 - online
Browse files Browse the repository at this point in the history
- log updates
  • Loading branch information
sponzillo committed Oct 23, 2022
1 parent 3d0272e commit 133897f
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 35 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@

**npm @chat21/chat21-server@0.2.22**
**npm @chat21/chat21-server@0.2.23**

available on:
▶️ https://www.npmjs.com/package/@chat21/chat21-server

## v0.2.23 - online
- log updates

## v0.2.21 - online
- Docker image update:16

Expand Down
64 changes: 33 additions & 31 deletions observer.js
Original file line number Diff line number Diff line change
Expand Up @@ -416,13 +416,14 @@ function process_outgoing(topic, message_string, callback) {
inline_group.uid = group_id;
inline_group.members[group_id] = 1
inline_group.members[sender_id] = 1
console.log("...inline_group:", inline_group);
logger.debug("...inline_group:", inline_group);
sendMessageToGroupMembers(outgoing_message, inline_group, app_id, (ack) => {
callback(ack);
});
return;
}
// chatdb.getGroup(group_id, function(err, group) { // REDIS?
logger.debug("getting group:", group_id)
getGroup(group_id, function(err, group) {
if (!group) { // created only to temporary store group-messages in group-timeline
// TODO: 1. create group (on-the-fly), 2. remove this code, 3. continue as if the group exists.
Expand All @@ -435,62 +436,63 @@ function process_outgoing(topic, message_string, callback) {
}
group.members[sender_id] = 1
}

logger.debug("got group:" + JSON.stringify(group));
// Adding the group as a "volatile" member, so we easily get a copy of
// all the group messages in timelineOf: group.uid
group.members[group.uid] = 1
sendMessageToGroupMembers(outgoing_message, group, app_id, (ack) => {
logger.debug("Message sent to group:" + JSON.stringify(group));
callback(ack);
});
})
}
}

function sendMessageToGroupMembers(outgoing_message, group, app_id, callback) {
// logger.debug("Writing to group:", group)
logger.debug("sendMessageToGroupMembers():", JSON.stringify(group));
let count = 0;
logger.debug("group members", group.members);
let max = Object.keys(group.members).length;
let error_encoutered = false;
logger.debug("sendMessageToGroupMembers() - group members", group.members);
// let max = Object.keys(group.members).length;
// let error_encoutered = false;
for (let [member_id, value] of Object.entries(group.members)) {
const inbox_of = member_id;
const convers_with = group.uid;
logger.debug("inbox_of: "+ inbox_of);
logger.debug("convers_with: " + convers_with);
logger.debug("sending group outgoing message to member", member_id);
logger.debug("sendMessageToGroupMembers() inbox_of: "+ inbox_of);
logger.debug("sendMessageToGroupMembers() convers_with: " + convers_with);
logger.debug("sendMessageToGroupMembers() sending group outgoing message to member", member_id);
// if (inbox_of === outgoing_message.sender) {
if (inbox_of === group.uid) { // choosing one member, the group ("volatile" member), for the "status=SENT", used by the "message-sent" webhook
logger.debug("inbox_of === outgoing_message.sender. status=SENT system YES?", inbox_of);
logger.debug("sendMessageToGroupMembers() inbox_of === outgoing_message.sender. status=SENT system YES?", inbox_of);
outgoing_message.status = MessageConstants.CHAT_MESSAGE_STATUS_CODE.SENT;
}
else if (outgoing_message.attributes && outgoing_message.attributes.hiddenFor && outgoing_message.attributes.hiddenFor === inbox_of) {
logger.debug('sendGroupMessageToMembersTimeline skip message for ' + outgoing_message.attributes.hiddenFor);
logger.debug('sendMessageToGroupMembers() sendGroupMessageToMembersTimeline skip message for ' + outgoing_message.attributes.hiddenFor);
break;
}
else {
logger.debug("inbox_of != outgoing_message.sender. status=DELIVERED no system, is:", inbox_of);
logger.debug("sendMessageToGroupMembers() inbox_of != outgoing_message.sender. status=DELIVERED no system, is:", inbox_of);
outgoing_message.status = MessageConstants.CHAT_MESSAGE_STATUS_CODE.DELIVERED;
}
console.log("delivering group message with status...", outgoing_message.status, " to:", inbox_of);
logger.debug("sendMessageToGroupMembers() delivering group message with status...", outgoing_message.status, " to:", inbox_of);
deliverMessage(outgoing_message, app_id, inbox_of, convers_with, function(ok) {
logger.debug("GROUP MESSAGE DELIVERED?", ok)
count++;
logger.debug("Sent Counting:", count);
logger.debug("Max:", max);
// count++;
// logger.debug("Sent Counting:", count);
// logger.debug("Max:", max);
if (!ok) {
logger.debug("Error sending message to group " + group.uid);
error_encoutered = true
}
if (count == max) {
if (error_encoutered) {
logger.error("ERROR SENDING MESSAGE TO GROUP!");
//callback(false)
}
else {
logger.log("ALL OK! MESSAGE SENT TO GROUP! ACK!");
//callback(true);
}
logger.debug("Error sending message to group " + group.uid + " inbox_of: " + inbox_of);
// error_encoutered = true
}
// if (count == max) {
// if (error_encoutered) {
// logger.error("ERROR SENDING MESSAGE TO GROUP!");
// //callback(false)
// }
// else {
// logger.log("ALL OK! MESSAGE SENT TO GROUP! ACK!");
// //callback(true);
// }
// }
})
} // end for
callback(true);
Expand Down Expand Up @@ -741,10 +743,10 @@ function process_update(topic, message_string, callback) {
const recipient_message_update_topic = 'apps.tilechat.users.' + convers_with + '.messages.' + me + '.' + message_id + '.clientupdated'
logger.debug(">>> NOW PUBLISHING... DEST_PATCH: RETURN_RECEIPT. TOPIC: " + recipient_message_update_topic + ", PATCH ", dest_message_patch)
publish(exchange, recipient_message_update_topic, Buffer.from(dest_message_patch_payload), function(err) {
logger.debug(">>> PUBLISHED!!!! RECIPIENT MESSAGE TOPIC UPDATE" + recipient_message_update_topic + " WITH PATCH " , dest_message_patch)
logger.debug(">>> PUBLISHED!!!! RECIPIENT MESSAGE TOPIC UPDATE" + recipient_message_update_topic + " WITH PATCH: " + JSON.stringify(dest_message_patch))
if (err) {
logger.error("publish error (noack):", err);
callback(false)
callback(false);
}
else {
logger.log("webhook_enabled?????", webhook_enabled);
Expand All @@ -770,7 +772,7 @@ function process_update(topic, message_string, callback) {

// TODO: MOVE TO A PERSIST_UPDATED TOPIC/QUEUE...
// TODO, BETTER: USE _WEBHOOK WITH MESSAGE-STATUS-UPDATED TO SAVE THE MESSAGE
logger.debug(">>> ON DISK... WITH A STATUS ON MY MESSAGE-UPDATE TOPIC", topic, "WITH PATCH", my_message_patch)
logger.debug(">>> ON DISK... WITH A STATUS ON MY MESSAGE-UPDATE TOPIC", topic, "WITH PATCH: " + JSON.stringify(my_message_patch));
chatdb.saveOrUpdateMessage(my_message_patch, function(err, msg) {
// logger.debug(">>> MESSAGE ON TOPIC", topic, "UPDATED!")
if (err) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@chat21/chat21-server",
"version": "0.2.22",
"version": "0.2.23",
"description": "Chat21 AMQP/MQTT messages dispatcher",
"dependencies": {
"aedes": "^0.40.1",
Expand Down
4 changes: 2 additions & 2 deletions webhooks/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ class Webhooks {

const endpoints = message['temp_webhook_endpoints'];
delete message['temp_webhook_endpoints'];
logger.log("Event JSON:", json);
logger.log("Event JSON:" + JSON.stringify(json));
endpoints.forEach((endpoint) => {
logger.debug("Sending notification to webhook (message_deliver) on webhook_endpoint:", endpoint);
// const message_id = message.message_id;
Expand Down Expand Up @@ -510,7 +510,7 @@ class Webhooks {
// });
// options.httpsAgent = httpsAgent;
}
logger.debug("Using request options:", options);
logger.debug("Using request options:" + JSON.stringify(options));
try {
const req = protocol.request(options, (response) => {
logger.debug("statusCode: "+ response.statusCode + " for webhook_endpoint: " + endpoint);
Expand Down

0 comments on commit 133897f

Please sign in to comment.