Skip to content

Commit

Permalink
Add Github connection, UX improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
StamTsag committed Apr 20, 2024
1 parent c6d4280 commit 710a7f5
Show file tree
Hide file tree
Showing 18 changed files with 1,197 additions and 1,518 deletions.
2,437 changes: 924 additions & 1,513 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@
"cross-env": "^7.0.3",
"date-fns": "^2.30.0",
"dotenv": "^10.0.0",
"firebase-admin": "^11.10.1",
"firebase-admin": "^12.1.0",
"gmail-send": "^1.8.14",
"gradient-string": "^1.2.0",
"imagekit": "^4.1.3",
"imagekit": "^5.0.1",
"node-fetch": "^2.6.12",
"npm-run-all": "^4.1.5",
"ora": "^5.4.1",
Expand Down
7 changes: 7 additions & 0 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ model Account {
spotifyRefreshToken String? @default("")
spotifyAccessToken String? @default("")
spotifyTokenType String? @default("")
hasGithub Boolean? @default(false)
githubName String? @default("")
githubURL String? @default("")
}

model Post {
Expand Down Expand Up @@ -96,6 +99,8 @@ model Message {
replyId String @default("")
isImage Boolean @default(false)
attachment String?
width Int? @default(0)
height Int? @default(0)
isSpotify Boolean? @default(false)
spotifyEmbed String? @default("")
isTenor Boolean @default(false)
Expand All @@ -115,6 +120,8 @@ model ChannelMessage {
replyId String @default("")
isImage Boolean @default(false)
attachment String?
width Int? @default(0)
height Int? @default(0)
isSpotify Boolean? @default(false)
spotifyEmbed String? @default("")
isTenor Boolean @default(false)
Expand Down
4 changes: 4 additions & 0 deletions src/events/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ import banMember from 'events/account/banMember';
import unbanMember from 'events/account/unbanMember';
import updateConnectionSpotify from 'events/account/updateConnectionSpotify';
import removeConnectionSpotify from 'events/account/removeConnectionSpotify';
import removeConnectionGithub from 'events/account/removeConnectionGithub';
import updateConnectionGithub from 'events/account/updateConnectionGithub';

import { EventExportTemplate } from 'interfaces/all';

Expand Down Expand Up @@ -110,6 +112,8 @@ const accountTemplate: EventExportTemplate = {
unbanMember,
updateConnectionSpotify,
removeConnectionSpotify,
removeConnectionGithub,
updateConnectionGithub,
};

export default accountTemplate;
2 changes: 2 additions & 0 deletions src/events/account/fetchChannelMessages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ async function fetchChannelMessages({
replyId: true,
isImage: true,
attachment: true,
width: true,
height: true,
isSpotify: true,
spotifyEmbed: true,
isTenor: true,
Expand Down
3 changes: 3 additions & 0 deletions src/events/account/fetchConvos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ async function fetchConvos({
spotifyName:
targetDMUserData.spotifyName,
spotifyURL: targetDMUserData.spotifyURL,
hasGithub: targetDMUserData.hasGithub,
githubName: targetDMUserData.githubName,
githubURL: targetDMUserData.githubURL,
},
dmHiddenFor: convo.dmHiddenFor,
totalMessages,
Expand Down
2 changes: 2 additions & 0 deletions src/events/account/fetchMessages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ async function fetchMessages({
replyId: true,
isImage: true,
attachment: true,
width: true,
height: true,
isSpotify: true,
spotifyEmbed: true,
isTenor: true,
Expand Down
3 changes: 3 additions & 0 deletions src/events/account/fetchProfileData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ async function fetchProfileData({
hasSpotify: targetAccount.hasSpotify,
spotifyName: targetAccount.spotifyName,
spotifyURL: targetAccount.spotifyURL,
hasGithub: targetAccount.hasGithub,
githubName: targetAccount.githubName,
githubURL: targetAccount.githubURL,
};

// More data if our profile
Expand Down
57 changes: 57 additions & 0 deletions src/events/account/removeConnectionGithub.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// ******************** //
// The removeConnectionGithub account event file.
// ******************** //

import {
RemoveConnectionGithubResult,
RemoveConnectionGithubServerParams,
} from 'interfaces/account/removeConnectionGithub';
import { EventTemplate, FronvoError } from 'interfaces/all';
import { prismaClient } from 'variables/global';

async function removeConnectionGithub({
io,
socket,
account,
}: RemoveConnectionGithubServerParams): Promise<
RemoveConnectionGithubResult | FronvoError
> {
if (!account.hasSpotify) {
return;
}

try {
await prismaClient.account.update({
where: {
profileId: account.profileId,
},

data: {
hasGithub: false,
githubName: '',
githubURL: '',
},
});

io.to(account.profileId)
.to(socket.id)
.emit('connectionsUpdated', {
profileId: account.profileId,

github: {
hasGithub: false,
githubName: '',
githubURL: '',
},
});
} catch (e) {}

return {};
}

const removeConnectionGithubTemplate: EventTemplate = {
func: removeConnectionGithub,
template: [],
};

export default removeConnectionGithubTemplate;
18 changes: 17 additions & 1 deletion src/events/account/sendChannelImage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ async function sendChannelImage({
serverId,
channelId,
attachment,
width,
height,
}: SendChannelImageServerParams): Promise<
SendChannelImageResult | FronvoError
> {
Expand Down Expand Up @@ -57,6 +59,8 @@ async function sendChannelImage({
messageId: v4(),
isImage: true,
attachment,
width: Number(width),
height: Number(height),
},

select: {
Expand All @@ -69,6 +73,8 @@ async function sendChannelImage({
replyId: true,
isImage: true,
attachment: true,
width: true,
height: true,
},
});
} catch (e) {
Expand Down Expand Up @@ -100,7 +106,7 @@ async function sendChannelImage({

const sendChannelImageTemplate: EventTemplate = {
func: sendChannelImage,
template: ['serverId', 'channelId', 'attachment'],
template: ['serverId', 'channelId', 'attachment', 'width', 'height'],
schema: new StringSchema({
...serverIdSchema,
...channelIdSchema,
Expand All @@ -109,6 +115,16 @@ const sendChannelImageTemplate: EventTemplate = {
// Ensure https
regex: /https:\/\/ik.imagekit.io\/fronvo(2)?\/[0-9A-Za-z]{8}-[0-9A-Za-z]{4}-4[0-9A-Za-z]{3}-[89ABab][0-9A-Za-z]{3}-[0-9A-Za-z]{12}.+/,
},

width: {
minLength: 2,
maxLength: 4,
},

height: {
minLength: 2,
maxLength: 4,
},
}),
};

Expand Down
18 changes: 17 additions & 1 deletion src/events/account/sendImage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ async function sendImage({
account,
roomId,
attachment,
width,
height,
}: SendImageServerParams): Promise<SendImageResult | FronvoError> {
const room = await prismaClient.dm.findFirst({
where: {
Expand All @@ -49,6 +51,8 @@ async function sendImage({
messageId: v4(),
isImage: true,
attachment,
width: Number(width),
height: Number(height),
},

select: {
Expand All @@ -61,6 +65,8 @@ async function sendImage({
replyId: true,
isImage: true,
attachment: true,
width: true,
height: true,
},
});
} catch (e) {
Expand Down Expand Up @@ -105,7 +111,7 @@ async function sendImage({

const sendImageTemplate: EventTemplate = {
func: sendImage,
template: ['roomId', 'attachment'],
template: ['roomId', 'attachment', 'width', 'height'],
schema: new StringSchema({
roomId: {
type: 'uuid',
Expand All @@ -115,6 +121,16 @@ const sendImageTemplate: EventTemplate = {
// Ensure https
regex: /https:\/\/ik.imagekit.io\/fronvo(2)?\/[0-9A-Za-z]{8}-[0-9A-Za-z]{4}-4[0-9A-Za-z]{3}-[89ABab][0-9A-Za-z]{3}-[0-9A-Za-z]{12}.+/,
},

width: {
minLength: 2,
maxLength: 4,
},

height: {
minLength: 2,
maxLength: 4,
},
}),
};

Expand Down
94 changes: 94 additions & 0 deletions src/events/account/updateConnectionGithub.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
// ******************** //
// The updateConnectionGithub account event file.
// ******************** //

import { StringSchema } from '@ezier/validate';
import {
UpdateConnectionGithubResult,
UpdateConnectionGithubServerParams,
} from 'interfaces/account/updateConnectionGithub';
import { EventTemplate, FronvoError } from 'interfaces/all';
import { generateError, getLoggedInSockets } from 'utilities/global';
import { prismaClient } from 'variables/global';
import { getEnv } from 'variables/varUtils';

async function updateConnectionGithub({
io,
socket,
account,
name,
url,
secret,
}: UpdateConnectionGithubServerParams): Promise<
UpdateConnectionGithubResult | FronvoError
> {
if (secret != getEnv('GENERAL_SECRET')) {
return generateError('UNKNOWN');
}

try {
await prismaClient.account.update({
where: {
profileId: account.profileId,
},

data: {
hasGithub: true,
githubName: name,
githubURL: url,
},
});

io.to(account.profileId)
.to(socket.id)
.emit('connectionsUpdated', {
profileId: account.profileId,

github: {
hasGithub: true,
githubName: name,
githubURL: url,
},
});

// To all sockets in this account
const targetSockets = getLoggedInSockets();

for (const socketIndex in targetSockets) {
const socketObj = targetSockets[socketIndex];

if (
socketObj.accountId == account.profileId &&
socketObj.socket.id != socket.id
) {
io.to(socketObj.socket.id).emit('connectionsUpdated', {
profileId: account.profileId,

github: {
hasGithub: true,
githubName: name,
githubURL: url,
},
});
}
}
} catch (e) {}

return {};
}

const updateConnectionGithubTemplate: EventTemplate = {
func: updateConnectionGithub,
template: ['name', 'url', 'secret'],
schema: new StringSchema({
name: {},

url: {},

secret: {
minLength: 36,
},
}),
};

export default updateConnectionGithubTemplate;
8 changes: 7 additions & 1 deletion src/interfaces/account/connectionsUpdated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,15 @@
export interface ConnectionsUpdatedParams {
profileId: string;

spotify: {
spotify?: {
hasSpotify: boolean;
spotifyName: string;
spotifyURL: string;
};

github?: {
hasGithub: boolean;
githubName: string;
githubURL: string;
};
}
17 changes: 17 additions & 0 deletions src/interfaces/account/removeConnectionGithub.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// ******************** //
// Interfaces for the removeConnectionGithub event file.
// ******************** //

import { FronvoError, EventArguments } from 'interfaces/all';

export interface RemoveConnectionGithubParams {}

export interface RemoveConnectionGithubServerParams
extends EventArguments,
RemoveConnectionGithubParams {}

export interface RemoveConnectionGithubResult {}

export interface RemoveConnectionGithubTestResult
extends FronvoError,
RemoveConnectionGithubResult {}
2 changes: 2 additions & 0 deletions src/interfaces/account/sendChannelImage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ export interface SendChannelImageParams {
serverId: string;
channelId: string;
attachment: string;
width: number;
height: number;
}

export interface SendChannelImageServerParams
Expand Down
Loading

0 comments on commit 710a7f5

Please sign in to comment.