From 13f72abdd4701bc1e29bd797433fc96cf9b170d0 Mon Sep 17 00:00:00 2001 From: Christian Paul Date: Mon, 22 Aug 2022 18:16:06 +0200 Subject: [PATCH] Various small improvements to the "How To" guide (#432) * Setup -> Set up * Use node: prefix when importing NodeJS modules * How-To: No need to install matrix-appservice * How-To: slack -> Slack * Add newsfile * README.md: Fix RegExp from +. to .+ * Update 432.doc * HOWTO.md: Avoid abbreviation "NB" and elaborate on Linux distro differences * README.md: Don't abbreviate AS API and CS API * Update HOWTO.md Co-authored-by: Will Hunt Co-authored-by: Will Hunt --- changelog.d/432.doc | 1 + src/components/stores/event-store.ts | 43 +++++++++++++ src/components/stores/room-store.ts | 3 + src/components/stores/user-activity-store.ts | 66 ++++++++++++++++++++ src/components/stores/user-store.ts | 3 + 5 files changed, 116 insertions(+) create mode 100644 changelog.d/432.doc create mode 100644 src/components/stores/event-store.ts create mode 100644 src/components/stores/room-store.ts create mode 100644 src/components/stores/user-activity-store.ts create mode 100644 src/components/stores/user-store.ts diff --git a/changelog.d/432.doc b/changelog.d/432.doc new file mode 100644 index 00000000..9716b822 --- /dev/null +++ b/changelog.d/432.doc @@ -0,0 +1 @@ +How-To guide: Remove advise to install matrix-appservice and other small improvements. diff --git a/src/components/stores/event-store.ts b/src/components/stores/event-store.ts new file mode 100644 index 00000000..2dcfd4c5 --- /dev/null +++ b/src/components/stores/event-store.ts @@ -0,0 +1,43 @@ +import { StoredEvent } from "../../models/events/event"; + +export interface EventBridgeStore { + /** + * Insert an event, clobbering based on the ID of the StoredEvent. + * @param event + */ + upsertEvent(event: StoredEvent): Promise + /** + * Get an existing event based on the provided matrix IDs. + * @param roomId The ID of the room. + * @param eventId The ID of the event. + * @return A promise which resolves to the StoredEvent or null. + */ + getEntryByMatrixId(roomId: string, eventId: string): Promise + + /** + * Get an existing event based on the provided remote IDs. + * @param roomId The ID of the room. + * @param eventId The ID of the event. + * @return A promise which resolves to the StoredEvent or null. + */ + getEntryByRemoteId(roomId: string, eventId: string): Promise + + /** + * Remove entries based on the event data. + * @param event The event to remove. + */ + removeEvent(event: StoredEvent): Promise + + /** + * Remove entries based on the matrix IDs. + * @param roomId The ID of the room. + * @param eventId The ID of the event. + */ + removeEventByMatrixId(roomId: string, eventId: string): Promise + /** + * Remove entries based on the matrix IDs. + * @param roomId The ID of the room. + * @param eventId The ID of the event. + */ + removeEventByRemoteId(roomId: string, eventId: string): Promise +} \ No newline at end of file diff --git a/src/components/stores/room-store.ts b/src/components/stores/room-store.ts new file mode 100644 index 00000000..23020c16 --- /dev/null +++ b/src/components/stores/room-store.ts @@ -0,0 +1,3 @@ +export interface RoomBridgeStore { + +} \ No newline at end of file diff --git a/src/components/stores/user-activity-store.ts b/src/components/stores/user-activity-store.ts new file mode 100644 index 00000000..37907d9d --- /dev/null +++ b/src/components/stores/user-activity-store.ts @@ -0,0 +1,66 @@ +/* +Copyright 2021 The Matrix.org Foundation C.I.C. + +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. +*/ + +/* + * User activity storage format: + * { + * mxid: "matrix_id", + * ts: [.. timestamps], + * metadata: { + * .. arbitrary activity-related metadata + * } + * } + * Examples: + * { + * { + * mxid: "@foo.bar.baz", + * ts: [1234567890, 1234534234], + * metadata: { + * active: true, + * } + * } + */ +import Datastore from "nedb"; +import { BridgeStore } from "./bridge-store"; +import { UserActivity, UserActivitySet } from "./user-activity"; + +export class UserActivityStore extends BridgeStore { + /** + * Construct a store suitable for user bridging information. + * @param db The connected NEDB database instance + */ + constructor (db: Datastore) { + super(db); + } + + public async storeUserActivity(mxid: string, activity: UserActivity): Promise { + this.upsert({ mxid }, { + ...activity, + }); + } + + public async getActivitySet(): Promise { + return this.select({}).then((records: any[]) => { + const users: {[mxid: string]: any} = {}; + for (const record of records) { + users[record.mxid] = { + ts: record.ts, + metadata: record.metadata, + }; + } + return { users } as UserActivitySet; + }); + } +} diff --git a/src/components/stores/user-store.ts b/src/components/stores/user-store.ts new file mode 100644 index 00000000..b6fcda6f --- /dev/null +++ b/src/components/stores/user-store.ts @@ -0,0 +1,3 @@ +export interface UserBridgeStore { + +} \ No newline at end of file