| 1780 | | no_threadid_sessions = filter(lambda s: not s.received_thread_id, sessions) |
|---|
| 1781 | | |
|---|
| 1782 | | if no_threadid_sessions: |
|---|
| 1783 | | no_threadid_sessions.sort(key=lambda s: s.last_send) |
|---|
| 1784 | | return no_threadid_sessions[-1] |
|---|
| | 1780 | |
|---|
| | 1781 | # sessions that we haven't received a thread ID in |
|---|
| | 1782 | idless = filter(lambda s: not s.received_thread_id, sessions) |
|---|
| | 1783 | |
|---|
| | 1784 | # filter out everything exceptthe default session type |
|---|
| | 1785 | chat_sessions = filter(lambda s: isinstance(s, ChatControlSession), idless) |
|---|
| | 1786 | |
|---|
| | 1787 | if chat_sessions: |
|---|
| | 1788 | # return the session that we last sent a message in |
|---|
| | 1789 | chat_sessions.sort(key=lambda s: s.last_send) |
|---|
| | 1790 | return chat_sessions[-1] |
|---|