From 903200c060b21fee2207e47c7e2119eed68fca3e Mon Sep 17 00:00:00 2001 From: Zyuhel Date: Tue, 9 Apr 2019 13:27:21 +0300 Subject: [PATCH 01/21] Change output format Return last transaction data in lastTransaction object according to [AIP-14](https://github.com/Adamant-im/AIPs/issues/14) --- build | 0 modules/chatrooms.js | 13 +++++++------ 2 files changed, 7 insertions(+), 6 deletions(-) delete mode 100644 build diff --git a/build b/build deleted file mode 100644 index e69de29b..00000000 diff --git a/modules/chatrooms.js b/modules/chatrooms.js index 4ec096fb..0095a590 100644 --- a/modules/chatrooms.js +++ b/modules/chatrooms.js @@ -127,19 +127,20 @@ __private.listChats = function (filter, cb) { }), params).then(function (rows) { let transactions = [], chats = {}; for (let i = 0; i < rows.length; i++) { - const trs = library.logic.transaction.dbRead(rows[i]); + const trs = {}; + trs.lastTransaction = library.logic.transaction.dbRead(rows[i]); trs.participants = [ - {address: trs.senderId, publicKey: trs.senderPublicKey}, - {address: trs.recipientId, publicKey: trs.recipientPublicKey} + {address: trs.lastTransaction.senderId, publicKey: trs.lastTransaction.senderPublicKey}, + {address: trs.lastTransaction.recipientId, publicKey: trs.lastTransaction.recipientPublicKey} ]; - const uid = trs.senderId !== filter.userId ? trs.senderId : trs.recipientId; + const uid = trs.lastTransaction.senderId !== filter.userId ? trs.lastTransaction.senderId : trs.lastTransaction.recipientId; if (!chats[uid]) { chats[uid] = []; } chats[uid].push(trs); } for (const uid in chats) { - transactions.push(chats[uid].sort((x, y) => x.timestamp - y.timestamp)[0]); + transactions.push(chats[uid].sort((x, y) => x.lastTransaction.timestamp - y.lastTransaction.timestamp)[0]); } const data = { chats: transactions, @@ -336,4 +337,4 @@ Chatrooms.prototype.internal = { Chatrooms.prototype.shared = {}; -module.exports = Chatrooms; \ No newline at end of file +module.exports = Chatrooms; From 7de8f47e72b5afc07d112c2f704ccaa3acd6cc6b Mon Sep 17 00:00:00 2001 From: Zyuhel Date: Tue, 9 Apr 2019 13:32:29 +0300 Subject: [PATCH 02/21] Add height to list chats query --- sql/chats.js | 1 + 1 file changed, 1 insertion(+) diff --git a/sql/chats.js b/sql/chats.js index 01700b5a..eb88f428 100644 --- a/sql/chats.js +++ b/sql/chats.js @@ -102,6 +102,7 @@ var ChatsSql = { 'first("c_own_message") as "c_own_message",', 'first("c_type") as "c_type",', 'first("t_type") as "t_type"', + 'max("b_height") as "height"', 'FROM ( SELECT *, t_timestamp as timestamp, ENCODE("publicKey", \'hex\') as "m_recipientPublicKey"', 'FROM full_blocks_list', 'LEFT OUTER JOIN mem_accounts ON address = "t_recipientId"', From 7cece092a1ca299128a11675c0da3ae4afeaf811 Mon Sep 17 00:00:00 2001 From: Zyuhel Date: Tue, 9 Apr 2019 15:04:13 +0300 Subject: [PATCH 03/21] return accidentaly deleted file --- build | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 build diff --git a/build b/build new file mode 100644 index 00000000..e69de29b From 984f63e8c4ad347d887ea58ceac4d0ce6fd94019 Mon Sep 17 00:00:00 2001 From: Zyuhel Date: Tue, 9 Apr 2019 15:08:54 +0300 Subject: [PATCH 04/21] missed typo --- sql/chats.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql/chats.js b/sql/chats.js index eb88f428..4d1a7016 100644 --- a/sql/chats.js +++ b/sql/chats.js @@ -101,7 +101,7 @@ var ChatsSql = { 'first("c_message") as "c_message",', 'first("c_own_message") as "c_own_message",', 'first("c_type") as "c_type",', - 'first("t_type") as "t_type"', + 'first("t_type") as "t_type",', 'max("b_height") as "height"', 'FROM ( SELECT *, t_timestamp as timestamp, ENCODE("publicKey", \'hex\') as "m_recipientPublicKey"', 'FROM full_blocks_list', From 567cda64ded6a972dcf265b94b1ed76df4b0e95b Mon Sep 17 00:00:00 2001 From: Zyuhel Date: Tue, 9 Apr 2019 16:58:31 +0300 Subject: [PATCH 05/21] Return blockId for last transaction --- sql/chats.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sql/chats.js b/sql/chats.js index 4d1a7016..33f6a3a2 100644 --- a/sql/chats.js +++ b/sql/chats.js @@ -102,7 +102,8 @@ var ChatsSql = { 'first("c_own_message") as "c_own_message",', 'first("c_type") as "c_type",', 'first("t_type") as "t_type",', - 'max("b_height") as "height"', + 'max("b_height") as "b_height",', + 'max("b_id") as "b_id"', 'FROM ( SELECT *, t_timestamp as timestamp, ENCODE("publicKey", \'hex\') as "m_recipientPublicKey"', 'FROM full_blocks_list', 'LEFT OUTER JOIN mem_accounts ON address = "t_recipientId"', From 3d5f914650b6ee17de82c13ad77c93e408996d47 Mon Sep 17 00:00:00 2001 From: Zyuhel Date: Tue, 16 Apr 2019 17:35:53 +0300 Subject: [PATCH 06/21] change const to let --- modules/chatrooms.js | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/modules/chatrooms.js b/modules/chatrooms.js index 0095a590..1106a3d1 100644 --- a/modules/chatrooms.js +++ b/modules/chatrooms.js @@ -70,7 +70,7 @@ __private.listChats = function (filter, cb) { if (filter.withPayments) { where.push(`("t_type" = ${transactionTypes.CHAT_MESSAGE} OR "t_type" = ${transactionTypes.SEND})`); } else { - where.push('"t_type" = '+ transactionTypes.CHAT_MESSAGE); + where.push('"t_type" = ' + transactionTypes.CHAT_MESSAGE); } if (filter.senderId) { @@ -127,7 +127,7 @@ __private.listChats = function (filter, cb) { }), params).then(function (rows) { let transactions = [], chats = {}; for (let i = 0; i < rows.length; i++) { - const trs = {}; + let trs = {}; trs.lastTransaction = library.logic.transaction.dbRead(rows[i]); trs.participants = [ {address: trs.lastTransaction.senderId, publicKey: trs.lastTransaction.senderPublicKey}, @@ -167,7 +167,7 @@ __private.listMessages = function (filter, cb) { if (filter.withPayments) { where.push(`("t_type" = ${transactionTypes.CHAT_MESSAGE} OR "t_type" = ${transactionTypes.SEND})`); } else { - where.push('"t_type" = '+ transactionTypes.CHAT_MESSAGE); + where.push('"t_type" = ' + transactionTypes.CHAT_MESSAGE); } if (filter.senderId) { @@ -231,8 +231,8 @@ __private.listMessages = function (filter, cb) { const data = { messages: transactions, participants: transactions.length ? [ - {address: transactions[0].senderId,publicKey: transactions[0].senderPublicKey}, - {address: transactions[0].recipientId,publicKey: transactions[0].recipientPublicKey} + {address: transactions[0].senderId, publicKey: transactions[0].senderPublicKey}, + {address: transactions[0].recipientId, publicKey: transactions[0].recipientPublicKey} ] : [], count: count }; @@ -271,8 +271,10 @@ Chatrooms.prototype.isLoaded = function () { Chatrooms.prototype.internal = { getChats: function (req, cb) { let validRequest; - [validRequest, req.body.userId,req.body.companionId] = req.path.match(/(U[0-9]+)\/?(U[0-9]+)?/); - if (!validRequest) { return setImmediate(cb, 'Invalid Request path'); } + [validRequest, req.body.userId, req.body.companionId] = req.path.match(/(U[0-9]+)\/?(U[0-9]+)?/); + if (!validRequest) { + return setImmediate(cb, 'Invalid Request path'); + } async.waterfall([ function (waterCb) { const params = req.body; @@ -303,8 +305,10 @@ Chatrooms.prototype.internal = { }, getMessages: function (req, cb) { let validRequest; - [validRequest, req.body.userId,req.body.companionId] = req.path.match(/(U[0-9]+)\/?(U[0-9]+)?/); - if (!validRequest) { return setImmediate(cb, 'Invalid Request path'); } + [validRequest, req.body.userId, req.body.companionId] = req.path.match(/(U[0-9]+)\/?(U[0-9]+)?/); + if (!validRequest) { + return setImmediate(cb, 'Invalid Request path'); + } async.waterfall([ function (waterCb) { const params = req.body; From 67aeffeb4cfa0e08a0317df66e221c79806ff8c9 Mon Sep 17 00:00:00 2001 From: Zyuhel Date: Tue, 16 Apr 2019 18:23:19 +0300 Subject: [PATCH 07/21] uniq by lastTransactions.id field --- modules/chatrooms.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/chatrooms.js b/modules/chatrooms.js index 1106a3d1..7ef51c9e 100644 --- a/modules/chatrooms.js +++ b/modules/chatrooms.js @@ -293,7 +293,7 @@ Chatrooms.prototype.internal = { return setImmediate(waterCb, 'Failed to get transactions: ' + err); } else { return setImmediate(waterCb, null, { - chats: _.uniqBy(data.chats, (x) => x.id), + chats: _.uniqBy(data.chats, (x) => x.lastTransaction.id), count: data.count }); } From 16ad5910365939f5270db33e2951036488db8c7c Mon Sep 17 00:00:00 2001 From: Zyuhel Date: Tue, 16 Apr 2019 18:25:43 +0300 Subject: [PATCH 08/21] filter out signal messages from chatrooms --- modules/chatrooms.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/chatrooms.js b/modules/chatrooms.js index 7ef51c9e..2f15c770 100644 --- a/modules/chatrooms.js +++ b/modules/chatrooms.js @@ -72,7 +72,7 @@ __private.listChats = function (filter, cb) { } else { where.push('"t_type" = ' + transactionTypes.CHAT_MESSAGE); } - + where.push('NOT( "t_type" = 3) '); if (filter.senderId) { where.push('"t_senderId" = ${name}'); params.name = filter.senderId; From 7e0c062e1f6308e46223f627ad93221f882acd70 Mon Sep 17 00:00:00 2001 From: Zyuhel Date: Thu, 18 Apr 2019 15:09:59 +0300 Subject: [PATCH 09/21] fix test --- test/api/chatrooms.js | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/test/api/chatrooms.js b/test/api/chatrooms.js index 8b0a9bf1..e990b0ff 100644 --- a/test/api/chatrooms.js +++ b/test/api/chatrooms.js @@ -187,14 +187,15 @@ describe('GET /api/chatrooms/:ID/:ID', function () { node.expect(res.body.chats[i].participants[0].address).to.equal(sender.address); node.expect(res.body.chats[i].participants[0].publicKey).to.equal(sender.publicKey.toString('hex')); node.expect(res.body.chats[i].participants[1].publicKey).to.not.equal(null); - node.expect(res.body.chats[i].timestamp).to.not.equal(null); - node.expect(res.body.chats[i].fee).to.not.equal(null); - node.expect(res.body.chats[i].amount).to.not.equal(null); - node.expect(res.body.chats[i]).to.have.property('asset').to.be.an('object'); - node.expect(res.body.chats[i].asset).to.have.property('chat').to.be.an('object'); - node.expect(res.body.chats[i].asset.chat).to.have.property('message').to.not.equal(null); - node.expect(res.body.chats[i].asset.chat).to.have.property('own_message').to.not.equal(null); - node.expect(res.body.chats[i].asset.chat).to.have.property('type').to.not.equal(null); + node.expect(res.body.chats[i]).to.have.property('lastTransaction').to.be.an('object'); + node.expect(res.body.chats[i].lastTransaction.timestamp).to.not.equal(null); + node.expect(res.body.chats[i].lastTransaction.fee).to.not.equal(null); + node.expect(res.body.chats[i].lastTransaction.amount).to.not.equal(null); + node.expect(res.body.chats[i].lastTransaction).to.have.property('asset').to.be.an('object'); + node.expect(res.body.chats[i].lastTransaction.asset).to.have.property('chat').to.be.an('object'); + node.expect(res.body.chats[i].lastTransaction.asset.chat).to.have.property('message').to.not.equal(null); + node.expect(res.body.chats[i].lastTransaction.asset.chat).to.have.property('own_message').to.not.equal(null); + node.expect(res.body.chats[i].lastTransaction.asset.chat).to.have.property('type').to.not.equal(null); } done(); }); @@ -209,9 +210,10 @@ describe('GET /api/chatrooms/:ID/:ID', function () { node.expect(res.body.chats[i]).to.have.property('participants').to.have.lengthOf(2); node.expect(res.body.chats[i].participants[0].publicKey).to.not.equal(null); node.expect(res.body.chats[i].participants[1].publicKey).to.not.equal(null); - node.expect(res.body.chats[i].timestamp).to.not.equal(null); - node.expect(res.body.chats[i].fee).to.not.equal(null); - node.expect(res.body.chats[i].amount).to.not.equal(null); + node.expect(res.body.chats[i]).to.have.property('lastTransaction').to.be.an('object'); + node.expect(res.body.chats[i].lastTransaction.timestamp).to.not.equal(null); + node.expect(res.body.chats[i].lastTransaction.fee).to.not.equal(null); + node.expect(res.body.chats[i].lastTransaction.amount).to.not.equal(null); } done(); }, { orderBy: 'timestamp:desc'}); @@ -226,9 +228,10 @@ describe('GET /api/chatrooms/:ID/:ID', function () { node.expect(res.body.chats[i]).to.have.property('participants').to.have.lengthOf(2); node.expect(res.body.chats[i].participants[0].publicKey).to.not.equal(null); node.expect(res.body.chats[i].participants[1].publicKey).to.not.equal(null); - node.expect(res.body.chats[i].timestamp).to.not.equal(null); - node.expect(res.body.chats[i].fee).to.not.equal(null); - node.expect(res.body.chats[i].amount).to.not.equal(null); + node.expect(res.body.chats[i]).to.have.property('lastTransaction').to.be.an('object'); + node.expect(res.body.chats[i].lastTransaction.timestamp).to.not.equal(null); + node.expect(res.body.chats[i].lastTransaction.fee).to.not.equal(null); + node.expect(res.body.chats[i].lastTransaction.amount).to.not.equal(null); } done(); }); @@ -470,4 +473,4 @@ describe('GET /api/chatrooms/:ID/:ID', function () { orderBy: 'timestamp:asc' }); }); -}); \ No newline at end of file +}); From 8269ff3b738232e07aa0ce5f493266c9a049add4 Mon Sep 17 00:00:00 2001 From: Zyuhel Date: Fri, 10 May 2019 17:24:52 +0300 Subject: [PATCH 10/21] we should filter out signal messages. --- modules/chatrooms.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/chatrooms.js b/modules/chatrooms.js index 2f15c770..98eb6aec 100644 --- a/modules/chatrooms.js +++ b/modules/chatrooms.js @@ -72,7 +72,7 @@ __private.listChats = function (filter, cb) { } else { where.push('"t_type" = ' + transactionTypes.CHAT_MESSAGE); } - where.push('NOT( "t_type" = 3) '); + where.push('NOT( "c_type" = 3) '); if (filter.senderId) { where.push('"t_senderId" = ${name}'); params.name = filter.senderId; From 20f414468f5038ad8ecb22147468ffd4670f8a0c Mon Sep 17 00:00:00 2001 From: Zyuhel Date: Fri, 10 May 2019 17:25:10 +0300 Subject: [PATCH 11/21] set default limit to 25 according AIP-14 --- modules/chatrooms.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/chatrooms.js b/modules/chatrooms.js index 98eb6aec..529520cc 100644 --- a/modules/chatrooms.js +++ b/modules/chatrooms.js @@ -90,7 +90,7 @@ __private.listChats = function (filter, cb) { } if (!filter.limit) { - params.limit = 100; + params.limit = 25; } else { params.limit = Math.abs(filter.limit); } From d814154897b5d575d8a9e14648b93d692272023e Mon Sep 17 00:00:00 2001 From: Zyuhel Date: Fri, 10 May 2019 19:52:21 +0300 Subject: [PATCH 12/21] Add order by for grouping functions to be sure that we got correct data --- sql/chats.js | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/sql/chats.js b/sql/chats.js index 33f6a3a2..38847bae 100644 --- a/sql/chats.js +++ b/sql/chats.js @@ -89,21 +89,21 @@ var ChatsSql = { let y = [ 'SELECT', 'CONCAT(LEAST("t_senderId", "t_recipientId"), GREATEST("t_senderId", "t_recipientId")) as "srt",', - 'first("t_id") as "t_id",', - 'first("t_senderPublicKey") as "t_senderPublicKey",', - 'first("m_recipientPublicKey") as "m_recipientPublicKey",', - 'first("t_senderId") as "t_senderId",', - 'first("t_recipientId") as "t_recipientId",', - 'first("t_timestamp") as "t_timestamp",', - 'first("t_timestamp") as "timestamp",', - 'first("t_amount") as "t_amount",', - 'first("t_fee") as "t_fee",', - 'first("c_message") as "c_message",', - 'first("c_own_message") as "c_own_message",', - 'first("c_type") as "c_type",', - 'first("t_type") as "t_type",', - 'max("b_height") as "b_height",', - 'max("b_id") as "b_id"', + 'first("t_id" ORDER BY b_height DESC, t_timestamp DESC) as "t_id",', + 'first("t_senderPublicKey" ORDER BY b_height DESC, t_timestamp DESC) as "t_senderPublicKey",', + 'first("m_recipientPublicKey" ORDER BY b_height DESC, t_timestamp DESC) as "m_recipientPublicKey",', + 'first("t_senderId" ORDER BY b_height DESC, t_timestamp DESC) as "t_senderId",', + 'first("t_recipientId" ORDER BY b_height DESC, t_timestamp DESC) as "t_recipientId",', + 'first("t_timestamp" ORDER BY b_height DESC, t_timestamp DESC) as "t_timestamp",', + 'first("t_timestamp" ORDER BY b_height DESC, t_timestamp DESC) as "timestamp",', + 'first("t_amount" ORDER BY b_height DESC, t_timestamp DESC) as "t_amount",', + 'first("t_fee" ORDER BY b_height DESC, t_timestamp DESC) as "t_fee",', + 'first("c_message" ORDER BY b_height DESC, t_timestamp DESC) as "c_message",', + 'first("c_own_message" ORDER BY b_height DESC, t_timestamp DESC) as "c_own_message",', + 'first("c_type" ORDER BY b_height DESC, t_timestamp DESC) as "c_type",', + 'first("t_type" ORDER BY b_height DESC, t_timestamp DESC) as "t_type",', + 'first("b_height" ORDER BY b_height DESC, t_timestamp DESC) as "b_height",', + 'first("b_id" ORDER BY b_height DESC, t_timestamp DESC) as "b_id"', 'FROM ( SELECT *, t_timestamp as timestamp, ENCODE("publicKey", \'hex\') as "m_recipientPublicKey"', 'FROM full_blocks_list', 'LEFT OUTER JOIN mem_accounts ON address = "t_recipientId"', From a905b43ce6407e60f5bb120a6b6d1fe0bac2bde2 Mon Sep 17 00:00:00 2001 From: Zyuhel Date: Fri, 10 May 2019 19:53:01 +0300 Subject: [PATCH 13/21] remove not needed comment --- sql/chats.js | 6 ------ 1 file changed, 6 deletions(-) diff --git a/sql/chats.js b/sql/chats.js index 38847bae..96f1131b 100644 --- a/sql/chats.js +++ b/sql/chats.js @@ -113,12 +113,6 @@ var ChatsSql = { ') as foo GROUP by srt', (params.sortField ? 'ORDER BY ' + [params.sortField, params.sortMethod].join(' ') : ''), 'LIMIT ${limit} OFFSET ${offset}' - // - // - // 'WHERE "t_type" = 8', - // 'AND ("t_senderId" = \'U1283640763437948723\'', - // 'OR "t_recipientId" = \'U1020291227689695733\')', - // 'ORDER BY "t_timestamp" DESC) as foo GROUP by srt' ].filter(Boolean).join(' '); return y; }, From 9c89aac75974c00a447b8a11dd53d50b1d98326a Mon Sep 17 00:00:00 2001 From: Zyuhel Date: Fri, 10 May 2019 20:00:01 +0300 Subject: [PATCH 14/21] set version to 0.5.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 000c58d3..435ae309 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "adamant", - "version": "0.5.0", + "version": "0.5.1", "private": true, "scripts": { "start": "node app.js", From a1c7e41bc9b94cea7c27dbcfc8b738bd52d9a817 Mon Sep 17 00:00:00 2001 From: Zyuhel Date: Fri, 10 May 2019 22:53:38 +0300 Subject: [PATCH 15/21] Adding default sort options --- sql/chats.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/sql/chats.js b/sql/chats.js index 96f1131b..1222b21b 100644 --- a/sql/chats.js +++ b/sql/chats.js @@ -2,7 +2,10 @@ var ChatsSql = { sortFields: ['type','timestamp'], - + chatroomsSortDefaults: { + sortField: 'timestamp', + sortMethod: 'desc' + }, countByTransactionId: 'SELECT COUNT(*)::int AS "count" FROM chats WHERE "transactionId" = ${id}', From 673903e5bf5118a4d90fe61478fd73d058b1af32 Mon Sep 17 00:00:00 2001 From: Zyuhel Date: Fri, 10 May 2019 22:54:00 +0300 Subject: [PATCH 16/21] Change default sorting --- modules/chatrooms.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/chatrooms.js b/modules/chatrooms.js index 529520cc..7617bcbe 100644 --- a/modules/chatrooms.js +++ b/modules/chatrooms.js @@ -106,9 +106,7 @@ __private.listChats = function (filter, cb) { } const orderBy = OrderBy( - filter.orderBy, { - sortFields: sql.sortFields - } + filter.orderBy, sql.chatroomsSortDefaults ); if (orderBy.error) { @@ -163,6 +161,8 @@ __private.listMessages = function (filter, cb) { if (filter.type >= 0) { where.push('"c_type" = ${type}'); params.type = filter.type; + } else { + where.push('NOT( "c_type" = 3) '); } if (filter.withPayments) { where.push(`("t_type" = ${transactionTypes.CHAT_MESSAGE} OR "t_type" = ${transactionTypes.SEND})`); From cb7c872a2f66f3d2acd93dd141b4d270030d6e5c Mon Sep 17 00:00:00 2001 From: Zyuhel Date: Fri, 10 May 2019 22:56:16 +0300 Subject: [PATCH 17/21] Change default sorting --- modules/chatrooms.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/modules/chatrooms.js b/modules/chatrooms.js index 7617bcbe..3d4245e7 100644 --- a/modules/chatrooms.js +++ b/modules/chatrooms.js @@ -204,9 +204,7 @@ __private.listMessages = function (filter, cb) { } const orderBy = OrderBy( - filter.orderBy, { - sortFields: sql.sortFields - } + filter.orderBy, sql.chatroomsSortDefaults ); if (orderBy.error) { From 4fb807f23cf044a6756a4b52555e523256a3122a Mon Sep 17 00:00:00 2001 From: Zyuhel Date: Fri, 10 May 2019 23:04:19 +0300 Subject: [PATCH 18/21] change withPayments filter to withoutDirectTransfers according to AIP-14 --- modules/chatrooms.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/chatrooms.js b/modules/chatrooms.js index 3d4245e7..7a6fe848 100644 --- a/modules/chatrooms.js +++ b/modules/chatrooms.js @@ -67,10 +67,10 @@ __private.listChats = function (filter, cb) { where.push('"c_type" = ${type}'); params.type = filter.type; } - if (filter.withPayments) { - where.push(`("t_type" = ${transactionTypes.CHAT_MESSAGE} OR "t_type" = ${transactionTypes.SEND})`); - } else { + if (filter.withoutDirectTransfers) { where.push('"t_type" = ' + transactionTypes.CHAT_MESSAGE); + } else { + where.push(`("t_type" = ${transactionTypes.CHAT_MESSAGE} OR "t_type" = ${transactionTypes.SEND})`); } where.push('NOT( "c_type" = 3) '); if (filter.senderId) { From 5417c9069f23c1adccf1b90c534f7560aef924f8 Mon Sep 17 00:00:00 2001 From: Zyuhel Date: Fri, 10 May 2019 23:04:45 +0300 Subject: [PATCH 19/21] change withPayments filter to withoutDirectTransfers according to AIP-14 --- modules/chatrooms.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/chatrooms.js b/modules/chatrooms.js index 7a6fe848..e857cf96 100644 --- a/modules/chatrooms.js +++ b/modules/chatrooms.js @@ -164,10 +164,10 @@ __private.listMessages = function (filter, cb) { } else { where.push('NOT( "c_type" = 3) '); } - if (filter.withPayments) { - where.push(`("t_type" = ${transactionTypes.CHAT_MESSAGE} OR "t_type" = ${transactionTypes.SEND})`); - } else { + if (filter.withoutDirectTransfers) { where.push('"t_type" = ' + transactionTypes.CHAT_MESSAGE); + } else { + where.push(`("t_type" = ${transactionTypes.CHAT_MESSAGE} OR "t_type" = ${transactionTypes.SEND})`); } if (filter.senderId) { From 3f4c05434033a8d59871ca9e47c8e925b872b83a Mon Sep 17 00:00:00 2001 From: Zyuhel Date: Tue, 14 May 2019 16:17:53 +0300 Subject: [PATCH 20/21] fix errors with not returning transfers --- modules/chatrooms.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/chatrooms.js b/modules/chatrooms.js index e857cf96..5b75c4c7 100644 --- a/modules/chatrooms.js +++ b/modules/chatrooms.js @@ -72,7 +72,7 @@ __private.listChats = function (filter, cb) { } else { where.push(`("t_type" = ${transactionTypes.CHAT_MESSAGE} OR "t_type" = ${transactionTypes.SEND})`); } - where.push('NOT( "c_type" = 3) '); + where.push('(NOT("c_type" = 3) OR c_type IS NULL) '); if (filter.senderId) { where.push('"t_senderId" = ${name}'); params.name = filter.senderId; @@ -162,7 +162,7 @@ __private.listMessages = function (filter, cb) { where.push('"c_type" = ${type}'); params.type = filter.type; } else { - where.push('NOT( "c_type" = 3) '); + where.push('(NOT("c_type" = 3) OR c_type IS NULL) '); } if (filter.withoutDirectTransfers) { where.push('"t_type" = ' + transactionTypes.CHAT_MESSAGE); From d851332f4498b3eac1cbf49a15fb0cfc91a6457e Mon Sep 17 00:00:00 2001 From: Zyuhel Date: Wed, 15 May 2019 07:38:51 +0300 Subject: [PATCH 21/21] Get rid of magic number --- helpers/transactionTypes.js | 8 +++++++- modules/chatrooms.js | 4 ++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/helpers/transactionTypes.js b/helpers/transactionTypes.js index c5ec427c..03b81ab7 100644 --- a/helpers/transactionTypes.js +++ b/helpers/transactionTypes.js @@ -10,5 +10,11 @@ module.exports = { IN_TRANSFER: 6, OUT_TRANSFER: 7, CHAT_MESSAGE: 8, - STATE: 9 + STATE: 9, + CHAT_MESSAGE_TYPES: { + LEGACY_MESSAGE: 0, + ORDINARY_MESSAGE: 1, + RICH_TEXT_MESSAGE: 2, + SIGNAL_MESSAGE: 3 + } }; diff --git a/modules/chatrooms.js b/modules/chatrooms.js index 5b75c4c7..82a512a6 100644 --- a/modules/chatrooms.js +++ b/modules/chatrooms.js @@ -72,7 +72,7 @@ __private.listChats = function (filter, cb) { } else { where.push(`("t_type" = ${transactionTypes.CHAT_MESSAGE} OR "t_type" = ${transactionTypes.SEND})`); } - where.push('(NOT("c_type" = 3) OR c_type IS NULL) '); + where.push(`(NOT("c_type" = ${transactionTypes.CHAT_MESSAGE_TYPES.SIGNAL_MESSAGE}) OR c_type IS NULL) `); if (filter.senderId) { where.push('"t_senderId" = ${name}'); params.name = filter.senderId; @@ -162,7 +162,7 @@ __private.listMessages = function (filter, cb) { where.push('"c_type" = ${type}'); params.type = filter.type; } else { - where.push('(NOT("c_type" = 3) OR c_type IS NULL) '); + where.push(`(NOT("c_type" = ${transactionTypes.CHAT_MESSAGE_TYPES.SIGNAL_MESSAGE}) OR c_type IS NULL)`); } if (filter.withoutDirectTransfers) { where.push('"t_type" = ' + transactionTypes.CHAT_MESSAGE);