Timeline.vue 55 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637
  1. <template>
  2. <div class="container" style="">
  3. <div v-if="layout === 'feed'" class="row">
  4. <div v-if="morePostsAvailable == true" class="col-12 mt-5 pt-3 mb-3 fixed-top">
  5. <p class="text-center">
  6. <button class="btn btn-dark px-4 rounded-pill font-weight-bold shadow" @click="syncNewPosts">Load New Posts</button>
  7. </p>
  8. </div>
  9. <div class="col-12 pl-3 pl-md-0 pt-3 pl-0">
  10. <div class="d-flex justify-content-between align-items-center">
  11. <p class="lead text-muted mb-0"><i :class="[scope == 'home' ? 'fas fa-home':'fas fa-stream']"></i> &nbsp; {{scope == 'local' ? 'Public' : 'Home'}} Timeline</p>
  12. <p class="mb-0">
  13. <a href="#" :class="[layout=='feed'?'font-weight-bold text-dark text-decoration-none':'font-weight-light text-muted text-decoration-none']" @click.prevent="switchFeedLayout('feed')"><i class="fas fa-list"></i> &nbsp; Feed</a>
  14. &nbsp; | &nbsp;
  15. <a href="#" :class="[layout!=='feed'?'font-weight-bold text-dark text-decoration-none':'font-weight-light text-muted text-decoration-none']" @click.prevent="switchFeedLayout('grid')"><i class="fas fa-th"></i> &nbsp; Grid</a>
  16. </p>
  17. </div>
  18. <hr>
  19. </div>
  20. <div :class="[modes.distractionFree ? 'col-md-8 col-lg-8 offset-md-2 px-0 mb-sm-3 timeline order-2 order-md-1':'col-md-8 col-lg-8 px-0 mb-sm-3 timeline order-2 order-md-1']">
  21. <div style="margin-top:-8px;">
  22. <story-component v-if="config.features.stories"></story-component>
  23. </div>
  24. <div>
  25. <div v-if="loading" class="text-center" style="padding-top:10px;">
  26. <div class="spinner-border" role="status">
  27. <span class="sr-only">Loading...</span>
  28. </div>
  29. </div>
  30. <div :data-status-id="status.id" v-for="(status, index) in feed" :key="`${index}-${status.id}`" class="pt-4">
  31. <div v-if="index == 0 && showTips && !loading" class="mb-4 card-tips">
  32. <announcements-card v-on:show-tips="showTips = $event"></announcements-card>
  33. </div>
  34. <div v-if="index == 2 && showSuggestions == true && suggestions.length" class="card mb-sm-4 status-card card-md-rounded-0 shadow-none border">
  35. <div class="card-header d-flex align-items-center justify-content-between bg-white border-0 pb-0">
  36. <h6 class="text-muted font-weight-bold mb-0">Suggestions For You</h6>
  37. <span class="cursor-pointer text-muted" v-on:click="hideSuggestions"><i class="fas fa-times"></i></span>
  38. </div>
  39. <div class="card-body row mx-0">
  40. <div class="col-12 col-md-4 mb-3" v-for="(rec, index) in suggestions">
  41. <div class="card">
  42. <div class="card-body text-center pt-3">
  43. <p class="mb-0">
  44. <a :href="'/'+rec.username">
  45. <img :src="rec.avatar" class="img-fluid rounded-circle cursor-pointer" width="45px" height="45px" onerror="this.onerror=null;this.src='/storage/avatars/default.png?v=2'" alt="avatar">
  46. </a>
  47. </p>
  48. <div class="py-3">
  49. <p class="font-weight-bold text-dark cursor-pointer mb-0">
  50. <a :href="'/'+rec.username" class="text-decoration-none text-dark">
  51. {{rec.username}}
  52. </a>
  53. </p>
  54. <p class="small text-muted mb-0">{{rec.message}}</p>
  55. </div>
  56. <p class="mb-0">
  57. <a class="btn btn-primary btn-block font-weight-bold py-0" href="#" @click.prevent="expRecFollow(rec.id, index)">Follow</a>
  58. </p>
  59. </div>
  60. </div>
  61. </div>
  62. </div>
  63. </div>
  64. <div v-if="index == 4 && showHashtagPosts && hashtagPosts.length" class="card mb-sm-4 status-card card-md-rounded-0 shadow-none border">
  65. <div class="card-header d-flex align-items-center justify-content-between bg-white border-0 pb-0">
  66. <span></span>
  67. <h6 class="text-muted font-weight-bold mb-0"><a :href="'/discover/tags/'+hashtagPostsName+'?src=tr'">#{{hashtagPostsName}}</a></h6>
  68. <span class="cursor-pointer text-muted" v-on:click="showHashtagPosts = false"><i class="fas fa-times"></i></span>
  69. </div>
  70. <div class="card-body row mx-0">
  71. <div v-for="(tag, index) in hashtagPosts" class="col-4 p-0 p-sm-2 p-md-3 hashtag-post-square">
  72. <a class="card info-overlay card-md-border-0" :href="tag.status.url">
  73. <div :class="[tag.status.filter ? 'square ' + tag.status.filter : 'square']">
  74. <div class="square-content" :style="'background-image: url('+tag.status.thumb+')'"></div>
  75. <div class="info-overlay-text">
  76. <h5 class="text-white m-auto font-weight-bold">
  77. <span class="pr-4">
  78. <span class="far fa-heart fa-lg pr-1"></span> {{tag.status.like_count}}
  79. </span>
  80. <span>
  81. <span class="fas fa-retweet fa-lg pr-1"></span> {{tag.status.share_count}}
  82. </span>
  83. </h5>
  84. </div>
  85. </div>
  86. </a>
  87. </div>
  88. </div>
  89. </div>
  90. <div class="card mb-sm-4 status-card card-md-rounded-0 shadow-none border">
  91. <div v-if="!modes.distractionFree && status" class="card-header d-inline-flex align-items-center bg-white">
  92. <!-- <img v-bind:src="status.account.avatar" width="38px" height="38px" class="cursor-pointer" style="border-radius: 38px;" @click="profileUrl(status)" onerror="this.onerror=null;this.src='/storage/avatars/default.png?v=2'"> -->
  93. <!-- <div v-if="hasStory" class="has-story has-story-sm cursor-pointer shadow-sm" @click="profileUrl(status)">
  94. <img class="rounded-circle box-shadow" :src="status.account.avatar" width="32px" height="32px" onerror="this.onerror=null;this.src='/storage/avatars/default.png?v=2'">
  95. </div>
  96. <div v-else> -->
  97. <div>
  98. <img class="rounded-circle box-shadow" :src="status.account.avatar" width="32px" height="32px" onerror="this.onerror=null;this.src='/storage/avatars/default.png?v=2'" alt="avatar">
  99. </div>
  100. <div class="pl-2">
  101. <!-- <a class="d-block username font-weight-bold text-dark" v-bind:href="status.account.url" style="line-height:0.5;"> -->
  102. <a class="username font-weight-bold text-dark text-decoration-none" v-bind:href="profileUrl(status)" v-html="statusCardUsernameFormat(status)">
  103. Loading...
  104. </a>
  105. <span v-if="status.account.is_admin" class="fa-stack" title="Admin Account" data-toggle="tooltip" style="height:1em; line-height:1em; max-width:19px;">
  106. <i class="fas fa-certificate text-danger fa-stack-1x"></i>
  107. <i class="fas fa-crown text-white fa-sm fa-stack-1x" style="font-size:7px;"></i>
  108. </span>
  109. <!-- <span v-if="scope != 'home' && status.account.id != profile.id && status.account.relationship">
  110. <span class="px-1">•</span>
  111. <span :class="'font-weight-bold cursor-pointer ' + [status.account.relationship.following == true ? 'text-muted' : 'text-primary']" @click="followAction(status)">{{status.account.relationship.following == true ? 'Following' : 'Follow'}}</span>
  112. </span> -->
  113. <!-- <span v-if="status.account.id != profile.id">
  114. <span class="px-1">•</span>
  115. <span class="font-weight-bold cursor-pointer text-primary">Follow</span>
  116. </span> -->
  117. <div class="d-flex align-items-center">
  118. <a v-if="status.place" class="small text-decoration-none text-muted" :href="'/discover/places/'+status.place.id+'/'+status.place.slug" title="Location" data-toggle="tooltip"><i class="fas fa-map-marked-alt"></i> {{status.place.name}}, {{status.place.country}}</a>
  119. </div>
  120. </div>
  121. <div class="text-right" style="flex-grow:1;">
  122. <button class="btn btn-link text-dark py-0" type="button" @click="ctxMenu(status)">
  123. <span class="fas fa-ellipsis-h text-lighter"></span>
  124. <span class="sr-only">Post Menu</span>
  125. </button>
  126. </div>
  127. </div>
  128. <div class="postPresenterContainer" style="background: #000;">
  129. <div v-if="status.pf_type === 'photo'" class="w-100">
  130. <photo-presenter :status="status" v-on:lightbox="lightbox"></photo-presenter>
  131. </div>
  132. <div v-else-if="status.pf_type === 'video'" class="w-100">
  133. <video-presenter :status="status"></video-presenter>
  134. </div>
  135. <div v-else-if="status.pf_type === 'photo:album'" class="w-100">
  136. <photo-album-presenter :status="status" v-on:lightbox="lightbox"></photo-album-presenter>
  137. </div>
  138. <div v-else-if="status.pf_type === 'video:album'" class="w-100">
  139. <video-album-presenter :status="status"></video-album-presenter>
  140. </div>
  141. <div v-else-if="status.pf_type === 'photo:video:album'" class="w-100">
  142. <mixed-album-presenter :status="status" v-on:lightbox="lightbox"></mixed-album-presenter>
  143. </div>
  144. <div v-else class="w-100">
  145. <p class="text-center p-0 font-weight-bold text-white">Error: Problem rendering preview.</p>
  146. </div>
  147. </div>
  148. <div class="card-body">
  149. <div v-if="!modes.distractionFree" class="reactions my-1 pb-2">
  150. <h3 v-bind:class="[status.favourited ? 'fas fa-heart text-danger pr-3 m-0 cursor-pointer' : 'far fa-heart pr-3 m-0 like-btn text-lighter cursor-pointer']" title="Like" v-on:click="likeStatus(status, $event)"></h3>
  151. <h3 v-if="!status.comments_disabled" class="far fa-comment text-lighter pr-3 m-0 cursor-pointer" title="Comment" v-on:click="commentFocus(status, $event)"></h3>
  152. <h3 v-if="status.visibility == 'public'" v-bind:class="[status.reblogged ? 'fas fa-retweet pr-3 m-0 text-primary cursor-pointer' : 'fas fa-retweet pr-3 m-0 text-lighter share-btn cursor-pointer']" title="Share" v-on:click="shareStatus(status, $event)"></h3>
  153. <h3 class="fas fa-expand pr-3 m-0 cursor-pointer text-lighter" v-on:click="lightbox(status)"></h3>
  154. <span v-if="status.taggedPeople.length" class="float-right">
  155. <span class="font-weight-light small" style="color:#718096">
  156. <i class="far fa-user" data-toggle="tooltip" title="Tagged People"></i>
  157. <span v-for="(tag, index) in status.taggedPeople" class="mr-n2">
  158. <a :href="'/'+tag.username">
  159. <img :src="tag.avatar" width="20px" height="20px" class="border rounded-circle" data-toggle="tooltip" :title="'@'+tag.username" alt="Avatar">
  160. </a>
  161. </span>
  162. </span>
  163. </span>
  164. </div>
  165. <div class="likes font-weight-bold" v-if="expLc(status) == true && !modes.distractionFree">
  166. <span class="like-count">{{status.favourites_count}}</span> {{status.favourites_count == 1 ? 'like' : 'likes'}}
  167. </div>
  168. <div class="caption">
  169. <p class="mb-2 read-more" style="overflow: hidden;">
  170. <span class="username font-weight-bold">
  171. <bdi><a class="text-dark" :href="profileUrl(status)">{{status.account.username}}</a></bdi>
  172. </span>
  173. <span class="status-content" v-html="status.content"></span>
  174. </p>
  175. </div>
  176. <div class="comments" v-if="status.id == replyId && !status.comments_disabled">
  177. <p class="mb-0 d-flex justify-content-between align-items-top read-more mt-2" style="overflow-y: hidden;" v-for="(reply, index) in replies">
  178. <span>
  179. <a class="text-dark font-weight-bold mr-1" :href="profileUrl(reply)">{{reply.account.username}}</a>
  180. <span v-html="reply.content" style="word-break: break-all;" class="comment-body"></span>
  181. </span>
  182. <span class="mb-0" style="min-width:38px">
  183. <span v-on:click="likeStatus(reply, $event)">
  184. <i v-bind:class="[reply.favourited ? 'fas fa-heart fa-sm text-danger cursor-pointer':'far fa-heart fa-sm text-lighter cursor-pointer']"></i>
  185. </span>
  186. <!-- <post-menu :status="reply" :profile="profile" size="sm" :modal="'true'" :feed="feed" class="d-inline-flex pl-2"></post-menu> -->
  187. <span class="text-lighter pl-2 cursor-pointer" @click="ctxMenu(reply)">
  188. <span class="fas fa-ellipsis-v text-lighter"></span>
  189. </span>
  190. </span>
  191. </p>
  192. </div>
  193. <div class="timestamp mt-2">
  194. <p class="small text-uppercase mb-0">
  195. <a :href="statusUrl(status)" class="text-muted">
  196. <timeago :datetime="status.created_at" :auto-update="60" :converter-options="{includeSeconds:true}" :title="timestampFormat(status.created_at)" v-b-tooltip.hover.bottom></timeago>
  197. </a>
  198. <a v-if="modes.distractionFree" class="float-right" :href="status.url">
  199. <i class="fas fa-ellipsis-h fa-lg text-muted"></i>
  200. </a>
  201. </p>
  202. </div>
  203. </div>
  204. <!--<div v-if="status.id == replyId && !status.comments_disabled" class="card-footer bg-white px-2 py-0">
  205. <ul class="nav align-items-center emoji-reactions" style="overflow-x: scroll;flex-wrap: unset;">
  206. <li class="nav-item" v-on:click="emojiReaction(status)" v-for="e in emoji">{{e}}</li>
  207. </ul>
  208. </div>-->
  209. <!--<div v-if="status.id == replyId && !status.comments_disabled" class="card-footer bg-white sticky-md-bottom p-0">
  210. <form class="border-0 rounded-0 align-middle" method="post" action="/i/comment" :data-id="status.id" data-truncate="false">
  211. <textarea class="form-control border-0 rounded-0" name="comment" placeholder="Add a comment…" autocomplete="off" autocorrect="off" style="height:56px;line-height: 18px;max-height:80px;resize: none; padding-right:4.2rem;" v-model="replyText"></textarea>
  212. <input type="button" value="Post" class="d-inline-block btn btn-link font-weight-bold reply-btn text-decoration-none" v-on:click.prevent="commentSubmit(status, $event)" :disabled="replyText.length == 0" />
  213. </form>
  214. </div>-->
  215. </div>
  216. </div>
  217. <div v-if="!loading && feed.length">
  218. <div class="card shadow-none">
  219. <div class="card-body">
  220. <infinite-loading @infinite="infiniteTimeline" :distance="800">
  221. <div slot="no-more" class="font-weight-bold">No more posts to load</div>
  222. <div slot="no-results" class="font-weight-bold">No more posts to load</div>
  223. </infinite-loading>
  224. </div>
  225. </div>
  226. </div>
  227. <div v-if="!loading && scope == 'home' && feed.length == 0">
  228. <div class="card shadow-none border">
  229. <div class="card-body text-center">
  230. <p class="h2 font-weight-lighter p-5">Hello, {{profile.acct}}</p>
  231. <p class="text-lighter"><i class="fas fa-camera-retro fa-5x"></i></p>
  232. <p class="h3 font-weight-lighter p-5">Start following people to build your timeline.</p>
  233. <p><a href="/discover" class="btn btn-primary font-weight-bold py-0">Discover new people and posts</a></p>
  234. </div>
  235. </div>
  236. </div>
  237. </div>
  238. </div>
  239. <div v-if="!modes.distractionFree" class="col-md-4 col-lg-4 my-3 order-1 order-md-2 d-none d-md-block">
  240. <div>
  241. <div class="mb-4">
  242. <div class="card shadow-none border">
  243. <div class="card-body pb-2">
  244. <div class="media d-flex align-items-center">
  245. <a :href="!userStory ? profile.url : '/stories/' + profile.acct" class="mr-3">
  246. <!-- <img class="mr-3 rounded-circle box-shadow" :src="profile.avatar || '/storage/avatars/default.png'" alt="avatar" width="64px" height="64px" onerror="this.onerror=null;this.src='/storage/avatars/default.png?v=2'"> -->
  247. <div v-if="userStory" class="has-story cursor-pointer shadow-sm" @click="storyRedirect()">
  248. <img class="rounded-circle box-shadow" :src="profile.avatar" width="64px" height="64px" onerror="this.onerror=null;this.src='/storage/avatars/default.png?v=2'" alt="avatar">
  249. </div>
  250. <div v-else>
  251. <img class="rounded-circle box-shadow" :src="profile.avatar" width="64px" height="64px" onerror="this.onerror=null;this.src='/storage/avatars/default.png?v=2'" alt="avatar">
  252. </div>
  253. </a>
  254. <div class="media-body d-flex justify-content-between word-break" >
  255. <div>
  256. <p class="mb-0 px-0 font-weight-bold"><a :href="profile.url" class="text-dark">{{profile.username || 'loading...'}}</a></p>
  257. <p class="my-0 text-muted pb-0">{{profile.display_name || 'loading...'}}</p>
  258. </div>
  259. <div class="ml-2">
  260. <a class="text-muted" href="/settings/home">
  261. <i class="fas fa-cog fa-lg"></i>
  262. <span class="sr-only">User Settings</span>
  263. </a>
  264. </div>
  265. </div>
  266. </div>
  267. </div>
  268. <div class="card-footer bg-transparent border-top mt-2 py-1">
  269. <div class="d-flex justify-content-between text-center">
  270. <span class="cursor-pointer" @click="redirect(profile.url)">
  271. <p class="mb-0 font-weight-bold">{{formatCount(profile.statuses_count)}}</p>
  272. <p class="mb-0 small text-muted">Posts</p>
  273. </span>
  274. <span class="cursor-pointer" @click="redirect(profile.url+'?md=followers')">
  275. <p class="mb-0 font-weight-bold">{{formatCount(profile.followers_count)}}</p>
  276. <p class="mb-0 small text-muted">Followers</p>
  277. </span>
  278. <span class="cursor-pointer" @click="redirect(profile.url+'?md=following')">
  279. <p class="mb-0 font-weight-bold">{{formatCount(profile.following_count)}}</p>
  280. <p class="mb-0 small text-muted">Following</p>
  281. </span>
  282. </div>
  283. </div>
  284. </div>
  285. </div>
  286. <div class="mb-4">
  287. <a class="btn btn-light btn-block btn-sm font-weight-bold text-dark mb-3 border bg-white" href="/i/compose" data-toggle="modal" data-target="#composeModal">
  288. <i class="far fa-plus-square pr-3 fa-lg pt-1"></i> Compose Post
  289. </a>
  290. </div>
  291. <div v-show="modes.notify == true && !loading" class="mb-4">
  292. <notification-card></notification-card>
  293. </div>
  294. <div v-show="showSuggestions == true && suggestions.length && config.ab && config.ab.rec == true" class="mb-4">
  295. <div class="card shadow-none border">
  296. <div class="card-header bg-white d-flex align-items-center justify-content-between">
  297. <a class="small text-muted cursor-pointer" href="#" @click.prevent="refreshSuggestions" ref="suggestionRefresh"><i class="fas fa-sync-alt"></i></a>
  298. <div class="small text-dark text-uppercase font-weight-bold">Suggestions</div>
  299. <div class="small text-muted cursor-pointer" v-on:click="hideSuggestions"><i class="fas fa-times"></i></div>
  300. </div>
  301. <div class="card-body pt-0">
  302. <div v-for="(rec, index) in suggestions" class="media align-items-center mt-3">
  303. <a :href="'/'+rec.username">
  304. <img :src="rec.avatar" width="32px" height="32px" class="rounded-circle mr-3" onerror="this.onerror=null;this.src='/storage/avatars/default.png?v=2'" alt="avatar">
  305. </a>
  306. <div class="media-body">
  307. <p class="mb-0 font-weight-bold small">
  308. <a :href="'/'+rec.username" class="text-decoration-none text-dark">
  309. {{rec.username}}
  310. </a>
  311. </p>
  312. <p class="mb-0 small text-muted">{{rec.message}}</p>
  313. </div>
  314. <a class="font-weight-bold small" href="#" @click.prevent="expRecFollow(rec.id, index)">Follow</a>
  315. </div>
  316. </div>
  317. </div>
  318. </div>
  319. <footer>
  320. <div class="container pb-5">
  321. <p class="mb-0 text-uppercase font-weight-bold text-muted small">
  322. <a href="/site/about" class="text-dark pr-2">About Us</a>
  323. <a href="/site/help" class="text-dark pr-2">Help</a>
  324. <a href="/site/language" class="text-dark pr-2">Language</a>
  325. <a href="/discover/profiles" class="text-dark pr-2">Profiles</a>
  326. <a href="/discover/places" class="text-dark pr-2">Places</a>
  327. <a href="/site/privacy" class="text-dark pr-2">Privacy</a>
  328. <a href="/site/terms" class="text-dark pr-2">Terms</a>
  329. </p>
  330. <p class="mb-0 text-uppercase font-weight-bold text-muted small">
  331. <a href="http://pixelfed.org" class="text-muted" rel="noopener" title="" data-toggle="tooltip">Powered by Pixelfed</a>
  332. </p>
  333. </div>
  334. </footer>
  335. </div>
  336. </div>
  337. </div>
  338. <div v-else class="row pt-2">
  339. <div class="col-12">
  340. <div v-if="loading" class="text-center">
  341. <div class="spinner-border" role="status">
  342. <span class="sr-only">Loading...</span>
  343. </div>
  344. </div>
  345. <div v-else class="row">
  346. <div class="col-12 pt-3">
  347. <div class="d-flex justify-content-between align-items-center">
  348. <p class="lead text-muted mb-0"><i :class="[scope == 'home' ? 'fas fa-home':'fas fa-stream']"></i> &nbsp; {{scope == 'local' ? 'Public' : 'Home'}} Timeline</p>
  349. <p class="mb-0">
  350. <a href="#" :class="[layout=='feed'?'font-weight-bold text-dark text-decoration-none':'font-weight-light text-muted text-decoration-none']" @click.prevent="switchFeedLayout('feed')"><i class="fas fa-list"></i> &nbsp; Feed</a>
  351. &nbsp; | &nbsp;
  352. <a href="#" :class="[layout!=='feed'?'font-weight-bold text-dark text-decoration-none':'font-weight-light text-muted text-decoration-none']" @click.prevent="switchFeedLayout('grid')"><i class="fas fa-th"></i> &nbsp; Grid</a>
  353. </p>
  354. </div>
  355. <hr>
  356. </div>
  357. <div class="col-12 col-md-4 p-1 p-md-3 mb-3" v-for="(s, index) in feed" :key="`${index}-${s.id}`">
  358. <a class="card info-overlay card-md-border-0 shadow-sm border border-light" :href="statusUrl(s)">
  359. <div :class="[s.sensitive ? 'square' : 'square ' + s.media_attachments[0].filter_class]">
  360. <span v-if="s.pf_type == 'photo:album'" class="float-right mr-3 post-icon"><i class="fas fa-images fa-2x"></i></span>
  361. <span v-if="s.pf_type == 'video'" class="float-right mr-3 post-icon"><i class="fas fa-video fa-2x"></i></span>
  362. <span v-if="s.pf_type == 'video:album'" class="float-right mr-3 post-icon"><i class="fas fa-film fa-2x"></i></span>
  363. <div class="square-content" v-bind:style="previewBackground(s)">
  364. </div>
  365. <div class="info-overlay-text px-4">
  366. <p class="text-white m-auto text-center">
  367. {{trimCaption(s.content_text)}}
  368. </p>
  369. </div>
  370. </div>
  371. </a>
  372. <div class="py-3 media align-items-center">
  373. <a class="text-decoration-none" :href="s.account.url"><img :src="s.account.avatar" class="mr-3 rounded-circle shadow-sm" :alt="s.account.username + ' \'s avatar'" width="30px" height="30px" onerror="this.onerror=null;this.src='/storage/avatars/default.png?v=2'"></a>
  374. <div class="media-body">
  375. <p class="mb-0 font-weight-bold small"><a class="text-dark" :href="s.account.url">{{s.account.username}}</a></p>
  376. <p class="mb-0" style="line-height: 0.7;">
  377. <a :href="statusUrl(s)" class="small text-lighter">
  378. <timeago :datetime="s.created_at" :auto-update="60" :converter-options="{includeSeconds:true}" :title="timestampFormat(s.created_at)" v-b-tooltip.hover.bottom></timeago>
  379. </a>
  380. </p>
  381. </div>
  382. <div class="ml-3">
  383. <p class="mb-0">
  384. <span v-if="statusOwner(s)" class="font-weight-bold small">{{s.favourites_count == 1 ? '1 like' : s.favourites_count+' likes'}}</span>
  385. <span class="px-2"><i v-bind:class="[s.favourited ? 'fas fa-heart text-danger cursor-pointer' : 'far fa-heart like-btn text-lighter cursor-pointer']" v-on:click="likeStatus(s, $event)"></i></span>
  386. <span class="mr-2 cursor-pointer"><i class="fas fa-ellipsis-v" @click="ctxMenu(s)"></i></span>
  387. </p>
  388. </div>
  389. </div>
  390. </div>
  391. </div>
  392. <div v-if="!loading && feed.length">
  393. <infinite-loading @infinite="infiniteTimeline" :distance="800">
  394. <div slot="no-more" class="font-weight-bold">No more posts to load</div>
  395. <div slot="no-results" class="font-weight-bold">No more posts to load</div>
  396. </infinite-loading>
  397. </div>
  398. </div>
  399. </div>
  400. <b-modal ref="ctxModal"
  401. id="ctx-modal"
  402. hide-header
  403. hide-footer
  404. centered
  405. rounded
  406. size="sm"
  407. body-class="list-group-flush p-0 rounded">
  408. <div class="list-group text-center">
  409. <div v-if="ctxMenuStatus && ctxMenuStatus.account.id != profile.id" class="list-group-item rounded cursor-pointer font-weight-bold text-danger" @click="ctxMenuReportPost()">Report inappropriate</div>
  410. <div v-if="ctxMenuStatus && ctxMenuStatus.account.id != profile.id && ctxMenuRelationship && ctxMenuRelationship.following" class="list-group-item rounded cursor-pointer font-weight-bold text-danger" @click="ctxMenuUnfollow()">Unfollow</div>
  411. <div v-if="ctxMenuStatus && ctxMenuStatus.account.id != profile.id && ctxMenuRelationship && !ctxMenuRelationship.following" class="list-group-item rounded cursor-pointer font-weight-bold text-primary" @click="ctxMenuFollow()">Follow</div>
  412. <div class="list-group-item rounded cursor-pointer" @click="ctxMenuGoToPost()">Go to post</div>
  413. <div v-if="ctxMenuStatus && ctxMenuStatus.local == true" class="list-group-item rounded cursor-pointer" @click="ctxMenuEmbed()">Embed</div>
  414. <!-- <div class="list-group-item rounded cursor-pointer" @click="ctxMenuShare()">Share</div> -->
  415. <div class="list-group-item rounded cursor-pointer" @click="ctxMenuCopyLink()">Copy Link</div>
  416. <div v-if="profile && profile.is_admin == true" class="list-group-item rounded cursor-pointer" @click="ctxModMenuShow()">Moderation Tools</div>
  417. <div v-if="ctxMenuStatus && (profile.is_admin || profile.id == ctxMenuStatus.account.id)" class="list-group-item rounded cursor-pointer" @click="deletePost(ctxMenuStatus)">Delete</div>
  418. <div class="list-group-item rounded cursor-pointer text-lighter" @click="closeCtxMenu()">Cancel</div>
  419. </div>
  420. </b-modal>
  421. <b-modal ref="ctxModModal"
  422. id="ctx-mod-modal"
  423. hide-header
  424. hide-footer
  425. centered
  426. rounded
  427. size="sm"
  428. body-class="list-group-flush p-0 rounded">
  429. <div class="list-group text-center">
  430. <div class="list-group-item rounded cursor-pointer" @click="moderatePost(ctxMenuStatus, 'unlist')">Unlist from Timelines</div>
  431. <div v-if="ctxMenuStatus.sensitive" class="list-group-item rounded cursor-pointer" @click="moderatePost(ctxMenuStatus, 'remcw')">Remove Content Warning</div>
  432. <div v-else class="list-group-item rounded cursor-pointer" @click="moderatePost(ctxMenuStatus, 'addcw')">Add Content Warning</div>
  433. <div class="list-group-item rounded cursor-pointer text-lighter" @click="ctxModMenuClose()">Cancel</div>
  434. </div>
  435. </b-modal>
  436. <b-modal ref="ctxShareModal"
  437. id="ctx-share-modal"
  438. title="Share"
  439. hide-footer
  440. centered
  441. rounded
  442. size="sm"
  443. body-class="list-group-flush p-0 rounded text-center">
  444. <div class="list-group-item rounded cursor-pointer border-top-0">Email</div>
  445. <div class="list-group-item rounded cursor-pointer">Facebook</div>
  446. <div class="list-group-item rounded cursor-pointer">Mastodon</div>
  447. <div class="list-group-item rounded cursor-pointer">Pinterest</div>
  448. <div class="list-group-item rounded cursor-pointer">Pixelfed</div>
  449. <div class="list-group-item rounded cursor-pointer">Twitter</div>
  450. <div class="list-group-item rounded cursor-pointer">VK</div>
  451. <div class="list-group-item rounded cursor-pointer text-lighter" @click="closeCtxShareMenu()">Cancel</div>
  452. </b-modal>
  453. <b-modal ref="ctxEmbedModal"
  454. id="ctx-embed-modal"
  455. hide-header
  456. hide-footer
  457. centered
  458. rounded
  459. size="md"
  460. body-class="p-2 rounded">
  461. <div>
  462. <div class="form-group">
  463. <textarea class="form-control disabled text-monospace" rows="8" style="overflow-y:hidden;border: 1px solid #efefef; font-size: 12px; line-height: 18px; margin: 0 0 7px;resize:none;" v-model="ctxEmbedPayload" disabled=""></textarea>
  464. </div>
  465. <div class="form-group pl-2 d-flex justify-content-center">
  466. <div class="form-check mr-3">
  467. <input class="form-check-input" type="checkbox" v-model="ctxEmbedShowCaption" :disabled="ctxEmbedCompactMode == true">
  468. <label class="form-check-label font-weight-light">
  469. Show Caption
  470. </label>
  471. </div>
  472. <div class="form-check mr-3">
  473. <input class="form-check-input" type="checkbox" v-model="ctxEmbedShowLikes" :disabled="ctxEmbedCompactMode == true">
  474. <label class="form-check-label font-weight-light">
  475. Show Likes
  476. </label>
  477. </div>
  478. <div class="form-check">
  479. <input class="form-check-input" type="checkbox" v-model="ctxEmbedCompactMode">
  480. <label class="form-check-label font-weight-light">
  481. Compact Mode
  482. </label>
  483. </div>
  484. </div>
  485. <hr>
  486. <button :class="copiedEmbed ? 'btn btn-primary btn-block btn-sm py-1 font-weight-bold disabed': 'btn btn-primary btn-block btn-sm py-1 font-weight-bold'" @click="ctxCopyEmbed" :disabled="copiedEmbed">{{copiedEmbed ? 'Embed Code Copied!' : 'Copy Embed Code'}}</button>
  487. <p class="mb-0 px-2 small text-muted">By using this embed, you agree to our <a href="/site/terms">Terms of Use</a></p>
  488. </div>
  489. </b-modal>
  490. <b-modal
  491. id="lightbox"
  492. ref="lightboxModal"
  493. hide-header
  494. hide-footer
  495. centered
  496. size="lg"
  497. body-class="p-0"
  498. >
  499. <div v-if="lightboxMedia" :class="lightboxMedia.filter_class" class="w-100 h-100">
  500. <img :src="lightboxMedia.url" style="max-height: 100%; max-width: 100%" alt="lightbox media">
  501. </div>
  502. </b-modal>
  503. <b-modal ref="replyModal"
  504. id="ctx-reply-modal"
  505. hide-footer
  506. centered
  507. rounded
  508. :title-html="replyStatus.account ? 'Reply to <span class=text-dark>' + replyStatus.account.username + '</span>' : ''"
  509. title-tag="p"
  510. title-class="font-weight-bold text-muted"
  511. size="md"
  512. body-class="p-2 rounded">
  513. <div>
  514. <textarea class="form-control" rows="4" style="border: none; font-size: 18px; resize: none; white-space: pre-wrap;outline: none;" placeholder="Reply here ..." v-model="replyText">
  515. </textarea>
  516. <div class="border-top border-bottom my-2">
  517. <ul class="nav align-items-center emoji-reactions" style="overflow-x: scroll;flex-wrap: unset;">
  518. <li class="nav-item" v-on:click="emojiReaction(status)" v-for="e in emoji">{{e}}</li>
  519. </ul>
  520. </div>
  521. <div class="d-flex justify-content-between align-items-center">
  522. <div>
  523. <span class="pl-2 small text-muted font-weight-bold text-monospace">
  524. <span :class="[replyText.length > config.uploader.max_caption_length ? 'text-danger':'text-dark']">{{replyText.length > config.uploader.max_caption_length ? config.uploader.max_caption_length - replyText.length : replyText.length}}</span>/{{config.uploader.max_caption_length}}
  525. </span>
  526. </div>
  527. <div class="d-flex align-items-center">
  528. <!-- <select class="custom-select custom-select-sm my-0 mr-2">
  529. <option value="public" selected="">Public</option>
  530. <option value="unlisted">Unlisted</option>
  531. <option value="followers">Followers Only</option>
  532. </select> -->
  533. <button class="btn btn-primary btn-sm py-2 px-4 lead text-uppercase font-weight-bold" v-on:click.prevent="commentSubmit(status, $event)" :disabled="replyText.length == 0">
  534. {{replySending == true ? 'POSTING' : 'POST'}}
  535. </button>
  536. </div>
  537. </div>
  538. </div>
  539. </b-modal>
  540. </div>
  541. </template>
  542. <style type="text/css" scoped>
  543. .postPresenterContainer {
  544. display: flex;
  545. align-items: center;
  546. background: #fff;
  547. }
  548. .word-break {
  549. word-break: break-all;
  550. }
  551. .small .custom-control-label {
  552. padding-top: 3px;
  553. }
  554. .reply-btn {
  555. position: absolute;
  556. bottom: 12px;
  557. right: 20px;
  558. width: 60px;
  559. text-align: center;
  560. border-radius: 0 3px 3px 0;
  561. }
  562. .emoji-reactions .nav-item {
  563. font-size: 1.2rem;
  564. padding: 9px;
  565. cursor: pointer;
  566. }
  567. .emoji-reactions::-webkit-scrollbar {
  568. width: 0px;
  569. height: 0px;
  570. background: transparent;
  571. }
  572. .reply-btn[disabled] {
  573. opacity: .3;
  574. color: #3897f0;
  575. }
  576. .has-story {
  577. width: 64px;
  578. height: 64px;
  579. border-radius: 50%;
  580. padding: 2px;
  581. background: radial-gradient(ellipse at 70% 70%, #ee583f 8%, #d92d77 42%, #bd3381 58%);
  582. }
  583. .has-story img {
  584. width: 60px;
  585. height: 60px;
  586. border-radius: 50%;
  587. padding: 3px;
  588. background: #fff;
  589. }
  590. .has-story.has-story-sm {
  591. width: 32px;
  592. height: 32px;
  593. border-radius: 50%;
  594. padding: 2px;
  595. background: radial-gradient(ellipse at 70% 70%, #ee583f 8%, #d92d77 42%, #bd3381 58%);
  596. }
  597. .has-story.has-story-sm img {
  598. width: 28px;
  599. height: 28px;
  600. border-radius: 50%;
  601. padding: 3px;
  602. background: #fff;
  603. }
  604. #ctx-reply-modal .form-control:focus {
  605. border: none;
  606. outline: 0;
  607. box-shadow: none;
  608. }
  609. </style>
  610. <script type="text/javascript">
  611. export default {
  612. props: ['scope', 'layout'],
  613. data() {
  614. return {
  615. ids: [],
  616. config: window.App.config,
  617. page: 2,
  618. feed: [],
  619. profile: {},
  620. min_id: 0,
  621. max_id: 0,
  622. suggestions: {},
  623. loading: true,
  624. replies: [],
  625. replyId: null,
  626. modes: {
  627. 'mod': false,
  628. 'dark': false,
  629. 'notify': true,
  630. 'distractionFree': false
  631. },
  632. followers: [],
  633. followerCursor: 1,
  634. followerMore: true,
  635. following: [],
  636. followingCursor: 1,
  637. followingMore: true,
  638. lightboxMedia: false,
  639. showSuggestions: true,
  640. showReadMore: true,
  641. replyStatus: {},
  642. replyText: '',
  643. emoji: window.App.util.emoji,
  644. showHashtagPosts: false,
  645. hashtagPosts: [],
  646. hashtagPostsName: '',
  647. ctxMenuStatus: false,
  648. ctxMenuRelationship: false,
  649. ctxEmbedPayload: false,
  650. copiedEmbed: false,
  651. showTips: true,
  652. userStory: false,
  653. replySending: false,
  654. ctxEmbedShowCaption: true,
  655. ctxEmbedShowLikes: false,
  656. ctxEmbedCompactMode: false,
  657. morePostsAvailable: false,
  658. mpCount: 0,
  659. mpData: false,
  660. mpInterval: 15000,
  661. mpEnabled: false,
  662. mpPoller: null
  663. }
  664. },
  665. watch: {
  666. ctxEmbedShowCaption: function (n,o) {
  667. if(n == true) {
  668. this.ctxEmbedCompactMode = false;
  669. }
  670. let mode = this.ctxEmbedCompactMode ? 'compact' : 'full';
  671. this.ctxEmbedPayload = window.App.util.embed.post(this.ctxMenuStatus.url, this.ctxEmbedShowCaption, this.ctxEmbedShowLikes, mode);
  672. },
  673. ctxEmbedShowLikes: function (n,o) {
  674. if(n == true) {
  675. this.ctxEmbedCompactMode = false;
  676. }
  677. let mode = this.ctxEmbedCompactMode ? 'compact' : 'full';
  678. this.ctxEmbedPayload = window.App.util.embed.post(this.ctxMenuStatus.url, this.ctxEmbedShowCaption, this.ctxEmbedShowLikes, mode);
  679. },
  680. ctxEmbedCompactMode: function (n,o) {
  681. if(n == true) {
  682. this.ctxEmbedShowCaption = false;
  683. this.ctxEmbedShowLikes = false;
  684. }
  685. let mode = this.ctxEmbedCompactMode ? 'compact' : 'full';
  686. this.ctxEmbedPayload = window.App.util.embed.post(this.ctxMenuStatus.url, this.ctxEmbedShowCaption, this.ctxEmbedShowLikes, mode);
  687. }
  688. },
  689. beforeMount() {
  690. this.fetchProfile();
  691. this.fetchTimelineApi();
  692. },
  693. mounted() {
  694. if(window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches || $('link[data-stylesheet="dark"]').length != 0) {
  695. this.modes.dark = true;
  696. // todo: release after dark mode updates
  697. /* let el = document.querySelector('link[data-stylesheet="light"]');
  698. el.setAttribute('href', '/css/appdark.css?id=' + Date.now());
  699. el.setAttribute('data-stylesheet', 'dark'); */
  700. }
  701. if(localStorage.getItem('pf_metro_ui.exp.rec') == 'false') {
  702. this.showSuggestions = false;
  703. } else {
  704. this.showSuggestions = true;
  705. }
  706. if(localStorage.getItem('pf_metro_ui.exp.rm') == 'false') {
  707. this.showReadMore = false;
  708. } else {
  709. this.showReadMore = true;
  710. }
  711. if(localStorage.getItem('pf_metro_ui.exp.df') == 'true') {
  712. this.modes.distractionFree = true;
  713. } else {
  714. this.modes.distractionFree = false;
  715. }
  716. if(localStorage.getItem('metro-tips') == 'false') {
  717. this.showTips = false;
  718. }
  719. this.$nextTick(function () {
  720. $('[data-toggle="tooltip"]').tooltip();
  721. let u = new URLSearchParams(window.location.search);
  722. if(u.has('a') && u.get('a') == 'co') {
  723. $('#composeModal').modal('show');
  724. }
  725. });
  726. },
  727. updated() {
  728. if(this.showReadMore == true) {
  729. pixelfed.readmore();
  730. }
  731. },
  732. methods: {
  733. fetchProfile() {
  734. axios.get('/api/pixelfed/v1/accounts/verify_credentials').then(res => {
  735. this.profile = res.data;
  736. if(this.profile.is_admin == true) {
  737. this.modes.mod = true;
  738. }
  739. window._sharedData.curUser = res.data;
  740. this.hasStory();
  741. // this.expRec();
  742. }).catch(err => {
  743. swal(
  744. 'Oops, something went wrong',
  745. 'Please reload the page.',
  746. 'error'
  747. );
  748. });
  749. },
  750. fetchTimelineApi() {
  751. let apiUrl = false;
  752. switch(this.scope) {
  753. case 'home':
  754. apiUrl = '/api/pixelfed/v1/timelines/home';
  755. break;
  756. case 'local':
  757. apiUrl = '/api/pixelfed/v1/timelines/public';
  758. break;
  759. case 'network':
  760. apiUrl = '/api/pixelfed/v1/timelines/network';
  761. break;
  762. }
  763. axios.get(apiUrl, {
  764. params: {
  765. max_id: this.max_id,
  766. limit: 3
  767. }
  768. }).then(res => {
  769. let data = res.data;
  770. this.feed.push(...data);
  771. let ids = data.map(status => status.id);
  772. this.ids = ids;
  773. this.min_id = Math.max(...ids).toString();
  774. this.max_id = Math.min(...ids).toString();
  775. this.loading = false;
  776. $('.timeline .pagination').removeClass('d-none');
  777. // if(this.feed.length == 4) {
  778. // this.fetchTimelineApi();
  779. // }
  780. if(this.hashtagPosts.length == 0) {
  781. this.fetchHashtagPosts();
  782. }
  783. // this.fetchStories();
  784. this.rtw();
  785. }).catch(err => {
  786. swal(
  787. 'Oops, something went wrong',
  788. 'Please reload the page.',
  789. 'error'
  790. );
  791. });
  792. },
  793. infiniteTimeline($state) {
  794. if(this.loading) {
  795. $state.complete();
  796. return;
  797. }
  798. if(this.page > 40) {
  799. this.loading = false;
  800. $state.complete();
  801. }
  802. let apiUrl = false;
  803. switch(this.scope) {
  804. case 'home':
  805. apiUrl = '/api/pixelfed/v1/timelines/home';
  806. break;
  807. case 'local':
  808. apiUrl = '/api/pixelfed/v1/timelines/public';
  809. break;
  810. case 'network':
  811. apiUrl = '/api/pixelfed/v1/timelines/network';
  812. break;
  813. }
  814. axios.get(apiUrl, {
  815. params: {
  816. max_id: this.max_id,
  817. limit: 6
  818. },
  819. }).then(res => {
  820. if (res.data.length && this.loading == false) {
  821. let data = res.data;
  822. let self = this;
  823. data.forEach((d, index) => {
  824. if(self.ids.indexOf(d.id) == -1) {
  825. self.feed.push(d);
  826. self.ids.push(d.id);
  827. }
  828. });
  829. this.min_id = Math.max(...this.ids).toString();
  830. this.max_id = Math.min(...this.ids).toString();
  831. this.page += 1;
  832. $state.loaded();
  833. this.loading = false;
  834. } else {
  835. $state.complete();
  836. }
  837. }).catch(err => {
  838. this.loading = false;
  839. $state.complete();
  840. });
  841. },
  842. reportUrl(status) {
  843. let type = status.in_reply_to ? 'comment' : 'post';
  844. let id = status.id;
  845. return '/i/report?type=' + type + '&id=' + id;
  846. },
  847. commentFocus(status, $event) {
  848. if(status.comments_disabled) {
  849. return;
  850. }
  851. this.status = status;
  852. this.replies = {};
  853. this.replyStatus = {};
  854. this.replyText = '';
  855. this.replyId = status.id;
  856. this.replyStatus = status;
  857. this.$refs.replyModal.show();
  858. this.fetchStatusComments(status, '');
  859. return;
  860. },
  861. likeStatus(status) {
  862. if($('body').hasClass('loggedIn') == false) {
  863. return;
  864. }
  865. let count = status.favourites_count;
  866. status.favourited = !status.favourited;
  867. axios.post('/i/like', {
  868. item: status.id
  869. }).then(res => {
  870. status.favourites_count = res.data.count;
  871. }).catch(err => {
  872. status.favourited = !status.favourited;
  873. status.favourites_count = count;
  874. swal('Error', 'Something went wrong, please try again later.', 'error');
  875. });
  876. },
  877. shareStatus(status, $event) {
  878. if($('body').hasClass('loggedIn') == false) {
  879. return;
  880. }
  881. axios.post('/i/share', {
  882. item: status.id
  883. }).then(res => {
  884. status.reblogs_count = res.data.count;
  885. status.reblogged = !status.reblogged;
  886. }).catch(err => {
  887. swal('Error', 'Something went wrong, please try again later.', 'error');
  888. });
  889. },
  890. timestampFormat(timestamp) {
  891. let ts = new Date(timestamp);
  892. return ts.toDateString() + ' ' + ts.toLocaleTimeString();
  893. },
  894. redirect(url) {
  895. window.location.href = url;
  896. return;
  897. },
  898. statusOwner(status) {
  899. let sid = status.account.id;
  900. let uid = this.profile.id;
  901. if(sid == uid) {
  902. return true;
  903. } else {
  904. return false;
  905. }
  906. },
  907. fetchStatusComments(status, card) {
  908. axios.get('/api/v2/status/'+status.id+'/replies')
  909. .then(res => {
  910. let data = res.data.filter(res => {
  911. return res.sensitive == false;
  912. });
  913. this.replies = _.reverse(data);
  914. setTimeout(function() {
  915. document.querySelectorAll('.comments .comment-body a').forEach(function(i, e) {
  916. if(i.href.startsWith(window.location.origin)) {
  917. return;
  918. }
  919. let tag = i.innerText;
  920. if(tag.startsWith('#')) {
  921. tag = tag.substr(1);
  922. }
  923. i.href = '/discover/tags/'+tag+'?src=rph';
  924. });
  925. }, 500);
  926. }).catch(err => {
  927. })
  928. },
  929. muteProfile(status) {
  930. if($('body').hasClass('loggedIn') == false) {
  931. return;
  932. }
  933. axios.post('/i/mute', {
  934. type: 'user',
  935. item: status.account.id
  936. }).then(res => {
  937. this.feed = this.feed.filter(s => s.account.id !== status.account.id);
  938. swal('Success', 'You have successfully muted ' + status.account.acct, 'success');
  939. }).catch(err => {
  940. swal('Error', 'Something went wrong. Please try again later.', 'error');
  941. });
  942. },
  943. blockProfile(status) {
  944. if($('body').hasClass('loggedIn') == false) {
  945. return;
  946. }
  947. axios.post('/i/block', {
  948. type: 'user',
  949. item: status.account.id
  950. }).then(res => {
  951. this.feed = this.feed.filter(s => s.account.id !== status.account.id);
  952. swal('Success', 'You have successfully blocked ' + status.account.acct, 'success');
  953. }).catch(err => {
  954. swal('Error', 'Something went wrong. Please try again later.', 'error');
  955. });
  956. },
  957. deletePost(status) {
  958. if($('body').hasClass('loggedIn') == false || this.ownerOrAdmin(status) == false) {
  959. return;
  960. }
  961. if(window.confirm('Are you sure you want to delete this post?') == false) {
  962. return;
  963. }
  964. axios.post('/i/delete', {
  965. type: 'status',
  966. item: status.id
  967. }).then(res => {
  968. this.feed = this.feed.filter(s => {
  969. return s.id != status.id;
  970. });
  971. this.$refs.ctxModal.hide();
  972. }).catch(err => {
  973. swal('Error', 'Something went wrong. Please try again later.', 'error');
  974. });
  975. },
  976. commentSubmit(status, $event) {
  977. this.replySending = true;
  978. let id = status.id;
  979. let comment = this.replyText;
  980. let limit = this.config.uploader.max_caption_length;
  981. if(comment.length > limit) {
  982. this.replySending = false;
  983. swal('Comment Too Long', 'Please make sure your comment is '+limit+' characters or less.', 'error');
  984. return;
  985. }
  986. axios.post('/i/comment', {
  987. item: id,
  988. comment: comment
  989. }).then(res => {
  990. this.replyText = '';
  991. this.replies.unshift(res.data.entity);
  992. this.$refs.replyModal.hide();
  993. });
  994. this.replySending = false;
  995. },
  996. moderatePost(status, action, $event) {
  997. let username = status.account.username;
  998. let msg = '';
  999. let self = this;
  1000. switch(action) {
  1001. case 'addcw':
  1002. msg = 'Are you sure you want to add a content warning to this post?';
  1003. swal({
  1004. title: 'Confirm',
  1005. text: msg,
  1006. icon: 'warning',
  1007. buttons: true,
  1008. dangerMode: true
  1009. }).then(res => {
  1010. if(res) {
  1011. axios.post('/api/v2/moderator/action', {
  1012. action: action,
  1013. item_id: status.id,
  1014. item_type: 'status'
  1015. }).then(res => {
  1016. swal('Success', 'Successfully added content warning', 'success');
  1017. status.sensitive = true;
  1018. self.ctxModMenuClose();
  1019. }).catch(err => {
  1020. swal(
  1021. 'Error',
  1022. 'Something went wrong, please try again later.',
  1023. 'error'
  1024. );
  1025. self.ctxModMenuClose();
  1026. });
  1027. }
  1028. });
  1029. break;
  1030. case 'remcw':
  1031. msg = 'Are you sure you want to remove the content warning on this post?';
  1032. swal({
  1033. title: 'Confirm',
  1034. text: msg,
  1035. icon: 'warning',
  1036. buttons: true,
  1037. dangerMode: true
  1038. }).then(res => {
  1039. if(res) {
  1040. axios.post('/api/v2/moderator/action', {
  1041. action: action,
  1042. item_id: status.id,
  1043. item_type: 'status'
  1044. }).then(res => {
  1045. swal('Success', 'Successfully added content warning', 'success');
  1046. status.sensitive = false;
  1047. self.ctxModMenuClose();
  1048. }).catch(err => {
  1049. swal(
  1050. 'Error',
  1051. 'Something went wrong, please try again later.',
  1052. 'error'
  1053. );
  1054. self.ctxModMenuClose();
  1055. });
  1056. }
  1057. });
  1058. break;
  1059. case 'unlist':
  1060. msg = 'Are you sure you want to unlist this post?';
  1061. swal({
  1062. title: 'Confirm',
  1063. text: msg,
  1064. icon: 'warning',
  1065. buttons: true,
  1066. dangerMode: true
  1067. }).then(res => {
  1068. if(res) {
  1069. axios.post('/api/v2/moderator/action', {
  1070. action: action,
  1071. item_id: status.id,
  1072. item_type: 'status'
  1073. }).then(res => {
  1074. this.feed = this.feed.filter(f => {
  1075. return f.id != status.id;
  1076. });
  1077. swal('Success', 'Successfully unlisted post', 'success');
  1078. self.ctxModMenuClose();
  1079. }).catch(err => {
  1080. self.ctxModMenuClose();
  1081. swal(
  1082. 'Error',
  1083. 'Something went wrong, please try again later.',
  1084. 'error'
  1085. );
  1086. });
  1087. }
  1088. });
  1089. break;
  1090. }
  1091. },
  1092. followingModal() {
  1093. if(this.following.length > 0) {
  1094. this.$refs.followingModal.show();
  1095. return;
  1096. }
  1097. axios.get('/api/pixelfed/v1/accounts/'+this.profile.id+'/following', {
  1098. params: {
  1099. page: this.followingCursor
  1100. }
  1101. })
  1102. .then(res => {
  1103. this.following = res.data;
  1104. this.followingCursor++;
  1105. });
  1106. if(res.data.length < 10) {
  1107. this.followingMore = false;
  1108. }
  1109. this.$refs.followingModal.show();
  1110. },
  1111. followersModal() {
  1112. if(this.followers.length > 0) {
  1113. this.$refs.followerModal.show();
  1114. return;
  1115. }
  1116. axios.get('/api/pixelfed/v1/accounts/'+this.profile.id+'/followers', {
  1117. params: {
  1118. page: this.followerCursor
  1119. }
  1120. })
  1121. .then(res => {
  1122. this.followers = res.data;
  1123. this.followerCursor++;
  1124. })
  1125. if(res.data.length < 10) {
  1126. this.followerMore = false;
  1127. }
  1128. this.$refs.followerModal.show();
  1129. },
  1130. followingLoadMore() {
  1131. axios.get('/api/pixelfed/v1/accounts/'+this.profile.id+'/following', {
  1132. params: {
  1133. page: this.followingCursor
  1134. }
  1135. })
  1136. .then(res => {
  1137. if(res.data.length > 0) {
  1138. this.following.push(...res.data);
  1139. this.followingCursor++;
  1140. }
  1141. if(res.data.length < 10) {
  1142. this.followingMore = false;
  1143. }
  1144. });
  1145. },
  1146. followersLoadMore() {
  1147. axios.get('/api/pixelfed/v1/accounts/'+this.profile.id+'/followers', {
  1148. params: {
  1149. page: this.followerCursor
  1150. }
  1151. })
  1152. .then(res => {
  1153. if(res.data.length > 0) {
  1154. this.followers.push(...res.data);
  1155. this.followerCursor++;
  1156. }
  1157. if(res.data.length < 10) {
  1158. this.followerMore = false;
  1159. }
  1160. });
  1161. },
  1162. lightbox(status) {
  1163. window.location.href = status.media_attachments[0].url;
  1164. return;
  1165. this.lightboxMedia = status.media_attachments[0];
  1166. this.$refs.lightboxModal.show();
  1167. },
  1168. expLc(status) {
  1169. if(this.config.ab.lc == false) {
  1170. return true;
  1171. }
  1172. if(this.statusOwner(status) == true) {
  1173. return true;
  1174. }
  1175. return false;
  1176. },
  1177. expRec() {
  1178. //return;
  1179. if(this.config.ab.rec == false) {
  1180. return;
  1181. }
  1182. axios.get('/api/local/exp/rec')
  1183. .then(res => {
  1184. this.suggestions = res.data;
  1185. })
  1186. },
  1187. expRecFollow(id, index) {
  1188. return;
  1189. if(this.config.ab.rec == false) {
  1190. return;
  1191. }
  1192. axios.post('/i/follow', {
  1193. item: id
  1194. }).then(res => {
  1195. this.suggestions.splice(index, 1);
  1196. }).catch(err => {
  1197. if(err.response.data.message) {
  1198. swal('Error', err.response.data.message, 'error');
  1199. }
  1200. });
  1201. },
  1202. followAction(status) {
  1203. let id = status.account.id;
  1204. axios.post('/i/follow', {
  1205. item: id
  1206. }).then(res => {
  1207. this.feed.forEach(s => {
  1208. if(s.account.id == id) {
  1209. s.account.relationship.following = !s.account.relationship.following;
  1210. }
  1211. });
  1212. let username = status.account.acct;
  1213. if(status.account.relationship.following) {
  1214. swal('Follow successful!', 'You are now following ' + username, 'success');
  1215. } else {
  1216. swal('Unfollow successful!', 'You are no longer following ' + username, 'success');
  1217. }
  1218. }).catch(err => {
  1219. if(err.response.data.message) {
  1220. swal('Error', err.response.data.message, 'error');
  1221. }
  1222. });
  1223. },
  1224. owner(status) {
  1225. return this.profile.id === status.account.id;
  1226. },
  1227. admin() {
  1228. return this.profile.is_admin == true;
  1229. },
  1230. ownerOrAdmin(status) {
  1231. return this.owner(status) || this.admin();
  1232. },
  1233. hideSuggestions() {
  1234. localStorage.setItem('pf_metro_ui.exp.rec', false);
  1235. this.showSuggestions = false;
  1236. },
  1237. emojiReaction(status) {
  1238. let em = event.target.innerText;
  1239. if(this.replyText.length == 0) {
  1240. this.replyText = em + ' ';
  1241. $('textarea[name="comment"]').focus();
  1242. } else {
  1243. this.replyText += em + ' ';
  1244. $('textarea[name="comment"]').focus();
  1245. }
  1246. },
  1247. refreshSuggestions() {
  1248. return;
  1249. let el = event.target.parentNode;
  1250. if(el.classList.contains('disabled') == true) {
  1251. return;
  1252. }
  1253. axios.get('/api/local/exp/rec', {
  1254. params: {
  1255. refresh: true
  1256. }
  1257. })
  1258. .then(res => {
  1259. this.suggestions = res.data;
  1260. if (el.classList) {
  1261. el.classList.add('disabled');
  1262. el.classList.add('text-light');
  1263. }
  1264. else {
  1265. el.className += ' ' + 'disabled text-light';
  1266. }
  1267. setTimeout(function() {
  1268. el.setAttribute('href', '#');
  1269. if (el.classList) {
  1270. el.classList.remove('disabled');
  1271. el.classList.remove('text-light');
  1272. }
  1273. else {
  1274. el.className = el.className.replace(new RegExp('(^|\\b)' + className.split(' ').join('|') + '(\\b|$)', 'gi'), 'disabled text-light');
  1275. }
  1276. }, 10000);
  1277. });
  1278. },
  1279. fetchHashtagPosts() {
  1280. axios.get('/api/local/discover/tag/list')
  1281. .then(res => {
  1282. let tags = res.data;
  1283. if(tags.length == 0) {
  1284. return;
  1285. }
  1286. let hashtag = tags[Math.floor(Math.random(), tags.length)];
  1287. this.hashtagPostsName = hashtag;
  1288. axios.get('/api/v2/discover/tag', {
  1289. params: {
  1290. hashtag: hashtag
  1291. }
  1292. }).then(res => {
  1293. if(res.data.tags.length > 3) {
  1294. this.showHashtagPosts = true;
  1295. this.hashtagPosts = res.data.tags.splice(0,3);
  1296. }
  1297. })
  1298. })
  1299. },
  1300. ctxMenu(status) {
  1301. this.ctxMenuStatus = status;
  1302. this.ctxEmbedPayload = window.App.util.embed.post(status.url);
  1303. if(status.account.id == this.profile.id) {
  1304. this.ctxMenuRelationship = false;
  1305. this.$refs.ctxModal.show();
  1306. } else {
  1307. axios.get('/api/pixelfed/v1/accounts/relationships', {
  1308. params: {
  1309. 'id[]': status.account.id
  1310. }
  1311. }).then(res => {
  1312. this.ctxMenuRelationship = res.data[0];
  1313. this.$refs.ctxModal.show();
  1314. });
  1315. }
  1316. },
  1317. closeCtxMenu(truncate) {
  1318. this.copiedEmbed = false;
  1319. this.ctxMenuStatus = false;
  1320. this.ctxMenuRelationship = false;
  1321. this.$refs.ctxModal.hide();
  1322. },
  1323. ctxMenuCopyLink() {
  1324. let status = this.ctxMenuStatus;
  1325. navigator.clipboard.writeText(status.url);
  1326. this.closeCtxMenu();
  1327. return;
  1328. },
  1329. ctxMenuGoToPost() {
  1330. let status = this.ctxMenuStatus;
  1331. window.location.href = this.statusUrl(status);
  1332. this.closeCtxMenu();
  1333. return;
  1334. },
  1335. ctxMenuFollow() {
  1336. let id = this.ctxMenuStatus.account.id;
  1337. axios.post('/i/follow', {
  1338. item: id
  1339. }).then(res => {
  1340. let username = this.ctxMenuStatus.account.acct;
  1341. this.closeCtxMenu();
  1342. setTimeout(function() {
  1343. swal('Follow successful!', 'You are now following ' + username, 'success');
  1344. }, 500);
  1345. });
  1346. },
  1347. ctxMenuUnfollow() {
  1348. let id = this.ctxMenuStatus.account.id;
  1349. axios.post('/i/follow', {
  1350. item: id
  1351. }).then(res => {
  1352. let username = this.ctxMenuStatus.account.acct;
  1353. if(this.scope == 'home') {
  1354. this.feed = this.feed.filter(s => {
  1355. return s.account.id != this.ctxMenuStatus.account.id;
  1356. });
  1357. }
  1358. this.closeCtxMenu();
  1359. setTimeout(function() {
  1360. swal('Unfollow successful!', 'You are no longer following ' + username, 'success');
  1361. }, 500);
  1362. });
  1363. },
  1364. ctxMenuReportPost() {
  1365. window.location.href = '/i/report?type=post&id=' + this.ctxMenuStatus.id;
  1366. },
  1367. ctxMenuEmbed() {
  1368. this.$refs.ctxModal.hide();
  1369. this.$refs.ctxEmbedModal.show();
  1370. },
  1371. ctxMenuShare() {
  1372. this.$refs.ctxModal.hide();
  1373. this.$refs.ctxShareModal.show();
  1374. },
  1375. closeCtxShareMenu() {
  1376. this.$refs.ctxShareModal.hide();
  1377. this.$refs.ctxModal.show();
  1378. },
  1379. ctxCopyEmbed() {
  1380. navigator.clipboard.writeText(this.ctxEmbedPayload);
  1381. this.ctxEmbedShowCaption = true;
  1382. this.ctxEmbedShowLikes = false;
  1383. this.ctxEmbedCompactMode = false;
  1384. this.$refs.ctxEmbedModal.hide();
  1385. },
  1386. ctxModMenuShow() {
  1387. this.$refs.ctxModal.hide();
  1388. this.$refs.ctxModModal.show();
  1389. },
  1390. ctxModMenu() {
  1391. this.$refs.ctxModal.hide();
  1392. },
  1393. ctxModMenuClose() {
  1394. this.$refs.ctxModal.hide();
  1395. this.$refs.ctxModModal.hide();
  1396. },
  1397. formatCount(count) {
  1398. return App.util.format.count(count);
  1399. },
  1400. statusUrl(status) {
  1401. if(status.local == true) {
  1402. return status.url;
  1403. }
  1404. return '/i/web/post/_/' + status.account.id + '/' + status.id;
  1405. },
  1406. profileUrl(status) {
  1407. if(status.local == true) {
  1408. return status.account.url;
  1409. }
  1410. return '/i/web/profile/_/' + status.account.id;
  1411. },
  1412. statusCardUsernameFormat(status) {
  1413. if(status.account.local == true) {
  1414. return status.account.username;
  1415. }
  1416. let fmt = window.App.config.username.remote.format;
  1417. let txt = window.App.config.username.remote.custom;
  1418. let usr = status.account.username;
  1419. let dom = document.createElement('a');
  1420. dom.href = status.account.url;
  1421. dom = dom.hostname;
  1422. switch(fmt) {
  1423. case '@':
  1424. return usr + '<span class="text-lighter font-weight-bold">@' + dom + '</span>';
  1425. break;
  1426. case 'from':
  1427. return usr + '<span class="text-lighter font-weight-bold"> <span class="font-weight-normal">from</span> ' + dom + '</span>';
  1428. break;
  1429. case 'custom':
  1430. return usr + '<span class="text-lighter font-weight-bold"> ' + txt + ' ' + dom + '</span>';
  1431. break;
  1432. default:
  1433. return usr + '<span class="text-lighter font-weight-bold">@' + dom + '</span>';
  1434. break;
  1435. }
  1436. },
  1437. previewUrl(status) {
  1438. return status.sensitive ? '/storage/no-preview.png?v=' + new Date().getTime() : status.media_attachments[0].preview_url;
  1439. },
  1440. previewBackground(status) {
  1441. let preview = this.previewUrl(status);
  1442. return 'background-image: url(' + preview + ');';
  1443. },
  1444. trimCaption(caption, len = 60) {
  1445. return _.truncate(caption, {
  1446. length: len
  1447. });
  1448. },
  1449. hasStory() {
  1450. axios.get('/api/stories/v0/exists/'+this.profile.id)
  1451. .then(res => {
  1452. this.userStory = res.data;
  1453. })
  1454. },
  1455. // real time watcher
  1456. rtw() {
  1457. this.mpPoller = setInterval(() => {
  1458. let apiUrl = false;
  1459. this.mpCount++;
  1460. if(this.mpCount > 10) {
  1461. this.mpInterval = 30000;
  1462. }
  1463. if(this.mpCount > 50) {
  1464. this.mpInterval = (5 * 60 * 1000);
  1465. }
  1466. switch(this.scope) {
  1467. case 'home':
  1468. apiUrl = '/api/pixelfed/v1/timelines/home';
  1469. break;
  1470. case 'local':
  1471. apiUrl = '/api/pixelfed/v1/timelines/public';
  1472. break;
  1473. case 'network':
  1474. apiUrl = '/api/pixelfed/v1/timelines/network';
  1475. break;
  1476. }
  1477. axios.get(apiUrl, {
  1478. params: {
  1479. max_id: 0,
  1480. limit: 20
  1481. }
  1482. }).then(res => {
  1483. let self = this;
  1484. let tids = this.feed.map(status => status.id);
  1485. let data = res.data.filter(d => {
  1486. return d.id > self.min_id && tids.indexOf(d.id) == -1;
  1487. });
  1488. let ids = data.map(status => status.id);
  1489. let max = Math.max(...ids).toString();
  1490. let newer = max > this.min_id;
  1491. if(newer) {
  1492. this.morePostsAvailable = true;
  1493. this.mpData = data;
  1494. }
  1495. });
  1496. }, this.mpInterval);
  1497. },
  1498. syncNewPosts() {
  1499. let self = this;
  1500. let data = this.mpData;
  1501. let ids = data.map(s => s.id);
  1502. this.min_id = Math.max(...ids).toString();
  1503. this.max_id = Math.min(...ids).toString();
  1504. this.feed.unshift(...data);
  1505. this.morePostsAvailable = false;
  1506. this.mpData = null;
  1507. },
  1508. switchFeedLayout(toggle) {
  1509. this.loading = true;
  1510. this.layout = toggle;
  1511. let self = this;
  1512. setTimeout(function() {
  1513. self.loading = false;
  1514. }, 500);
  1515. },
  1516. },
  1517. beforeDestroy () {
  1518. clearInterval(this.mpInterval);
  1519. },
  1520. }
  1521. </script>