2018-02-19 22:36:00 +01:00
// This file is part of Friendiqa
2018-11-09 22:06:13 +01:00
// https://git.friendi.ca/lubuwest/Friendiqa
2020-05-24 21:14:23 +02:00
// Copyright (C) 2020 Marco R. <thomasschmidt45@gmx.net>
2018-02-19 22:36:00 +01:00
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// In addition, as a special exception, the copyright holders give
// permission to link the code of portions of this program with the
// OpenSSL library under certain conditions as described in each
// individual source file, and distribute linked combinations including
// the two.
//
// You must obey the GNU General Public License in all respects for all
// of the code used other than OpenSSL. If you modify file(s) with this
// exception, you may extend this exception to your version of the
// file(s), but you are not obligated to do so. If you do not wish to do
// so, delete this exception statement from your version. If you delete
// this exception statement from all source files in the program, then
// also delete it here.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
2018-10-01 21:17:54 +02:00
function findend ( text , startpos ) {
var indexOf = text . substring ( startpos || 0 ) . search ( /\s/ ) ;
2018-11-09 22:06:13 +01:00
return ( indexOf >= 0 ) ? ( indexOf + ( startpos || 0 ) ) : text . length ;
2018-10-01 21:17:54 +02:00
}
2020-01-27 21:53:51 +01:00
function beautify ( newsitemobject , msg ) {
var forumname = "" ;
2020-05-24 21:14:23 +02:00
try {
if ( newsitemobject . messagetype == 0 && newsitemobject . hasOwnProperty ( 'friendica_author' ) &&
2020-01-27 21:53:51 +01:00
( ( newsitemobject . friendica _author . url ) != ( newsitemobject . user . url ) ) && ( ( newsitemobject . friendica _author . url ) != null ) ) {
2020-05-24 21:14:23 +02:00
//print(" Friendica Author "+JSON.stringify(newsitemobject));
forumname = " via " + newsitemobject . user . name ;
newsitemobject . user = newsitemobject . friendica _author ;
}
if ( typeof ( newsitemobject . friendica _activities _self ) == "string" ) {
newsitemobject . friendica _activities _self = JSON . parse ( newsitemobject . friendica _activities _self ) ;
}
} catch ( e ) { print ( "forum name " + e ) }
var self = ( { } )
if ( newsitemobject . hasOwnProperty ( "friendica_activities_self" ) ) {
if ( newsitemobject . friendica _activities _self . indexOf ( 3 ) != - 1 ) { self . attending = qsTr ( "yes" ) }
if ( newsitemobject . friendica _activities _self . indexOf ( 4 ) != - 1 ) { self . attending = qsTr ( "no" ) }
if ( newsitemobject . friendica _activities _self . indexOf ( 5 ) != - 1 ) { self . attending = qsTr ( "maybe" ) }
if ( newsitemobject . friendica _activities _self . indexOf ( 1 ) != - 1 ) { self . liked = 1 }
if ( newsitemobject . friendica _activities _self . indexOf ( 2 ) != - 1 ) { self . disliked = 1 }
}
var friendica _activities = { self : self }
2021-05-12 21:41:34 +02:00
var imageAttachmentList = [ ] ;
var videoAttachmentList = [ ] ;
2020-01-27 21:53:51 +01:00
var videoformats = [ "mp4" , "avi" , "webm" , "ogg" , "mp3" ]
try { if ( newsitemobject . attachments ) {
var attachArray = newsitemobject . attachments ;
for ( var image in attachArray ) {
var attachhelper = { mimetype : attachArray [ image ] . mimetype }
2021-10-28 21:56:00 +02:00
var attachhelperstring = "<img" //Qt.btoa(attachArray[image].url)
2020-01-27 21:53:51 +01:00
var helperstringposition = newsitemobject . statusnet _html . indexOf ( attachhelperstring ) ;
2021-10-28 21:56:00 +02:00
// if (helperstringposition>-1){attachhelper.url=newsitemobject.statusnet_html.substring(newsitemobject.statusnet_html.lastIndexOf("http",helperstringposition),helperstringposition+attachhelperstring.length);
// if (attachArray[image].mimetype=="image/jpeg"){attachhelper.url=attachhelper.url+".jpg"}
// else if (attachArray[image].mimetype=="image/gif"){attachhelper.url=attachhelper.url+".gif"}
// else if (attachArray[image].mimetype=="image/png"){attachhelper.url=attachhelper.url+".png"}
// }
// else {
attachhelper . url = attachArray [ image ] . url
// }
if ( helperstringposition > - 1 ) { var removeme = newsitemobject . statusnet _html . substring ( helperstringposition , newsitemobject . statusnet _html . indexOf ( '">' , helperstringposition ) + 2 ) ; }
2020-01-27 21:53:51 +01:00
//print("Attachhelper "+attachhelper.url)
2021-10-28 21:56:00 +02:00
newsitemobject . statusnet _html = newsitemobject . statusnet _html . replace ( removeme , "" )
//newsitemobject.statusnet_html=newsitemobject.statusnet_html.replace(attachhelper.url.substring(0,attachhelper.url.length-4)+".jpeg","")
//newsitemobject.statusnet_html=newsitemobject.statusnet_html.replace(attachhelper.url.substring(0,attachhelper.url.length-4),"")
2021-05-18 21:01:32 +02:00
imageAttachmentList . push ( attachhelper )
2018-08-25 16:17:09 +02:00
}
2020-01-27 21:53:51 +01:00
}
} catch ( e ) { print ( "attachment " + e ) }
for ( var format in videoformats ) {
if ( newsitemobject . text . indexOf ( "." + videoformats [ format ] ) > - 1 ) {
var videohelper = { mimetype : "video/" + videoformats [ format ] }
var videotext = newsitemobject . text ;
while ( videotext . indexOf ( "." + videoformats [ format ] ) > - 1 ) {
var videohelperstringposition = videotext . indexOf ( "." + videoformats [ format ] ) ;
videohelper . url = videotext . substring ( videotext . lastIndexOf ( "http" , videohelperstringposition ) , videohelperstringposition + 4 ) ;
videotext = videotext . substring ( videohelperstringposition + 4 , videotext . length )
2021-05-12 21:41:34 +02:00
if ( ( videoAttachmentList . length == 0 ) || ( videoAttachmentList [ videoAttachmentList . length - 1 ] . url != videohelper . url ) ) { videoAttachmentList . push ( videohelper ) }
2018-10-01 21:17:54 +02:00
}
}
2020-01-27 21:53:51 +01:00
}
if ( newsitemobject . text . indexOf ( "/videos/watch/" ) > - 1 ) {
var ptvideohelper = { mimetype : "video/mp4" }
var ptvideotext = newsitemobject . text ;
while ( ptvideotext . indexOf ( "/videos/watch/" ) > - 1 ) {
var ptvideohelperstringposition = ptvideotext . indexOf ( "/videos/watch/" ) ;
var ptposend = findend ( ptvideotext , ptvideohelperstringposition ) ;
if ( ptposend == - 1 ) { ptposend = ptvideotext . length } ;
ptvideohelper . url = ptvideotext . substring ( ptvideotext . lastIndexOf ( "http" , ptvideohelperstringposition ) , ptposend ) + "-480.mp4" ;
ptvideohelper . url = ptvideohelper . url . replace ( "/videos/watch" , "/static/webseed" ) ;
ptvideotext = ptvideotext . substring ( ptposend , ptvideotext . length )
2021-05-12 21:41:34 +02:00
if ( ( videoAttachmentList . length == 0 ) || ( videoAttachmentList [ videoAttachmentList . length - 1 ] . url != ptvideohelper . url ) ) { videoAttachmentList . push ( ptvideohelper ) }
2020-01-27 21:53:51 +01:00
}
2020-05-24 21:14:23 +02:00
}
if ( newsitemobject . text . indexOf ( "youtube.com/watch?v" ) > - 1 ) {
2020-01-27 21:53:51 +01:00
var yttext = newsitemobject . text ;
while ( yttext . indexOf ( "youtube.com/watch?v" ) > - 1 ) {
var ythelperstringposition = yttext . indexOf ( "watch?v=" ) ;
var ytposend = findend ( yttext , ythelperstringposition ) ;
var ythelper = { mimetype : "video/youtube" }
ythelper . url = yttext . substring ( ythelperstringposition + 8 , ytposend ) ;
yttext = yttext . substring ( ytposend , yttext . length ) ;
2021-05-12 21:41:34 +02:00
if ( ( videoAttachmentList . length == 0 ) || ( videoAttachmentList [ videoAttachmentList . length - 1 ] . url != ythelper . url ) ) { videoAttachmentList . push ( ythelper ) }
2020-01-27 21:53:51 +01:00
}
2020-05-24 21:14:23 +02:00
}
2021-05-12 21:41:34 +02:00
newsitemobject . videoAttachmentList = videoAttachmentList ;
newsitemobject . imageAttachmentList = imageAttachmentList ;
2020-01-27 21:53:51 +01:00
if ( ( msg . options . hasOwnProperty ( "hide_nsfw" ) ) && ( msg . options . hide _nsfw == 1 ) && ( newsitemobject . text . indexOf ( "#nsfw" ) > - 1 ) ) {
newsitemobject . nsfw = true
} else { newsitemobject . nsfw = false }
2019-12-10 21:12:32 +01:00
2020-05-24 21:14:23 +02:00
newsitemobject . dateDiff = ( msg . currentTime - newsitemobject . created _at ) / 1000 ;
2020-01-27 21:53:51 +01:00
newsitemobject . friendica _activities _view = friendica _activities ;
newsitemobject . forumname = forumname ;
return newsitemobject ;
}
2019-12-10 21:12:32 +01:00
2017-11-07 21:57:40 +01:00
2020-01-27 21:53:51 +01:00
WorkerScript . onMessage = function ( msg ) {
if ( msg . deleteId !== undefined )
{ msg . model . remove ( msg . deleteId ) ;
msg . model . sync ( )
}
else {
2021-10-28 21:56:00 +02:00
if ( msg . method == "refresh" || msg . method == "contact" || ( msg . method == "conversation" && msg . news . length > 0 ) ) { msg . model . clear ( ) } ;
2020-01-27 21:53:51 +01:00
msg . model . sync ( )
2021-10-28 21:56:00 +02:00
//for (var j=0;j<msg.news.length;j++){
for ( var j in msg . news ) {
let data = ( { } )
2020-02-02 21:49:07 +01:00
if ( msg . news [ j ] ) {
var newsitemobject = msg . news [ j ] ;
newsitemobject = beautify ( newsitemobject , msg ) ;
2021-08-11 20:06:17 +02:00
if ( newsitemobject . hasOwnProperty ( "currentconversation" ) && ( newsitemobject . currentconversation . length > 0 ) ) {
2020-02-02 21:49:07 +01:00
newsitemobject . lastcomment = beautify ( newsitemobject . currentconversation [ newsitemobject . currentconversation . length - 1 ] , msg ) ;
2020-11-25 21:40:17 +01:00
newsitemobject . lastcomment . indent = 1
2021-10-28 21:56:00 +02:00
}
2020-05-24 21:14:23 +02:00
if ( msg . method == "conversation" ) {
if ( j == 0 ) { newsitemobject . indent = 0 } else {
for ( var k = msg . model . count - 1 ; k > - 1 ; k -- ) {
if ( newsitemobject . in _reply _to _status _id == msg . model . get ( k ) . newsitemobject . id ) {
2021-05-12 21:41:34 +02:00
newsitemobject . indent = ( msg . model . get ( k ) . newsitemobject . indent || 0 ) + 1 ;
2020-05-24 21:14:23 +02:00
if ( newsitemobject . indent > 6 ) { newsitemobject . indent = 6 } ;
2021-05-12 21:41:34 +02:00
}
2020-05-24 21:14:23 +02:00
}
} }
2021-10-28 21:56:00 +02:00
data = ( { "newsitemobject" : newsitemobject } )
2020-01-27 21:53:51 +01:00
}
2018-08-25 16:17:09 +02:00
if ( msg . method == "append" ) {
msg . model . insert ( j , data ) }
else {
2020-02-02 21:49:07 +01:00
msg . model . append ( data )
}
2017-11-07 21:57:40 +01:00
}
2021-10-28 21:56:00 +02:00
//if (j==msg.news.length){
2017-11-07 21:57:40 +01:00
msg . model . sync ( )
2021-10-28 21:56:00 +02:00
//}
2017-11-07 21:57:40 +01:00
}
2017-01-26 21:55:31 +01:00
}