|
@ -1030,8 +1030,9 @@ class ConnectionState: |
|
|
else: |
|
|
else: |
|
|
thread = Thread(guild=guild, state=self, data=data) |
|
|
thread = Thread(guild=guild, state=self, data=data) |
|
|
guild._add_thread(thread) |
|
|
guild._add_thread(thread) |
|
|
self.dispatch('thread_create', thread) |
|
|
if data.get('newly_created', False): |
|
|
if self.self_id in thread._member_ids: # Thread was created by us/we were added to a private thread |
|
|
self.dispatch('thread_create', thread) |
|
|
|
|
|
else: |
|
|
self.dispatch('thread_join', thread) |
|
|
self.dispatch('thread_join', thread) |
|
|
|
|
|
|
|
|
def parse_thread_update(self, data) -> None: |
|
|
def parse_thread_update(self, data) -> None: |
|
@ -1049,9 +1050,6 @@ class ConnectionState: |
|
|
else: # Shouldn't happen |
|
|
else: # Shouldn't happen |
|
|
thread = Thread(guild=guild, state=self, data=data) |
|
|
thread = Thread(guild=guild, state=self, data=data) |
|
|
guild._add_thread(thread) |
|
|
guild._add_thread(thread) |
|
|
self.dispatch('thread_create', thread) |
|
|
|
|
|
if self.self_id in thread.member_ids: # Thread was created by us/we were added to a private thread |
|
|
|
|
|
self.dispatch('thread_join', thread) |
|
|
|
|
|
|
|
|
|
|
|
def parse_thread_delete(self, data) -> None: |
|
|
def parse_thread_delete(self, data) -> None: |
|
|
guild_id = int(data['guild_id']) |
|
|
guild_id = int(data['guild_id']) |
|
@ -1074,7 +1072,7 @@ class ConnectionState: |
|
|
_log.debug('THREAD_LIST_SYNC referencing an unknown guild ID: %s. Discarding.', guild_id) |
|
|
_log.debug('THREAD_LIST_SYNC referencing an unknown guild ID: %s. Discarding.', guild_id) |
|
|
return |
|
|
return |
|
|
|
|
|
|
|
|
try: # Never had this actually happen so IDK |
|
|
try: |
|
|
channel_ids = set(data['channel_ids']) |
|
|
channel_ids = set(data['channel_ids']) |
|
|
except KeyError: |
|
|
except KeyError: |
|
|
channel_ids = None |
|
|
channel_ids = None |
|
@ -1086,12 +1084,12 @@ class ConnectionState: |
|
|
for d in data.get('threads', []): |
|
|
for d in data.get('threads', []): |
|
|
if (thread := threads.pop(int(d['id']), None)) is not None: |
|
|
if (thread := threads.pop(int(d['id']), None)) is not None: |
|
|
old = thread._update(d) |
|
|
old = thread._update(d) |
|
|
if old is not None: # None = wasn't updated |
|
|
if old is not None: |
|
|
self.dispatch('thread_update', old, thread) |
|
|
self.dispatch('thread_update', old, thread) # Honestly not sure if this is right |
|
|
else: |
|
|
else: |
|
|
thread = Thread(guild=guild, state=self, data=d) |
|
|
thread = Thread(guild=guild, state=self, data=d) |
|
|
new_threads[thread.id] = thread |
|
|
new_threads[thread.id] = thread |
|
|
old_threads = [t for t in threads.values() if t not in new_threads] |
|
|
old_threads = [t for t in threads.values() if t.id not in new_threads] |
|
|
|
|
|
|
|
|
for member in data.get('members', []): |
|
|
for member in data.get('members', []): |
|
|
try: # Note: member['id'] is the thread_id |
|
|
try: # Note: member['id'] is the thread_id |
|
@ -1103,15 +1101,10 @@ class ConnectionState: |
|
|
|
|
|
|
|
|
for k in new_threads.values(): |
|
|
for k in new_threads.values(): |
|
|
guild._add_thread(k) |
|
|
guild._add_thread(k) |
|
|
if guild._threads_synced: |
|
|
|
|
|
self.dispatch('thread_create', k) |
|
|
|
|
|
if self_id in k.member_ids: |
|
|
|
|
|
self.dispatch('thread_join', k) |
|
|
|
|
|
|
|
|
|
|
|
for k in old_threads: |
|
|
for k in old_threads: |
|
|
del guild._threads[k.id] |
|
|
del guild._threads[k.id] |
|
|
if guild._threads_synced: |
|
|
self.dispatch('thread_delete', k) # Again, not sure |
|
|
self.dispatch('thread_delete', k) # Did the thread get deleted or did we get yeeted? |
|
|
|
|
|
|
|
|
|
|
|
for message in data.get('most_recent_messages', []): |
|
|
for message in data.get('most_recent_messages', []): |
|
|
guild_id = utils._get_as_snowflake(message, 'guild_id') |
|
|
guild_id = utils._get_as_snowflake(message, 'guild_id') |
|
@ -1124,8 +1117,6 @@ class ConnectionState: |
|
|
if self._messages is not None: |
|
|
if self._messages is not None: |
|
|
self._messages.append(message) |
|
|
self._messages.append(message) |
|
|
|
|
|
|
|
|
guild._threads_synced = True |
|
|
|
|
|
|
|
|
|
|
|
def parse_thread_member_update(self, data) -> None: |
|
|
def parse_thread_member_update(self, data) -> None: |
|
|
guild_id = int(data['guild_id']) |
|
|
guild_id = int(data['guild_id']) |
|
|
guild: Optional[Guild] = self._get_guild(guild_id) |
|
|
guild: Optional[Guild] = self._get_guild(guild_id) |
|
|