Browse Source

start delete msg, kick chat member:

bugfix/timeout-logging
Evan Feenstra 5 years ago
parent
commit
a82eb3f959
  1. 8
      api/controllers/chats.ts
  2. 4
      api/controllers/index.ts
  3. 35
      api/controllers/messages.ts
  4. 8
      api/network/receive.ts
  5. 3
      config/constants.json
  6. 7
      dist/api/controllers/chats.js
  7. 2
      dist/api/controllers/chats.js.map
  8. 2
      dist/api/controllers/index.js
  9. 2
      dist/api/controllers/index.js.map
  10. 31
      dist/api/controllers/messages.js
  11. 2
      dist/api/controllers/messages.js.map
  12. 7
      dist/api/network/receive.js
  13. 2
      dist/api/network/receive.js.map
  14. 3
      dist/config/constants.json

8
api/controllers/chats.ts

@ -12,6 +12,12 @@ import {replayChatHistory,createTribeChatParams} from './chatTribes'
const constants = require(path.join(__dirname,'../../config/constants.json'))
async function kickChatMember(){
// kick - remove from ChatMembers
// send group_leave to all ?? need to do this?
}
async function getChats(req, res) {
const chats = await models.Chat.findAll({ where:{deleted:false}, raw: true })
const c = chats.map(chat => jsonUtils.chatToJson(chat));
@ -474,7 +480,7 @@ function createGroupChatParams(owner, contactIds, members, name) {
}
export {
getChats, mute, addGroupMembers,
getChats, mute, addGroupMembers, kickChatMember,
receiveGroupCreateOrInvite, createGroupChat,
deleteChat, receiveGroupLeave, receiveGroupJoin,
}

4
api/controllers/index.ts

@ -38,6 +38,7 @@ async function set(app) {
app.post('/chats/:chat_id/:mute_unmute', chats.mute)
app.delete('/chat/:id', chats.deleteChat)
app.put('/chat/:id', chats.addGroupMembers)
app.put('/kick/:id', chats.kickChatMember)
app.post('/tribe', chatTribes.joinTribe)
app.put('/group/:id', chatTribes.editTribe)
@ -130,7 +131,8 @@ const ACTIONS = {
[msgtypes.group_create]: chats.receiveGroupCreateOrInvite,
[msgtypes.group_invite]: chats.receiveGroupCreateOrInvite,
[msgtypes.group_join]: chats.receiveGroupJoin,
[msgtypes.group_leave]: chats.receiveGroupLeave,
[msgtypes.group_leave]: chats.receiveGroupLeave,
[msgtypes.delete]: messages.receiveDeleteMessage,
}
export {set, ACTIONS}

35
api/controllers/messages.ts

@ -91,8 +91,23 @@ const getAllMessages = async (req, res) => {
async function deleteMessage(req, res){
const id = req.params.id
const {chat_id} = req.body
const message = await models.Message.findOne({where:{id}})
const uuid = message.uuid
await models.Message.destroy({ where: {id} })
success(res, {id})
if(chat_id) {
const chat = await models.Chat.findOne({where:{id:chat_id}})
const owner = await models.Contact.findOne({ where: { isOwner: true }})
network.sendMessage({
chat: chat,
sender: owner,
type: constants.message_types.delete,
message: {id,uuid},
})
}
}
const sendMessage = async (req, res) => {
@ -204,6 +219,25 @@ const receiveMessage = async (payload) => {
sendConfirmation({ chat:theChat, sender: owner, msg_id })
}
const receiveDeleteMessage = async (payload) => {
// console.log('received message', { payload })
const {owner, sender, chat, chat_type, msg_uuid} = await helpers.parseReceiveParams(payload)
if(!owner || !sender || !chat) {
return console.log('=> no group chat!')
}
// check the sender is the creator of the msg
const isTribe = chat_type===constants.chat_types.tribe
if(isTribe) {
// ?
}
await models.Message.destroy({where:{uuid:msg_uuid}})
socket.sendJson({
type: 'delete',
response: jsonUtils.messageToJson({uuid:msg_uuid}, chat, sender)
})
}
const readMessages = async (req, res) => {
const chat_id = req.params.chat_id;
@ -235,4 +269,5 @@ export {
readMessages,
deleteMessage,
getAllMessages,
receiveDeleteMessage,
}

8
api/network/receive.ts

@ -13,6 +13,14 @@ import {decryptMessage,encryptTribeBroadcast} from '../utils/msg'
import { Op } from 'sequelize'
import * as timers from '../utils/timers'
/*
delete type:
owner needs to check that the delete is the one who made the msg
in receiveDeleteMessage check the deleter is og sender?
*/
const constants = require(path.join(__dirname,'../../config/constants.json'))
const msgtypes = constants.message_types

3
config/constants.json

@ -36,7 +36,8 @@
"group_invite": 13,
"group_join": 14,
"group_leave": 15,
"group_query": 16
"group_query": 16,
"delete": 17
},
"payment_errors": {
"timeout": "Timed Out",

7
dist/api/controllers/chats.js

@ -21,6 +21,13 @@ const path = require("path");
const tribes = require("../utils/tribes");
const chatTribes_1 = require("./chatTribes");
const constants = require(path.join(__dirname, '../../config/constants.json'));
function kickChatMember() {
return __awaiter(this, void 0, void 0, function* () {
// kick - remove from ChatMembers
// send group_leave to all ?? need to do this?
});
}
exports.kickChatMember = kickChatMember;
function getChats(req, res) {
return __awaiter(this, void 0, void 0, function* () {
const chats = yield models_1.models.Chat.findAll({ where: { deleted: false }, raw: true });

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

File diff suppressed because one or more lines are too long

2
dist/api/controllers/index.js

@ -45,6 +45,7 @@ function set(app) {
app.post('/chats/:chat_id/:mute_unmute', chats.mute);
app.delete('/chat/:id', chats.deleteChat);
app.put('/chat/:id', chats.addGroupMembers);
app.put('/kick/:id', chats.kickChatMember);
app.post('/tribe', chatTribes.joinTribe);
app.put('/group/:id', chatTribes.editTribe);
app.post('/upload', uploads.avatarUpload.single('file'), uploads.uploadFile);
@ -129,6 +130,7 @@ const ACTIONS = {
[msgtypes.group_invite]: chats.receiveGroupCreateOrInvite,
[msgtypes.group_join]: chats.receiveGroupJoin,
[msgtypes.group_leave]: chats.receiveGroupLeave,
[msgtypes.delete]: messages.receiveDeleteMessage,
};
exports.ACTIONS = ACTIONS;
//# sourceMappingURL=index.js.map

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

File diff suppressed because one or more lines are too long

31
dist/api/controllers/messages.js

@ -87,8 +87,21 @@ exports.getAllMessages = getAllMessages;
function deleteMessage(req, res) {
return __awaiter(this, void 0, void 0, function* () {
const id = req.params.id;
const { chat_id } = req.body;
const message = yield models_1.models.Message.findOne({ where: { id } });
const uuid = message.uuid;
yield models_1.models.Message.destroy({ where: { id } });
res_1.success(res, { id });
if (chat_id) {
const chat = yield models_1.models.Chat.findOne({ where: { id: chat_id } });
const owner = yield models_1.models.Contact.findOne({ where: { isOwner: true } });
network.sendMessage({
chat: chat,
sender: owner,
type: constants.message_types.delete,
message: { id, uuid },
});
}
});
}
exports.deleteMessage = deleteMessage;
@ -185,6 +198,24 @@ const receiveMessage = (payload) => __awaiter(void 0, void 0, void 0, function*
confirmations_1.sendConfirmation({ chat: theChat, sender: owner, msg_id });
});
exports.receiveMessage = receiveMessage;
const receiveDeleteMessage = (payload) => __awaiter(void 0, void 0, void 0, function* () {
// console.log('received message', { payload })
const { owner, sender, chat, chat_type, msg_uuid } = yield helpers.parseReceiveParams(payload);
if (!owner || !sender || !chat) {
return console.log('=> no group chat!');
}
// check the sender is the creator of the msg
const isTribe = chat_type === constants.chat_types.tribe;
if (isTribe) {
// ?
}
yield models_1.models.Message.destroy({ where: { uuid: msg_uuid } });
socket.sendJson({
type: 'delete',
response: jsonUtils.messageToJson({ uuid: msg_uuid }, chat, sender)
});
});
exports.receiveDeleteMessage = receiveDeleteMessage;
const readMessages = (req, res) => __awaiter(void 0, void 0, void 0, function* () {
const chat_id = req.params.chat_id;
const owner = yield models_1.models.Contact.findOne({ where: { isOwner: true } });

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

File diff suppressed because one or more lines are too long

7
dist/api/network/receive.js

@ -23,6 +23,13 @@ const modify_1 = require("./modify");
const msg_1 = require("../utils/msg");
const sequelize_1 = require("sequelize");
const timers = require("../utils/timers");
/*
delete type:
owner needs to check that the delete is the one who made the msg
in receiveDeleteMessage check the deleter is og sender?
*/
const constants = require(path.join(__dirname, '../../config/constants.json'));
const msgtypes = constants.message_types;
exports.typesToForward = [

2
dist/api/network/receive.js.map

File diff suppressed because one or more lines are too long

3
dist/config/constants.json

@ -36,7 +36,8 @@
"group_invite": 13,
"group_join": 14,
"group_leave": 15,
"group_query": 16
"group_query": 16,
"delete": 17
},
"payment_errors": {
"timeout": "Timed Out",

Loading…
Cancel
Save