StoryViewer.vue 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987
  1. <template>
  2. <div
  3. class="story-viewer-component container mt-0 mt-md-5 bg-black">
  4. <button type="button" class="d-none d-md-block btn btn-link fixed-top" style="left: auto;right:0;" @click="backToFeed">
  5. <i class="fal fa-times-circle fa-2x text-lighter"></i>
  6. </button>
  7. <div v-if="!viewWarning" class="row d-flex justify-content-center align-items-center">
  8. <div class="d-none d-md-block col-md-1 cursor-pointer text-center" @click="prev">
  9. <div v-if="storyIndex > 0">
  10. <i class="fas fa-chevron-circle-left text-muted fa-2x"></i>
  11. </div>
  12. </div>
  13. <div v-if="!loading" class="col-12 col-md-6 rounded-lg">
  14. <div v-if="activeReactionEmoji" style="position: absolute;z-index: 999;" class="w-100 h-100 d-flex justify-content-center align-items-center">
  15. <div class="d-flex justify-content-center align-items-center rounded-pill shadow-lg" style="width: 120px;height: 30px;font-size:13px;background-color: rgba(0, 0, 0, 0.6);">
  16. <span class="text-lighter">{{ $t("story.reactionSent") }}</span>
  17. </div>
  18. </div>
  19. <div v-if="activeReply" style="position: absolute;z-index: 999;" class="w-100 h-100 d-flex justify-content-center align-items-center">
  20. <div class="d-flex justify-content-center align-items-center rounded-pill shadow-lg" style="width: 120px;height: 30px;font-size:13px;background-color: rgba(0, 0, 0, 0.6);">
  21. <span class="text-lighter">{{ $t("story.replySent") }}</span>
  22. </div>
  23. </div>
  24. <transition name="fade">
  25. <div v-if="stories[storyIndex].type == 'photo'" class="media-slot rounded-lg" :key="'msl:'+storyIndex" :style="{ background: 'url(' + stories[storyIndex].url + ')' }"></div>
  26. <div v-else-if="stories[storyIndex].type == 'poll'" class="media-slot rounded-lg" :key="'msl:'+storyIndex" :style="{ background: 'linear-gradient(to right, #F27121, #E94057, #8A2387)' }"></div>
  27. <video
  28. v-else-if="stories[storyIndex].type == 'video'"
  29. :key="'plyr'+stories[storyIndex].id"
  30. id="playr"
  31. class="media-slot rounded-lg"
  32. style="object-fit: contain;"
  33. :muted="muted"
  34. loop
  35. autoplay
  36. no-controls>
  37. <source :src="stories[storyIndex].url" type="video/mp4">
  38. </video>
  39. </transition>
  40. <div class="story-viewer-component-card card bg-transparent border-0 shadow-none d-flex justify-content-center">
  41. <div class="card-body">
  42. <div class="px-0 top-overlay">
  43. <div class="pt-4 pt-md-3 px-4 d-flex">
  44. <div style="width: 100%;height:5px;" class="d-none bg-muted"></div>
  45. <div
  46. v-for="(story, index) in stories"
  47. :key="'sp:s'+index"
  48. v-on:click="gotoSlide(index)"
  49. class="w-100 cursor-pointer"
  50. :class="{ 'mr-2': index != stories.length - 1 }">
  51. <div
  52. class="progress w-100"
  53. style="z-index:3;height: 4px;"
  54. :style="{opacity: story.progress == 0 ? 0.7 : 0.8}">
  55. <div
  56. :key="'sp:si'+index"
  57. class="progress-bar bg-light"
  58. role="progressbar"
  59. :aria-valuenow="story.progress"
  60. aria-valuemin="0"
  61. aria-valuemax="100"
  62. :style="{
  63. width: story.progress +'%',
  64. transition: 'none !important'
  65. }">
  66. </div>
  67. </div>
  68. </div>
  69. </div>
  70. <div class="pt-4 px-4 media align-items-center">
  71. <img :src="avatar" width="32" height="32" class="rounded-circle mr-2" onerror="this.onerror=null;this.src='/storage/avatars/default.png?v=2'">
  72. <div class="media-body d-flex justify-content-between align-items-center">
  73. <div class="user-select-none d-flex align-items-center">
  74. <span v-if="account.local" class="text-white font-weight-bold mr-2">
  75. {{username}}
  76. </span>
  77. <span v-else class="text-white font-weight-bold mr-3 text-truncate" style="max-width:200px;">
  78. <span class="d-block mb-n2">{{account.username}}</span>
  79. <span class="small">{{account.domain}}</span>
  80. </span>
  81. <span class="text-white font-weight-light" style="font-size: 14px;">{{timeago(stories[storyIndex].created_at)}}</span>
  82. <span v-if="stories[storyIndex].type == 'poll'">
  83. <span class="btn btn-outline-light font-weight-light btn-sm px-1 rounded py-0 ml-2">POLL</span>
  84. </span>
  85. </div>
  86. <div>
  87. <button class="btn btn-link btn-sm text-white mr-0 px-1" @click.prevent="pause">
  88. <i :class="[ paused ? 'fa-play' : 'fa-pause' ]" class="fas fa-lg"></i>
  89. </button>
  90. <button v-if="stories[storyIndex].type == 'video'" class="btn btn-link text-white px-2" @click="toggleMute">
  91. <i :class="[ muted ? 'fa-volume-mute' : 'fa-volume-up' ]" class="fas fa-lg"></i>
  92. </button>
  93. <button @click="showMenu" class="btn btn-link text-white px-1">
  94. <i class="fas fa-ellipsis-h fa-lg"></i>
  95. </button>
  96. <button class="d-inline-block d-md-none btn btn-link text-white pl-1 pr-0" @click="backToFeed">
  97. <i class="far fa-times-circle fa-lg"></i>
  98. </button>
  99. </div>
  100. </div>
  101. </div>
  102. </div>
  103. <div @click="pause" style="height: 70vh;">
  104. <div v-if="stories[storyIndex].type == 'poll'" class="w-100 h-100 d-flex justify-content-center align-items-center">
  105. <div>
  106. <p
  107. class="text-white pb-5 text-break font-weight-lighter"
  108. :class="[stories[storyIndex].question.length < 60 ? 'h1' : 'h3']">
  109. {{stories[storyIndex].question}}
  110. </p>
  111. <div class="text-center mt-3">
  112. <div v-for="(option, index) in stories[storyIndex].options" class="mb-3">
  113. <button
  114. class="btn border px-4 py-3 text-uppercase btn-block"
  115. :class="[
  116. option.length < 14 ? 'btn-lg': '',
  117. index == stories[storyIndex].voted_index ? 'btn-light' : 'btn-outline-light'
  118. ]"
  119. style="min-width: 300px;"
  120. :disabled="stories[storyIndex].voted || owner"
  121. @click="selectPollOption(index)">
  122. <span
  123. class="text-break"
  124. :class="[
  125. index == stories[storyIndex].voted_index ? 'option-red' : ''
  126. ]">
  127. {{ option }}
  128. </span>
  129. </button>
  130. <p
  131. v-if="owner && pollResults.length"
  132. class="small text-left mt-1 text-light">
  133. {{ pollPercent(index) }}% - {{ pollResults[index] }} {{ pollResults[index] == 1 ? 'vote' : 'votes' }}
  134. </p>
  135. </div>
  136. </div>
  137. <div v-if="owner && !showingPollResults && pollResults.length == 0" class="mt-3 text-center">
  138. <button class="btn btn-light font-weight-bold" @click="showPollResults" :disabled="loadingPollResults">
  139. {{ loadingPollResults ? 'Loading...' : 'View Results' }}
  140. </button>
  141. </div>
  142. </div>
  143. </div>
  144. </div>
  145. </div>
  146. <div v-if="!owner && stories[storyIndex] && stories[storyIndex].can_reply" class="card-footer bg-transparent border-0">
  147. <div class="px-0 bottom-overlay">
  148. <div class="px-3 form-group d-flex">
  149. <input class="form-control bg-transparent border border-white rounded-pill text-white" :placeholder="'Reply to ' + username + '...'" v-model="composeText">
  150. <button class="btn btn-outline-light rounded-pill ml-2" @click="comment">
  151. SEND
  152. </button>
  153. </div>
  154. </div>
  155. </div>
  156. </div>
  157. </div>
  158. <div class="d-none d-md-block col-md-1 cursor-pointer text-center">
  159. <div v-if="(storyIndex + 1) < stories.length" @click="next">
  160. <i class="fas fa-chevron-circle-right text-muted fa-2x"></i>
  161. </div>
  162. <div v-if="(storyIndex + 1) == stories.length && owner" @click="addToStory">
  163. <i class="fal fa-plus-circle text-muted fa-2x"></i>
  164. </div>
  165. </div>
  166. <div v-if="loading" class="col-12 col-md-6 rounded-lg">
  167. <div class="card border-0 shadow-none d-flex justify-content-center" style="background: #000;height: 90vh;">
  168. <div class="card-body d-flex justify-content-center align-items-center">
  169. <div class="spinner-border text-lighter" role="status">
  170. <span class="sr-only">Loading...</span>
  171. </div>
  172. </div>
  173. </div>
  174. </div>
  175. </div>
  176. <div v-else class="row d-flex justify-content-center align-items-center">
  177. <div v-if="!loading" class="col-12 col-md-6 rounded-lg p-0">
  178. <div v-if="stories[storyIndex].type == 'photo'" class="media-slot rounded-lg" :key="'msl:'+storyIndex" :style="{ backgroundImage: 'url(' + stories[storyIndex].url + ')' }"></div>
  179. <div class="story-viewer-component-card card bg-transparent border-0 shadow-none d-flex justify-content-center" style="backdrop-filter: blur(40px) brightness(0.3); -webkit-backdrop-filter: blur(10px);">
  180. <div class="card-body">
  181. <div class="w-100 h-100 d-flex justify-content-center align-items-center">
  182. <div class="text-center">
  183. <img :src="profile.avatar" width="120" height="120" class="rounded-circle border mb-3 shadow">
  184. <p class="lead text-lighter mb-1">View as <span class="text-white">{{profile.username}}</span></p>
  185. <p class="text-lighter font-weight-lighter px-md-5 py-3">
  186. <span class="text-white font-weight-bold">{{account.acct}}</span> will be able to see that you viewed their story.
  187. </p>
  188. <button class="btn btn-outline-lighter rounded-pill py-1 font-weight-bold" @click="confirmViewStory">View Story</button>
  189. <button class="btn btn-outline-lighter rounded-pill py-1 font-weight-bold" @click="cancelViewStory">Cancel</button>
  190. </div>
  191. </div>
  192. </div>
  193. </div>
  194. </div>
  195. </div>
  196. <div class="modal-stack">
  197. <b-modal ref="ctxMenu"
  198. id="ctx-modal"
  199. hide-header
  200. hide-footer
  201. centered
  202. rounded
  203. size="sm"
  204. body-class="list-group-flush p-0 rounded">
  205. <div class="list-group text-center">
  206. <div v-if="owner" class="list-group-item rounded py-3">
  207. <div class="d-flex justify-content-between align-items-center font-weight-light">
  208. <span>{{ $t("story.expiresIn")}} {{timeahead(stories[storyIndex].expires_at)}}</span>
  209. <span>
  210. <span class="btn btn-light btn-sm font-weight-bold">
  211. <i class="fas fa-eye"></i>
  212. {{ stories[storyIndex].view_count }}
  213. </span>
  214. </span>
  215. </div>
  216. </div>
  217. <div v-if="!owner && stories[storyIndex] && stories[storyIndex].can_react" class="list-group-item rounded d-flex justify-content-between">
  218. <button
  219. v-for="e in reactionEmoji"
  220. class="btn btn-light rounded-pill py-1 px-2"
  221. style="font-size: 20px;"
  222. @click="react(e)">
  223. {{ e }}
  224. </button>
  225. </div>
  226. <div v-if="owner" class="list-group-item rounded cursor-pointer" @click="fetchViewers">{{ $t("story.viewers")}}</div>
  227. <div v-if="!owner" class="list-group-item rounded cursor-pointer" @click="ctxMenuReport">{{ $t("story.report")}}</div>
  228. <div v-if="owner" class="list-group-item rounded cursor-pointer" @click="deleteStory">{{ $t("story.delete")}}</div>
  229. <div class="list-group-item rounded cursor-pointer text-muted" @click="closeCtxMenu">{{ $t("story.close")}}</div>
  230. </div>
  231. </b-modal>
  232. <b-modal ref="viewersModal"
  233. id="viewers"
  234. title="Viewers"
  235. header-class="border-0"
  236. hide-footer
  237. centered
  238. rounded
  239. scrollable
  240. lazy
  241. size="sm"
  242. body-class="list-group-flush p-0 rounded">
  243. <div class="list-group" style="max-height: 40vh;">
  244. <div v-for="(profile, index) in viewers" class="list-group-item">
  245. <div class="media align-items-center">
  246. <img :src="profile.avatar" width="32" height="32" class="rounded-circle border mr-2">
  247. <div v-if="profile.local" class="media-body user-select-none">
  248. <p class="font-weight-bold mb-0">{{profile.username}}</p>
  249. </div>
  250. <div v-else class="media-body user-select-none">
  251. <p class="font-weight-bold mb-0">{{profile.username}}</p>
  252. <p class="mb-0 small mt-n1 text-muted">{{profile.acct.split('@')[1]}}</p>
  253. </div>
  254. </div>
  255. </div>
  256. <div v-if="viewers.length == 0" class="list-group-item text-center text-dark font-weight-light py-5">
  257. No viewers yet
  258. </div>
  259. <div v-if="viewersHasMore" class="list-group-item text-center border-bottom-0">
  260. <button class="btn btn-light font-weight-bold border rounded-pill" @click="viewersLoadMore">Load More</button>
  261. </div>
  262. <div class="list-group-item text-center rounded cursor-pointer text-muted" @click="closeViewersModal">{{ $t("story.close")}}</div>
  263. </div>
  264. </b-modal>
  265. <b-modal ref="ctxReport"
  266. id="ctx-report"
  267. hide-header
  268. hide-footer
  269. centered
  270. rounded
  271. size="sm"
  272. body-class="list-group-flush p-0 rounded">
  273. <p class="py-2 px-3 mb-0">
  274. <div class="text-center font-weight-bold text-danger">Report</div>
  275. <div class="small text-center text-muted">Select one of the following options</div>
  276. </p>
  277. <div class="list-group text-center">
  278. <div class="list-group-item rounded cursor-pointer font-weight-bold" @click="sendReport('spam')">Spam</div>
  279. <div class="list-group-item rounded cursor-pointer font-weight-bold" @click="sendReport('sensitive')">Sensitive Content</div>
  280. <div class="list-group-item rounded cursor-pointer font-weight-bold" @click="sendReport('abusive')">Abusive or Harmful</div>
  281. <div class="list-group-item rounded cursor-pointer font-weight-bold" @click="openCtxReportOtherMenu()">Other</div>
  282. <!-- <div class="list-group-item rounded cursor-pointer" @click="ctxReportMenuGoBack()">Go Back</div> -->
  283. <div class="list-group-item rounded cursor-pointer text-lighter" @click="ctxReportMenuGoBack()">Cancel</div>
  284. </div>
  285. </b-modal>
  286. <b-modal ref="ctxReportOther"
  287. id="ctx-report-other"
  288. hide-header
  289. hide-footer
  290. centered
  291. rounded
  292. size="sm"
  293. body-class="list-group-flush p-0 rounded">
  294. <p class="py-2 px-3 mb-0">
  295. <div class="text-center font-weight-bold text-danger">Report</div>
  296. <div class="small text-center text-muted">Select one of the following options</div>
  297. </p>
  298. <div class="list-group text-center">
  299. <div class="list-group-item rounded cursor-pointer font-weight-bold" @click="sendReport('underage')">Underage Account</div>
  300. <div class="list-group-item rounded cursor-pointer font-weight-bold" @click="sendReport('copyright')">Copyright Infringement</div>
  301. <div class="list-group-item rounded cursor-pointer font-weight-bold" @click="sendReport('impersonation')">Impersonation</div>
  302. <div class="list-group-item rounded cursor-pointer font-weight-bold" @click="sendReport('scam')">Scam or Fraud</div>
  303. <!-- <div class="list-group-item rounded cursor-pointer font-weight-bold" @click="sendReport('terrorism')">Terrorism Related</div> -->
  304. <!-- <div class="list-group-item rounded cursor-pointer font-weight-bold" @click="sendReport('other')">Other or Not listed</div> -->
  305. <!-- <div class="list-group-item rounded cursor-pointer" @click="ctxReportOtherMenuGoBack()">Go Back</div> -->
  306. <div class="list-group-item rounded cursor-pointer text-lighter" @click="ctxReportOtherMenuGoBack()">Cancel</div>
  307. </div>
  308. </b-modal>
  309. </div>
  310. </div>
  311. </template>
  312. <script type="text/javascript">
  313. export default {
  314. props: {
  315. pid: {
  316. type: String
  317. },
  318. selfProfile: {
  319. type: Object
  320. },
  321. redirectUrl: {
  322. type: String,
  323. default: '/'
  324. }
  325. },
  326. data() {
  327. return {
  328. loading: true,
  329. profile: null,
  330. account: {
  331. local: false
  332. },
  333. owner: false,
  334. stories: [],
  335. username: 'loading...',
  336. avatar: '/storage/avatars/default.jpg',
  337. storyIndex: 0,
  338. progress: 0,
  339. constInterval: 383,
  340. progressInterval: undefined,
  341. composeText: null,
  342. paused: false,
  343. muted: true,
  344. reactionEmoji: [ "❤️", "🔥", "💯", "😂", "😎", "👀" ],
  345. activeReactionEmoji: false,
  346. activeReply: false,
  347. showProgress: false,
  348. redirectOnEnd: '/',
  349. viewerSid: false,
  350. viewerPage: 1,
  351. loadingViewers: false,
  352. viewersHasMore: true,
  353. viewers: [],
  354. viewWarning: false,
  355. showingPollResults: false,
  356. loadingPollResults: false,
  357. pollResults: [],
  358. pollTotalVotes: 0
  359. }
  360. },
  361. watch: {
  362. composeText: function(val) {
  363. if(val.length == 0) {
  364. if(this.paused) {
  365. this.pause();
  366. }
  367. } else {
  368. if(!this.paused) {
  369. this.pause();
  370. }
  371. }
  372. event.currentTarget.focus();
  373. }
  374. },
  375. beforeMount() {
  376. this.redirectOnEnd = this.redirectUrl;
  377. },
  378. mounted() {
  379. let u = new URLSearchParams(window.location.search);
  380. if(u.has('t')) {
  381. switch(u.get('t')) {
  382. case '1':
  383. this.redirectOnEnd = '/';
  384. break;
  385. case '2':
  386. this.redirectOnEnd = '/timeline/public';
  387. break;
  388. case '3':
  389. this.redirectOnEnd = '/timeline/network';
  390. break;
  391. case '4':
  392. this.redirectOnEnd = '/' + window.location.pathname.split('/').slice(-1).pop();
  393. break;
  394. }
  395. } else {
  396. this.viewWarning = true;
  397. }
  398. if(!this.selfProfile || !this.selfProfile.hasOwnProperty('avatar')) {
  399. axios.get('/api/pixelfed/v1/accounts/verify_credentials')
  400. .then(res => {
  401. this.profile = res.data;
  402. this.fetchStories();
  403. });
  404. } else {
  405. this.profile = this.selfProfile;
  406. }
  407. let el = document.querySelector('body');
  408. el.style.width = '100%';
  409. el.style.height = '100vh !important';
  410. el.style.overflow = 'hidden';
  411. el.style.backgroundColor = '#262626';
  412. },
  413. methods: {
  414. init() {
  415. clearInterval(this.progressInterval);
  416. this.loading = false;
  417. this.constInterval = Math.ceil(this.stories[this.storyIndex].duration * 38.3);
  418. this.progressInterval = setInterval(() => {
  419. this.do();
  420. }, this.constInterval);
  421. },
  422. do() {
  423. this.loading = false;
  424. if(this.stories[this.storyIndex].progress != 100) {
  425. this.stories[this.storyIndex].progress = this.stories[this.storyIndex].progress + 4;
  426. } else {
  427. clearInterval(this.progressInterval);
  428. this.next();
  429. }
  430. },
  431. prev() {
  432. if(this.storyIndex == 0) {
  433. return;
  434. }
  435. this.pollResults = [];
  436. this.progress = 0;
  437. this.gotoSlide(this.storyIndex - 1);
  438. },
  439. next() {
  440. axios.post('/api/web/stories/v1/viewed', {
  441. id: this.stories[this.storyIndex].id
  442. });
  443. this.stories[this.storyIndex].progress = 100;
  444. if(this.storyIndex == this.stories.length - 1) {
  445. if(this.composeText && this.composeText.length) {
  446. return;
  447. }
  448. window.location.href = this.redirectOnEnd;
  449. return;
  450. }
  451. this.pollResults = [];
  452. this.progress = 0;
  453. this.muted = true;
  454. this.storyIndex = this.storyIndex + 1;
  455. this.init();
  456. },
  457. pause() {
  458. if(event) {
  459. event.currentTarget.blur();
  460. }
  461. if(this.paused) {
  462. this.paused = false;
  463. if(this.stories[this.storyIndex].type == 'video') {
  464. let el = document.getElementById('playr');
  465. el.play();
  466. }
  467. this.init();
  468. } else {
  469. clearInterval(this.progressInterval);
  470. if(this.stories[this.storyIndex].type == 'video') {
  471. let el = document.getElementById('playr');
  472. el.pause();
  473. }
  474. this.paused = true;
  475. }
  476. },
  477. toggleMute() {
  478. if(event) {
  479. event.currentTarget.blur();
  480. }
  481. if(this.stories[this.storyIndex].type == 'video') {
  482. this.muted = !this.muted;
  483. let el = document.getElementById('playr');
  484. el.muted = this.muted;
  485. }
  486. },
  487. gotoSlide(index) {
  488. this.paused = false;
  489. clearInterval(this.progressInterval);
  490. this.progressInterval = null;
  491. this.stories = this.stories.map(function(s,k) {
  492. if(k < index) {
  493. s.progress = 100;
  494. } else {
  495. s.progress = 0;
  496. }
  497. return s;
  498. });
  499. this.storyIndex = index;
  500. this.stories[index].progress = 0;
  501. this.init();
  502. },
  503. showMenu() {
  504. if(!this.paused) {
  505. this.pause();
  506. }
  507. event.currentTarget.blur();
  508. this.$refs.ctxMenu.show();
  509. },
  510. react(emoji) {
  511. this.$refs.ctxMenu.hide();
  512. this.activeReactionEmoji = true;
  513. axios.post('/api/web/stories/v1/react', {
  514. sid: this.stories[this.storyIndex].id,
  515. reaction: emoji
  516. })
  517. .then(res => {
  518. setTimeout(() => {
  519. this.activeReactionEmoji = false;
  520. this.pause();
  521. }, 2000);
  522. }).catch(err => {
  523. this.activeReactionEmoji = false;
  524. swal('Error', 'An error occured when attempting to react to this story. Please try again later.', 'error');
  525. });
  526. },
  527. comment() {
  528. if(this.composeText.length < 2) {
  529. return;
  530. }
  531. if(!this.paused) {
  532. this.pause();
  533. }
  534. this.activeReply = true;
  535. axios.post('/api/web/stories/v1/comment', {
  536. sid: this.stories[this.storyIndex].id,
  537. caption: this.composeText
  538. })
  539. .then(res => {
  540. this.composeText = null;
  541. setTimeout(() => {
  542. this.activeReply = false;
  543. this.pause();
  544. }, 2000);
  545. }).catch(err => {
  546. this.activeReply = false;
  547. swal('Error', 'An error occured when attempting to reply to this story. Please try again later.', 'error');
  548. });
  549. },
  550. closeCtxMenu() {
  551. this.$refs.ctxMenu.hide();
  552. },
  553. backToFeed() {
  554. if(this.composeText) {
  555. swal('Are you sure you want to leave without sending this reply?')
  556. .then(confirm => {
  557. if(confirm) {
  558. window.location.href = this.redirectOnEnd;
  559. }
  560. })
  561. return;
  562. } else {
  563. window.location.href = this.redirectOnEnd;
  564. }
  565. },
  566. timeago(ts) {
  567. return App.util.format.timeAgo(ts);
  568. },
  569. timeahead(ts) {
  570. let d = new Date(ts);
  571. return App.util.format.timeAhead(d.toUTCString());
  572. },
  573. fetchStories() {
  574. let self = this;
  575. axios.get('/api/web/stories/v1/profile/' + this.pid)
  576. .then(res => {
  577. if(res.data.length == 0) {
  578. window.location.href = this.redirectOnEnd;
  579. }
  580. self.account = res.data[0].account;
  581. if(self.account.local == false) {
  582. self.account.domain = self.account.acct.split('@')[1]
  583. }
  584. self.stories = res.data[0].nodes.map(function(i, k) {
  585. let r = {
  586. id: i.id,
  587. created_at: i.created_at,
  588. expires_at: i.expires_at,
  589. progress: i.progress == 100 && k == res.data[0].nodes.length - 1 ? 0 : i.progress,
  590. view_count: i.view_count,
  591. url: i.src,
  592. type: i.type,
  593. duration: i.duration,
  594. can_reply: i.can_reply,
  595. can_react: i.can_react,
  596. }
  597. if(r.type == 'poll') {
  598. r.question = i.question;
  599. r.options = i.options;
  600. r.voted = i.voted;
  601. r.voted_index = i.voted_index;
  602. }
  603. return r;
  604. });
  605. self.username = res.data[0].account.username;
  606. self.avatar = res.data[0].account.avatar;
  607. if(self.profile.id == res.data[0].account.id) {
  608. this.viewWarning = false;
  609. }
  610. if(this.viewWarning) {
  611. this.loading = false;
  612. return;
  613. }
  614. let seen = res.data[0].nodes.filter(function(i, k) {
  615. return i.seen == true;
  616. }).map(function(i, k) {
  617. return k;
  618. });
  619. if(seen.length && this.pid != this.profile.id) {
  620. let n = (seen[seen.length - 1] + 1) == self.stories.length ? seen[seen.length - 1] : (seen[seen.length - 1] + 1);
  621. self.gotoSlide(n);
  622. }
  623. if(this.pid == this.profile.id) {
  624. self.gotoSlide(self.stories.length - 1);
  625. }
  626. self.showProgress = true;
  627. if(self.profile.id == self.account.id) {
  628. self.owner = true;
  629. }
  630. if(res.data.length == 0) {
  631. window.location.href = this.redirectOnEnd;
  632. return;
  633. }
  634. this.init();
  635. })
  636. .catch(err => {
  637. return;
  638. });
  639. },
  640. fetchViewers() {
  641. this.closeCtxMenu();
  642. this.$refs.viewersModal.show();
  643. if(this.stories[this.storyIndex].id == this.viewerSid) {
  644. return;
  645. }
  646. this.loadingViewers = true;
  647. axios.get('/api/web/stories/v1/viewers', {
  648. params: {
  649. sid: this.stories[this.storyIndex].id
  650. }
  651. }).then(res => {
  652. this.viewerSid = this.stories[this.storyIndex].id;
  653. this.viewers = res.data;
  654. this.loadingViewers = false;
  655. this.viewerPage = 2;
  656. if(this.viewers.length == 10) {
  657. this.viewersHasMore = true;
  658. } else {
  659. this.viewersHasMore = false;
  660. }
  661. }).catch(err => {
  662. swal('Cannot load viewers', 'Cannot load viewers of this story, please try again later.', 'error');
  663. })
  664. },
  665. viewersLoadMore() {
  666. axios.get('/api/web/stories/v1/viewers', {
  667. params: {
  668. sid: this.stories[this.storyIndex].id,
  669. page: this.viewerPage
  670. }
  671. }).then(res => {
  672. if(!res.data || res.data.length == 0) {
  673. this.viewersHasMore = false;
  674. return;
  675. }
  676. if(res.data.length != 10) {
  677. this.viewersHasMore = false;
  678. }
  679. this.viewers.push(...res.data);
  680. this.viewerPage++;
  681. }).catch(err => {
  682. swal('Cannot load viewers', 'Cannot load viewers of this story, please try again later.', 'error');
  683. });
  684. },
  685. closeViewersModal() {
  686. this.$refs.viewersModal.hide();
  687. },
  688. deleteStory() {
  689. this.closeCtxMenu();
  690. if(!window.confirm('Are you sure you want to delete this story?')) {
  691. this.pause();
  692. return;
  693. }
  694. axios.delete('/api/web/stories/v1/delete/' + this.stories[this.storyIndex].id)
  695. .then(res => {
  696. let i = this.storyIndex;
  697. let c = this.stories.length;
  698. if(c == 1) {
  699. window.location.href = '/';
  700. return;
  701. }
  702. window.location.reload();
  703. });
  704. },
  705. selectPollOption(index) {
  706. if(!this.paused) {
  707. this.pause();
  708. }
  709. axios.post('/i/stories/viewed', {
  710. id: this.stories[this.storyIndex].id
  711. });
  712. axios.post('/api/web/stories/v1/poll/vote', {
  713. sid: this.stories[this.storyIndex].id,
  714. ci: index
  715. }).then(res => {
  716. this.stories[this.storyIndex].voted = true;
  717. this.stories[this.storyIndex].voted_index = index;
  718. this.next();
  719. })
  720. },
  721. ctxMenuReport() {
  722. this.$refs.ctxMenu.hide();
  723. this.$refs.ctxReport.show();
  724. },
  725. openCtxReportOtherMenu() {
  726. this.closeCtxMenu();
  727. this.$refs.ctxReport.hide();
  728. this.$refs.ctxReportOther.show();
  729. },
  730. ctxReportMenuGoBack() {
  731. this.closeMenus();
  732. },
  733. ctxReportOtherMenuGoBack() {
  734. this.closeMenus();
  735. },
  736. closeMenus() {
  737. this.$refs.ctxReportOther.hide();
  738. this.$refs.ctxReport.hide();
  739. this.$refs.ctxMenu.hide();
  740. },
  741. sendReport(type) {
  742. let id = this.stories[this.storyIndex].id;
  743. swal({
  744. 'title': 'Confirm Report',
  745. 'text': 'Are you sure you want to report this post?',
  746. 'icon': 'warning',
  747. 'buttons': true,
  748. 'dangerMode': true
  749. }).then((res) => {
  750. if(res) {
  751. axios.post('/api/web/stories/v1/report', {
  752. 'type': type,
  753. 'id': id,
  754. }).then(res => {
  755. this.closeMenus();
  756. swal('Report Sent!', 'We have successfully received your report', 'success');
  757. }).catch(err => {
  758. if(err.response.status === 409) {
  759. swal('Already reported', 'You have already reported this story', 'info');
  760. } else {
  761. swal('Oops!', 'There was an issue reporting this story', 'error');
  762. }
  763. })
  764. } else {
  765. this.closeMenus();
  766. }
  767. });
  768. },
  769. cancelViewStory() {
  770. event.currentTarget.blur();
  771. location.href = '/i/web';
  772. },
  773. confirmViewStory() {
  774. let self = this;
  775. let seen = this.stories.filter(function(i, k) {
  776. return i.seen == true;
  777. }).map(function(i, k) {
  778. return k;
  779. });
  780. if(seen.length && this.pid != this.profile.id) {
  781. let n = (seen[seen.length - 1] + 1) == self.stories.length ? seen[seen.length - 1] : (seen[seen.length - 1] + 1);
  782. self.gotoSlide(n);
  783. }
  784. if(this.pid == this.profile.id) {
  785. self.gotoSlide(self.stories.length - 1);
  786. }
  787. self.showProgress = true;
  788. if(self.profile.username == self.username) {
  789. self.owner = true;
  790. }
  791. this.viewWarning = false;
  792. this.init();
  793. },
  794. showPollResults() {
  795. this.loadingPollResults = true;
  796. if(!this.paused) {
  797. this.pause();
  798. }
  799. axios.get('/api/web/stories/v1/poll/results', {
  800. params: {
  801. sid: this.stories[this.storyIndex].id
  802. }
  803. }).then(res => {
  804. this.loadingPollResults = false;
  805. this.pollResults = res.data;
  806. const sum = (a, b) => a + b;
  807. this.pollTotalVotes = this.pollResults.reduce(sum);
  808. });
  809. },
  810. addToStory() {
  811. window.location.href = '/i/stories/new';
  812. },
  813. pollPercent(index) {
  814. return this.pollTotalVotes == 0 ? 0 : Math.round((this.pollResults[index] / this.pollTotalVotes) * 100)
  815. }
  816. }
  817. }
  818. </script>
  819. <style lang="scss" scoped>
  820. #content {
  821. width: 100%;
  822. height: 100vh !important;
  823. overflow: hidden;
  824. background-color: #262626;
  825. }
  826. .story-viewer-component {
  827. &-card {
  828. height: 100vh;
  829. @media (min-width: 768px) {
  830. height: 90vh;
  831. }
  832. }
  833. &.bg-black {
  834. background-color: #262626;
  835. }
  836. .option-green {
  837. font-size: 20px;
  838. font-weight: 600;
  839. background: #11998e; /* fallback for old browsers */
  840. background: -webkit-linear-gradient(180deg, #38ef7d, #11998e);
  841. background: linear-gradient(180deg, #38ef7d, #11998e);
  842. -webkit-background-clip: text;
  843. -webkit-text-fill-color: transparent;
  844. }
  845. .option-red {
  846. font-weight: 600;
  847. background: linear-gradient(to right, #F27121, #E94057, #8A2387);
  848. -webkit-background-clip: text;
  849. -webkit-text-fill-color: transparent;
  850. }
  851. .bg-black {
  852. background-color: #262626;
  853. }
  854. .fade-enter-active, .fade-leave-active {
  855. transition: opacity .5s;
  856. }
  857. .fade-enter, .fade-leave-to {
  858. opacity: 0;
  859. }
  860. .progress {
  861. background-color: #979a9a;
  862. }
  863. .media-slot {
  864. border-radius: 0;
  865. width: 100%;
  866. height: 100%;
  867. position: absolute;
  868. left: 0;
  869. top: 0;
  870. background: #000;
  871. background-size: cover !important;
  872. z-index: 0;
  873. }
  874. .card-body {
  875. .top-overlay {
  876. height:100px;
  877. margin-left: -35px;
  878. margin-right: -35px;
  879. margin-top: -20px;
  880. padding-bottom: 20px;
  881. border-radius: 5px;
  882. background: linear-gradient(180deg, rgba(38,38,38, 0.8) 0%, rgba(38,38,38,0) 100%);
  883. }
  884. }
  885. .card-footer {
  886. ::placeholder {
  887. color: #fff;
  888. opacity: 1;
  889. }
  890. .bottom-overlay {
  891. margin-left: -35px;
  892. margin-right: -35px;
  893. margin-bottom: -20px;
  894. border-radius: 5px;
  895. background: linear-gradient(0deg, rgba(38,38,38, 0.8) 0%, rgba(38,38,38,0) 100%);
  896. .form-group {
  897. padding-top: 40px;
  898. padding-bottom: 20px;
  899. margin-bottom: 0;
  900. }
  901. }
  902. }
  903. }
  904. </style>