Skip to content

Commit

Permalink
Merge pull request #4 from stakwork/sender-socket
Browse files Browse the repository at this point in the history
sender socket
  • Loading branch information
Evanfeenstra authored Mar 30, 2020
2 parents 58d5c32 + afb2dbf commit c8db0d9
Show file tree
Hide file tree
Showing 21 changed files with 36 additions and 33 deletions.
4 changes: 2 additions & 2 deletions api/controllers/confirmations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export async function receiveConfirmation(payload) {
})
socket.sendJson({
type: 'confirmation',
response: jsonUtils.messageToJson(message, chat)
response: jsonUtils.messageToJson(message, chat, sender)
})
}
done()
Expand All @@ -71,7 +71,7 @@ export async function receiveConfirmation(payload) {

socket.sendJson({
type: 'confirmation',
response: jsonUtils.messageToJson(message, chat)
response: jsonUtils.messageToJson(message, chat, sender)
})
}
}
2 changes: 1 addition & 1 deletion api/controllers/invoices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ const receiveInvoice = async (payload) => {

socket.sendJson({
type: 'invoice',
response: jsonUtils.messageToJson(message, chat)
response: jsonUtils.messageToJson(message, chat, sender)
})

sendNotification(chat, sender.alias, 'message')
Expand Down
8 changes: 4 additions & 4 deletions api/controllers/media.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ const purchase = async (req, res) => {
message: msg,
success: async (data) => {
console.log('purchase sent', { data })
resUtils.success(res, jsonUtils.messageToJson(message))
resUtils.success(res, jsonUtils.messageToJson(message, chat))
},
failure: error=> resUtils.failure(res, error.message),
})
Expand Down Expand Up @@ -318,7 +318,7 @@ const receivePurchaseAccept = async (payload) => {
})
socket.sendJson({
type: 'purchase_accept',
response: jsonUtils.messageToJson(msg, chat)
response: jsonUtils.messageToJson(msg, chat, sender)
})
}

Expand All @@ -344,7 +344,7 @@ const receivePurchaseDeny = async (payload) => {
})
socket.sendJson({
type: 'purchase_deny',
response: jsonUtils.messageToJson(msg, chat)
response: jsonUtils.messageToJson(msg, chat, sender)
})
}

Expand Down Expand Up @@ -378,7 +378,7 @@ const receiveAttachment = async (payload) => {

socket.sendJson({
type: 'attachment',
response: jsonUtils.messageToJson(message, chat)
response: jsonUtils.messageToJson(message, chat, sender)
})

sendNotification(chat, sender.alias, 'message')
Expand Down
2 changes: 1 addition & 1 deletion api/controllers/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ const receiveMessage = async (payload) => {

socket.sendJson({
type: 'message',
response: jsonUtils.messageToJson(message, chat)
response: jsonUtils.messageToJson(message, chat, sender)
})

sendNotification(chat, sender.alias, 'message')
Expand Down
2 changes: 1 addition & 1 deletion api/controllers/payment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ const receivePayment = async (payload) => {

socket.sendJson({
type: 'direct_payment',
response: jsonUtils.messageToJson(message, chat)
response: jsonUtils.messageToJson(message, chat, sender)
})

sendNotification(chat, sender.alias, 'message')
Expand Down
8 changes: 5 additions & 3 deletions api/grpc/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,14 @@ function subscribeInvoices(actions) {
createdAt: new Date(settleDate),
updatedAt: new Date(settleDate)
})

const sender = await models.Contact.findOne({ where: { id: senderId } })

socket.sendJson({
type: 'payment',
response: jsonUtils.messageToJson(message, chat)
response: jsonUtils.messageToJson(message, chat, sender)
})

const sender = await models.Contact.findOne({ where: { id: senderId } })

sendNotification(chat, sender.alias, 'message')
}
});
Expand Down
3 changes: 2 additions & 1 deletion api/utils/json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function chatToJson(c) {
})
}

function messageToJson(msg, chat = null) {
function messageToJson(msg, chat, contact?) {
const message = msg.dataValues||msg
let statusMap = message.statusMap || null
if(message.statusMap && typeof message.statusMap==='string'){
Expand All @@ -23,6 +23,7 @@ function messageToJson(msg, chat = null) {
...message,
statusMap,
chat: chat ? chatToJson(chat) : null,
contact: contact ? contactToJson(contact) : null
})
}

Expand Down
4 changes: 2 additions & 2 deletions dist/api/controllers/confirmations.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/api/controllers/confirmations.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/api/controllers/invoices.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/api/controllers/invoices.js.map

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions dist/api/controllers/media.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit c8db0d9

Please sign in to comment.