only trigger new msg on open group if we are still running

pull/1381/head
Audric Ackermann 4 years ago
parent c039c89a26
commit 190d597814
No known key found for this signature in database
GPG Key ID: 999F434D76324AD4

@ -1034,7 +1034,7 @@ class LokiPublicChannelAPI {
this.channelId = channelId; this.channelId = channelId;
this.baseChannelUrl = `channels/${this.channelId}`; this.baseChannelUrl = `channels/${this.channelId}`;
this.conversationId = conversationId; this.conversationId = conversationId;
this.conversation = ConversationController.get(conversationId); this.conversation = ConversationController.getOrThrow(conversationId);
this.lastGot = null; this.lastGot = null;
this.modStatus = false; this.modStatus = false;
this.deleteLastId = 1; this.deleteLastId = 1;
@ -1185,8 +1185,10 @@ class LokiPublicChannelAPI {
moderators.includes(ourNumberDevice); moderators.includes(ourNumberDevice);
} }
if(this.running) {
await this.conversation.setModerators(moderators || []); await this.conversation.setModerators(moderators || []);
} }
}
async setChannelSettings(settings) { async setChannelSettings(settings) {
if (!this.modStatus) { if (!this.modStatus) {
@ -1335,6 +1337,9 @@ class LokiPublicChannelAPI {
} }
return; return;
} }
if (!this.running) {
return;
}
const { data } = res.response; const { data } = res.response;
@ -1474,7 +1479,7 @@ class LokiPublicChannelAPI {
// update where we last checked // update where we last checked
this.deleteLastId = res.response.meta.max_id; this.deleteLastId = res.response.meta.max_id;
more = res.response.meta.more && res.response.data.length >= params.count; more = res.response.meta.more && res.response.data.length >= params.count && this.running;
} }
} }
@ -1818,13 +1823,14 @@ class LokiPublicChannelAPI {
}) })
); );
// do we really need this? // return early if we should stop processing
if (!pendingMessages.length) { if (!pendingMessages.length || !this.running) {
this.conversation.setLastRetrievedMessage(this.lastGot); this.conversation.setLastRetrievedMessage(this.lastGot);
this.messagesPollLock = false; this.messagesPollLock = false;
return; return;
} }
// slave to primary map for this group of messages // slave to primary map for this group of messages
let slavePrimaryMap = {}; let slavePrimaryMap = {};
@ -1883,6 +1889,7 @@ class LokiPublicChannelAPI {
message, message,
}); });
}); });
sendNow = false; sendNow = false;
} }
primaryMessages = false; // free memory primaryMessages = false; // free memory
@ -1955,6 +1962,7 @@ class LokiPublicChannelAPI {
return; return;
} }
} }
if (this.running) {
log.info( log.info(
'emitting pending message', 'emitting pending message',
message.serverId, message.serverId,
@ -1966,6 +1974,7 @@ class LokiPublicChannelAPI {
this.chatAPI.emit('publicMessage', { this.chatAPI.emit('publicMessage', {
message, message,
}); });
}
}); });
/* eslint-enable no-param-reassign */ /* eslint-enable no-param-reassign */

@ -432,21 +432,22 @@ export class LeftPaneMessageSection extends React.Component<Props, State> {
// Connect to server // Connect to server
try { try {
ToastUtils.pushToastSuccess( ToastUtils.pushToastInfo(
'connectingToServer', 'connectingToServer',
window.i18n('connectingToServer') window.i18n('connectingToServer')
); );
this.setState({ loading: true }); this.setState({ loading: true });
await OpenGroup.join(serverUrl, async () => { await OpenGroup.join(serverUrl);
if (await OpenGroup.serverExists(serverUrl)) { if (await OpenGroup.serverExists(serverUrl)) {
ToastUtils.pushToastSuccess( ToastUtils.pushToastSuccess(
'connectToServerSuccess', 'connectToServerSuccess',
window.i18n('connectToServerSuccess') window.i18n('connectToServerSuccess')
); );
} else {
throw new Error('Open group joined but the corresponding server does not exist');
} }
this.setState({ loading: false }); this.setState({ loading: false });
});
const openGroupConversation = await OpenGroup.getConversation(serverUrl); const openGroupConversation = await OpenGroup.getConversation(serverUrl);
if (openGroupConversation) { if (openGroupConversation) {
@ -460,6 +461,7 @@ export class LeftPaneMessageSection extends React.Component<Props, State> {
'Joined an opengroup but did not find ther corresponding conversation' 'Joined an opengroup but did not find ther corresponding conversation'
); );
} }
this.handleToggleOverlay(undefined);
} catch (e) { } catch (e) {
window.log.error('Failed to connect to server:', e); window.log.error('Failed to connect to server:', e);
ToastUtils.pushToastError( ToastUtils.pushToastError(
@ -467,11 +469,6 @@ export class LeftPaneMessageSection extends React.Component<Props, State> {
window.i18n('connectToServerFail') window.i18n('connectToServerFail')
); );
this.setState({ loading: false }); this.setState({ loading: false });
} finally {
this.setState({
loading: false,
});
this.handleToggleOverlay(undefined);
} }
} }

@ -95,8 +95,7 @@ export class OpenGroup {
* @returns `OpenGroup` if connection success or if already connected * @returns `OpenGroup` if connection success or if already connected
*/ */
public static async join( public static async join(
server: string, server: string
onLoading?: any
): Promise<OpenGroup | undefined> { ): Promise<OpenGroup | undefined> {
const prefixedServer = OpenGroup.prefixify(server); const prefixedServer = OpenGroup.prefixify(server);
if (!OpenGroup.validate(server)) { if (!OpenGroup.validate(server)) {
@ -123,14 +122,11 @@ export class OpenGroup {
// Try to connect to server // Try to connect to server
try { try {
if (onLoading) {
onLoading();
}
conversation = await PromiseUtils.timeout( conversation = await PromiseUtils.timeout(
window.attemptConnection(prefixedServer, channel), window.attemptConnection(prefixedServer, channel),
15000 20000
); );
if (!conversation) { if (!conversation) {
throw new Error(window.i18n('connectToServerFail')); throw new Error(window.i18n('connectToServerFail'));
} }

Loading…
Cancel
Save