src/lib/Repositories/SolidLoaderRepository.js
/**
     * Finds all Messages in a URL.
     * @param {string} messageUrl: URL to inspect.
     * @returns {Promise}: a promise that resolves with an array of all messages found.
     */
Finds all Messages in a URL.
@param {string} messageUrl: URL to inspect.
@returns {Promise}: a promise that resolves with an array of all messages found.
Finds all Messages in a URL . @param { string } messageUrl : URL to inspect . @returns { Promise } : a promise that resolves with an array of all messages found .
async _findMessage(messageUrl) {
        const deferred = Q.defer();
        let results = [];
        const rdfjsSource = await this._getRDFjsSourceFromUrl(messageUrl);
        let nextMessageFound = false;
        const self = this;
        this.engine.query(`SELECT * {
		?message a <${namespaces.schema}Message>;
		<${namespaces.schema}dateSent> ?time;
		<${namespaces.schema}givenName> ?username;
		<${namespaces.schema}text> ?msgtext. }`, {
                sources: [{
                    type: "rdfjsSource",
                    value: rdfjsSource
                }]
            })
            .then(function(result) {
                result.bindingsStream.on("data", (data) => {
                    data = data.toObject();
                    if (data["?msgtext"]) {
                        if (data["?msgtext"].value.includes("data:image") ||
                            data["?msgtext"].value.includes("data:video") ||
                            data["?msgtext"].value.includes("data:text")
                        ) {
                            var messageText = data["?msgtext"].value;
                            var author = data["?username"].value.split("/").pop();
                            results.push({
                                messagetext: messageText,
                                url: data["?message"].value,
                                author: author.replace(/U\+0020/g, " "),
                                time: data["?time"].value.split("/")[4]
                            });
                        } else {
                            var txFields = data["?msgtext"].value.split("/");
                            var auFields = data["?username"].value.split("/");
                            var tmFields = data["?time"].value.split("/");
                            var messageText = self.encrypter.decrypt(txFields.splice(4, txFields.length).join("/"), false);
                            var authorr = self.encrypter.decrypt(auFields.splice(4, auFields.length).join("/"), false);
                            results.push({
                                messagetext: messageText,
                                url: data["?message"].value,
                                author: authorr,
                                time: self.encrypter.decrypt(tmFields.splice(4, tmFields.length).join("/"), false)
                            });
                        }
                    }
                });
                result.bindingsStream.on("end", function() {
                    deferred.resolve(results);
                });
            });
        return deferred.promise;
    }
async _findMessage ( messageUrl ) { const deferred = Q . defer ( ) ; let results = [ ] ; const rdfjsSource = await this . _getRDFjsSourceFromUrl ( messageUrl ) ; let nextMessageFound = false ; const self = this ; this . engine . query ( ` ${ namespaces . schema } ${ namespaces . schema } ${ namespaces . schema } ${ namespaces . schema } ` , { sources : [ { type : "rdfjsSource" , value : rdfjsSource } ] } ) . then ( function ( result ) { result . bindingsStream . on ( "data" , ( data ) => { data = data . toObject ( ) ; if ( data [ "?msgtext" ] ) { if ( data [ "?msgtext" ] . value . includes ( "data:image" ) || data [ "?msgtext" ] . value . includes ( "data:video" ) || data [ "?msgtext" ] . value . includes ( "data:text" ) ) { var messageText = data [ "?msgtext" ] . value ; var author = data [ "?username" ] . value . split ( "/" ) . pop ( ) ; results . push ( { messagetext : messageText , url : data [ "?message" ] . value , author : author . replace ( / U\+0020 / g , " " ) , time : data [ "?time" ] . value . split ( "/" ) [ 4 ] } ) ; } else { var txFields = data [ "?msgtext" ] . value . split ( "/" ) ; var auFields = data [ "?username" ] . value . split ( "/" ) ; var tmFields = data [ "?time" ] . value . split ( "/" ) ; var messageText = self . encrypter . decrypt ( txFields . splice ( 4 , txFields . length ) . join ( "/" ) , false ) ; var authorr = self . encrypter . decrypt ( auFields . splice ( 4 , auFields . length ) . join ( "/" ) , false ) ; results . push ( { messagetext : messageText , url : data [ "?message" ] . value , author : authorr , time : self . encrypter . decrypt ( tmFields . splice ( 4 , tmFields . length ) . join ( "/" ) , false ) } ) ; } } } ) ; result . bindingsStream . on ( "end" , function ( ) { deferred . resolve ( results ) ; } ) ; } ) ; return deferred . promise ; }
Finds all Messages in a URL.
Finds all Messages in a URL .