Switch from delete+recreate to PUT in-place updates
- Removes flicker caused by delete+recreate pattern
- PUT updates modify post content in-place (smooth)
- Trade-off: Mattermost shows (edited) label, and PUT clears pin status
- Pin+PUT are incompatible in Mattermost API — every PUT clears is_pinned
- Fix pin API calls to use {} body instead of null
- Remove post-replaced event handler (no longer needed)
This commit is contained in:
@@ -240,6 +240,14 @@ async function startDaemon() {
|
||||
const initialText = buildInitialText(agentId, sessionKey);
|
||||
postId = await sharedStatusBox.createPost(channelId, initialText, rootPostId);
|
||||
logger.info({ sessionKey, postId, channelId }, 'Created status box');
|
||||
|
||||
// Auto-pin the status post so it's always visible
|
||||
try {
|
||||
await sharedStatusBox._apiCall('POST', '/api/v4/posts/' + postId + '/pin', {});
|
||||
logger.debug({ sessionKey, postId }, 'Status post pinned');
|
||||
} catch (pinErr) {
|
||||
logger.warn({ sessionKey, err: pinErr }, 'Failed to pin status post');
|
||||
}
|
||||
} catch (err) {
|
||||
logger.error({ sessionKey, err }, 'Failed to create status post');
|
||||
globalMetrics.lastError = err.message;
|
||||
@@ -282,18 +290,6 @@ async function startDaemon() {
|
||||
logger.debug({ sessionKey }, 'Session removed from sessions.json');
|
||||
});
|
||||
|
||||
// ---- Post Replaced (delete+recreate) ----
|
||||
sharedStatusBox.on('post-replaced', (oldPostId, newPostId) => {
|
||||
// Update activeBoxes to point to new post ID
|
||||
for (var entry of activeBoxes.entries()) {
|
||||
if (entry[1].postId === oldPostId) {
|
||||
entry[1].postId = newPostId;
|
||||
logger.debug({ sessionKey: entry[0], oldPostId, newPostId }, 'Post replaced (delete+recreate)');
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// ---- Session Update (from watcher) ----
|
||||
watcher.on('session-update', (sessionKey, state) => {
|
||||
const box = activeBoxes.get(sessionKey);
|
||||
@@ -345,7 +341,7 @@ async function startDaemon() {
|
||||
|
||||
// Unpin the status post when session is done
|
||||
try {
|
||||
await sharedStatusBox._apiCall('POST', `/api/v4/posts/${box.postId}/unpin`, null);
|
||||
await sharedStatusBox._apiCall('POST', `/api/v4/posts/${box.postId}/unpin`, {});
|
||||
logger.debug({ sessionKey, postId: box.postId }, 'Status post unpinned');
|
||||
} catch (unpinErr) {
|
||||
logger.warn({ sessionKey, err: unpinErr }, 'Failed to unpin status post');
|
||||
|
||||
Reference in New Issue
Block a user