add group chat sending and fix bugs

This commit is contained in:
JJTech0130 2023-07-31 13:57:50 -04:00
parent 84fe9ed44a
commit a4dbc56d8d
No known key found for this signature in database
GPG key ID: 23C92EBCCF8F93D6
2 changed files with 13 additions and 9 deletions

19
demo.py
View file

@ -126,10 +126,10 @@ threading.Thread(target=input_thread, daemon=True).start()
print("Type 'help' for help") print("Type 'help' for help")
current_chat = None current_participants = []
while True: while True:
msg = im.receive() msg = im.receive()
if msg is not None and msg.sender != user.handles[0]: if msg is not None:
print(f'[{msg.sender}] {msg.text}') print(f'[{msg.sender}] {msg.text}')
if len(INPUT_QUEUE) > 0: if len(INPUT_QUEUE) > 0:
@ -144,20 +144,21 @@ while True:
print('\\: escape commands (will be removed from message)') print('\\: escape commands (will be removed from message)')
elif msg == 'quit' or msg == 'q': elif msg == 'quit' or msg == 'q':
break break
elif msg.startswith('filter') or msg.startswith('f'): elif msg.startswith('filter ') or msg.startswith('f '):
# Set the curernt chat # Set the curernt chat
msg = msg.split(' ') msg = msg.split(' ')
if len(msg) < 2: if len(msg) < 2 or msg[1] == '':
print('filter [recipient]') print('filter [recipients]')
else: else:
current_chat = msg[1] print(f'Filtering to {msg[1:]}')
elif current_chat is not None: current_participants = msg[1:]
elif current_participants != []:
if msg.startswith('\\'): if msg.startswith('\\'):
msg = msg[1:] msg = msg[1:]
im.send(imessage.iMessage( im.send(imessage.iMessage(
text=msg, text=msg,
participants=[current_chat, user.handles[0]], participants=current_participants,
#sender=user.handles[0] sender=user.handles[0]
)) ))
else: else:
print('No chat selected, use help for help') print('No chat selected, use help for help')

View file

@ -386,6 +386,9 @@ class iMessageUser:
bundled_payloads = [] bundled_payloads = []
for participant in message.participants: for participant in message.participants:
for push_token in self.USER_CACHE[participant]: for push_token in self.USER_CACHE[participant]:
if push_token == self.connection.token:
continue # Don't send to ourselves
identity_keys = ids.identity.IDSIdentity.decode( identity_keys = ids.identity.IDSIdentity.decode(
self.KEY_CACHE[push_token][0] self.KEY_CACHE[push_token][0]
) )