add namespaces
This commit is contained in:
@@ -73,7 +73,7 @@ export default class ChatListModel {
|
||||
|
||||
for (const chatModel of this.chatModels) {
|
||||
for (const channel of allChannels) {
|
||||
if (channel != chatModel.info.primaryChannel) continue;
|
||||
if (channel != chatModel.unwrappedPrimaryChannel) continue;
|
||||
fn(chatModel);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -37,6 +37,10 @@ export default class ChatModel {
|
||||
info: ChatInfo;
|
||||
color: Colors;
|
||||
|
||||
get unwrappedPrimaryChannel(): string {
|
||||
return this.info.namespace + this.info.primaryChannel;
|
||||
}
|
||||
|
||||
get secondaryChannels(): string[] {
|
||||
return this.info.secondaryChannels.sort(localeCompare);
|
||||
}
|
||||
@@ -133,6 +137,12 @@ export default class ChatModel {
|
||||
this.storeInfo();
|
||||
this.subscribe();
|
||||
};
|
||||
|
||||
readonly setNamespace = (namespace: string): void => {
|
||||
this.info.namespace = namespace;
|
||||
this.storeInfo();
|
||||
this.subscribe();
|
||||
};
|
||||
|
||||
readonly setSecondaryChannels = (secondaryChannels: string[]): void => {
|
||||
this.info.secondaryChannels = secondaryChannels;
|
||||
@@ -170,7 +180,7 @@ export default class ChatModel {
|
||||
const senderName: string = this.settingsModel.username;
|
||||
if (senderName == "") return false;
|
||||
|
||||
const allChannels: string[] = [this.info.primaryChannel];
|
||||
const allChannels: string[] = [this.unwrappedPrimaryChannel];
|
||||
for (const secondaryChannel of this.info.secondaryChannels) {
|
||||
allChannels.push(secondaryChannel);
|
||||
}
|
||||
@@ -238,7 +248,7 @@ export default class ChatModel {
|
||||
};
|
||||
|
||||
readonly subscribe = (): void => {
|
||||
this.connectionModel.addChannel(this.info.primaryChannel);
|
||||
this.connectionModel.addChannel(this.unwrappedPrimaryChannel);
|
||||
};
|
||||
|
||||
readonly setReadStatus = (hasUnreadMessages: boolean): void => {
|
||||
@@ -367,6 +377,7 @@ export default class ChatModel {
|
||||
dataVersion: DATA_VERSION,
|
||||
|
||||
primaryChannel,
|
||||
namespace: "",
|
||||
secondaryChannels: [],
|
||||
encryptionKey: "",
|
||||
hasUnreadMessages: false,
|
||||
@@ -454,6 +465,7 @@ export enum ReactionSymbols {
|
||||
|
||||
export interface ChatInfo extends ValidObject {
|
||||
primaryChannel: string;
|
||||
namespace: string;
|
||||
secondaryChannels: string[];
|
||||
encryptionKey: string;
|
||||
|
||||
@@ -494,6 +506,7 @@ export const ChatInfoReference: ChatInfo = {
|
||||
dataVersion: DATA_VERSION,
|
||||
|
||||
primaryChannel: "",
|
||||
namespace: "",
|
||||
secondaryChannels: [""],
|
||||
encryptionKey: "",
|
||||
|
||||
|
||||
@@ -77,6 +77,46 @@ export function SettingsPage(
|
||||
|
||||
<hr></hr>
|
||||
|
||||
<label class="tile flex-no">
|
||||
<span class="icon">category</span>
|
||||
<div>
|
||||
<span>
|
||||
{
|
||||
coreViewModel.translations.chatPage
|
||||
.settings.namespaceLabel
|
||||
}
|
||||
</span>
|
||||
<input
|
||||
bind:value={
|
||||
settingsPageViewModel.namespaceInput
|
||||
}
|
||||
on:enter={
|
||||
settingsPageViewModel.setNamespace
|
||||
}
|
||||
></input>
|
||||
</div>
|
||||
</label>
|
||||
<div class="flex-row justify-end width-input">
|
||||
<button
|
||||
class="width-50"
|
||||
aria-label={
|
||||
coreViewModel.translations.chatPage.settings
|
||||
.setNamespaceButtonAudioLabel
|
||||
}
|
||||
on:click={
|
||||
settingsPageViewModel.setNamespace
|
||||
}
|
||||
toggle:disabled={
|
||||
settingsPageViewModel.cannotSetNamespace
|
||||
}
|
||||
>
|
||||
{coreViewModel.translations.general.setButton}
|
||||
<span class="icon">check</span>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<hr></hr>
|
||||
|
||||
<div class="flex-row width-input margin-bottom">
|
||||
<input
|
||||
aria-label={
|
||||
|
||||
@@ -171,6 +171,10 @@ const englishTranslations = {
|
||||
primaryChannelLabel: "Primary channel",
|
||||
setPrimaryChannelButtonAudioLabel: "set primary channel",
|
||||
|
||||
namespaceLabel: "Namespace",
|
||||
namespacePlaceholder: "No namespace",
|
||||
setNamespaceButtonAudioLabel: "set namespace",
|
||||
|
||||
newSecondaryChannelPlaceholder: "Add secondary channel",
|
||||
newSecondaryChannelAudioLabel: "name of new secondary channel",
|
||||
addSecondaryChannelButtonAudioLabel: "add secondary channel",
|
||||
@@ -472,6 +476,10 @@ export const allTranslations: {
|
||||
primaryChannelLabel: "Hauptkanal",
|
||||
setPrimaryChannelButtonAudioLabel: "Hauptkanal festlegen",
|
||||
|
||||
namespaceLabel: "Namensraum",
|
||||
namespacePlaceholder: "Ohne Namensraum",
|
||||
setNamespaceButtonAudioLabel: "Namensraum festlegen",
|
||||
|
||||
newSecondaryChannelPlaceholder: "Sekundären Kanal hinzufügen",
|
||||
newSecondaryChannelAudioLabel:
|
||||
"Name des neuen sekundären Kanals",
|
||||
@@ -749,6 +757,10 @@ export const allTranslations: {
|
||||
primaryChannelLabel: "Canal principal",
|
||||
setPrimaryChannelButtonAudioLabel: "establecer canal principal",
|
||||
|
||||
namespaceLabel: "Espacio de nombres",
|
||||
namespacePlaceholder: "Sin espacio de nombres",
|
||||
setNamespaceButtonAudioLabel: "establecer espacio de nombres",
|
||||
|
||||
newSecondaryChannelPlaceholder: "Añadir canal secundario",
|
||||
newSecondaryChannelAudioLabel:
|
||||
"nombre del nuevo canal secundario",
|
||||
|
||||
@@ -9,7 +9,7 @@ import ConnectionModel from "../../Model/Global/connectionModel";
|
||||
import ChatListModel from "../../Model/Chat/chatListModel";
|
||||
|
||||
export default class CoreViewModel {
|
||||
readonly BUILD = "Build 26.05.05.B";
|
||||
readonly BUILD = "Build 26.05.06.A";
|
||||
|
||||
translations: Translations;
|
||||
|
||||
|
||||
@@ -98,7 +98,7 @@ export default class FileTransferViewModel extends Context {
|
||||
this.coreViewModel.chatListModel.chatModels;
|
||||
for (const chatModel of chatModels) {
|
||||
this.chatFileOptions.add({
|
||||
label: chatModel.info.primaryChannel,
|
||||
label: chatModel.unwrappedPrimaryChannel,
|
||||
path: chatModel.getBasePath(),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -20,8 +20,8 @@ export default class NotificationViewModel {
|
||||
if (this.chatListViewModel.selectedChat.value == undefined) return;
|
||||
|
||||
const currentChat =
|
||||
this.chatListViewModel.selectedChat.value.chatModel.info
|
||||
.primaryChannel;
|
||||
this.chatListViewModel.selectedChat.value.chatModel.
|
||||
unwrappedPrimaryChannel
|
||||
const currentPage =
|
||||
this.chatListViewModel.selectedChat.value.selectedPage.value;
|
||||
if (
|
||||
@@ -41,7 +41,7 @@ export default class NotificationViewModel {
|
||||
const chat = [
|
||||
...this.chatListViewModel.chatViewModels.value.values(),
|
||||
].find(
|
||||
(chat) => chat.chatModel.info.primaryChannel == notification.chat,
|
||||
(chat) => chat.chatModel.unwrappedPrimaryChannel == notification.chat,
|
||||
);
|
||||
chat.open();
|
||||
chat.openPage(ChatPageTypes.Messages);
|
||||
@@ -79,7 +79,7 @@ export default class NotificationViewModel {
|
||||
};
|
||||
|
||||
// init
|
||||
constructor(public readonly chatListViewModel: ChatListViewModel) {}
|
||||
constructor(public readonly chatListViewModel: ChatListViewModel) { }
|
||||
|
||||
// util
|
||||
static createNotification(message: ChatMessage): Notification {
|
||||
|
||||
@@ -8,6 +8,9 @@ export default class SettingsPageViewModel extends Context {
|
||||
primaryChannel: React.State<string> = new React.State("");
|
||||
primaryChannelInput: React.State<string> = new React.State("");
|
||||
|
||||
namespace: React.State<string> = new React.State("");
|
||||
namespaceInput: React.State<string> = new React.State("");
|
||||
|
||||
secondaryChannels: React.ListState<string> = new React.ListState();
|
||||
newSecondaryChannelInput: React.State<string> = new React.State("");
|
||||
|
||||
@@ -27,6 +30,11 @@ export default class SettingsPageViewModel extends Context {
|
||||
this.primaryChannelInput.value == "" ||
|
||||
this.primaryChannelInput.value == this.primaryChannel.value,
|
||||
);
|
||||
cannotSetNamespace: React.State<boolean> = React.createProxyState(
|
||||
[this.namespace, this.namespaceInput],
|
||||
() =>
|
||||
this.namespaceInput.value == this.namespace.value,
|
||||
);
|
||||
cannotAddSecondaryChannel: React.State<boolean> = React.createProxyState(
|
||||
[this.newSecondaryChannelInput],
|
||||
() => this.newSecondaryChannelInput.value == "",
|
||||
@@ -44,6 +52,14 @@ export default class SettingsPageViewModel extends Context {
|
||||
this.chatViewModel.chatListViewModel.updateIndices();
|
||||
};
|
||||
|
||||
setNamespace = (): void => {
|
||||
this.chatViewModel.chatModel.setNamespace(
|
||||
this.namespaceInput.value,
|
||||
);
|
||||
this.namespace.value =
|
||||
this.chatViewModel.chatModel.info.namespace;
|
||||
};
|
||||
|
||||
addSecondaryChannel = (): void => {
|
||||
this.secondaryChannels.add(this.newSecondaryChannelInput.value);
|
||||
this.newSecondaryChannelInput.value = "";
|
||||
@@ -85,13 +101,17 @@ export default class SettingsPageViewModel extends Context {
|
||||
preloadData = (): void => {
|
||||
this.primaryChannel.value =
|
||||
this.chatViewModel.chatModel.info.primaryChannel;
|
||||
this.namespace.value =
|
||||
this.chatViewModel.chatModel.info.namespace;
|
||||
|
||||
this.color.value = this.chatViewModel.chatModel.color;
|
||||
};
|
||||
|
||||
loadData = (): void => {
|
||||
this.primaryChannelInput.value =
|
||||
this.chatViewModel.chatModel.info.primaryChannel;
|
||||
this.primaryChannel.value;
|
||||
this.namespaceInput.value =
|
||||
this.namespace.value;
|
||||
|
||||
this.loadSecondaryChannels();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user