Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
f72f14d
feat(huddle): Pulse beside the composer's +, and the video posts itself
morepriyam Oct 6, 2026
4c12299
Merge feat/pulse-button into feat/pulse-huddle, with the Huddle revie…
morepriyam Oct 6, 2026
c081c2b
Merge feat/pulse-button into feat/pulse-huddle, with the Huddle revie…
morepriyam Oct 6, 2026
d11a968
Merge main (#658 merged) into feat/pulse-huddle
morepriyam Oct 7, 2026
3cba05e
feat(pulse): the composer's Pulse video attaches to the post you are …
morepriyam Oct 7, 2026
06ef258
feat(pulse): the composers take the one Pulse button, and the video a…
morepriyam Oct 7, 2026
3591502
feat(pulse): the composer's words for the Pulse hint and landed line …
morepriyam Oct 7, 2026
83e6d61
fix(pulse): a composer holds its post while a Pulse video is on its w…
morepriyam Oct 7, 2026
da8afb6
fix(pulse): the chip says nothing beside itself when the video has la…
morepriyam Oct 7, 2026
f9d8c3f
fix(pulse): a composer holds its post from the reserve request until …
morepriyam Oct 7, 2026
3ee7944
feat(huddle): Pulse beside the message box posts the video itself whe…
morepriyam Oct 7, 2026
2a53a12
feat(huddle): Pulse sits after the composer's +, behind a /
morepriyam Oct 7, 2026
c71f1ea
feat(clock): Clock in and out with Pulse — the video is the plan or t…
morepriyam Oct 7, 2026
afb199a
fix(clock): a clock delivery that stopped halfway finishes on replay,…
morepriyam Oct 7, 2026
ef06fad
fix(clock): a Pulse clock change touches only the session it was for
morepriyam Oct 7, 2026
721d84e
fix(clock): a landed Pulse clears only the draft it was recorded over…
morepriyam Oct 7, 2026
798ea69
fix(clock): a Pulse plan joins or opens a shift in one upsert, and a …
morepriyam Oct 7, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
439 changes: 243 additions & 196 deletions meteor-backend/server/clock.js

Large diffs are not rendered by default.

230 changes: 145 additions & 85 deletions meteor-backend/server/huddle.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function toId(id) {
}

// postDate is a plain calendar date string (client-local), e.g. "2026-07-22"
const POST_DATE_RE = /^\d{4}-\d{2}-\d{2}$/;
export const POST_DATE_RE = /^\d{4}-\d{2}-\d{2}$/;

// Drafts (status: 'draft') can no longer be created, but rows saved before
// they were removed still exist — keep them out of every feed. Absent status =
Expand Down Expand Up @@ -368,6 +368,149 @@ Meteor.publish('huddlePosts.byTeam', async function (teamId, since) {
});

// Methods
/** The team, if `userId` is on it as a member or an admin; throws otherwise. */
export async function requireTeamMember(userId, teamId) {
if (!teamId || typeof teamId !== 'string') {
throw new Meteor.Error('bad-request', 'teamId is required');
}
const team = await getTeam(teamId);
if (!team) {
throw new Meteor.Error('not-found', 'Team not found');
}
const isMember = (team.members ?? []).includes(userId) || (team.admins ?? []).includes(userId);
if (!isMember) {
throw new Meteor.Error('forbidden', 'Not a team member');
}
return team;
}

/**
* Create a published Huddle post as `userId`, after the same checks the
* `huddle.createPost` method makes (team membership, ticket, mentions, clock
* session ownership). Shared with server-side callers — a Pulse upload that
* posts itself. Returns `{ id }`.
*/
export async function createHuddlePost(
userId,
{ teamId, content, ticketId, attachments, postDate, clockEventId, wrapUp },
) {
if (!content || typeof content.text !== 'string') {
throw new Meteor.Error('bad-request', 'content.text is required');
}
if (postDate !== undefined && (typeof postDate !== 'string' || !POST_DATE_RE.test(postDate))) {
throw new Meteor.Error('bad-request', 'postDate must be a YYYY-MM-DD string');
}
await requireTeamMember(userId, teamId);

// Validate ticketId if provided
if (ticketId) {
const ticket = await rawDb().collection('tickets').findOne({ _id: toId(ticketId) });
if (!ticket) {
throw new Meteor.Error('not-found', 'Ticket not found');
}
if (ticket.teamId !== teamId) {
throw new Meteor.Error('bad-request', 'Ticket does not belong to this team');
}
}

// Validate mentions if provided
if (content.mentions && Array.isArray(content.mentions)) {
for (const mentionedUserId of content.mentions) {
const user = await rawDb().collection('users').findOne({ _id: String(mentionedUserId) });
if (!user) {
throw new Meteor.Error('not-found', `User ${mentionedUserId} not found`);
}
}
}

// Validate clockEventId if provided — must be the caller's own session in
// this team, so a spoofed id can't later surface someone else's clock-in/
// out times through the feed (enrichPost scopes its lookup the same way).
if (clockEventId) {
if (typeof clockEventId !== 'string' || !isValidId(clockEventId)) {
throw new Meteor.Error('bad-request', 'Invalid clockEventId');
}
const event = await rawDb()
.collection('clockevents')
.findOne(
{ _id: toId(clockEventId), userId, teamId },
{ projection: { _id: 1 } },
);
if (!event) {
throw new Meteor.Error('forbidden', 'Clock event does not belong to you in this team');
}
}

const doc = {
_id: new ObjectId(),
teamId,
userId,
content: {
text: content.text,
mentions: content.mentions ?? [],
},
ticketId: ticketId ?? undefined,
attachments: attachments ?? [],
likes: [],
commentCount: 0,
...(postDate ? { postDate } : {}),
// Optionally link to a clock session (per-session gate) and/or stamp a
// wrap-up at creation — used by the clock-out recovery path when a
// session somehow has no plan post.
...(clockEventId ? { clockEventId } : {}),
...(wrapUp === true ? { wrapUpAt: new Date() } : {}),
createdAt: new Date(),
updatedAt: new Date(),
};

await rawDb().collection('huddlePosts').insertOne(doc);

return { id: doc._id.toHexString() };
}

/**
* Add a wrap-up to `userId`'s post for a clock session: `line` goes under the
* plan text and `attachment` joins its attachments. A session with no post
* yet gets one, stamped as the wrap-up. Shared with server-side callers — a
* Pulse wrap-up video that lands on its own.
*/
export async function appendWrapUp(userId, { teamId, clockEventId, postDate, line, attachment }) {
await requireTeamMember(userId, teamId);
const posts = rawDb().collection('huddlePosts');
// Legacy posts carry the team id as an ObjectId; the feed matches both forms, so this does too.
const sessionPost = await posts.findOne(
{ teamId: { $in: [teamId, toId(teamId)] }, userId, clockEventId, ...PUBLISHED },
{ sort: SESSION_POST_SORT },
);
Comment thread
Copilot marked this conversation as resolved.
Resolved
if (!sessionPost) {
await createHuddlePost(userId, {
teamId,
content: { text: line, mentions: [] },
attachments: [attachment],
postDate,
clockEventId,
wrapUp: true,
});
return;
}
// Appended to the post as stored at write time (an update pipeline), so an
// edit to the plan made meanwhile isn't overwritten. `$literal`: text
// starting with `$` would otherwise read as a field path.
const text = { $ifNull: ['$content.text', ''] };
await posts.updateOne({ _id: sessionPost._id }, [
{
$set: {
'content.text': {
$cond: [{ $eq: [text, ''] }, { $literal: line }, { $concat: [text, '\n\n', { $literal: line }] }],
},
attachments: { $concatArrays: [{ $ifNull: ['$attachments', []] }, [{ $literal: attachment }]] },
wrapUpAt: '$$NOW',
updatedAt: '$$NOW',
},
},
]);
}

Meteor.methods({
async 'huddle.getPosts'({ teamId, since }) {
// requireIdentity, not this.userId: this is the REST feed refresh the
Expand Down Expand Up @@ -453,90 +596,7 @@ Meteor.methods({
if (draft === true) {
throw new Meteor.Error('bad-request', 'Drafts are no longer supported; update the app to post');
}
if (!teamId || typeof teamId !== 'string') {
throw new Meteor.Error('bad-request', 'teamId is required');
}
if (!content || typeof content.text !== 'string') {
throw new Meteor.Error('bad-request', 'content.text is required');
}
if (postDate !== undefined && (typeof postDate !== 'string' || !POST_DATE_RE.test(postDate))) {
throw new Meteor.Error('bad-request', 'postDate must be a YYYY-MM-DD string');
}

const team = await getTeam(teamId);
if (!team) {
throw new Meteor.Error('not-found', 'Team not found');
}

const isMember = (team.members ?? []).includes(identity.userId) || (team.admins ?? []).includes(identity.userId);
if (!isMember) {
throw new Meteor.Error('forbidden', 'Not a team member');
}

// Validate ticketId if provided
if (ticketId) {
const ticket = await rawDb().collection('tickets').findOne({ _id: toId(ticketId) });
if (!ticket) {
throw new Meteor.Error('not-found', 'Ticket not found');
}
if (ticket.teamId !== teamId) {
throw new Meteor.Error('bad-request', 'Ticket does not belong to this team');
}
}

// Validate mentions if provided
if (content.mentions && Array.isArray(content.mentions)) {
for (const mentionedUserId of content.mentions) {
const user = await rawDb().collection('users').findOne({ _id: String(mentionedUserId) });
if (!user) {
throw new Meteor.Error('not-found', `User ${mentionedUserId} not found`);
}
}
}

// Validate clockEventId if provided — must be the caller's own session in
// this team, so a spoofed id can't later surface someone else's clock-in/
// out times through the feed (enrichPost scopes its lookup the same way).
if (clockEventId) {
if (typeof clockEventId !== 'string' || !isValidId(clockEventId)) {
throw new Meteor.Error('bad-request', 'Invalid clockEventId');
}
const event = await rawDb()
.collection('clockevents')
.findOne(
{ _id: toId(clockEventId), userId: identity.userId, teamId },
{ projection: { _id: 1 } },
);
if (!event) {
throw new Meteor.Error('forbidden', 'Clock event does not belong to you in this team');
}
}

const doc = {
_id: new ObjectId(),
teamId,
userId: identity.userId,
content: {
text: content.text,
mentions: content.mentions ?? [],
},
ticketId: ticketId ?? undefined,
attachments: attachments ?? [],
likes: [],
commentCount: 0,
...(postDate ? { postDate } : {}),
// Optionally link to a clock session (per-session gate) and/or stamp a
// wrap-up at creation — used by the clock-out recovery path when a
// session somehow has no plan post.
...(clockEventId ? { clockEventId } : {}),
...(wrapUp === true ? { wrapUpAt: new Date() } : {}),
createdAt: new Date(),
updatedAt: new Date(),
};

await rawDb().collection('huddlePosts').insertOne(doc);

return { id: doc._id.toHexString() };
return createHuddlePost(identity.userId, { teamId, content, ticketId, attachments, postDate, clockEventId, wrapUp });
},

async 'huddle.updatePost'({ postId, content, wrapUp, attachments, ticketId }) {
Expand Down
8 changes: 7 additions & 1 deletion meteor-backend/server/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -2200,7 +2200,13 @@ Meteor.startup(async() => {
description: 'Where the finished video lands (see pulse-destinations.js)',
properties: {
kind: { type: 'string', enum: PULSE_DESTINATION_KINDS },
id: { type: 'string', description: 'The ticket or Redmine issue id, for those kinds' },
id: { type: 'string', description: 'The ticket, Redmine issue or clock session id, for those kinds' },
teamId: { type: 'string', description: 'The team to post to, for huddle and clock-plan' },
clockEventId: { type: 'string', description: 'The session to wrap up, for clock-wrapup' },
postDate: {
type: 'string',
description: "The poster's calendar date (YYYY-MM-DD), for clock-plan and clock-wrapup",
},
},
required: ['kind'],
},
Expand Down
Loading
Loading