mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-11-29 08:13:53 +08:00
unfollow the staff member who closes a ticket
This commit is contained in:
@@ -317,9 +317,18 @@ export async function caseAction(storage,env,b){
|
||||
}
|
||||
const post=await botPost(env,channel,payload);
|
||||
if(nextStatus==='Closed'){
|
||||
let followNotice='';
|
||||
if(action==='status' && /^\d{1,20}$/.test(actor)){
|
||||
try{
|
||||
const membership=await fetch('https://discord.com/api/v10/channels/'+channel+'/thread-members/'+actor,{
|
||||
method:'DELETE',headers:{Authorization:'Bot '+env.DISCORD_BOT_TOKEN},redirect:'manual',signal:AbortSignal.timeout(5000)
|
||||
});
|
||||
if(!membership.ok && membership.status!==404)followNotice=' Discord could not unfollow you.';
|
||||
}catch{followNotice=' Discord could not confirm that you unfollowed.';}
|
||||
}
|
||||
try{await discordTags(env,'/channels/'+channel,{archived:true});}
|
||||
catch{return result('Tagged Closed, but archiving failed. Check Manage Threads, then choose Closed again.');}
|
||||
return result(post.ok?'Closed and archived. The original thread link still works.':'Closed and archived. Discord did not confirm the status card.');
|
||||
return result((post.ok?'Closed and archived. The original thread link still works.':'Closed and archived. Discord did not confirm the status card.')+followNotice);
|
||||
}
|
||||
return result(post.ok?'Updated this report.':'Could not confirm the update message. Refresh the thread.');
|
||||
}
|
||||
|
||||
@@ -86,7 +86,13 @@ test('closing archives after the status card and reopening restores the same thr
|
||||
const store={get:k=>data.get(k),put:(k,v)=>data.set(k,v),transaction:fn=>fn(store)};
|
||||
const thread={id:'4',type:11,parent_id:supportForum,applied_tags:['42','1565236988913913887'],thread_metadata:{archived:false}};
|
||||
const events=[];
|
||||
let unfollowStatus=204;
|
||||
t.mock.method(globalThis,'fetch',async(url,options)=>{
|
||||
if(options.method==='DELETE'){
|
||||
assert.equal(url,'https://discord.com/api/v10/channels/4/thread-members/3');
|
||||
events.push('unfollow closer');
|
||||
return new Response(null,{status:unfollowStatus});
|
||||
}
|
||||
if(options.method==='PATCH'){
|
||||
const patch=JSON.parse(options.body);
|
||||
if(patch.applied_tags)thread.applied_tags=patch.applied_tags;
|
||||
@@ -101,10 +107,18 @@ test('closing archives after the status card and reopening restores the same thr
|
||||
});
|
||||
const act=(action,value,id)=>caseAction(store,env,{channel:'4',user:'1',platform:'ios',actor:'3',action,value,interaction:id});
|
||||
await act('status','Closed','1');
|
||||
assert.deepEqual(events,[{applied_tags:['42','1565237052524466207']},0x3498db,{archived:true}]);
|
||||
assert.deepEqual(events,[{applied_tags:['42','1565237052524466207']},0x3498db,'unfollow closer',{archived:true}]);
|
||||
assert.match((await (await act('working',null,'2')).json()).message,/closed or archived/);
|
||||
await act('status','Open','3');
|
||||
assert.deepEqual(events.slice(3),[{applied_tags:['42','1565236988913913887'],archived:false},0xe74c3c]);
|
||||
assert.deepEqual(events.slice(4),[{applied_tags:['42','1565236988913913887'],archived:false},0xe74c3c]);
|
||||
unfollowStatus=403;
|
||||
assert.match((await (await act('status','Closed','4')).json()).message,/archived.*could not unfollow you/);
|
||||
assert.equal(thread.thread_metadata.archived,true);
|
||||
await act('status','Open','5');
|
||||
events.length=0;
|
||||
await caseAction(store,env,{channel:'4',user:'1',platform:'ios',actor:'1',action:'fulfilled',interaction:'6'});
|
||||
assert.equal(events.includes('unfollow closer'),false);
|
||||
assert.equal(thread.thread_metadata.archived,true);
|
||||
});
|
||||
|
||||
test('the overview is staff-only and reads archived tickets without posting',async t=>{
|
||||
|
||||
Reference in New Issue
Block a user