Commit bcadc418 authored by Grant's avatar Grant
Browse files

Merge branch '158-move-away-from-ap-handles' into 'main'

Move away from ActivityPub handles

Closes #158

See merge request sc07/canvas!103
parents 697cc198 2449e148
Loading
Loading
Loading
Loading
+2 −8
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@ interface IPixel {

interface IUser {
  sub: string;
  username: string;
  display_name?: string;
  picture_url?: string;
  profile_url?: string;
@@ -179,12 +180,5 @@ const SmallCanvas = ({
    }
  }, [surrounding]);

  return (
    <canvas
      width={300}
      height={300}
      ref={(r) => (canvasRef.current = r)}
      {...props}
    />
  );
  return <canvas width={300} height={300} ref={canvasRef} {...props} />;
};
+8 −6
Original line number Diff line number Diff line
@@ -21,13 +21,15 @@ export const ProfileModal = () => {
      return;
    }

    api<{ user: IUser }>("/api/user/" + profile).then(({ status, data }) => {
    api<{ user: IUser }>("/api/user/" + encodeURIComponent(profile)).then(
      ({ status, data }) => {
        if (status === 200 && data.success) {
          setUser(data.user);
        } else {
          handleError({ status, data });
        }
    });
      }
    );
  }, [profile]);

  return (
+4 −18
Original line number Diff line number Diff line
@@ -2,12 +2,13 @@ import { faMessage, faWarning } from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { Button, Link, Spinner, User } from "@nextui-org/react";
import { ClientConfig } from "@sc07-canvas/lib/src/net";
import { MouseEvent, useEffect, useMemo, useState } from "react";
import { MouseEvent, useEffect, useState } from "react";
import { toast } from "react-toastify";
import { useAppContext } from "../../contexts/AppContext";

export interface IUser {
  sub: string;
  username: string;
  display_name?: string;
  picture_url?: string;
  profile_url?: string;
@@ -39,7 +40,7 @@ export const UserCard = ({ user }: { user: IUser }) => {
    setMessageStatus("loading");

    fetch(
      `https://${config.chat.matrix_homeserver}/_matrix/client/v3/profile/${encodeURIComponent(`@${user.sub.replace("@", "=40")}:${config.chat.matrix_homeserver}`)}`
      `https://${config.chat.matrix_homeserver}/_matrix/client/v3/profile/${encodeURIComponent(`@${user.username.replace("@", "=40")}:${config.chat.matrix_homeserver}`)}`
    )
      .then((req) => {
        if (req.status === 200) {
@@ -72,26 +73,11 @@ export const UserCard = ({ user }: { user: IUser }) => {
    setProfile(user.sub);
  };

  const name = useMemo(() => {
    if (!user || !user.sub) {
      return "Unknown";
    }

    const regex = /^(.*)@/;
    const match = user.sub.match(regex);

    if (match) {
      return match[1];
    }

    return "Unknown";
  }, [user]);

  return (
    <div className="flex flex-col gap-1">
      <div className="flex flex-row space-between p-2">
        <User
          name={user?.display_name || name}
          name={user?.display_name || user?.username}
          description={user?.sub || "Unknown"}
          avatarProps={{
            showFallback: true,
+8 −0
Original line number Diff line number Diff line
@@ -231,6 +231,14 @@ export type AuthSession = {
    };
  };
  user: {
    /**
     * URL
     * @example https://grants.cafe/users/grant
     */
    sub: string;
    /**
     * @example grant@grants.cafe
     */
    username: string;
    display_name?: string;
    picture_url?: string;
+8 −0
Original line number Diff line number Diff line
/*
  Warnings:

  - Added the required column `username` to the `User` table without a default value. This is not possible if the table is not empty.

*/
-- AlterTable
ALTER TABLE "User" ADD COLUMN     "username" TEXT NOT NULL;
Loading