Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

oldest_message is undefined #1692

Closed
laszlovl opened this issue Aug 28, 2019 · 1 comment

Comments

@laszlovl
Copy link
Contributor

commented Aug 28, 2019

TypeError: oldest_message is undefined converse-mam-views.js:49:28

Probably happens if this.model.messages.length > 0, but getOldestMessage() returns undefined because none of the message types match.

This obviously prevents the error, don't know if it masks a different error though.

diff --git a/src/converse-mam-views.js b/src/converse-mam-views.js
index 93775a2..b5a532d 100644
--- a/src/converse-mam-views.js
+++ b/src/converse-mam-views.js
@@ -37,17 +37,21 @@ converse.plugins.add('converse-mam-views', {
                 const { _converse } = this.__super__;
                 if (this.content.scrollTop === 0 && this.model.messages.length) {
                     const oldest_message = this.model.getOldestMessage();
-                    const by_jid = this.model.get('jid');
-                    const stanza_id = oldest_message && oldest_message.get(`stanza_id ${by_jid}`);
-                    this.addSpinner();
-                    if (stanza_id) {
-                        await this.model.fetchArchivedMessages({
-                            'before': stanza_id
-                        });
-                    } else {
-                        await this.model.fetchArchivedMessages({
-                            'end': oldest_message.get('time')
-                        });
+
+                    // oldest_message can be undefined despite model.messages.length > 0, because of the message_type check
+                    if (oldest_message) {
+                        const by_jid = this.model.get('jid');
+                        const stanza_id = oldest_message.get(`stanza_id ${by_jid}`);
+                        this.addSpinner();
+                        if (stanza_id) {
+                            await this.model.fetchArchivedMessages({
+                                'before': stanza_id
+                            });
+                        } else {
+                            await this.model.fetchArchivedMessages({
+                                'end': oldest_message.get('time')
+                            });
+                        }
@jcbrand jcbrand closed this in 46ccc1a Sep 6, 2019
@jcbrand

This comment has been minimized.

Copy link
Member

commented Sep 6, 2019

Thanks, your assessment was correct.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.