${targetUserid}'s last ${Chat.count(count, "teams")}
`;
buf += refresh(this);
buf += `
Search your teams `;
buf += `
Browse public teams`;
if (targetUserid === user.id) {
buf += `
Upload new`;
}
buf += `
`;
for (const team of teams) {
buf += TeamsHandler.preview(team, user);
buf += `
`;
}
const total = await TeamsHandler.count(user.id);
if (total > count) {
buf += `
`;
}
return buf;
},
async filtered(query, user, connection) {
if (!user.named) return Rooms.RETRY_AFTER_LOGIN;
const type = query.shift() || "";
TeamsHandler.validateAccess(connection);
let count = Number(query.shift()) || 50;
if (count > MAX_TEAMS) count = MAX_TEAMS;
let teams: StoredTeam[] = [], title = '';
const buttons: { [k: string]: string } = {
views: `
`,
latest: `
`,
};
switch (type) {
case 'views':
this.title = `[Most Viewed Teams]`;
teams = await TeamsHandler.query(
`SELECT * FROM teams WHERE private IS NULL ORDER BY views DESC LIMIT $1`, [count]
);
title = `Most viewed teams:`;
delete buttons.views;
break;
default:
this.title = `[Latest Teams]`;
teams = await TeamsHandler.query(
`SELECT * FROM teams WHERE private IS NULL ORDER BY date DESC LIMIT $1`, [count]
);
title = `Recently uploaded teams:`;
delete buttons.latest;
break;
}
let buf = `
${title}
${refresh(this)}`;
buf += Object.values(buttons).join('
');
buf += `
`;
buf += teams.map(team => TeamsHandler.preview(team, user)).join('
');
buf += ``;
return buf;
},
async view(query, user, connection) {
if (!user.named) return Rooms.RETRY_AFTER_LOGIN;
TeamsHandler.validateAccess(connection);
const rawTeamid = toID(query.shift() || "");
const password = toID(query.shift());
this.title = `[View Team]`;
const teamid = Number(rawTeamid);
if (isNaN(teamid)) {
throw new Chat.ErrorMessage(`Invalid team ID.`);
}
const team = await TeamsHandler.get(teamid);
if (!team) {
this.title = `[Invalid Team]`;
return this.errorReply(`No team with the ID ${teamid} was found.`);
}
if (team?.private && user.id !== team.ownerid && password !== team.private) {
this.title = `[Private Team]`;
return this.errorReply(`That team is private.`);
}
this.title = `[Team] ${team.teamid}`;
if (user.id !== team.ownerid && team.views >= 0) {
void TeamsHandler.updateViews(team.teamid);
}
return `
` + TeamsHandler.renderTeam(team, user) + "
";
},
upload(query, user, connection) {
if (!user.named) return Rooms.RETRY_AFTER_LOGIN;
TeamsHandler.validateAccess(connection);
this.title = `[Upload Team]`;
let buf = `
Upload a team
${refresh(this)}
`;
// let [teamName, formatid, rawPrivacy, rawTeam] = Utils.splitFirst(target, ',', 4);
buf += ``;
return buf;
},
async edit(query, user, connection) {
if (!user.named) return Rooms.RETRY_AFTER_LOGIN;
TeamsHandler.validateAccess(connection);
const teamID = toID(query.shift() || "");
if (!teamID.length) {
return this.errorReply(`Invalid team ID.`);
}
this.title = `[Edit Team] ${teamID}`;
const data = await TeamsHandler.get(teamID);
if (!data) {
return this.errorReply(`Team ${teamID} not found.`);
}
let buf = `
Edit team ${teamID}
${refresh(this)}
`;
// let [teamName, formatid, rawPrivacy, rawTeam] = Utils.splitFirst(target, ',', 4);
buf += ``;
return buf;
},
async searchpublic(query, user, connection) {
if (!user.named) return Rooms.RETRY_AFTER_LOGIN;
TeamsHandler.validateAccess(connection, true);
this.title = '[Teams] Search';
let buf = '
';
buf += refresh(this);
buf += '
Search all teams';
const type = this.pageid.split('-')[2];
const isPersonal = type === 'searchpersonal';
query = query.join('-').split('--');
if (!query.map(toID).filter(Boolean).length || (isPersonal && query.length === 1)) {
buf += `
`;
buf += `