Browse Source

new group_kick msg type, receiveGroupKick

bugfix/timeout-logging
Evan Feenstra 5 years ago
parent
commit
391a62495f
  1. 84
      api/controllers/chats.ts
  2. 1
      api/controllers/index.ts
  3. 2
      config/constants.json
  4. 84
      dist/api/controllers/chats.js
  5. 2
      dist/api/controllers/chats.js.map
  6. 1
      dist/api/controllers/index.js
  7. 2
      dist/api/controllers/index.js.map
  8. 2
      dist/config/constants.json

84
api/controllers/chats.ts

@ -30,20 +30,54 @@ export async function kickChatMember(req, res){
chatId, contactId,
}})
const contact = await models.Contact.findOne({where:{id:contactId}})
const members = {
[contact.publicKey]: {key:contact.contactKey, alias:contact.alias}
}
const kickedContact = await models.Contact.findOne({where:{id:contactId}})
const owner = await models.Contact.findOne({ where: { isOwner: true } })
network.sendMessage({
chat: { ...chat.dataValues, contactIds:[contactId], members }, // send only to the guy u kicked
sender: contact,
chat: { ...chat.dataValues, contactIds:[contactId] }, // send only to the guy u kicked
sender: owner,
message: {},
type: constants.message_types.group_leave,
type: constants.message_types.group_kick,
})
// delete all timers for this member
timers.removeTimersByContactId(contactId)
success(res, true)
if(kickedContact){
// send group_leave to others
network.sendMessage({
chat: {...chat.dataValues, contactIds:newContactIds},
sender: {...owner.dataValues, alias:kickedContact.alias},
message: {},
type: constants.message_types.group_leave,
})
}
success(res, jsonUtils.chatToJson(chat))
}
export async function receiveGroupKick(payload) {
console.log('=> receiveGroupKick')
const { chat } = await helpers.parseReceiveParams(payload)
if (!chat) return
const owner = await models.Contact.findOne({where:{isOwner:true}})
await chat.update({
deleted: true,
uuid:'',
groupKey:'',
host:'',
photoUrl:'',
contactIds:'[]',
name:''
})
await models.Message.destroy({ where: { chatId: chat.id } })
socket.sendJson({
type: 'group_kick',
response: {
contact: jsonUtils.contactToJson(owner),
}
})
}
export async function getChats(req, res) {
@ -324,7 +358,7 @@ export async function receiveGroupJoin(payload) {
export async function receiveGroupLeave(payload) {
console.log('=> receiveGroupLeave')
const { sender_pub_key, chat_uuid, chat_type, sender_alias, isTribeOwner, date_string, chat_members } = await helpers.parseReceiveParams(payload)
const { sender_pub_key, chat_uuid, chat_type, sender_alias, isTribeOwner, date_string } = await helpers.parseReceiveParams(payload)
const chat = await models.Chat.findOne({ where: { uuid: chat_uuid } })
if (!chat) return
@ -353,38 +387,6 @@ export async function receiveGroupLeave(payload) {
})
}
}
} else {
console.log('==> received leave as subsribers')
// check if im in "members", if so i've been kicked out!
const owner = await models.Contact.findOne({where:{isOwner:true}})
let imKickedOut = false
for (let pubkey of Object.keys(chat_members)) {
console.log('==> member pubkey', pubkey, owner.publicKey)
if(pubkey===owner.publicKey) {
imKickedOut = true
}
}
if(imKickedOut) {
console.log('==> IM kicked out!')
await chat.update({
deleted: true,
uuid:'',
groupKey:'',
host:'',
photoUrl:'',
contactIds:'[]',
name:''
})
await models.Message.destroy({ where: { chatId: chat.id } })
socket.sendJson({
type: 'group_leave',
response: {
contact: jsonUtils.contactToJson(owner),
chat: jsonUtils.chatToJson(chat),
}
})
return // done - I've been kicked out
}
}
var date = new Date();

1
api/controllers/index.ts

@ -132,6 +132,7 @@ export const ACTIONS = {
[msgtypes.group_invite]: chats.receiveGroupCreateOrInvite,
[msgtypes.group_join]: chats.receiveGroupJoin,
[msgtypes.group_leave]: chats.receiveGroupLeave,
[msgtypes.group_kick]: chats.receiveGroupKick,
[msgtypes.delete]: messages.receiveDeleteMessage,
[msgtypes.repayment]: ()=>{},
}

2
config/constants.json

@ -37,7 +37,7 @@
"group_invite": 13,
"group_join": 14,
"group_leave": 15,
"group_query": 16,
"group_kick": 16,
"delete": 17,
"repayment": 18
},

84
dist/api/controllers/chats.js

@ -38,22 +38,55 @@ function kickChatMember(req, res) {
yield models_1.models.ChatMember.destroy({ where: {
chatId, contactId,
} });
const contact = yield models_1.models.Contact.findOne({ where: { id: contactId } });
const members = {
[contact.publicKey]: { key: contact.contactKey, alias: contact.alias }
};
const kickedContact = yield models_1.models.Contact.findOne({ where: { id: contactId } });
const owner = yield models_1.models.Contact.findOne({ where: { isOwner: true } });
network.sendMessage({
chat: Object.assign(Object.assign({}, chat.dataValues), { contactIds: [contactId], members }),
sender: contact,
chat: Object.assign(Object.assign({}, chat.dataValues), { contactIds: [contactId] }),
sender: owner,
message: {},
type: constants.message_types.group_leave,
type: constants.message_types.group_kick,
});
// delete all timers for this member
timers.removeTimersByContactId(contactId);
res_1.success(res, true);
if (kickedContact) {
// send group_leave to others
network.sendMessage({
chat: Object.assign(Object.assign({}, chat.dataValues), { contactIds: newContactIds }),
sender: Object.assign(Object.assign({}, owner.dataValues), { alias: kickedContact.alias }),
message: {},
type: constants.message_types.group_leave,
});
}
res_1.success(res, jsonUtils.chatToJson(chat));
});
}
exports.kickChatMember = kickChatMember;
function receiveGroupKick(payload) {
return __awaiter(this, void 0, void 0, function* () {
console.log('=> receiveGroupKick');
const { chat } = yield helpers.parseReceiveParams(payload);
if (!chat)
return;
const owner = yield models_1.models.Contact.findOne({ where: { isOwner: true } });
yield chat.update({
deleted: true,
uuid: '',
groupKey: '',
host: '',
photoUrl: '',
contactIds: '[]',
name: ''
});
yield models_1.models.Message.destroy({ where: { chatId: chat.id } });
socket.sendJson({
type: 'group_kick',
response: {
contact: jsonUtils.contactToJson(owner),
}
});
});
}
exports.receiveGroupKick = receiveGroupKick;
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 });
@ -312,7 +345,7 @@ exports.receiveGroupJoin = receiveGroupJoin;
function receiveGroupLeave(payload) {
return __awaiter(this, void 0, void 0, function* () {
console.log('=> receiveGroupLeave');
const { sender_pub_key, chat_uuid, chat_type, sender_alias, isTribeOwner, date_string, chat_members } = yield helpers.parseReceiveParams(payload);
const { sender_pub_key, chat_uuid, chat_type, sender_alias, isTribeOwner, date_string } = yield helpers.parseReceiveParams(payload);
const chat = yield models_1.models.Chat.findOne({ where: { uuid: chat_uuid } });
if (!chat)
return;
@ -340,39 +373,6 @@ function receiveGroupLeave(payload) {
}
}
}
else {
console.log('==> received leave as subsribers');
// check if im in "members", if so i've been kicked out!
const owner = yield models_1.models.Contact.findOne({ where: { isOwner: true } });
let imKickedOut = false;
for (let pubkey of Object.keys(chat_members)) {
console.log('==> member pubkey', pubkey, owner.publicKey);
if (pubkey === owner.publicKey) {
imKickedOut = true;
}
}
if (imKickedOut) {
console.log('==> IM kicked out!');
yield chat.update({
deleted: true,
uuid: '',
groupKey: '',
host: '',
photoUrl: '',
contactIds: '[]',
name: ''
});
yield models_1.models.Message.destroy({ where: { chatId: chat.id } });
socket.sendJson({
type: 'group_leave',
response: {
contact: jsonUtils.contactToJson(owner),
chat: jsonUtils.chatToJson(chat),
}
});
return; // done - I've been kicked out
}
}
var date = new Date();
date.setMilliseconds(0);
if (date_string)

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

File diff suppressed because one or more lines are too long

1
dist/api/controllers/index.js

@ -130,6 +130,7 @@ exports.ACTIONS = {
[msgtypes.group_invite]: chats.receiveGroupCreateOrInvite,
[msgtypes.group_join]: chats.receiveGroupJoin,
[msgtypes.group_leave]: chats.receiveGroupLeave,
[msgtypes.group_kick]: chats.receiveGroupKick,
[msgtypes.delete]: messages.receiveDeleteMessage,
[msgtypes.repayment]: () => { },
};

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

File diff suppressed because one or more lines are too long

2
dist/config/constants.json

@ -37,7 +37,7 @@
"group_invite": 13,
"group_join": 14,
"group_leave": 15,
"group_query": 16,
"group_kick": 16,
"delete": 17,
"repayment": 18
},

Loading…
Cancel
Save