Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
SupertigerDev committed Jul 13, 2023
2 parents 22e9be7 + dd27845 commit ef92037
Show file tree
Hide file tree
Showing 17 changed files with 355 additions and 46 deletions.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"@types/markdown-it-emoji": "^2.0.2",
"@types/node": "^18.16.18",
"@types/simple-peer": "^9.11.5",
"@types/voice-activity-detection": "^0.0.2",
"events": "^3.3.0",
"global": "^4.4.0",
"process": "^0.11.10",
Expand Down Expand Up @@ -45,7 +46,8 @@
"solid-js": "^1.7.6",
"solid-sortablejs": "^2.0.9",
"solid-styled-components": "^0.28.5",
"twemoji": "^14.0.2"
"twemoji": "^14.0.2",
"voice-activity-detection": "^0.0.5"
},
"engines": {
"npm": "please-use-pnpm",
Expand Down
32 changes: 32 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/chat-api/EventNames.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ export const ServerEvents = {

USER_PRESENCE_UPDATE: 'user:presence_update',

USER_BLOCKED: 'user:blocked',
USER_UNBLOCKED: 'user:unblocked',

FRIEND_REQUEST_SENT: 'friend:request_sent',
FRIEND_REQUEST_PENDING: 'friend:request_pending',
FRIEND_REQUEST_ACCEPTED: 'friend:request_accepted',
Expand Down
1 change: 1 addition & 0 deletions src/chat-api/RawData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ export enum FriendStatus {
SENT = 0,
PENDING = 1,
FRIENDS = 2,
BLOCKED = 3,
}

export interface RawFriend {
Expand Down
8 changes: 7 additions & 1 deletion src/chat-api/events/messageEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,13 @@ export function onMessageCreated(payload: {socketId: string, message: RawMessage
}

const mentionCount = () => mentions.get(payload.message.channelId)?.count || 0;
const isMentioned = () => payload.message.mentions?.find(u => u.id === accountUser?.id)

const isMentioned = () => {
const mention = payload.message.mentions?.find(u => u.id === accountUser?.id);
if (mention) return true;
const quoteMention = payload.message.quotedMessages?.find(m => m.createdBy?.id === accountUser?.id);
return quoteMention;
}

if (payload.message.createdBy.id !== accountUser?.id) {

Expand Down
20 changes: 19 additions & 1 deletion src/chat-api/events/userEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import useMention from "../store/useMention";
import useStore from "../store/useStore";
import useUsers, { UserStatus } from "../store/useUsers";
import { SelfUser } from "./connectionEventTypes";
import { RawServerSettings } from "../RawData";
import { FriendStatus, RawServerSettings, RawUser } from "../RawData";
import useFriends from "../store/useFriends";
import useAccount from "../store/useAccount";

export function onUserPresenceUpdate(payload: {status?: UserStatus, custom?: string; userId: string}) {
const users = useUsers();
Expand Down Expand Up @@ -36,4 +38,20 @@ export function onUserUpdated(payload: Partial<SelfUser>) {
export function onUserServerSettingsUpdate(payload: {serverId: string, updated: Partial<RawServerSettings>}) {
const {account} = useStore();
account.setServerSettings(payload.serverId, payload.updated)
}


export function onUserBlocked(payload: {user: RawUser}) {
const account = useAccount();
const friends = useFriends();
friends.set({
createdAt: Date.now(),
recipient: payload.user,
userId: account.user()?.id!,
status: FriendStatus.BLOCKED,
})
}
export function onUserUnblocked(payload: {userId: string}) {
const friends = useFriends();
friends.delete(payload.userId);
}
31 changes: 30 additions & 1 deletion src/chat-api/services/UserService.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import env from "../../common/env";
import { RawChannel, RawInboxWithoutChannel, RawPost, RawUser } from "../RawData";
import { RawChannel, RawInboxWithoutChannel, RawMessage, RawPost, RawServer, RawUser } from "../RawData";
import { Presence, UserStatus } from "../store/useUsers";
import { request } from "./Request";
import ServiceEndpoints from "./ServiceEndpoints";
Expand Down Expand Up @@ -65,6 +65,19 @@ export async function getUserDetailsRequest(userId?: string) {
});
}

export interface RawNotification {
message: RawMessage;
server: RawServer
}

export async function getUserNotificationsRequest() {
return request<RawNotification[]>({
url: env.SERVER_URL + "/api" + ServiceEndpoints.user("notifications"),
method: "GET",
useToken: true
});
}

export async function getFollowers(userId?: string) {
return request<RawUser[]>({
url: env.SERVER_URL + "/api" + ServiceEndpoints.user(userId || "") + "/followers",
Expand Down Expand Up @@ -95,6 +108,22 @@ export async function closeDMChannelRequest(channelId: string) {
useToken: true
});
}

export async function blockUser(userId: string) {
return request({
url: env.SERVER_URL + "/api" + ServiceEndpoints.user(userId) + "/block",
method: 'POST',
useToken: true
});
}
export async function unblockUser(userId: string) {
return request({
url: env.SERVER_URL + "/api" + ServiceEndpoints.user(userId) + "/block",
method: 'DELETE',
useToken: true
});
}

export async function updatePresence(presence: Partial<Presence>) {
return request<RawInboxWithoutChannel & {channel: RawChannel}>({
url: env.SERVER_URL + "/api" + ServiceEndpoints.updatePresence(),
Expand Down
5 changes: 4 additions & 1 deletion src/chat-api/socketClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { onFriendRemoved, onFriendRequestAccepted, onFriendRequestPending, onFri
import { onInboxClosed, onInboxOpened } from './events/inboxEvents';
import { onMessageCreated, onMessageDeleted, onMessageReactionAdded, onMessageReactionRemoved, onMessageUpdated } from './events/messageEvents';
import { onServerChannelCreated, onServerChannelDeleted, onServerChannelOrderUpdated, onServerChannelUpdated, onServerEmojiAdd, onServerEmojiRemove, onServerEmojiUpdate, onServerJoined, onServerLeft, onServerMemberJoined, onServerMemberLeft, onServerMemberUpdated, onServerOrderUpdated, onServerRoleCreated, onServerRoleDeleted, onServerRoleOrderUpdated, onServerRoleUpdated, onServerUpdated } from './events/serverEvents';
import { onNotificationDismissed, onUserPresenceUpdate, onUserServerSettingsUpdate, onUserUpdated } from './events/userEvents';
import { onNotificationDismissed, onUserBlocked, onUserPresenceUpdate, onUserServerSettingsUpdate, onUserUnblocked, onUserUpdated } from './events/userEvents';
import { onCleanup, onMount } from 'solid-js';
import { onVoiceSignalReceived, onVoiceUserJoined, onVoiceUserLeft } from './events/voiceEvents';

Expand Down Expand Up @@ -47,6 +47,9 @@ socket.on(ServerEvents.USER_AUTHENTICATED, onAuthenticated);
socket.on(ServerEvents.USER_UPDATED, onUserUpdated);
socket.on(ServerEvents.USER_SERVER_SETTINGS_UPDATE, onUserServerSettingsUpdate);

socket.on(ServerEvents.USER_BLOCKED, onUserBlocked);
socket.on(ServerEvents.USER_UNBLOCKED, onUserUnblocked);


socket.on(ServerEvents.USER_PRESENCE_UPDATE, onUserPresenceUpdate)

Expand Down
Loading

0 comments on commit ef92037

Please sign in to comment.