|
|
|
@ -3,7 +3,7 @@ import { ConversationController } from '../../session/conversations';
|
|
|
|
|
import { PromiseUtils } from '../../session/utils';
|
|
|
|
|
import { allowOnlyOneAtATime } from '../../session/utils/Promise';
|
|
|
|
|
import { forceSyncConfigurationNowIfNeeded } from '../../session/utils/syncUtils';
|
|
|
|
|
import { prefixify } from '../utils/OpenGroupUtils';
|
|
|
|
|
import { openGroupPrefix, prefixify } from '../utils/OpenGroupUtils';
|
|
|
|
|
|
|
|
|
|
interface OpenGroupParams {
|
|
|
|
|
server: string;
|
|
|
|
@ -12,20 +12,11 @@ interface OpenGroupParams {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export class OpenGroup {
|
|
|
|
|
/**
|
|
|
|
|
* Just a constant to have less `publicChat:` everywhere
|
|
|
|
|
* Note: It does already have the ':' included
|
|
|
|
|
*/
|
|
|
|
|
public static readonly openGroupPrefix = 'publicChat:';
|
|
|
|
|
/**
|
|
|
|
|
* Just a regex to match a public chat (i.e. a string starting with publicChat:)
|
|
|
|
|
*/
|
|
|
|
|
public static readonly openGroupPrefixRegex = new RegExp(`/^${OpenGroup.openGroupPrefix}/`);
|
|
|
|
|
private static readonly serverRegex = new RegExp(
|
|
|
|
|
'^((https?:\\/\\/){0,1})([\\w-]{2,}\\.){1,2}[\\w-]{2,}$'
|
|
|
|
|
);
|
|
|
|
|
private static readonly groupIdRegex = new RegExp(
|
|
|
|
|
`^${OpenGroup.openGroupPrefix}:[0-9]*@([\\w-]{2,}.){1,2}[\\w-]{2,}$`
|
|
|
|
|
`^${openGroupPrefix}:[0-9]*@([\\w-]{2,}.){1,2}[\\w-]{2,}$`
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
public readonly server: string;
|
|
|
|
@ -39,7 +30,7 @@ export class OpenGroup {
|
|
|
|
|
*
|
|
|
|
|
* @param params.server The server URL. `https` will be prepended if `http` or `https` is not explicitly set
|
|
|
|
|
* @param params.channel The server channel
|
|
|
|
|
* @param params.groupId The string corresponding to the server. Eg. `${OpenGroup.openGroupPrefix}1@chat.getsession.org`
|
|
|
|
|
* @param params.groupId The string corresponding to the server. Eg. `${openGroupPrefix}1@chat.getsession.org`
|
|
|
|
|
* @param params.conversationId The conversation ID for the backbone model
|
|
|
|
|
*/
|
|
|
|
|
constructor(params: OpenGroupParams) {
|
|
|
|
@ -76,7 +67,7 @@ export class OpenGroup {
|
|
|
|
|
* Try to make a new instance of `OpenGroup`.
|
|
|
|
|
* This does NOT respect `ConversationController` and does not guarentee the conversation's existence.
|
|
|
|
|
*
|
|
|
|
|
* @param groupId The string corresponding to the server. Eg. `${OpenGroup.openGroupPrefix}1@chat.getsession.org`
|
|
|
|
|
* @param groupId The string corresponding to the server. Eg. `${openGroupPrefix}1@chat.getsession.org`
|
|
|
|
|
* @param conversationId The conversation ID for the backbone model
|
|
|
|
|
* @returns `OpenGroup` if valid otherwise returns `undefined`.
|
|
|
|
|
*/
|
|
|
|
@ -167,7 +158,7 @@ export class OpenGroup {
|
|
|
|
|
}
|
|
|
|
|
const rawServerURL = server.replace(/^https?:\/\//i, '').replace(/[/\\]+$/i, '');
|
|
|
|
|
const channelId = 1;
|
|
|
|
|
const conversationId = `${OpenGroup.openGroupPrefix}${channelId}@${rawServerURL}`;
|
|
|
|
|
const conversationId = `${openGroupPrefix}${channelId}@${rawServerURL}`;
|
|
|
|
|
|
|
|
|
|
// Quickly peak to make sure we don't already have it
|
|
|
|
|
return ConversationController.getInstance().get(conversationId);
|
|
|
|
@ -210,7 +201,7 @@ export class OpenGroup {
|
|
|
|
|
const prefixRegex = new RegExp('https?:\\/\\/');
|
|
|
|
|
const strippedServer = server.replace(prefixRegex, '');
|
|
|
|
|
|
|
|
|
|
return `${OpenGroup.openGroupPrefix}${channel}@${strippedServer}`;
|
|
|
|
|
return `${openGroupPrefix}${channel}@${strippedServer}`;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -252,7 +243,7 @@ export class OpenGroup {
|
|
|
|
|
|
|
|
|
|
const rawServerURL = serverUrl.replace(/^https?:\/\//i, '').replace(/[/\\]+$/i, '');
|
|
|
|
|
|
|
|
|
|
const conversationId = `${OpenGroup.openGroupPrefix}${channelId}@${rawServerURL}`;
|
|
|
|
|
const conversationId = `${openGroupPrefix}${channelId}@${rawServerURL}`;
|
|
|
|
|
|
|
|
|
|
// Quickly peak to make sure we don't already have it
|
|
|
|
|
const conversationExists = ConversationController.getInstance().get(conversationId);
|
|
|
|
|