Edits history of script submission #191 for ' Is a Matrix user X a joined member of a Matrix room Y? (matrix)'

  • deno
    /**
     * This function throws an error, if you're not a room member.
     *
     * Expected return values:
     *
     * {
     *   "is_joined": false,
     *   "user_info": null
     * }
     *
     * or
     *
     * {
     *   "is_member": true,
     *   "user_info": {
     *     "avatar_url": "mxc://matrix.org/abc123",
     *     "display_name": "Jane Doe"
     *   }
     * }
     */
    type Matrix = {
      baseUrl: string;
      token: string;
    };
    export async function main(
      matrix_res: Matrix,
      room_id: string,
      user_id: string,
    ) {
      const url = `${
        matrix_res.baseUrl
      }/_matrix/client/v3/rooms/${encodeURIComponent(room_id)}/joined_members`;
      const resp = await fetch(url, {
        headers: {
          Authorization: `Bearer ${matrix_res.token}`,
        },
      });
      if (!resp.ok) {
        throw Error(`Failed to fetch joined member list: Error HTTP${resp.status}`);
      }
      const data = await resp.json();
      return {
        is_joined: user_id in data?.joined,
        user_info: data?.joined?.[user_id],
      };
    }
    

    Submitted by hugo697 399 days ago

  • deno
    /**
     * This function throws an error, if you're not a room member.
     *
     * Expected return values:
     *
     * {
     *   "is_joined": false,
     *   "user_info": null
     * }
     *
     * or
     *
     * {
     *   "is_member": true,
     *   "user_info": {
     *     "avatar_url": "mxc://matrix.org/abc123",
     *     "display_name": "Jane Doe"
     *   }
     * }
     */
    type Matrix = {
      baseUrl: string;
      token: string;
    };
    export async function main(
      matrix_res: Matrix,
      room_id: string,
      user_id: string,
    ) {
      const url = `${
        matrix_res.baseUrl
      }/_matrix/client/v3/rooms/${encodeURIComponent(room_id)}/joined_members`;
      const resp = await fetch(url, {
        headers: {
          Authorization: `Bearer ${matrix_res.token}`,
        },
      });
      if (!resp.ok) {
        throw Error(`Failed to fetch joined member list: Error HTTP${resp.status}`);
      }
      const data = await resp.json();
      return {
        is_joined: user_id in data?.joined,
        user_info: data?.joined?.[user_id],
      };
    }
    

    Submitted by admin 1031 days ago

  • deno
    
    /**
     * This function throws an error, if you're not a room member.
     * 
     * Expected return values:
     * 
     * {
     *   "is_joined": false,
     *   "user_info": null
     * }
     * 
     * or
     * 
     * {
     *   "is_member": true,
     *   "user_info": {
     *     "avatar_url": "mxc://matrix.org/abc123",
     *     "display_name": "Jane Doe"
     *   }
     * }
     */
    type Matrix = {
      baseUrl: string;
      token: string;
    };
    export async function main(
      matrix_res: Matrix,
      room_id: string,
      user_id: string,
    ) {
      const url = `${matrix_res.baseUrl}/_matrix/client/v3/rooms/${encodeURIComponent(room_id)}/joined_members`;
      const resp = await fetch(url, {
        headers: {
          "Authorization": `Bearer ${matrix_res.token}`,
        },
      });
      if (!resp.ok) {
        throw Error(`Failed to fetch joined member list: Error HTTP${resp.status}`);
      }
      const data = await resp.json();
      return {
        is_joined: user_id in data?.joined,
        user_info: data?.joined?.[user_id],
      };
    }
    

    Submitted by admin 1034 days ago

  • deno
    import * as wmill from "https://deno.land/x/[email protected]/mod.ts"
    
    /**
     * This function throws an error, if you're not a room member.
     * 
     * Expected return values:
     * 
     * {
     *   "is_joined": false,
     *   "user_info": null
     * }
     * 
     * or
     * 
     * {
     *   "is_member": true,
     *   "user_info": {
     *     "avatar_url": "mxc://matrix.org/abc123",
     *     "display_name": "Jane Doe"
     *   }
     * }
     */
    export async function main(
      matrix_res: wmill.Resource<"matrix">,
      room_id: string,
      user_id: string,
    ) {
      const url = `${matrix_res.baseUrl}/_matrix/client/v3/rooms/${encodeURIComponent(room_id)}/joined_members`;
      const resp = await fetch(url, {
        headers: {
          "Authorization": `Bearer ${matrix_res.token}`,
        },
      });
      if (!resp.ok) {
        throw Error(`Failed to fetch joined member list: Error HTTP${resp.status}`);
      }
      const data = await resp.json();
      return {
        is_joined: user_id in data?.joined,
        user_info: data?.joined?.[user_id],
      };
    }
    

    Submitted by adam186 1163 days ago

  • deno
    import * as wmill from "https://deno.land/x/[email protected]/mod.ts"
    
    /**
     * This function throws an error, if you're not a room member.
     * 
     * Expected return values:
     * 
     * {
     *   "is_joined": false,
     *   "user_info": null
     * }
     * 
     * or
     * 
     * {
     *   "is_member": true,
     *   "user_info": {
     *     "avatar_url": "mxc://matrix.org/abc123",
     *     "display_name": "Jane Doe"
     *   }
     * }
     */
    export async function main(
      matrix_res: wmill.Resource<"matrix">,
      room_id: string,
      user_id: string,
    ) {
      const url = `${matrix_res.baseUrl}/_matrix/client/v3/rooms/${encodeURIComponent(room_id)}/joined_members`;
      const resp = await fetch(url, {
        headers: {
          "Authorization": `Bearer ${matrix_res.token}`,
        },
      });
      if (!resp.ok) {
        throw Error(`Failed to fetch joined member list: Error HTTP${resp.status}`);
      }
      const data = await resp.json();
      return {
        is_joined: user_id in data?.joined,
        user_info: data?.joined?.[user_id],
      };
    }
    

    Submitted by adam186 1198 days ago

  • deno
    import * as wmill from "https://deno.land/x/[email protected]/mod.ts"
    
    /**
     * This function throws an error, if you're not a room member.
     * 
     * Expected return values:
     * 
     * {
     *   "is_joined": false,
     *   "user_info": null
     * }
     * 
     * or
     * 
     * {
     *   "is_member": true,
     *   "user_info": {
     *     "avatar_url": "mxc://matrix.org/abc123",
     *     "display_name": "Jane Doe"
     *   }
     * }
     */
    export async function main(
      matrix_res: wmill.Resource<"matrix">,
      room_id: string,
      user_id: string,
    ) {
      const url = `${matrix_res.baseUrl}/_matrix/client/v3/rooms/${encodeURIComponent(room_id)}/joined_members`;
      const resp = await fetch(url, {
        headers: {
          "Authorization": `Bearer ${matrix_res.token}`,
        },
      });
      if (!resp.ok) {
        throw Error(`Failed to fetch joined member list: Error HTTP${resp.status}`);
      }
      const data = await resp.json();
      return {
        is_joined: user_id in data?.joined,
        user_info: data?.joined?.[user_id],
      };
    }
    

    Submitted by jaller94 1300 days ago