Skip to content

Commit

Permalink
Various small improvements to the "How To" guide (#432)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>

Co-authored-by: Will Hunt <[email protected]>
  • Loading branch information
Christian Paul and Half-Shot committed Oct 5, 2022
1 parent 511be4f commit 13f72ab
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 0 deletions.
1 change: 1 addition & 0 deletions changelog.d/432.doc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
How-To guide: Remove advise to install matrix-appservice and other small improvements.
43 changes: 43 additions & 0 deletions src/components/stores/event-store.ts
Original file line number Diff line number Diff line change
@@ -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<void>
/**
* 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<StoredEvent|null>

/**
* 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<StoredEvent|null>

/**
* Remove entries based on the event data.
* @param event The event to remove.
*/
removeEvent(event: StoredEvent): Promise<void>

/**
* 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<void>
/**
* 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<void>
}
3 changes: 3 additions & 0 deletions src/components/stores/room-store.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export interface RoomBridgeStore {

}
66 changes: 66 additions & 0 deletions src/components/stores/user-activity-store.ts
Original file line number Diff line number Diff line change
@@ -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<void> {
this.upsert({ mxid }, {
...activity,
});
}

public async getActivitySet(): Promise<UserActivitySet> {
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;
});
}
}
3 changes: 3 additions & 0 deletions src/components/stores/user-store.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export interface UserBridgeStore {

}

0 comments on commit 13f72ab

Please sign in to comment.