Skip to content

Commit

Permalink
work on reactions
Browse files Browse the repository at this point in the history
  • Loading branch information
targoninc-alex committed Jun 3, 2024
1 parent 2373ac7 commit 6c050b9
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 67 deletions.
132 changes: 66 additions & 66 deletions src/enums/defaultReactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -521,72 +521,72 @@ export const defaultReactions = [
{content: "🐌", groupId: 12, identifier: "snail"},
{content: "🐍", groupId: 12, identifier: "snake"},
{content: "🐎", groupId: 12, identifier: "horse"},
{content: "🐏", groupId: 12, identifier: "emoji"},
{content: "🐐", groupId: 12, identifier: "emoji"},
{content: "🐑", groupId: 12, identifier: "emoji"},
{content: "🐒", groupId: 12, identifier: "emoji"},
{content: "🐓", groupId: 12, identifier: "emoji"},
{content: "🐔", groupId: 12, identifier: "emoji"},
{content: "🐕", groupId: 12, identifier: "emoji"},
{content: "🐖", groupId: 12, identifier: "emoji"},
{content: "🐗", groupId: 12, identifier: "emoji"},
{content: "🐘", groupId: 12, identifier: "emoji"},
{content: "🐙", groupId: 12, identifier: "emoji"},
{content: "🐚", groupId: 12, identifier: "emoji"},
{content: "🐛", groupId: 12, identifier: "emoji"},
{content: "🐜", groupId: 12, identifier: "emoji"},
{content: "🐝", groupId: 12, identifier: "emoji"},
{content: "🐞", groupId: 12, identifier: "emoji"},
{content: "🐟", groupId: 12, identifier: "emoji"},
{content: "🐠", groupId: 12, identifier: "emoji"},
{content: "🐡", groupId: 12, identifier: "emoji"},
{content: "🐢", groupId: 12, identifier: "emoji"},
{content: "🐣", groupId: 12, identifier: "emoji"},
{content: "🐤", groupId: 12, identifier: "emoji"},
{content: "🐥", groupId: 12, identifier: "emoji"},
{content: "🐦", groupId: 12, identifier: "emoji"},
{content: "🐧", groupId: 12, identifier: "emoji"},
{content: "🐨", groupId: 12, identifier: "emoji"},
{content: "🐩", groupId: 12, identifier: "emoji"},
{content: "🐪", groupId: 12, identifier: "emoji"},
{content: "🐫", groupId: 12, identifier: "emoji"},
{content: "🐬", groupId: 12, identifier: "emoji"},
{content: "🐭", groupId: 12, identifier: "emoji"},
{content: "🐮", groupId: 12, identifier: "emoji"},
{content: "🐯", groupId: 12, identifier: "emoji"},
{content: "🐰", groupId: 12, identifier: "emoji"},
{content: "🐱", groupId: 12, identifier: "emoji"},
{content: "🐲", groupId: 12, identifier: "emoji"},
{content: "🐳", groupId: 12, identifier: "emoji"},
{content: "🐴", groupId: 12, identifier: "emoji"},
{content: "🐵", groupId: 12, identifier: "emoji"},
{content: "🐶", groupId: 12, identifier: "emoji"},
{content: "🐷", groupId: 12, identifier: "emoji"},
{content: "🐸", groupId: 12, identifier: "emoji"},
{content: "🐹", groupId: 12, identifier: "emoji"},
{content: "🐺", groupId: 12, identifier: "emoji"},
{content: "🐻", groupId: 12, identifier: "emoji"},
{content: "🐼", groupId: 12, identifier: "emoji"},
{content: "🐽", groupId: 12, identifier: "emoji"},
{content: "🐾", groupId: 0, identifier: "emoji"},
{content: "🐿️", groupId: 0, identifier: "emoji"},
{content: "👀", groupId: 0, identifier: "emoji"},
{content: "👁️", groupId: 0, identifier: "emoji"},
{content: "👂", groupId: 0, identifier: "emoji"},
{content: "👃", groupId: 0, identifier: "emoji"},
{content: "👄", groupId: 0, identifier: "emoji"},
{content: "👅", groupId: 0, identifier: "emoji"},
{content: "👆", groupId: 0, identifier: "emoji"},
{content: "👇", groupId: 0, identifier: "emoji"},
{content: "👈", groupId: 0, identifier: "emoji"},
{content: "👉", groupId: 0, identifier: "emoji"},
{content: "👊", groupId: 0, identifier: "emoji"},
{content: "👋", groupId: 0, identifier: "emoji"},
{content: "👌", groupId: 0, identifier: "emoji"},
{content: "👍", groupId: 0, identifier: "emoji"},
{content: "👎", groupId: 0, identifier: "emoji"},
{content: "👏", groupId: 0, identifier: "emoji"},
{content: "👐", groupId: 0, identifier: "emoji"},
{content: "🐏", groupId: 12, identifier: "ram"},
{content: "🐐", groupId: 12, identifier: "goat"},
{content: "🐑", groupId: 12, identifier: "sheep"},
{content: "🐒", groupId: 12, identifier: "monkey"},
{content: "🐓", groupId: 12, identifier: "rooster"},
{content: "🐔", groupId: 12, identifier: "chicken"},
{content: "🐕", groupId: 12, identifier: "dog"},
{content: "🐖", groupId: 12, identifier: "pig"},
{content: "🐗", groupId: 12, identifier: "boar"},
{content: "🐘", groupId: 12, identifier: "elephant"},
{content: "🐙", groupId: 12, identifier: "octopus"},
{content: "🐚", groupId: 4, identifier: "shell"},
{content: "🐛", groupId: 12, identifier: "bug"},
{content: "🐜", groupId: 12, identifier: "ant"},
{content: "🐝", groupId: 12, identifier: "bee"},
{content: "🐞", groupId: 12, identifier: "ladybug"},
{content: "🐟", groupId: 12, identifier: "fish"},
{content: "🐠", groupId: 12, identifier: "fish_tropical"},
{content: "🐡", groupId: 12, identifier: "fish_blowfish"},
{content: "🐢", groupId: 12, identifier: "turtle"},
{content: "🐣", groupId: 12, identifier: "hatching_chick"},
{content: "🐤", groupId: 12, identifier: "baby_chick"},
{content: "🐥", groupId: 12, identifier: "chick"},
{content: "🐦", groupId: 12, identifier: "bird"},
{content: "🐧", groupId: 12, identifier: "penguin"},
{content: "🐨", groupId: 12, identifier: "koala"},
{content: "🐩", groupId: 12, identifier: "poodle"},
{content: "🐪", groupId: 12, identifier: "dromedary_camel"},
{content: "🐫", groupId: 12, identifier: "camel"},
{content: "🐬", groupId: 12, identifier: "dolphin"},
{content: "🐭", groupId: 12, identifier: "mouse"},
{content: "🐮", groupId: 12, identifier: "cow"},
{content: "🐯", groupId: 12, identifier: "tiger"},
{content: "🐰", groupId: 12, identifier: "rabbit"},
{content: "🐱", groupId: 12, identifier: "cat"},
{content: "🐲", groupId: 12, identifier: "dragon"},
{content: "🐳", groupId: 12, identifier: "whale"},
{content: "🐴", groupId: 12, identifier: "horse"},
{content: "🐵", groupId: 12, identifier: "monkey_face"},
{content: "🐶", groupId: 12, identifier: "dog_face"},
{content: "🐷", groupId: 12, identifier: "pig_face"},
{content: "🐸", groupId: 12, identifier: "frog_face"},
{content: "🐹", groupId: 12, identifier: "hamster_face"},
{content: "🐺", groupId: 12, identifier: "wolf_face"},
{content: "🐻", groupId: 12, identifier: "bear_face"},
{content: "🐼", groupId: 12, identifier: "panda_face"},
{content: "🐽", groupId: 12, identifier: "pig_nose"},
{content: "🐾", groupId: 12, identifier: "paw_prints"},
{content: "🐿️", groupId: 12, identifier: "chipmunk"},
{content: "👀", groupId: 1, identifier: "eyes"},
{content: "👁️", groupId: 1, identifier: "eye"},
{content: "👂", groupId: 1, identifier: "ear"},
{content: "👃", groupId: 1, identifier: "nose"},
{content: "👄", groupId: 1, identifier: "mouth"},
{content: "👅", groupId: 1, identifier: "tongue"},
{content: "👆", groupId: 1, identifier: "point_up"},
{content: "👇", groupId: 1, identifier: "point_down"},
{content: "👈", groupId: 1, identifier: "point_left"},
{content: "👉", groupId: 1, identifier: "point_right"},
{content: "👊", groupId: 1, identifier: "fist"},
{content: "👋", groupId: 1, identifier: "wave"},
{content: "👌", groupId: 1, identifier: "ok_hand"},
{content: "👍", groupId: 1, identifier: "emoji"},
{content: "👎", groupId: 1, identifier: "emoji"},
{content: "👏", groupId: 1, identifier: "emoji"},
{content: "👐", groupId: 1, identifier: "emoji"},
{content: "👑", groupId: 0, identifier: "emoji"},
{content: "👒", groupId: 0, identifier: "emoji"},
{content: "👓", groupId: 0, identifier: "emoji"},
Expand Down
4 changes: 4 additions & 0 deletions src/features/database/mariaDbDatabase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -313,4 +313,8 @@ WHERE ur.userId = ?`, [userId]);
async addReaction(userId: Id, messageId: Id, reactionId: Id) {
await this.query("INSERT INTO venel.messageReactions (userId, messageId, reactionId) VALUES (?, ?, ?)", [userId, messageId, reactionId]);
}

async removeReaction(userId: Id, messageId: Id, reactionId: Id) {
await this.query("DELETE FROM venel.messageReactions WHERE userId = ? AND messageId = ? AND reactionId = ?", [userId, messageId, reactionId]);
}
}
49 changes: 49 additions & 0 deletions src/features/liveFeature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ export class LiveFeature {
case "addReaction":
await LiveFeature.addReaction(data, ws.user, clients, ws, db);
break;
case "removeReaction":
await LiveFeature.removeReaction(data, ws.user, clients, ws, db);
break;
case "updateAvatar":
await LiveFeature.updateAvatar(userMap, data, ws.user, clients, ws, db);
break;
Expand Down Expand Up @@ -213,6 +216,52 @@ export class LiveFeature {
}
}

static async removeReaction(data: any, user: User, clients: Set<UserWebSocket>, client: UserWebSocket, db: MariaDbDatabase) {
const messageId = data.messageId;
if (!messageId) {
client.send(JSON.stringify({error: "Message ID is required"}));
return;
}

const message = await db.getMessageById(messageId);
if (!message) {
client.send(JSON.stringify({error: "Message not found"}));
return;
}

const invalid = await MessagingEndpoints.checkChannelAccess(db, user, message.channelId);
if (invalid !== null) {
client.send(JSON.stringify({error: invalid}));
return;
}

const reactionId = data.reactionId;
if (!reactionId) {
client.send(JSON.stringify({error: "Reaction is required"}));
return;
}

await db.removeReaction(user.id, messageId, reactionId);
const payload = JSON.stringify({
type: "removeReaction",
messageId,
reactionId,
userId: user.id
});
CLI.debug(`Propagating reaction removal from ${user.id} to ${clients.size} clients.`);
for (const ws of clients) {
if (ws.readyState !== ws.OPEN) {
continue;
}

const invalid = await MessagingEndpoints.checkChannelAccess(db, ws.user, message.channelId);
if (invalid !== null) {
continue;
}
ws.send(payload);
}
}

private static async updateAvatar(userMap: Map<string, User>, data: any, user: User, clients: Set<UserWebSocket>, client: UserWebSocket, db: MariaDbDatabase) {
let avatar = data.avatar;

Expand Down
2 changes: 1 addition & 1 deletion updateDb.sql
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ create table if not exists venel.messageReactions
messageId bigint not null,
reactionId bigint not null,
userId bigint not null,
primary key (messageId, reactionId),
primary key (messageId, reactionId, userId),
constraint messageReactions_ibfk_1
foreign key (messageId) references venel.messages (id)
on delete cascade,
Expand Down

0 comments on commit 6c050b9

Please sign in to comment.