Browse Source

member_request, member_approve, member_reject msg types, start routes

push-params
Evan Feenstra 4 years ago
parent
commit
f2e708e5a0
  1. 157
      api/controllers/chatTribes.ts
  2. 15
      api/controllers/chats.ts
  3. 12
      api/controllers/contacts.ts
  4. 5
      api/controllers/index.ts
  5. 2
      api/models/ts/chatMember.ts
  6. 2
      api/utils/setup.ts
  7. 6
      api/utils/tribes.ts
  8. 7
      config/constants.json
  9. 146
      dist/api/controllers/chatTribes.js
  10. 2
      dist/api/controllers/chatTribes.js.map
  11. 13
      dist/api/controllers/chats.js
  12. 2
      dist/api/controllers/chats.js.map
  13. 13
      dist/api/controllers/contacts.js
  14. 2
      dist/api/controllers/contacts.js.map
  15. 5
      dist/api/controllers/index.js
  16. 2
      dist/api/controllers/index.js.map
  17. 4
      dist/api/models/ts/chatMember.js
  18. 2
      dist/api/models/ts/chatMember.js.map
  19. 2
      dist/api/utils/setup.js
  20. 2
      dist/api/utils/setup.js.map
  21. 6
      dist/api/utils/tribes.js
  22. 2
      dist/api/utils/tribes.js.map
  23. 10
      dist/config/constants.json

157
api/controllers/chatTribes.ts

@ -3,6 +3,8 @@ import * as jsonUtils from '../utils/json'
import { success, failure } from '../utils/res' import { success, failure } from '../utils/res'
import * as network from '../network' import * as network from '../network'
import * as rsa from '../crypto/rsa' import * as rsa from '../crypto/rsa'
import * as helpers from '../helpers'
import * as socket from '../utils/socket'
import * as tribes from '../utils/tribes' import * as tribes from '../utils/tribes'
import * as path from 'path' import * as path from 'path'
import {personalizeMessage, decryptMessage} from '../utils/msg' import {personalizeMessage, decryptMessage} from '../utils/msg'
@ -13,6 +15,7 @@ const constants = require(path.join(__dirname,'../../config/constants.json'))
export async function joinTribe(req, res){ export async function joinTribe(req, res){
console.log('=> joinTribe') console.log('=> joinTribe')
const { uuid, group_key, name, host, amount, img, owner_pubkey, owner_alias } = req.body const { uuid, group_key, name, host, amount, img, owner_pubkey, owner_alias } = req.body
const is_private = req.body.private
const existing = await models.Chat.findOne({where:{uuid}}) const existing = await models.Chat.findOne({where:{uuid}})
if(existing) { if(existing) {
@ -51,6 +54,9 @@ export async function joinTribe(req, res){
let date = new Date() let date = new Date()
date.setMilliseconds(0) date.setMilliseconds(0)
const chatStatus = is_private ?
constants.chat_statuses.pending :
constants.chat_statuses.approved
const chatParams = { const chatParams = {
uuid: uuid, uuid: uuid,
contactIds: JSON.stringify(contactIds), contactIds: JSON.stringify(contactIds),
@ -62,11 +68,21 @@ export async function joinTribe(req, res){
host: host || tribes.getHost(), host: host || tribes.getHost(),
groupKey: group_key, groupKey: group_key,
ownerPubkey: owner_pubkey, ownerPubkey: owner_pubkey,
private: is_private||false,
status: chatStatus
} }
const typeToSend = is_private ?
constants.message_types.member_request :
constants.message_types.group_join
const contactIdsToSend = is_private ?
[theTribeOwner.id] : // ONLY SEND TO TRIBE OWNER IF ITS A REQUEST
chatParams.contactIds
network.sendMessage({ // send my data to tribe owner network.sendMessage({ // send my data to tribe owner
chat: { chat: {
...chatParams, members: { ...chatParams,
contactIds: contactIdsToSend,
members: {
[owner.publicKey]: { [owner.publicKey]: {
key: owner.contactKey, key: owner.contactKey,
alias: owner.alias||'' alias: owner.alias||''
@ -76,7 +92,7 @@ export async function joinTribe(req, res){
amount:amount||0, amount:amount||0,
sender: owner, sender: owner,
message: {}, message: {},
type: constants.message_types.group_join, type: typeToSend,
failure: function (e) { failure: function (e) {
failure(res, e) failure(res, e)
}, },
@ -87,69 +103,84 @@ export async function joinTribe(req, res){
chatId: chat.id, chatId: chat.id,
role: constants.chat_roles.owner, role: constants.chat_roles.owner,
lastActive: date, lastActive: date,
status: constants.chat_statuses.approved
}) })
success(res, jsonUtils.chatToJson(chat)) success(res, jsonUtils.chatToJson(chat))
} }
}) })
} }
export async function editTribe(req, res) { export async function receiveMemberRequest(payload) {
const { const { sender_pub_key, sender_alias, chat_uuid, chat_members, chat_type, isTribeOwner } = await helpers.parseReceiveParams(payload)
name,
price_per_message,
price_to_join,
escrow_amount,
escrow_millis,
img,
description,
tags,
unlisted,
} = req.body
const { id } = req.params
if(!id) return failure(res, 'group id is required')
const chat = await models.Chat.findOne({where:{id}})
if(!chat) {
return failure(res, 'cant find chat')
}
const owner = await models.Contact.findOne({ where: { isOwner: true } }) const chat = await models.Chat.findOne({ where: { uuid: chat_uuid } })
if (!chat) return
let okToUpdate = true const isTribe = chat_type===constants.chat_types.tribe
try{ if(!isTribe || !isTribeOwner) return
await tribes.edit({
uuid: chat.uuid,
name: name,
host: chat.host,
price_per_message: price_per_message||0,
price_to_join: price_to_join||0,
escrow_amount: escrow_amount||0,
escrow_millis: escrow_millis||0,
description,
tags,
img,
owner_alias: owner.alias,
unlisted,
})
} catch(e) {
okToUpdate = false
}
if(okToUpdate) { var date = new Date()
await chat.update({ date.setMilliseconds(0)
photoUrl: img||'',
name: name, let theSender: any = null
pricePerMessage: price_per_message||0, const member = chat_members[sender_pub_key]
priceToJoin: price_to_join||0, const senderAlias = sender_alias || (member && member.alias) || 'Unknown'
escrowAmount: escrow_amount||0,
escrowMillis: escrow_millis||0, const sender = await models.Contact.findOne({ where: { publicKey: sender_pub_key } })
unlisted: unlisted||false, if (sender) {
}) theSender = sender // might already include??
success(res, jsonUtils.chatToJson(chat))
} else { } else {
failure(res, 'failed to update tribe') if(member && member.key) {
const createdContact = await models.Contact.create({
publicKey: sender_pub_key,
contactKey: member.key,
alias: senderAlias,
status: 1,
fromGroup: true,
})
theSender = createdContact
}
}
if(!theSender) return console.log('no sender') // fail (no contact key?)
models.ChatMember.create({
contactId: theSender.id,
chatId: chat.id,
role: constants.chat_roles.reader,
status: constants.chat_statuses.pending,
lastActive: date,
})
const msg:{[k:string]:any} = {
chatId: chat.id,
type: constants.message_types.member_request,
sender: (theSender && theSender.id) || 0,
messageContent:'', remoteMessageContent:'',
status: constants.statuses.confirmed,
date: date, createdAt: date, updatedAt: date
}
if(isTribe) {
msg.senderAlias = sender_alias
} }
const message = await models.Message.create(msg)
const theChat = addPendingContactIdsToChat(chat)
socket.sendJson({
type: 'member_request',
response: {
contact: jsonUtils.contactToJson(theSender||{}),
chat: jsonUtils.chatToJson(theChat),
message: jsonUtils.messageToJson(message, null)
}
})
}
export async function receiveMemberApprove(payload) {
}
export async function receiveMemberReject(payload) {
} }
export async function replayChatHistory(chat, contact) { export async function replayChatHistory(chat, contact) {
@ -206,7 +237,7 @@ export async function replayChatHistory(chat, contact) {
}) })
} }
export async function createTribeChatParams(owner, contactIds, name, img, price_per_message, price_to_join, escrow_amount, escrow_millis, unlisted): Promise<{[k:string]:any}> { export async function createTribeChatParams(owner, contactIds, name, img, price_per_message, price_to_join, escrow_amount, escrow_millis, unlisted, is_private): Promise<{[k:string]:any}> {
let date = new Date() let date = new Date()
date.setMilliseconds(0) date.setMilliseconds(0)
if (!(owner && contactIds && Array.isArray(contactIds))) { if (!(owner && contactIds && Array.isArray(contactIds))) {
@ -234,6 +265,21 @@ export async function createTribeChatParams(owner, contactIds, name, img, price_
escrowMillis: escrow_millis||0, escrowMillis: escrow_millis||0,
escrowAmount: escrow_amount||0, escrowAmount: escrow_amount||0,
unlisted: unlisted||false, unlisted: unlisted||false,
private: is_private||false,
}
}
export async function addPendingContactIdsToChat(achat){
const members = await models.ChatMember.findAll({where:{
chatId: achat.id,
status: constants.chat_statuses.pending // only pending
}})
if (!members) return achat
const pendingContactIds:number[] = members.map(m=>m.contactId)
const chat = achat.dataValues||achat
return {
...chat,
pendingContactIds,
} }
} }
@ -243,3 +289,4 @@ async function asyncForEach(array, callback) {
} }
} }

15
api/controllers/chats.ts

@ -9,7 +9,7 @@ import * as md5 from 'md5'
import * as path from 'path' import * as path from 'path'
import * as tribes from '../utils/tribes' import * as tribes from '../utils/tribes'
import * as timers from '../utils/timers' import * as timers from '../utils/timers'
import {replayChatHistory,createTribeChatParams} from './chatTribes' import {replayChatHistory,createTribeChatParams,addPendingContactIdsToChat} from './chatTribes'
const constants = require(path.join(__dirname,'../../config/constants.json')) const constants = require(path.join(__dirname,'../../config/constants.json'))
@ -165,7 +165,7 @@ export async function createGroupChat(req, res) {
let chatParams:any = null let chatParams:any = null
let okToCreate = true let okToCreate = true
if(is_tribe){ if(is_tribe){
chatParams = await createTribeChatParams(owner, contact_ids, name, img, price_per_message, price_to_join, escrow_amount, escrow_millis, unlisted) chatParams = await createTribeChatParams(owner, contact_ids, name, img, price_per_message, price_to_join, escrow_amount, escrow_millis, unlisted, req.body.private)
if(chatParams.uuid){ if(chatParams.uuid){
// publish to tribe server // publish to tribe server
try { try {
@ -182,6 +182,7 @@ export async function createGroupChat(req, res) {
owner_pubkey: owner.publicKey, owner_pubkey: owner.publicKey,
owner_alias: owner.alias, owner_alias: owner.alias,
unlisted: unlisted||false, unlisted: unlisted||false,
is_private: req.body.private||false,
}) })
} catch(e) { } catch(e) {
okToCreate = false okToCreate = false
@ -212,6 +213,7 @@ export async function createGroupChat(req, res) {
contactId: owner.id, contactId: owner.id,
chatId: chat.id, chatId: chat.id,
role: constants.chat_roles.owner, role: constants.chat_roles.owner,
status: constants.chat_statuses.approved
}) })
} }
success(res, jsonUtils.chatToJson(chat)) success(res, jsonUtils.chatToJson(chat))
@ -312,7 +314,7 @@ export async function receiveGroupJoin(payload) {
const member = chat_members[sender_pub_key] const member = chat_members[sender_pub_key]
const senderAlias = sender_alias || (member && member.alias) || 'Unknown' const senderAlias = sender_alias || (member && member.alias) || 'Unknown'
if(!isTribe || isTribeOwner) { // dont need to create contacts for these if(!isTribe || isTribeOwner) {
const sender = await models.Contact.findOne({ where: { publicKey: sender_pub_key } }) const sender = await models.Contact.findOne({ where: { publicKey: sender_pub_key } })
const contactIds = JSON.parse(chat.contactIds || '[]') const contactIds = JSON.parse(chat.contactIds || '[]')
if (sender) { if (sender) {
@ -341,12 +343,13 @@ export async function receiveGroupJoin(payload) {
await chat.update({ contactIds: JSON.stringify(contactIds) }) await chat.update({ contactIds: JSON.stringify(contactIds) })
if(isTribeOwner){ // IF TRIBE, ADD TO XREF if(isTribeOwner){ // IF TRIBE, ADD new member TO XREF
models.ChatMember.create({ models.ChatMember.create({
contactId: theSender.id, contactId: theSender.id,
chatId: chat.id, chatId: chat.id,
role: constants.chat_roles.reader, role: constants.chat_roles.reader,
lastActive: date, lastActive: date,
status: constants.chat_statuses.approved
}) })
replayChatHistory(chat, theSender) replayChatHistory(chat, theSender)
tribes.putstats({ tribes.putstats({
@ -370,11 +373,12 @@ export async function receiveGroupJoin(payload) {
} }
const message = await models.Message.create(msg) const message = await models.Message.create(msg)
const theChat = addPendingContactIdsToChat(chat)
socket.sendJson({ socket.sendJson({
type: 'group_join', type: 'group_join',
response: { response: {
contact: jsonUtils.contactToJson(theSender||{}), contact: jsonUtils.contactToJson(theSender||{}),
chat: jsonUtils.chatToJson(chat), chat: jsonUtils.chatToJson(theChat),
message: jsonUtils.messageToJson(message, null) message: jsonUtils.messageToJson(message, null)
} }
}) })
@ -508,6 +512,7 @@ export async function receiveGroupCreateOrInvite(payload) {
chatId: chat.id, chatId: chat.id,
role: c.role||constants.chat_roles.reader, role: c.role||constants.chat_roles.reader,
lastActive: date, lastActive: date,
status: constants.chat_statuses.approved
}) })
}) })
} }

12
api/controllers/contacts.ts

@ -15,6 +15,9 @@ export const getContacts = async (req, res) => {
const invites = await models.Invite.findAll({ raw: true }) const invites = await models.Invite.findAll({ raw: true })
const chats = await models.Chat.findAll({ where:{deleted:false}, raw: true }) const chats = await models.Chat.findAll({ where:{deleted:false}, raw: true })
const subscriptions = await models.Subscription.findAll({ raw: true }) const subscriptions = await models.Subscription.findAll({ raw: true })
const pendingMembers = await models.ChatMember.findAll({where:{
status: constants.chat_statuses.pending
}})
const contactsResponse = contacts.map(contact => { const contactsResponse = contacts.map(contact => {
let contactJson = jsonUtils.contactToJson(contact) let contactJson = jsonUtils.contactToJson(contact)
@ -28,7 +31,13 @@ export const getContacts = async (req, res) => {
}); });
const subsResponse = subscriptions.map(s=> jsonUtils.subscriptionToJson(s,null)) const subsResponse = subscriptions.map(s=> jsonUtils.subscriptionToJson(s,null))
const chatsResponse = chats.map(chat => jsonUtils.chatToJson(chat)) const chatsResponse = chats.map(chat=> {
const theChat = chat.dataValues||chat
if(!pendingMembers) return jsonUtils.chatToJson(theChat)
const membs = pendingMembers.filter(m=>m.chatId===chat.id) || []
theChat.pendingContactIds = membs.map(m=>m.contactId)
return jsonUtils.chatToJson(theChat)
})
success(res, { success(res, {
contacts: contactsResponse, contacts: contactsResponse,
@ -208,7 +217,6 @@ export const receiveContactKey = async (payload) => {
const owner = await models.Contact.findOne({ where: { isOwner: true }}) const owner = await models.Contact.findOne({ where: { isOwner: true }})
const sender = await models.Contact.findOne({ where: { publicKey: sender_pub_key, status: constants.contact_statuses.confirmed }}) const sender = await models.Contact.findOne({ where: { publicKey: sender_pub_key, status: constants.contact_statuses.confirmed }})
console.log("FOUND SENDER",sender&&sender.dataValue)
if (sender_contact_key && sender) { if (sender_contact_key && sender) {
const objToUpdate:{[k:string]:any} = {contactKey: sender_contact_key} const objToUpdate:{[k:string]:any} = {contactKey: sender_contact_key}
if(sender_alias) objToUpdate.alias = sender_alias if(sender_alias) objToUpdate.alias = sender_alias

5
api/controllers/index.ts

@ -41,7 +41,7 @@ export async function set(app) {
app.put('/chat/:id', chats.addGroupMembers) app.put('/chat/:id', chats.addGroupMembers)
app.put('/kick/:chat_id/:contact_id', chats.kickChatMember) app.put('/kick/:chat_id/:contact_id', chats.kickChatMember)
app.post('/tribe', chatTribes.joinTribe) app.post('/tribe', chatTribes.joinTribe)
app.put('/group/:id', chatTribes.editTribe) // app.put('/group/:id', chatTribes.editTribe)
app.post('/upload', uploads.avatarUpload.single('file'), uploads.uploadFile) app.post('/upload', uploads.avatarUpload.single('file'), uploads.uploadFile)
@ -136,4 +136,7 @@ export const ACTIONS = {
[msgtypes.group_kick]: chats.receiveGroupKick, [msgtypes.group_kick]: chats.receiveGroupKick,
[msgtypes.delete]: messages.receiveDeleteMessage, [msgtypes.delete]: messages.receiveDeleteMessage,
[msgtypes.repayment]: ()=>{}, [msgtypes.repayment]: ()=>{},
[msgtypes.member_request]: chatTribes.receiveMemberRequest,
[msgtypes.member_approve]: chatTribes.receiveMemberApprove,
[msgtypes.member_reject]: chatTribes.receiveMemberReject,
} }

2
api/models/ts/chatMember.ts

@ -22,6 +22,6 @@ export default class ChatMember extends Model<ChatMember> {
lastActive: Date lastActive: Date
@Column @Column
approved: boolean status: number
} }

2
api/utils/setup.ts

@ -33,7 +33,7 @@ async function setVersion(){
async function migrate(){ async function migrate(){
addTableColumn('sphinx_chats', 'private', 'BOOLEAN') addTableColumn('sphinx_chats', 'private', 'BOOLEAN')
addTableColumn('sphinx_chats', 'unlisted', 'BOOLEAN') addTableColumn('sphinx_chats', 'unlisted', 'BOOLEAN')
addTableColumn('sphinx_chat_members', 'approved', 'BOOLEAN') addTableColumn('sphinx_chat_members', 'status', 'BIGINT')
addTableColumn('sphinx_chats', 'seen', 'BOOLEAN') addTableColumn('sphinx_chats', 'seen', 'BOOLEAN')

6
api/utils/tribes.ts

@ -72,7 +72,7 @@ export function publish(topic, msg, cb) {
}) })
} }
export async function declare({ uuid, name, description, tags, img, group_key, host, price_per_message, price_to_join, owner_alias, owner_pubkey, escrow_amount, escrow_millis, unlisted }) { export async function declare({ uuid, name, description, tags, img, group_key, host, price_per_message, price_to_join, owner_alias, owner_pubkey, escrow_amount, escrow_millis, unlisted, is_private }) {
try { try {
await fetch('https://' + host + '/tribes', { await fetch('https://' + host + '/tribes', {
method: 'POST', method: 'POST',
@ -85,6 +85,7 @@ export async function declare({ uuid, name, description, tags, img, group_key, h
escrow_amount: escrow_amount || 0, escrow_amount: escrow_amount || 0,
escrow_millis: escrow_millis || 0, escrow_millis: escrow_millis || 0,
unlisted: unlisted||false, unlisted: unlisted||false,
private: is_private||false,
}), }),
headers: { 'Content-Type': 'application/json' } headers: { 'Content-Type': 'application/json' }
}) })
@ -95,7 +96,7 @@ export async function declare({ uuid, name, description, tags, img, group_key, h
} }
} }
export async function edit({ uuid, host, name, description, tags, img, price_per_message, price_to_join, owner_alias, escrow_amount, escrow_millis, unlisted }) { export async function edit({ uuid, host, name, description, tags, img, price_per_message, price_to_join, owner_alias, escrow_amount, escrow_millis, unlisted, is_private }) {
try { try {
const token = await genSignedTimestamp() const token = await genSignedTimestamp()
await fetch('https://' + host + '/tribe?token=' + token, { await fetch('https://' + host + '/tribe?token=' + token, {
@ -109,6 +110,7 @@ export async function edit({ uuid, host, name, description, tags, img, price_per
escrow_millis: escrow_millis || 0, escrow_millis: escrow_millis || 0,
owner_alias, owner_alias,
unlisted: unlisted||false, unlisted: unlisted||false,
private: is_private||false,
}), }),
headers: { 'Content-Type': 'application/json' } headers: { 'Content-Type': 'application/json' }
}) })

7
config/constants.json

@ -21,7 +21,7 @@
"deleted": 5 "deleted": 5
}, },
"chat_statuses": { "chat_statuses": {
"active": 0, "approved": 0,
"pending": 1, "pending": 1,
"rejected": 2 "rejected": 2
}, },
@ -45,8 +45,9 @@
"group_kick": 16, "group_kick": 16,
"delete": 17, "delete": 17,
"repayment": 18, "repayment": 18,
"member_approve": 19, "member_request": 19,
"member_reject": 20 "member_approve": 20,
"member_reject": 21
}, },
"payment_errors": { "payment_errors": {
"timeout": "Timed Out", "timeout": "Timed Out",

146
dist/api/controllers/chatTribes.js

@ -14,6 +14,8 @@ const jsonUtils = require("../utils/json");
const res_1 = require("../utils/res"); const res_1 = require("../utils/res");
const network = require("../network"); const network = require("../network");
const rsa = require("../crypto/rsa"); const rsa = require("../crypto/rsa");
const helpers = require("../helpers");
const socket = require("../utils/socket");
const tribes = require("../utils/tribes"); const tribes = require("../utils/tribes");
const path = require("path"); const path = require("path");
const msg_1 = require("../utils/msg"); const msg_1 = require("../utils/msg");
@ -23,6 +25,7 @@ function joinTribe(req, res) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
console.log('=> joinTribe'); console.log('=> joinTribe');
const { uuid, group_key, name, host, amount, img, owner_pubkey, owner_alias } = req.body; const { uuid, group_key, name, host, amount, img, owner_pubkey, owner_alias } = req.body;
const is_private = req.body.private;
const existing = yield models_1.models.Chat.findOne({ where: { uuid } }); const existing = yield models_1.models.Chat.findOne({ where: { uuid } });
if (existing) { if (existing) {
console.log('[tribes] u are already in this tribe'); console.log('[tribes] u are already in this tribe');
@ -56,6 +59,9 @@ function joinTribe(req, res) {
} }
let date = new Date(); let date = new Date();
date.setMilliseconds(0); date.setMilliseconds(0);
const chatStatus = is_private ?
constants.chat_statuses.pending :
constants.chat_statuses.approved;
const chatParams = { const chatParams = {
uuid: uuid, uuid: uuid,
contactIds: JSON.stringify(contactIds), contactIds: JSON.stringify(contactIds),
@ -67,9 +73,17 @@ function joinTribe(req, res) {
host: host || tribes.getHost(), host: host || tribes.getHost(),
groupKey: group_key, groupKey: group_key,
ownerPubkey: owner_pubkey, ownerPubkey: owner_pubkey,
private: is_private || false,
status: chatStatus
}; };
const typeToSend = is_private ?
constants.message_types.member_request :
constants.message_types.group_join;
const contactIdsToSend = is_private ?
[theTribeOwner.id] : // ONLY SEND TO TRIBE OWNER IF ITS A REQUEST
chatParams.contactIds;
network.sendMessage({ network.sendMessage({
chat: Object.assign(Object.assign({}, chatParams), { members: { chat: Object.assign(Object.assign({}, chatParams), { contactIds: contactIdsToSend, members: {
[owner.publicKey]: { [owner.publicKey]: {
key: owner.contactKey, key: owner.contactKey,
alias: owner.alias || '' alias: owner.alias || ''
@ -78,7 +92,7 @@ function joinTribe(req, res) {
amount: amount || 0, amount: amount || 0,
sender: owner, sender: owner,
message: {}, message: {},
type: constants.message_types.group_join, type: typeToSend,
failure: function (e) { failure: function (e) {
res_1.failure(res, e); res_1.failure(res, e);
}, },
@ -90,6 +104,7 @@ function joinTribe(req, res) {
chatId: chat.id, chatId: chat.id,
role: constants.chat_roles.owner, role: constants.chat_roles.owner,
lastActive: date, lastActive: date,
status: constants.chat_statuses.approved
}); });
res_1.success(res, jsonUtils.chatToJson(chat)); res_1.success(res, jsonUtils.chatToJson(chat));
}); });
@ -98,55 +113,79 @@ function joinTribe(req, res) {
}); });
} }
exports.joinTribe = joinTribe; exports.joinTribe = joinTribe;
function editTribe(req, res) { function receiveMemberRequest(payload) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
const { name, price_per_message, price_to_join, escrow_amount, escrow_millis, img, description, tags, unlisted, } = req.body; const { sender_pub_key, sender_alias, chat_uuid, chat_members, chat_type, isTribeOwner } = yield helpers.parseReceiveParams(payload);
const { id } = req.params; const chat = yield models_1.models.Chat.findOne({ where: { uuid: chat_uuid } });
if (!id) if (!chat)
return res_1.failure(res, 'group id is required'); return;
const chat = yield models_1.models.Chat.findOne({ where: { id } }); const isTribe = chat_type === constants.chat_types.tribe;
if (!chat) { if (!isTribe || !isTribeOwner)
return res_1.failure(res, 'cant find chat'); return;
} var date = new Date();
const owner = yield models_1.models.Contact.findOne({ where: { isOwner: true } }); date.setMilliseconds(0);
let okToUpdate = true; let theSender = null;
try { const member = chat_members[sender_pub_key];
yield tribes.edit({ const senderAlias = sender_alias || (member && member.alias) || 'Unknown';
uuid: chat.uuid, const sender = yield models_1.models.Contact.findOne({ where: { publicKey: sender_pub_key } });
name: name, if (sender) {
host: chat.host, theSender = sender; // might already include??
price_per_message: price_per_message || 0,
price_to_join: price_to_join || 0,
escrow_amount: escrow_amount || 0,
escrow_millis: escrow_millis || 0,
description,
tags,
img,
owner_alias: owner.alias,
unlisted,
});
}
catch (e) {
okToUpdate = false;
}
if (okToUpdate) {
yield chat.update({
photoUrl: img || '',
name: name,
pricePerMessage: price_per_message || 0,
priceToJoin: price_to_join || 0,
escrowAmount: escrow_amount || 0,
escrowMillis: escrow_millis || 0,
unlisted: unlisted || false,
});
res_1.success(res, jsonUtils.chatToJson(chat));
} }
else { else {
res_1.failure(res, 'failed to update tribe'); if (member && member.key) {
const createdContact = yield models_1.models.Contact.create({
publicKey: sender_pub_key,
contactKey: member.key,
alias: senderAlias,
status: 1,
fromGroup: true,
});
theSender = createdContact;
}
}
if (!theSender)
return console.log('no sender'); // fail (no contact key?)
models_1.models.ChatMember.create({
contactId: theSender.id,
chatId: chat.id,
role: constants.chat_roles.reader,
status: constants.chat_statuses.pending,
lastActive: date,
});
const msg = {
chatId: chat.id,
type: constants.message_types.member_request,
sender: (theSender && theSender.id) || 0,
messageContent: '', remoteMessageContent: '',
status: constants.statuses.confirmed,
date: date, createdAt: date, updatedAt: date
};
if (isTribe) {
msg.senderAlias = sender_alias;
} }
const message = yield models_1.models.Message.create(msg);
const theChat = addPendingContactIdsToChat(chat);
socket.sendJson({
type: 'member_request',
response: {
contact: jsonUtils.contactToJson(theSender || {}),
chat: jsonUtils.chatToJson(theChat),
message: jsonUtils.messageToJson(message, null)
}
});
});
}
exports.receiveMemberRequest = receiveMemberRequest;
function receiveMemberApprove(payload) {
return __awaiter(this, void 0, void 0, function* () {
}); });
} }
exports.editTribe = editTribe; exports.receiveMemberApprove = receiveMemberApprove;
function receiveMemberReject(payload) {
return __awaiter(this, void 0, void 0, function* () {
});
}
exports.receiveMemberReject = receiveMemberReject;
function replayChatHistory(chat, contact) { function replayChatHistory(chat, contact) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
if (!(chat && chat.id && contact && contact.id)) { if (!(chat && chat.id && contact && contact.id)) {
@ -197,7 +236,7 @@ function replayChatHistory(chat, contact) {
}); });
} }
exports.replayChatHistory = replayChatHistory; exports.replayChatHistory = replayChatHistory;
function createTribeChatParams(owner, contactIds, name, img, price_per_message, price_to_join, escrow_amount, escrow_millis, unlisted) { function createTribeChatParams(owner, contactIds, name, img, price_per_message, price_to_join, escrow_amount, escrow_millis, unlisted, is_private) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
let date = new Date(); let date = new Date();
date.setMilliseconds(0); date.setMilliseconds(0);
@ -225,10 +264,25 @@ function createTribeChatParams(owner, contactIds, name, img, price_per_message,
escrowMillis: escrow_millis || 0, escrowMillis: escrow_millis || 0,
escrowAmount: escrow_amount || 0, escrowAmount: escrow_amount || 0,
unlisted: unlisted || false, unlisted: unlisted || false,
private: is_private || false,
}; };
}); });
} }
exports.createTribeChatParams = createTribeChatParams; exports.createTribeChatParams = createTribeChatParams;
function addPendingContactIdsToChat(achat) {
return __awaiter(this, void 0, void 0, function* () {
const members = yield models_1.models.ChatMember.findAll({ where: {
chatId: achat.id,
status: constants.chat_statuses.pending // only pending
} });
if (!members)
return achat;
const pendingContactIds = members.map(m => m.contactId);
const chat = achat.dataValues || achat;
return Object.assign(Object.assign({}, chat), { pendingContactIds });
});
}
exports.addPendingContactIdsToChat = addPendingContactIdsToChat;
function asyncForEach(array, callback) { function asyncForEach(array, callback) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
for (let index = 0; index < array.length; index++) { for (let index = 0; index < array.length; index++) {

2
dist/api/controllers/chatTribes.js.map

File diff suppressed because one or more lines are too long

13
dist/api/controllers/chats.js

@ -161,7 +161,7 @@ function createGroupChat(req, res) {
let chatParams = null; let chatParams = null;
let okToCreate = true; let okToCreate = true;
if (is_tribe) { if (is_tribe) {
chatParams = yield chatTribes_1.createTribeChatParams(owner, contact_ids, name, img, price_per_message, price_to_join, escrow_amount, escrow_millis, unlisted); chatParams = yield chatTribes_1.createTribeChatParams(owner, contact_ids, name, img, price_per_message, price_to_join, escrow_amount, escrow_millis, unlisted, req.body.private);
if (chatParams.uuid) { if (chatParams.uuid) {
// publish to tribe server // publish to tribe server
try { try {
@ -178,6 +178,7 @@ function createGroupChat(req, res) {
owner_pubkey: owner.publicKey, owner_pubkey: owner.publicKey,
owner_alias: owner.alias, owner_alias: owner.alias,
unlisted: unlisted || false, unlisted: unlisted || false,
is_private: req.body.private || false,
}); });
} }
catch (e) { catch (e) {
@ -209,6 +210,7 @@ function createGroupChat(req, res) {
contactId: owner.id, contactId: owner.id,
chatId: chat.id, chatId: chat.id,
role: constants.chat_roles.owner, role: constants.chat_roles.owner,
status: constants.chat_statuses.approved
}); });
} }
res_1.success(res, jsonUtils.chatToJson(chat)); res_1.success(res, jsonUtils.chatToJson(chat));
@ -301,7 +303,7 @@ function receiveGroupJoin(payload) {
let theSender = null; let theSender = null;
const member = chat_members[sender_pub_key]; const member = chat_members[sender_pub_key];
const senderAlias = sender_alias || (member && member.alias) || 'Unknown'; const senderAlias = sender_alias || (member && member.alias) || 'Unknown';
if (!isTribe || isTribeOwner) { // dont need to create contacts for these if (!isTribe || isTribeOwner) {
const sender = yield models_1.models.Contact.findOne({ where: { publicKey: sender_pub_key } }); const sender = yield models_1.models.Contact.findOne({ where: { publicKey: sender_pub_key } });
const contactIds = JSON.parse(chat.contactIds || '[]'); const contactIds = JSON.parse(chat.contactIds || '[]');
if (sender) { if (sender) {
@ -331,12 +333,13 @@ function receiveGroupJoin(payload) {
if (!theSender) if (!theSender)
return console.log('no sender'); // fail (no contact key?) return console.log('no sender'); // fail (no contact key?)
yield chat.update({ contactIds: JSON.stringify(contactIds) }); yield chat.update({ contactIds: JSON.stringify(contactIds) });
if (isTribeOwner) { // IF TRIBE, ADD TO XREF if (isTribeOwner) { // IF TRIBE, ADD new member TO XREF
models_1.models.ChatMember.create({ models_1.models.ChatMember.create({
contactId: theSender.id, contactId: theSender.id,
chatId: chat.id, chatId: chat.id,
role: constants.chat_roles.reader, role: constants.chat_roles.reader,
lastActive: date, lastActive: date,
status: constants.chat_statuses.approved
}); });
chatTribes_1.replayChatHistory(chat, theSender); chatTribes_1.replayChatHistory(chat, theSender);
tribes.putstats({ tribes.putstats({
@ -358,11 +361,12 @@ function receiveGroupJoin(payload) {
msg.senderAlias = sender_alias; msg.senderAlias = sender_alias;
} }
const message = yield models_1.models.Message.create(msg); const message = yield models_1.models.Message.create(msg);
const theChat = chatTribes_1.addPendingContactIdsToChat(chat);
socket.sendJson({ socket.sendJson({
type: 'group_join', type: 'group_join',
response: { response: {
contact: jsonUtils.contactToJson(theSender || {}), contact: jsonUtils.contactToJson(theSender || {}),
chat: jsonUtils.chatToJson(chat), chat: jsonUtils.chatToJson(theChat),
message: jsonUtils.messageToJson(message, null) message: jsonUtils.messageToJson(message, null)
} }
}); });
@ -491,6 +495,7 @@ function receiveGroupCreateOrInvite(payload) {
chatId: chat.id, chatId: chat.id,
role: c.role || constants.chat_roles.reader, role: c.role || constants.chat_roles.reader,
lastActive: date, lastActive: date,
status: constants.chat_statuses.approved
}); });
}); });
} }

2
dist/api/controllers/chats.js.map

File diff suppressed because one or more lines are too long

13
dist/api/controllers/contacts.js

@ -24,6 +24,9 @@ exports.getContacts = (req, res) => __awaiter(void 0, void 0, void 0, function*
const invites = yield models_1.models.Invite.findAll({ raw: true }); const invites = yield models_1.models.Invite.findAll({ raw: true });
const chats = yield models_1.models.Chat.findAll({ where: { deleted: false }, raw: true }); const chats = yield models_1.models.Chat.findAll({ where: { deleted: false }, raw: true });
const subscriptions = yield models_1.models.Subscription.findAll({ raw: true }); const subscriptions = yield models_1.models.Subscription.findAll({ raw: true });
const pendingMembers = yield models_1.models.ChatMember.findAll({ where: {
status: constants.chat_statuses.pending
} });
const contactsResponse = contacts.map(contact => { const contactsResponse = contacts.map(contact => {
let contactJson = jsonUtils.contactToJson(contact); let contactJson = jsonUtils.contactToJson(contact);
let invite = invites.find(invite => invite.contactId == contact.id); let invite = invites.find(invite => invite.contactId == contact.id);
@ -33,7 +36,14 @@ exports.getContacts = (req, res) => __awaiter(void 0, void 0, void 0, function*
return contactJson; return contactJson;
}); });
const subsResponse = subscriptions.map(s => jsonUtils.subscriptionToJson(s, null)); const subsResponse = subscriptions.map(s => jsonUtils.subscriptionToJson(s, null));
const chatsResponse = chats.map(chat => jsonUtils.chatToJson(chat)); const chatsResponse = chats.map(chat => {
const theChat = chat.dataValues || chat;
if (!pendingMembers)
return jsonUtils.chatToJson(theChat);
const membs = pendingMembers.filter(m => m.chatId === chat.id) || [];
theChat.pendingContactIds = membs.map(m => m.contactId);
return jsonUtils.chatToJson(theChat);
});
res_1.success(res, { res_1.success(res, {
contacts: contactsResponse, contacts: contactsResponse,
chats: chatsResponse, chats: chatsResponse,
@ -184,7 +194,6 @@ exports.receiveContactKey = (payload) => __awaiter(void 0, void 0, void 0, funct
} }
const owner = yield models_1.models.Contact.findOne({ where: { isOwner: true } }); const owner = yield models_1.models.Contact.findOne({ where: { isOwner: true } });
const sender = yield models_1.models.Contact.findOne({ where: { publicKey: sender_pub_key, status: constants.contact_statuses.confirmed } }); const sender = yield models_1.models.Contact.findOne({ where: { publicKey: sender_pub_key, status: constants.contact_statuses.confirmed } });
console.log("FOUND SENDER", sender && sender.dataValue);
if (sender_contact_key && sender) { if (sender_contact_key && sender) {
const objToUpdate = { contactKey: sender_contact_key }; const objToUpdate = { contactKey: sender_contact_key };
if (sender_alias) if (sender_alias)

2
dist/api/controllers/contacts.js.map

File diff suppressed because one or more lines are too long

5
dist/api/controllers/index.js

@ -48,7 +48,7 @@ function set(app) {
app.put('/chat/:id', chats.addGroupMembers); app.put('/chat/:id', chats.addGroupMembers);
app.put('/kick/:chat_id/:contact_id', chats.kickChatMember); app.put('/kick/:chat_id/:contact_id', chats.kickChatMember);
app.post('/tribe', chatTribes.joinTribe); app.post('/tribe', chatTribes.joinTribe);
app.put('/group/:id', chatTribes.editTribe); // app.put('/group/:id', chatTribes.editTribe)
app.post('/upload', uploads.avatarUpload.single('file'), uploads.uploadFile); app.post('/upload', uploads.avatarUpload.single('file'), uploads.uploadFile);
app.post('/invites', invites.createInvite); app.post('/invites', invites.createInvite);
app.post('/invites/:invite_string/pay', invites.payInvite); app.post('/invites/:invite_string/pay', invites.payInvite);
@ -134,5 +134,8 @@ exports.ACTIONS = {
[msgtypes.group_kick]: chats.receiveGroupKick, [msgtypes.group_kick]: chats.receiveGroupKick,
[msgtypes.delete]: messages.receiveDeleteMessage, [msgtypes.delete]: messages.receiveDeleteMessage,
[msgtypes.repayment]: () => { }, [msgtypes.repayment]: () => { },
[msgtypes.member_request]: chatTribes.receiveMemberRequest,
[msgtypes.member_approve]: chatTribes.receiveMemberApprove,
[msgtypes.member_reject]: chatTribes.receiveMemberReject,
}; };
//# sourceMappingURL=index.js.map //# sourceMappingURL=index.js.map

2
dist/api/controllers/index.js.map

File diff suppressed because one or more lines are too long

4
dist/api/models/ts/chatMember.js

@ -38,8 +38,8 @@ __decorate([
], ChatMember.prototype, "lastActive", void 0); ], ChatMember.prototype, "lastActive", void 0);
__decorate([ __decorate([
sequelize_typescript_1.Column, sequelize_typescript_1.Column,
__metadata("design:type", Boolean) __metadata("design:type", Number)
], ChatMember.prototype, "approved", void 0); ], ChatMember.prototype, "status", void 0);
ChatMember = __decorate([ ChatMember = __decorate([
sequelize_typescript_1.Table({ tableName: 'sphinx_chat_members', underscored: true }) sequelize_typescript_1.Table({ tableName: 'sphinx_chat_members', underscored: true })
], ChatMember); ], ChatMember);

2
dist/api/models/ts/chatMember.js.map

@ -1 +1 @@
{"version":3,"file":"chatMember.js","sourceRoot":"","sources":["../../../../api/models/ts/chatMember.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,+DAA4D;AAG5D,IAAqB,UAAU,GAA/B,MAAqB,UAAW,SAAQ,4BAAiB;CAuBxD,CAAA;AApBC;IADC,6BAAM;;0CACO;AAGd;IADC,6BAAM;;6CACU;AAGjB;IADC,6BAAM;;wCACK;AAGZ;IADC,6BAAM;;8CACW;AAGlB;IADC,6BAAM;;iDACc;AAGrB;IADC,6BAAM;8BACK,IAAI;8CAAA;AAGhB;IADC,6BAAM;;4CACU;AArBE,UAAU;IAD9B,4BAAK,CAAC,EAAC,SAAS,EAAE,qBAAqB,EAAE,WAAW,EAAE,IAAI,EAAC,CAAC;GACxC,UAAU,CAuB9B;kBAvBoB,UAAU"} {"version":3,"file":"chatMember.js","sourceRoot":"","sources":["../../../../api/models/ts/chatMember.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,+DAA4D;AAG5D,IAAqB,UAAU,GAA/B,MAAqB,UAAW,SAAQ,4BAAiB;CAuBxD,CAAA;AApBC;IADC,6BAAM;;0CACO;AAGd;IADC,6BAAM;;6CACU;AAGjB;IADC,6BAAM;;wCACK;AAGZ;IADC,6BAAM;;8CACW;AAGlB;IADC,6BAAM;;iDACc;AAGrB;IADC,6BAAM;8BACK,IAAI;8CAAA;AAGhB;IADC,6BAAM;;0CACO;AArBK,UAAU;IAD9B,4BAAK,CAAC,EAAC,SAAS,EAAE,qBAAqB,EAAE,WAAW,EAAE,IAAI,EAAC,CAAC;GACxC,UAAU,CAuB9B;kBAvBoB,UAAU"}

2
dist/api/utils/setup.js

@ -46,7 +46,7 @@ function migrate() {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
addTableColumn('sphinx_chats', 'private', 'BOOLEAN'); addTableColumn('sphinx_chats', 'private', 'BOOLEAN');
addTableColumn('sphinx_chats', 'unlisted', 'BOOLEAN'); addTableColumn('sphinx_chats', 'unlisted', 'BOOLEAN');
addTableColumn('sphinx_chat_members', 'approved', 'BOOLEAN'); addTableColumn('sphinx_chat_members', 'status', 'BIGINT');
addTableColumn('sphinx_chats', 'seen', 'BOOLEAN'); addTableColumn('sphinx_chats', 'seen', 'BOOLEAN');
try { try {
yield models_1.sequelize.query(`CREATE INDEX idx_messages_sender ON sphinx_messages (sender);`); yield models_1.sequelize.query(`CREATE INDEX idx_messages_sender ON sphinx_messages (sender);`);

2
dist/api/utils/setup.js.map

@ -1 +1 @@
{"version":3,"file":"setup.js","sourceRoot":"","sources":["../../../api/utils/setup.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,2CAA2C;AAC3C,sCAA2C;AAC3C,iDAAoC;AACpC,iCAAgC;AAChC,sCAAqC;AACrC,gDAAwC;AACxC,8CAA0D;AAE1D,MAAM,YAAY,GAAG,CAAC,CAAA;AAEtB,MAAM,aAAa,GAAG,GAAS,EAAE;IAC/B,OAAO,CAAC,GAAG,CAAC,2BAA2B,CAAC,CAAA;IACxC,MAAM,UAAU,EAAE,CAAA;IAClB,IAAI;QACF,MAAM,kBAAS,CAAC,IAAI,EAAE,CAAA;QACtB,OAAO,CAAC,GAAG,CAAC,sBAAsB,CAAC,CAAA;KACpC;IAA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IAAI,EAAC,UAAU,EAAC,EAAE,UAAU,GAAG,EAAE,GAAG;YACvD,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;QAClB,CAAC,CAAC,CAAA;IACJ,CAAC;CAAA"}

6
dist/api/utils/tribes.js

@ -89,7 +89,7 @@ function publish(topic, msg, cb) {
}); });
} }
exports.publish = publish; exports.publish = publish;
function declare({ uuid, name, description, tags, img, group_key, host, price_per_message, price_to_join, owner_alias, owner_pubkey, escrow_amount, escrow_millis, unlisted }) { function declare({ uuid, name, description, tags, img, group_key, host, price_per_message, price_to_join, owner_alias, owner_pubkey, escrow_amount, escrow_millis, unlisted, is_private }) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
try { try {
yield fetch('https://' + host + '/tribes', { yield fetch('https://' + host + '/tribes', {
@ -103,6 +103,7 @@ function declare({ uuid, name, description, tags, img, group_key, host, price_pe
escrow_amount: escrow_amount || 0, escrow_amount: escrow_amount || 0,
escrow_millis: escrow_millis || 0, escrow_millis: escrow_millis || 0,
unlisted: unlisted || false, unlisted: unlisted || false,
private: is_private || false,
}), }),
headers: { 'Content-Type': 'application/json' } headers: { 'Content-Type': 'application/json' }
}); });
@ -115,7 +116,7 @@ function declare({ uuid, name, description, tags, img, group_key, host, price_pe
}); });
} }
exports.declare = declare; exports.declare = declare;
function edit({ uuid, host, name, description, tags, img, price_per_message, price_to_join, owner_alias, escrow_amount, escrow_millis, unlisted }) { function edit({ uuid, host, name, description, tags, img, price_per_message, price_to_join, owner_alias, escrow_amount, escrow_millis, unlisted, is_private }) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
try { try {
const token = yield genSignedTimestamp(); const token = yield genSignedTimestamp();
@ -130,6 +131,7 @@ function edit({ uuid, host, name, description, tags, img, price_per_message, pri
escrow_millis: escrow_millis || 0, escrow_millis: escrow_millis || 0,
owner_alias, owner_alias,
unlisted: unlisted || false, unlisted: unlisted || false,
private: is_private || false,
}), }),
headers: { 'Content-Type': 'application/json' } headers: { 'Content-Type': 'application/json' }
}); });

2
dist/api/utils/tribes.js.map

File diff suppressed because one or more lines are too long

10
dist/config/constants.json

@ -20,6 +20,11 @@
"failed": 4, "failed": 4,
"deleted": 5 "deleted": 5
}, },
"chat_statuses": {
"approved": 0,
"pending": 1,
"rejected": 2
},
"message_types": { "message_types": {
"message": 0, "message": 0,
"confirmation": 1, "confirmation": 1,
@ -40,8 +45,9 @@
"group_kick": 16, "group_kick": 16,
"delete": 17, "delete": 17,
"repayment": 18, "repayment": 18,
"member_approve": 19, "member_request": 19,
"member_reject": 20 "member_approve": 20,
"member_reject": 21
}, },
"payment_errors": { "payment_errors": {
"timeout": "Timed Out", "timeout": "Timed Out",

Loading…
Cancel
Save