${targetUserid}'s last ${Chat.count(count, "teams")}
`;
+ buf += refresh(this);
+ buf += `
Search 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) {
+ 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 = false 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 != true 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) {
+ TeamsHandler.validateAccess(connection);
+ const teamid = toID(query.shift() || "");
+ this.title = `[View Team]`;
+ if (!teamid.length) {
+ 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.`);
+ }
+ this.title = `[Team] ${team.teamid}`;
+ if (user.id !== team.ownerid) {
+ void TeamsHandler.updateViews(team.teamid);
+ }
+ return `
` + TeamsHandler.renderTeam(team, user) + "
";
+ },
+ upload(query, user, connection) {
+ 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) {
+ 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) {
+ 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.length || (isPersonal && query.length === 1)) {
+ buf += `
`;
+ buf += `