Skip to content
Extraits de code Groupes Projets
Sélectionner une révision Git
1 résultat Searching

imstb_textedit.h

Blame
  • roomstore.ts 12,50 Kio
    /*
    Copyright 2019 matrix-appservice-discord
    
    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at
    
        http://www.apache.org/licenses/LICENSE-2.0
    
    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
    */
    import { Log } from "../log";
    import { IDatabaseConnector } from "./connector";
    
    import * as uuid from "uuid/v4";
    
    const log = new Log("DbRoomStore");
    
    /**
     * A RoomStore compatible with
     * https://github.com/matrix-org/matrix-appservice-bridge/blob/master/lib/components/room-bridge-store.js
     * that accesses the database instead.
     */
    
    interface IRemoteRoomData extends IRemoteRoomDataLazy {
        discord_guild: string;
        discord_channel: string;
    }
    
    interface IRemoteRoomDataLazy  {
        discord_guild?: string;
        discord_channel?: string;
        discord_name?: string|null;
        discord_topic?: string|null;
        discord_type?: string|null;
        discord_iconurl?: string|null;
        discord_iconurl_mxc?: string|null;
        update_name?: number|boolean|null;
        update_topic?: number|boolean|null;
        update_icon?: number|boolean|null;
        plumbed?: number|boolean|null;
    }
    
    export class RemoteStoreRoom {
        public data: IRemoteRoomData;
        constructor(public readonly roomId: string, data: IRemoteRoomData) {
            for (const k of ["discord_guild", "discord_channel", "discord_name",
            "discord_topic", "discord_iconurl", "discord_iconurl_mxc", "discord_type"]) {
                data[k] = typeof(data[k]) === "number" ? String(data[k]) : data[k] || null;
            }
            for (const k of ["update_name", "update_topic", "update_icon", "plumbed"]) {
                data[k] = Number(data[k]) || 0;
            }
            this.data = data;
        }
    
        public getId() {
            return this.roomId;
        }
    
        public get(key: string): string|boolean|null {
            return this.data[key];
        }
    
        public set(key: string, value: string|boolean|null) {
            this.data[key] = typeof(value) === "boolean" ? Number(value) : value;