Skip to content

Commit ac4aaa3

Browse files
dbieberclaude
andcommitted
Improve Slack uploader handling of indentation events
- Add ENTER_EMPTY event handling - Remove unnecessary try/except block - Clean up imports and formatting 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 234ec2e commit ac4aaa3

File tree

1 file changed

+34
-40
lines changed

1 file changed

+34
-40
lines changed

gonotego/uploader/slack/slack_uploader.py

Lines changed: 34 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
"""Uploader for Slack workspace channels."""
22

3-
import os
4-
import time
53
import logging
64
from typing import List, Optional
75

@@ -113,51 +111,47 @@ def upload(self, note_events: List[events.NoteEvent]) -> bool:
113111
"""Upload note events to Slack.
114112
115113
Args:
116-
note_events: List of NoteEvent objects.
114+
note_events: List of NoteEvent objects.
117115
118116
Returns:
119-
bool: True if upload successful, False otherwise.
117+
bool: True if upload successful, False otherwise.
120118
"""
121-
if not note_events:
122-
return True
123-
124-
try:
125-
for note_event in note_events:
126-
# Handle indent/unindent events to track indentation level
127-
if note_event.action == events.INDENT:
128-
self._indent_level += 1
129-
continue
130-
elif note_event.action == events.UNINDENT:
131-
self._indent_level = max(0, self._indent_level - 1)
132-
continue
133-
elif note_event.action == events.CLEAR_EMPTY:
134-
self._indent_level = 0
119+
for note_event in note_events:
120+
# Handle indent/unindent events to track indentation level
121+
if note_event.action == events.INDENT:
122+
self._indent_level += 1
123+
continue
124+
elif note_event.action == events.UNINDENT:
125+
self._indent_level = max(0, self._indent_level - 1)
126+
continue
127+
elif note_event.action == events.CLEAR_EMPTY:
128+
self._indent_level = 0
129+
continue
130+
elif note_event.action == events.ENTER_EMPTY:
131+
# When you submit from an empty note, that pops from the stack.
132+
self._indent_level = max(0, self._indent_level - 1)
133+
elif note_event.action == events.SUBMIT:
134+
text = note_event.text.strip()
135+
136+
# Skip empty notes
137+
if not text:
135138
continue
136-
elif note_event.action == events.SUBMIT:
137-
text = note_event.text.strip()
138139

139-
# Skip empty notes
140-
if not text:
141-
continue
140+
# Start a new session for the first note
141+
if not self._session_started:
142+
success = self._start_session(text)
143+
else:
144+
# Send as a reply to the thread with proper indentation
145+
success = self._send_note_to_thread(text, self._indent_level)
142146

143-
# Start a new session for the first note
144-
if not self._session_started:
145-
success = self._start_session(text)
146-
else:
147-
# Send as a reply to the thread with proper indentation
148-
success = self._send_note_to_thread(text, self._indent_level)
147+
if not success:
148+
logger.error("Failed to upload note to Slack")
149+
return False
149150

150-
if not success:
151-
logger.error("Failed to upload note to Slack")
152-
return False
151+
elif note_event.action == events.END_SESSION:
152+
self.end_session()
153153

154-
elif note_event.action == events.END_SESSION:
155-
self.end_session()
156-
157-
return True
158-
except Exception as e:
159-
logger.exception(f"Error uploading notes to Slack: {e}")
160-
return False
154+
return True
161155

162156
def end_session(self) -> None:
163157
"""End the current session."""
@@ -173,4 +167,4 @@ def handle_inactivity(self) -> None:
173167
def handle_disconnect(self) -> None:
174168
"""Handle disconnection by ending the session and clearing client."""
175169
self._client = None
176-
self.end_session()
170+
self.end_session()

0 commit comments

Comments
 (0)