A self hosted chat application with end-to-end encrypted messaging.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

85 lines
2.9 KiB

import { NotificationService } from "./NotificationService";
// @ts-ignore
import * as alertify from "alertifyjs";
import { ActiveUserViewModel } from "../viewmodel/ActiveUserViewModel";
import log = require("loglevel");
import bootbox = require("bootbox");
import { ChatMessageViewModel } from "../viewmodel/ChatMessageViewModel";
export class AlertifyNotificationService implements NotificationService {
private readonly _alertify = alertify;
constructor() {
this._alertify.set("notifier", "position", "top-center");
}
success(message: string): void {
this._alertify.success(message);
}
error(message: string): void {
this._alertify.error(message);
}
errorWithDelay(message: string, delay: number): void {
const _delay = this._alertify.get("notifier", "delay");
this._alertify.set("notifier", "delay", delay);
this._alertify.error(message);
this._alertify.set("notifier", "delay", _delay);
}
warning(message: string): void {
this._alertify.warning(message);
}
message(message: string): void {
this._alertify.message(message);
}
passphrasePrompt(
vm: ActiveUserViewModel,
vms: ActiveUserViewModel[],
cb1: (v: ActiveUserViewModel, op: string) => ChatMessageViewModel[],
cb2: (...x: any) => any,
cb3: (...x: any) => any
): void {
if (!vm.passphrase) {
bootbox.prompt({
title: "Please enter the passphrase",
inputType: "password",
callback: async function (result) {
if (result) {
const valid = await cb3(result, vm.userName);
if (!valid) {
bootbox.alert("Some error occured. Please check your password");
log.error("invalid password");
return;
}
vm.unlocked = true;
vm.passphrase = result;
const chatMessages: ChatMessageViewModel[] = await cb1(vm, "new");
vms
.filter((v) => v.userName == vm.userName)
.map((v) => {
v.passphrase = result;
v.unlocked = true;
if (chatMessages.length > 0) {
v.lastMessageTime = new Date(
chatMessages[chatMessages.length - 1].messageTime
);
const lastMessageText = (v.lastMessageText =
chatMessages[chatMessages.length - 1].message);
if (lastMessageText.length > 15) {
v.lastMessageText =
chatMessages[chatMessages.length - 1].message.slice(
0,
15
) + "...";
}
}
});
// vm.lastMessageTime = new Date(chatMessages[chatMessages.length - 1].messageTime);
cb2(vm, vms);
// log.debug(vm);
// log.debug(vms);
}
},
});
} else {
cb1(vm, "new");
}
}
}