Skip to content

Commit

Permalink
fix: messages to old groups creating new threads #22
Browse files Browse the repository at this point in the history
  • Loading branch information
ifedapoolarewaju committed Dec 3, 2017
1 parent b4a6d06 commit ee06584
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
9 changes: 5 additions & 4 deletions browser/js/funcs.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,19 +73,20 @@ function markAsRead (id, li) {

delete unreadChats[id];
}
li.classList.remove('notification'); // or whatever
li.classList.remove('notification');
}

function sendMessage (message, accounts, isNewChat) {
function sendMessage (message, accounts, chatId) {
const isNewChat = !chatId;
var users = accounts.map((account) => account.id);
ipcRenderer.send('message', { message, isNewChat, users })
ipcRenderer.send('message', { message, isNewChat, users, chatId });
}

function submitMessage (chat_) {
var input = document.querySelector(MSG_INPUT_SELECTOR);
var message = input.value;
if (message.trim()) {
sendMessage(message, chat_.accounts, !chat_.id);
sendMessage(message, chat_.accounts, chat_.id);
input.value = '';
var div = renderMessage(message, 'outward');
var msgContainer = document.querySelector('.chat .messages');
Expand Down
11 changes: 10 additions & 1 deletion instagram.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,21 @@ exports.getChat = function (session, chatId) {
})
}

exports.sendMessage = function (session, message, recipients) {
exports.sendNewChatMessage = function (session, message, recipients) {
return new Promise((resolve, reject) => {
Client.Thread.configureText(session, recipients, message).then(resolve).catch(reject)
})
}

exports.sendMessage = function (session, message, chatId) {
return new Promise((resolve, reject) => {
Client.Thread.getById(session, chatId)
.then((thread) => {
thread.broadcastText(message).then(resolve).catch(reject)
}).catch(reject)
})
}

exports.searchUsers = function (session, search) {
return new Promise((resolve, reject) => {
Client.Account.search(session, search).then(resolve).catch(reject)
Expand Down
8 changes: 5 additions & 3 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,11 @@ electron.ipcMain.on('getChatList', getChatList)
electron.ipcMain.on('getChat', getChat)

electron.ipcMain.on('message', (evt, data) => {
instagram.sendMessage(session, data.message, data.users).then((chat) => {
if (data.isNewChat) getChat(null, chat[0].id)
})
if (data.isNewChat) {
instagram.sendNewChatMessage(session, data.message, data.users).then((chat) => getChat(null, chat[0].id))
} else {
instagram.sendMessage(session, data.message, data.chatId)
}
})

electron.ipcMain.on('searchUsers', (evt, search) => {
Expand Down

0 comments on commit ee06584

Please sign in to comment.