Skip to content

Commit 9958577

Browse files
committed
Update agent.js
1 parent 8e21b2a commit 9958577

File tree

1 file changed

+15
-17
lines changed

1 file changed

+15
-17
lines changed

agent.js

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -181,15 +181,16 @@ export const agentLogic = async ({messages, conversationId, senderFid, name}) =>
181181
'accepted',
182182
);
183183

184+
const otherFid = parseInt(match.user1_fid) === senderFid
185+
? match.user2_fid
186+
: match.user1_fid;
187+
188+
const currentUser = await findUserByFid(senderFid);
189+
const otherUser = await findUserByFid(otherFid);
190+
184191
// If this is the first acceptance, notify the other user
185192
if (match.status === 'pending') {
186-
const otherFid = parseInt(match.user1_fid) === senderFid
187-
? match.user2_fid
188-
: match.user1_fid;
189-
190-
const currentUser = await findUserByFid(senderFid);
191-
const otherUser = await findUserByFid(otherFid);
192-
193+
193194
await sendToolMessage({fid: senderFid, messages, content: JSON.stringify({
194195
result: 'pending',
195196
content: `Waiting for ${otherUser.name} to accept`
@@ -200,26 +201,23 @@ export const agentLogic = async ({messages, conversationId, senderFid, name}) =>
200201
return;
201202

202203
} else if (match.status === 'accepted') {
203-
// Both users have accepted, create the group
204-
const currentUser = await findUserByFid(match.user1_fid);
205-
const matchedUser = await findUserByFid(match.user2_fid);
206-
204+
// Both users have accepted, create the group
207205
await sendToolMessage({fid: currentUser.fid, messages, content: JSON.stringify({
208206
result: 'accepted',
209-
content: `You and ${matchedUser.name} now both accepted. Agent now will connect both of you.`
207+
content: `You and ${otherUser.name} now both accepted. Agent now will connect both of you.`
210208
})});
211209

212-
const otherMessages = await farcaster.getMessages(`${matchedUser.fid}-${agentFID}`)
213-
await sendToolMessage({fid: matchedUser.fid, messages: otherMessages, content: JSON.stringify({
210+
const otherMessages = await farcaster.getMessages(`${otherUser.fid}-${agentFID}`)
211+
await sendToolMessage({fid: otherUser.fid, messages: otherMessages, content: JSON.stringify({
214212
result: 'accepted',
215213
content: `You and ${currentUser.name} is accepted. Agent now will connect both of you. `
216214
})})
217215

218-
const groupMessage = await prepareMatchSuccessMessage(currentUser, matchedUser);
216+
const groupMessage = await prepareMatchSuccessMessage(currentUser, otherUser);
219217

220218
await farcaster.matchUsers(
221-
`${currentUser.name} <> ${matchedUser.name}`,
222-
[parseInt(currentUser.fid), parseInt(matchedUser.fid)],
219+
`${currentUser.name} <> ${otherUser.name}`,
220+
[parseInt(currentUser.fid), parseInt(otherUser.fid)],
223221
groupMessage
224222
);
225223
}

0 commit comments

Comments
 (0)