This functionality has now been merged into matrix-appservice-bridge here. Users wishing to track activity can import that component into their project freely.
A small utility to determine when a user was last active.
Install with
npm i matrix-lastactive
To use
import { MatrixActivityTracker } from "matrix-lastactive";
// Create the tracker object.
const tracker = new MatrixActivityTracker({
homeserverUrl: "https://localhost",
accessToken: "ABCDE",
serverName: "localhost",
defaultOnline: false,
});
tracker.isUserOnline(
"@Half-Shot:half-shot.uk"
1000 * 60 * 60 * 24 // 24 hours
).then((isOnline) => {
if (isOnline) {
console.log("Half-Shot is online");
} else {
console.log("Half-Shot is offline");
}
});
// You could also plug the library into an event handler..
myfakeemitter.on("event", (event) => {
// ..and keep track of how long ago you saw a message from a user.
tracker.bumpLastActiveTime(event.sender);
});
If you need help with this library, please contact @Half-Shot:half-shot.uk