Skip to content

Find group chats by chat id #37

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 6 additions & 17 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ class App extends MatrixPuppetBridgeBase {
ghostIntent.client.sendReadReceipt (event);
return this.receiptHistory.delete(roomId);
} catch (err) {
debug('could not send read event', err.message);
console.log('could not send read event', err.message);
}
}

Expand All @@ -159,18 +159,7 @@ class App extends MatrixPuppetBridgeBase {
}
prepareToSend(id, matrixEvent) {
if ( id.match(/^chat/) ) {
// it's a multi party chat... we need to send to participants list
// luckily we can find out about all the ghosts (they get preloaded)
// and pull their handles down and use that to chat with the group
const roomMembers = this.puppet.getMatrixRoomMembers(matrixEvent.room_id);
const handles = roomMembers.reduce((acc, gid) => {
let tpid = this.getThirdPartyUserIdFromMatrixGhostId(gid);
return tpid ? [...acc, tpid] : acc;
},[]);
return Promise.resolve({
isGroup: true,
handles
});
return Promise.resolve({ isGroup: true });
} else {
return this.getRoomService(id).then(service => ({
isGroup: false,
Expand All @@ -183,17 +172,17 @@ class App extends MatrixPuppetBridgeBase {
matrixEvent.getRoomId = () => matrixEvent.room_id;
matrixEvent.getId = () => matrixEvent.event_id;
this.receiptHistory.set(id, matrixEvent);
return this.prepareToSend(id, matrixEvent).then(({isGroup, handles, service})=>{
return isGroup ? sendGroupMessage(handles, text) : sendMessage(id, service, text);
return this.prepareToSend(id, matrixEvent).then(({isGroup, service})=>{
return isGroup ? sendGroupMessage(id, text) : sendMessage(id, service, text);
});
}

sendImageMessageAsPuppetToThirdPartyRoomWithId(id, { url, text }, matrixEvent) {
const { sendGroupMessage, sendMessage } = this.client;
return download.getTempfile(url, { tagFilename: true }).then(({path}) => {
const img = path;
return this.prepareToSend(id, matrixEvent).then(({isGroup, handles, service})=>{
return isGroup ? sendGroupMessage(handles, text, img) : sendMessage(id, service, text, img);
return this.prepareToSend(id, matrixEvent).then(({isGroup, service})=>{
return isGroup ? sendGroupMessage(id, text, img) : sendMessage(id, service, text, img);
});
});
}
Expand Down
4 changes: 2 additions & 2 deletions src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ class Client extends EventEmitter {
sendMessage (id, service, text, file) {
return iMessageSend(id, service != "iMessage" ? "sms" : "iMessage", text, file);
}
sendGroupMessage (handles, text, file) {
return iMessageSendGroup(handles, text, file);
sendGroupMessage (id, text, file) {
return iMessageSendGroup(id, text, file);
Comment on lines +26 to +27
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this requires also a change in https://github.com/matrix-hacks/matrix-puppet-imessage/blob/master/index.js#L196

This probably resolved the issue of @ericmigi

}
init (ichatArchives) {
const storage = nodePersist.create({
Expand Down
62 changes: 24 additions & 38 deletions src/imessage-send-group.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,41 +4,40 @@ const escapeString = (str) => {
return str.replace(/[\\"]/g, '\\$&');
};

module.exports = function(handles, _message, file) {
module.exports = function(id, _message, file) {
console.log(id);
let message = escapeString(_message);
let args = ['-e'];

let buddyVars = [];
let buddySetters = [];
handles.forEach((handle, i)=>{
const buddyVar = 'buddy'+i;
buddyVars.push(buddyVar);
buddySetters.push(`set ${buddyVar} to first buddy whose handle is "${handle}"`);
});
const setAttachment = `
tell application "System Events"
set theAttachment to POSIX file "${file}"
end tell
`;

const tellBody = () => {
if ( file ){
return `
set theAttachment1 to POSIX file "${file}"
send theAttachment1 to thisChat
`;
} else {
return `send "${message}" to thisChat`;
}
};
const sendAttachment = `
send theAttachment to thisChat
`;

const sendMessage = `
send "${message}" to thisChat
`;

args.push(`tell application "Messages"
activate
${buddySetters.join('\n\t')}
set thisChat to make new text chat with properties {participants:{${buddyVars.join(',')}}}
${tellBody()}
end tell`);
args.push(`
${file ? setAttachment : ''}

tell application "Messages"
activate
set thisChat to a reference to chat id "iMessage;+;${id}"
${file ? sendAttachment : sendMessage}
end tell
`);

console.log('full applescript', args[1]);

return new Promise(function(resolve, reject) {
// Check user input
if (!handles) reject(new Error('You didn\'t enter a recipient!'));
if (!id) reject(new Error('You didn\'t enter a chat id!'));
else if (!message) reject(new Error('You didn\'t enter a message!'));
else {
var proc = spawn('/usr/bin/osascript', args );
Expand All @@ -54,16 +53,3 @@ module.exports = function(handles, _message, file) {
}
});
};

if (!module.parent) {

const handles = [
process.env.PHONE1,
process.env.PHONE2
];

module.exports(handles, "testing group send from javascript (no image)..");
module.exports(handles, "testing group send from javascript (with image)..", __dirname+"/../mr-goldenfold.png");
}