Browse Source

dont gen the group_leave on admins node, user who was kicked out can leave

bugfix/timeout-logging v0.9.22
Evan Feenstra 4 years ago
parent
commit
e0444fe06e
  1. 32
      api/controllers/chats.ts
  2. 30
      dist/api/controllers/chats.js
  3. 2
      dist/api/controllers/chats.js.map

32
api/controllers/chats.ts

@ -30,8 +30,6 @@ export async function kickChatMember(req, res){
chatId, contactId, chatId, contactId,
}}) }})
const kickedContact = await models.Contact.findOne({where:{id:contactId}})
const owner = await models.Contact.findOne({ where: { isOwner: true } }) const owner = await models.Contact.findOne({ where: { isOwner: true } })
network.sendMessage({ network.sendMessage({
chat: { ...chat.dataValues, contactIds:[contactId] }, // send only to the guy u kicked chat: { ...chat.dataValues, contactIds:[contactId] }, // send only to the guy u kicked
@ -43,36 +41,6 @@ export async function kickChatMember(req, res){
// delete all timers for this member // delete all timers for this member
timers.removeTimersByContactIdChatId(contactId,chatId) timers.removeTimersByContactIdChatId(contactId,chatId)
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,
})
var date = new Date()
date.setMilliseconds(0)
const msg:{[k:string]:any} = {
chatId: chat.id,
type: constants.message_types.group_leave,
sender: (kickedContact.id) || 0,
messageContent:'', remoteMessageContent:'',
status: constants.statuses.confirmed,
date:date, createdAt:date, updatedAt:date,
senderAlias: kickedContact.alias
}
const message = await models.Message.create(msg)
socket.sendJson({
type: 'group_leave',
response: {
contact: jsonUtils.contactToJson(kickedContact),
chat: jsonUtils.chatToJson(chat),
message: jsonUtils.messageToJson(message, null)
}
})
}
success(res, jsonUtils.chatToJson(chat)) success(res, jsonUtils.chatToJson(chat))
} }

30
dist/api/controllers/chats.js

@ -38,7 +38,6 @@ function kickChatMember(req, res) {
yield models_1.models.ChatMember.destroy({ where: { yield models_1.models.ChatMember.destroy({ where: {
chatId, contactId, chatId, contactId,
} }); } });
const kickedContact = yield models_1.models.Contact.findOne({ where: { id: contactId } });
const owner = yield models_1.models.Contact.findOne({ where: { isOwner: true } }); const owner = yield models_1.models.Contact.findOne({ where: { isOwner: true } });
network.sendMessage({ network.sendMessage({
chat: Object.assign(Object.assign({}, chat.dataValues), { contactIds: [contactId] }), chat: Object.assign(Object.assign({}, chat.dataValues), { contactIds: [contactId] }),
@ -48,35 +47,6 @@ function kickChatMember(req, res) {
}); });
// delete all timers for this member // delete all timers for this member
timers.removeTimersByContactIdChatId(contactId, chatId); timers.removeTimersByContactIdChatId(contactId, chatId);
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,
});
var date = new Date();
date.setMilliseconds(0);
const msg = {
chatId: chat.id,
type: constants.message_types.group_leave,
sender: (kickedContact.id) || 0,
messageContent: '', remoteMessageContent: '',
status: constants.statuses.confirmed,
date: date, createdAt: date, updatedAt: date,
senderAlias: kickedContact.alias
};
const message = yield models_1.models.Message.create(msg);
socket.sendJson({
type: 'group_leave',
response: {
contact: jsonUtils.contactToJson(kickedContact),
chat: jsonUtils.chatToJson(chat),
message: jsonUtils.messageToJson(message, null)
}
});
}
res_1.success(res, jsonUtils.chatToJson(chat)); res_1.success(res, jsonUtils.chatToJson(chat));
}); });
} }

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

File diff suppressed because one or more lines are too long
Loading…
Cancel
Save