Profile.vue 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869
  1. <template>
  2. <div>
  3. <div class="d-flex justify-content-center py-5 my-5" v-if="loading">
  4. <img src="/img/pixelfed-icon-grey.svg" class="">
  5. </div>
  6. <div v-if="!loading">
  7. <div class="bg-white py-5 border-bottom">
  8. <div class="container">
  9. <div class="row">
  10. <div class="col-12 col-md-4 d-flex">
  11. <div class="profile-avatar mx-md-auto">
  12. <div class="d-block d-md-none">
  13. <div class="row">
  14. <div class="col-5">
  15. <img class="rounded-circle box-shadow mr-5" :src="profile.avatar" width="77px" height="77px">
  16. </div>
  17. <div class="col-7 pl-2">
  18. <p class="font-weight-ultralight h3 mb-0">{{profile.username}}</p>
  19. <p v-if="profile.id == user.id && user.hasOwnProperty('id')">
  20. <a class="btn btn-outline-dark py-0 px-4 mt-3" href="/settings/home">Edit Profile</a>
  21. </p>
  22. <div v-if="profile.id != user.id && user.hasOwnProperty('id')">
  23. <p class="mt-3 mb-0" v-if="relationship.following == true">
  24. <button type="button" class="btn btn-outline-dark font-weight-bold px-4 py-0" v-on:click="followProfile()" data-toggle="tooltip" title="Unfollow">Unfollow</button>
  25. </p>
  26. <p class="mt-3 mb-0" v-if="!relationship.following">
  27. <button type="button" class="btn btn-outline-dark font-weight-bold px-4 py-0" v-on:click="followProfile()" data-toggle="tooltip" title="Follow">Follow</button>
  28. </p>
  29. </div>
  30. </div>
  31. </div>
  32. </div>
  33. <div class="d-none d-md-block">
  34. <img class="rounded-circle box-shadow" :src="profile.avatar" width="172px" height="172px">
  35. </div>
  36. </div>
  37. </div>
  38. <div class="col-12 col-md-8 d-flex align-items-center">
  39. <div class="profile-details">
  40. <div class="d-none d-md-flex username-bar pb-2 align-items-center">
  41. <span class="font-weight-ultralight h3">{{profile.username}}</span>
  42. <span class="pl-4" v-if="profile.is_admin">
  43. <span class="btn btn-outline-secondary font-weight-bold py-0">ADMIN</span>
  44. </span>
  45. <span class="pl-4">
  46. <a :href="'/users/'+profile.username+'.atom'" class="fas fa-rss fa-lg text-muted text-decoration-none"></a>
  47. </span>
  48. <span class="pl-4" v-if="owner">
  49. <a class="fas fa-cog fa-lg text-muted text-decoration-none" href="/settings/home"></a>
  50. </span>
  51. <span class="pl-4" v-if="profile.id != user.id && user.hasOwnProperty('id')">
  52. <a class="fas fa-cog fa-lg text-muted text-decoration-none" href="#" @click.prevent="visitorMenu"></a>
  53. </span>
  54. <span v-if="profile.id != user.id && user.hasOwnProperty('id')">
  55. <span class="pl-4" v-if="relationship.following == true">
  56. <button type="button" class="btn btn-outline-secondary font-weight-bold btn-sm" v-on:click="followProfile()" data-toggle="tooltip" title="Unfollow"><i class="fas fa-user-minus"></i></button>
  57. </span>
  58. <span class="pl-4" v-if="!relationship.following">
  59. <button type="button" class="btn btn-primary font-weight-bold btn-sm" v-on:click="followProfile()" data-toggle="tooltip" title="Follow"><i class="fas fa-user-plus"></i></button>
  60. </span>
  61. </span>
  62. </div>
  63. <div class="d-none d-md-inline-flex profile-stats pb-3 lead">
  64. <div class="font-weight-light pr-5">
  65. <a class="text-dark" :href="profile.url">
  66. <span class="font-weight-bold">{{profile.statuses_count}}</span>
  67. Posts
  68. </a>
  69. </div>
  70. <div v-if="profileSettings.followers.count" class="font-weight-light pr-5">
  71. <a class="text-dark cursor-pointer" v-on:click="followersModal()">
  72. <span class="font-weight-bold">{{profile.followers_count}}</span>
  73. Followers
  74. </a>
  75. </div>
  76. <div v-if="profileSettings.following.count" class="font-weight-light">
  77. <a class="text-dark cursor-pointer" v-on:click="followingModal()">
  78. <span class="font-weight-bold">{{profile.following_count}}</span>
  79. Following
  80. </a>
  81. </div>
  82. </div>
  83. <p class="lead mb-0 d-flex align-items-center pt-3">
  84. <span class="font-weight-bold pr-3">{{profile.display_name}}</span>
  85. </p>
  86. <div v-if="profile.note" class="mb-0 lead" v-html="profile.note"></div>
  87. <p v-if="profile.website" class="mb-0"><a :href="profile.website" class="font-weight-bold" rel="me external nofollow noopener" target="_blank">{{profile.website}}</a></p>
  88. </div>
  89. </div>
  90. </div>
  91. </div>
  92. </div>
  93. <div class="d-block d-md-none bg-white my-0 py-2 border-bottom">
  94. <ul class="nav d-flex justify-content-center">
  95. <li class="nav-item">
  96. <div class="font-weight-light">
  97. <span class="text-dark text-center">
  98. <p class="font-weight-bold mb-0">{{profile.statuses_count}}</p>
  99. <p class="text-muted mb-0">Posts</p>
  100. </span>
  101. </div>
  102. </li>
  103. <li class="nav-item px-5">
  104. <div v-if="profileSettings.followers.count" class="font-weight-light">
  105. <a class="text-dark cursor-pointer text-center" v-on:click="followersModal()">
  106. <p class="font-weight-bold mb-0">{{profile.followers_count}}</p>
  107. <p class="text-muted mb-0">Followers</p>
  108. </a>
  109. </div>
  110. </li>
  111. <li class="nav-item">
  112. <div v-if="profileSettings.following.count" class="font-weight-light">
  113. <a class="text-dark cursor-pointer text-center" v-on:click="followingModal()">
  114. <p class="font-weight-bold mb-0">{{profile.following_count}}</p>
  115. <p class="text-muted mb-0">Following</p>
  116. </a>
  117. </div>
  118. </li>
  119. </ul>
  120. </div>
  121. <div class="bg-white">
  122. <ul class="nav nav-topbar d-flex justify-content-center border-0">
  123. <!-- <li class="nav-item">
  124. <a class="nav-link active font-weight-bold text-uppercase" :href="profile.url">Posts</a>
  125. </li>
  126. -->
  127. <li class="nav-item">
  128. <a :class="this.mode == 'grid' ? 'nav-link font-weight-bold text-uppercase text-primary' : 'nav-link font-weight-bold text-uppercase'" href="#" v-on:click.prevent="switchMode('grid')"><i class="fas fa-th fa-lg"></i></a>
  129. </li>
  130. <!-- <li class="nav-item">
  131. <a :class="this.mode == 'masonry' ? 'nav-link font-weight-bold text-uppercase active' : 'nav-link font-weight-bold text-uppercase'" href="#" v-on:click.prevent="switchMode('masonry')"><i class="fas fa-th-large"></i></a>
  132. </li> -->
  133. <li class="nav-item px-3">
  134. <a :class="this.mode == 'list' ? 'nav-link font-weight-bold text-uppercase text-primary' : 'nav-link font-weight-bold text-uppercase'" href="#" v-on:click.prevent="switchMode('list')"><i class="fas fa-th-list fa-lg"></i></a>
  135. </li>
  136. <li class="nav-item" v-if="owner">
  137. <a class="nav-link font-weight-bold text-uppercase" :href="profile.url + '/saved'">Saved</a>
  138. </li>
  139. </ul>
  140. </div>
  141. <div class="container">
  142. <div class="profile-timeline mt-md-4">
  143. <div class="row" v-if="mode == 'grid'">
  144. <div class="col-4 p-0 p-sm-2 p-md-3" v-for="(s, index) in timeline">
  145. <a class="card info-overlay card-md-border-0" :href="s.url">
  146. <div class="square">
  147. <span v-if="s.pf_type == 'photo:album'" class="float-right mr-3 post-icon"><i class="fas fa-images fa-2x"></i></span>
  148. <span v-if="s.pf_type == 'video'" class="float-right mr-3 post-icon"><i class="fas fa-video fa-2x"></i></span>
  149. <span v-if="s.pf_type == 'video:album'" class="float-right mr-3 post-icon"><i class="fas fa-film fa-2x"></i></span>
  150. <div class="square-content" v-bind:style="previewBackground(s)">
  151. </div>
  152. <div class="info-overlay-text">
  153. <h5 class="text-white m-auto font-weight-bold">
  154. <span>
  155. <span class="far fa-heart fa-lg p-2 d-flex-inline"></span>
  156. <span class="d-flex-inline">{{s.favourites_count}}</span>
  157. </span>
  158. <span>
  159. <span class="fas fa-retweet fa-lg p-2 d-flex-inline"></span>
  160. <span class="d-flex-inline">{{s.reblogs_count}}</span>
  161. </span>
  162. </h5>
  163. </div>
  164. </div>
  165. </a>
  166. </div>
  167. </div>
  168. <div class="row" v-if="mode == 'list'">
  169. <div class="col-md-8 col-lg-8 offset-md-2 px-0 mb-3 timeline">
  170. <div class="card status-card card-md-rounded-0 my-sm-2 my-md-3 my-lg-4" :data-status-id="status.id" v-for="(status, index) in timeline" :key="status.id">
  171. <div class="card-header d-inline-flex align-items-center bg-white">
  172. <img v-bind:src="status.account.avatar" width="32px" height="32px" style="border-radius: 32px;">
  173. <a class="username font-weight-bold pl-2 text-dark" v-bind:href="status.account.url">
  174. {{status.account.username}}
  175. </a>
  176. <div class="text-right" style="flex-grow:1;">
  177. <div class="dropdown">
  178. <button class="btn btn-link text-dark no-caret dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" title="Post options">
  179. <span class="fas fa-ellipsis-v fa-lg text-muted"></span>
  180. </button>
  181. <div class="dropdown-menu dropdown-menu-right" aria-labelledby="dropdownMenuButton">
  182. <a class="dropdown-item font-weight-bold" :href="status.url">Go to post</a>
  183. <span v-bind:class="[statusOwner(status) ? 'd-none' : '']">
  184. <a class="dropdown-item font-weight-bold" :href="reportUrl(status)">Report</a>
  185. <a class="dropdown-item font-weight-bold" v-on:click="muteProfile(status)">Mute Profile</a>
  186. <a class="dropdown-item font-weight-bold" v-on:click="blockProfile(status)">Block Profile</a>
  187. </span>
  188. <span v-bind:class="[statusOwner(status) ? '' : 'd-none']">
  189. <a class="dropdown-item font-weight-bold" :href="editUrl(status)">Edit</a>
  190. <a class="dropdown-item font-weight-bold text-danger" v-on:click="deletePost(status)">Delete</a>
  191. </span>
  192. </div>
  193. </div>
  194. </div>
  195. </div>
  196. <div class="postPresenterContainer">
  197. <div v-if="status.pf_type === 'photo'" class="w-100">
  198. <photo-presenter :status="status"></photo-presenter>
  199. </div>
  200. <div v-else-if="status.pf_type === 'video'" class="w-100">
  201. <video-presenter :status="status"></video-presenter>
  202. </div>
  203. <div v-else-if="status.pf_type === 'photo:album'" class="w-100">
  204. <photo-album-presenter :status="status"></photo-album-presenter>
  205. </div>
  206. <div v-else-if="status.pf_type === 'video:album'" class="w-100">
  207. <video-album-presenter :status="status"></video-album-presenter>
  208. </div>
  209. <div v-else-if="status.pf_type === 'photo:video:album'" class="w-100">
  210. <mixed-album-presenter :status="status"></mixed-album-presenter>
  211. </div>
  212. <div v-else class="w-100">
  213. <p class="text-center p-0 font-weight-bold text-white">Error: Problem rendering preview.</p>
  214. </div>
  215. </div>
  216. <div class="card-body">
  217. <div class="reactions my-1">
  218. <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 cursor-pointer']" title="Like" v-on:click="likeStatus(status, $event)"></h3>
  219. <h3 class="far fa-comment pr-3 m-0 cursor-pointer" title="Comment" v-on:click="commentFocus(status, $event)"></h3>
  220. <h3 v-bind:class="[status.reblogged ? 'far fa-share-square pr-3 m-0 text-primary cursor-pointer' : 'far fa-share-square pr-3 m-0 share-btn cursor-pointer']" title="Share" v-on:click="shareStatus(status, $event)"></h3>
  221. </div>
  222. <div class="likes font-weight-bold">
  223. <span class="like-count">{{status.favourites_count}}</span> {{status.favourites_count == 1 ? 'like' : 'likes'}}
  224. </div>
  225. <div class="caption">
  226. <p class="mb-2 read-more" style="overflow: hidden;">
  227. <span class="username font-weight-bold">
  228. <bdi><a class="text-dark" :href="status.account.url">{{status.account.username}}</a></bdi>
  229. </span>
  230. <span v-html="status.content"></span>
  231. </p>
  232. </div>
  233. <div class="comments">
  234. </div>
  235. <div class="timestamp pt-1">
  236. <p class="small text-uppercase mb-0">
  237. <a :href="status.url" class="text-muted">
  238. <timeago :datetime="status.created_at" :auto-update="60" :converter-options="{includeSeconds:true}" :title="timestampFormat(status.created_at)" v-b-tooltip.hover.bottom></timeago>
  239. </a>
  240. </p>
  241. </div>
  242. </div>
  243. <div class="card-footer bg-white d-none">
  244. <form class="" v-on:submit.prevent="commentSubmit(status, $event)">
  245. <input type="hidden" name="item" value="">
  246. <input class="form-control status-reply-input" name="comment" placeholder="Add a comment…" autocomplete="off">
  247. </form>
  248. </div>
  249. </div>
  250. </div>
  251. </div>
  252. <div class="masonry-grid" v-if="mode == 'masonry'">
  253. <div class="d-inline p-0 p-sm-2 p-md-3 masonry-item" v-for="(status, index) in timeline">
  254. <a class="" v-on:click.prevent="statusModal(status)" :href="status.url">
  255. <img :src="previewUrl(status)" :class="'o-'+masonryOrientation(status)">
  256. </a>
  257. </div>
  258. </div>
  259. <div v-if="timeline.length">
  260. <infinite-loading @infinite="infiniteTimeline">
  261. <div slot="no-more"></div>
  262. <div slot="no-results"></div>
  263. </infinite-loading>
  264. </div>
  265. </div>
  266. </div>
  267. </div>
  268. <!-- <b-modal id="statusModal" ref="statusModalRef" hide-footer hide-header v-if="modalStatus" size="lg" v-on:hide.native="closeModal()" lazy class="border-0">
  269. <post-component v-bind:status-template="modalStatus.pf_type" v-bind:status-id="modalStatus.id" v-bind:status-username="modalStatus.account.username" v-bind:status-url="modalStatus.url" v-bind:status-profile-url="modalStatus.account.url" v-bind:status-avatar="modalStatus.account.avatar"></post-component>
  270. </b-modal> -->
  271. <b-modal ref="followingModal"
  272. id="following-modal"
  273. hide-footer
  274. centered
  275. title="Following"
  276. body-class="list-group-flush p-0">
  277. <div class="list-group">
  278. <div class="list-group-item border-0" v-for="(user, index) in following" :key="'following_'+index">
  279. <div class="media">
  280. <a :href="user.url">
  281. <img class="mr-3 rounded-circle box-shadow" :src="user.avatar" :alt="user.username + '’s avatar'" width="30px">
  282. </a>
  283. <div class="media-body">
  284. <p class="mb-0" style="font-size: 14px">
  285. <a :href="user.url" class="font-weight-bold text-dark">
  286. {{user.username}}
  287. </a>
  288. </p>
  289. <p class="text-muted mb-0" style="font-size: 14px">
  290. {{user.display_name}}
  291. </p>
  292. </div>
  293. </div>
  294. </div>
  295. <div v-if="followingMore" class="list-group-item text-center" v-on:click="followingLoadMore()">
  296. <p class="mb-0 small text-muted font-weight-light cursor-pointer">Load more</p>
  297. </div>
  298. </div>
  299. </b-modal>
  300. <b-modal ref="followerModal"
  301. id="follower-modal"
  302. hide-footer
  303. centered
  304. title="Followers"
  305. body-class="list-group-flush p-0">
  306. <div class="list-group">
  307. <div class="list-group-item border-0" v-for="(user, index) in followers" :key="'follower_'+index">
  308. <div class="media">
  309. <a :href="user.url">
  310. <img class="mr-3 rounded-circle box-shadow" :src="user.avatar" :alt="user.username + '’s avatar'" width="30px" loading="lazy">
  311. </a>
  312. <div class="media-body">
  313. <p class="mb-0" style="font-size: 14px">
  314. <a :href="user.url" class="font-weight-bold text-dark">
  315. {{user.username}}
  316. </a>
  317. </p>
  318. <p class="text-muted mb-0" style="font-size: 14px">
  319. {{user.display_name}}
  320. </p>
  321. </div>
  322. </div>
  323. </div>
  324. <div v-if="followerMore" class="list-group-item text-center" v-on:click="followersLoadMore()">
  325. <p class="mb-0 small text-muted font-weight-light cursor-pointer">Load more</p>
  326. </div>
  327. </div>
  328. </b-modal>
  329. <b-modal ref="visitorContextMenu"
  330. id="visitor-context-menu"
  331. hide-footer
  332. hide-header
  333. centered
  334. size="sm"
  335. body-class="list-group-flush p-0">
  336. <div class="list-group">
  337. <div class="list-group-item cursor-pointer text-center font-weight-bold lead rounded text-danger" @click="reportProfile">
  338. Report User
  339. </div>
  340. <div class="list-group-item cursor-pointer text-center font-weight-bold lead rounded" @click="muteProfile">
  341. Mute
  342. </div>
  343. <div class="list-group-item cursor-pointer text-center font-weight-bold lead rounded text-danger" @click="blockProfile">
  344. Block
  345. </div>
  346. <div class="list-group-item cursor-pointer text-center font-weight-bold lead rounded text-muted" @click="$refs.visitorContextMenu.hide()">
  347. Close
  348. </div>
  349. </div>
  350. </b-modal>
  351. </div>
  352. </template>
  353. <!-- <style type="text/css" scoped="">
  354. .modal-body {
  355. padding: 0;
  356. margin: 0;
  357. }
  358. @media (min-width: 992px) {
  359. .modal-lg, .modal-xl {
  360. max-width: 900px;
  361. }
  362. }
  363. </style> -->
  364. <style type="text/css" scoped>
  365. .o-square {
  366. max-width: 320px;
  367. }
  368. .o-portrait {
  369. max-width: 320px;
  370. }
  371. .o-landscape {
  372. max-width: 320px;
  373. }
  374. .post-icon {
  375. color: #fff;
  376. position:relative;
  377. margin-top: 10px;
  378. z-index: 9;
  379. opacity: 0.6;
  380. text-shadow: 3px 3px 16px #272634;
  381. }
  382. </style>
  383. <script type="text/javascript">
  384. export default {
  385. props: [
  386. 'profile-id',
  387. 'profile-settings'
  388. ],
  389. data() {
  390. return {
  391. profile: {},
  392. user: {},
  393. timeline: [],
  394. timelinePage: 2,
  395. min_id: 0,
  396. max_id: 0,
  397. loading: true,
  398. owner: false,
  399. mode: 'grid',
  400. modes: ['grid', 'list', 'masonry'],
  401. modalStatus: false,
  402. relationship: {},
  403. followers: [],
  404. followerCursor: 1,
  405. followerMore: true,
  406. following: [],
  407. followingCursor: 1,
  408. followingMore: true
  409. }
  410. },
  411. beforeMount() {
  412. this.fetchProfile();
  413. },
  414. mounted() {
  415. },
  416. updated() {
  417. },
  418. methods: {
  419. fetchProfile() {
  420. axios.get('/api/v1/accounts/' + this.profileId).then(res => {
  421. this.profile = res.data;
  422. });
  423. if($('body').hasClass('loggedIn') == true) {
  424. axios.get('/api/v1/accounts/verify_credentials').then(res => {
  425. this.user = res.data;
  426. });
  427. axios.get('/api/v1/accounts/relationships', {
  428. params: {
  429. 'id[]': this.profileId
  430. }
  431. }).then(res => {
  432. this.relationship = res.data[0];
  433. });
  434. }
  435. let apiUrl = '/api/v1/accounts/' + this.profileId + '/statuses';
  436. axios.get(apiUrl, {
  437. params: {
  438. only_media: true,
  439. min_id: 1,
  440. }
  441. })
  442. .then(res => {
  443. let data = res.data;
  444. this.timeline = data;
  445. let ids = data.map(status => status.id);
  446. this.min_id = Math.max(...ids);
  447. this.max_id = Math.min(...ids);
  448. this.modalStatus = _.first(res.data);
  449. this.loading = false;
  450. this.ownerCheck();
  451. }).catch(err => {
  452. swal(
  453. 'Oops, something went wrong',
  454. 'Please release the page.',
  455. 'error'
  456. );
  457. });
  458. },
  459. ownerCheck() {
  460. this.owner = this.profile.id === this.user.id;
  461. },
  462. infiniteTimeline($state) {
  463. let apiUrl = '/api/v1/accounts/' + this.profileId + '/statuses';
  464. axios.get(apiUrl, {
  465. params: {
  466. only_media: true,
  467. max_id: this.max_id
  468. },
  469. }).then(res => {
  470. if (res.data.length && this.loading == false) {
  471. let data = res.data;
  472. this.timeline.push(...data);
  473. let ids = data.map(status => status.id);
  474. this.max_id = Math.min(...ids);
  475. this.loading = false;
  476. $state.loaded();
  477. } else {
  478. $state.complete();
  479. }
  480. });
  481. },
  482. previewUrl(status) {
  483. return status.media_attachments[0].preview_url;
  484. },
  485. previewBackground(status) {
  486. let preview = this.previewUrl(status);
  487. return 'background-image: url(' + preview + ');';
  488. },
  489. switchMode(mode) {
  490. this.mode = _.indexOf(this.modes, mode) ? mode : 'grid';
  491. if(this.mode == 'masonry') {
  492. $('.masonry').masonry({
  493. columnWidth: 200,
  494. itemSelector: '.masonry-item'
  495. });
  496. }
  497. },
  498. reportProfile() {
  499. let id = this.profile.id;
  500. window.location.href = '/i/report?type=profile&id=' + id;
  501. },
  502. reportUrl(status) {
  503. let type = status.in_reply_to ? 'comment' : 'post';
  504. let id = status.id;
  505. return '/i/report?type=' + type + '&id=' + id;
  506. },
  507. commentFocus(status, $event) {
  508. let el = event.target;
  509. let card = el.parentElement.parentElement.parentElement;
  510. let comments = card.getElementsByClassName('comments')[0];
  511. if(comments.children.length == 0) {
  512. comments.classList.add('mb-2');
  513. this.fetchStatusComments(status, card);
  514. }
  515. let footer = card.querySelectorAll('.card-footer')[0];
  516. let input = card.querySelectorAll('.status-reply-input')[0];
  517. if(footer.classList.contains('d-none') == true) {
  518. footer.classList.remove('d-none');
  519. input.focus();
  520. } else {
  521. footer.classList.add('d-none');
  522. input.blur();
  523. }
  524. },
  525. likeStatus(status, $event) {
  526. if($('body').hasClass('loggedIn') == false) {
  527. return;
  528. }
  529. axios.post('/i/like', {
  530. item: status.id
  531. }).then(res => {
  532. status.favourites_count = res.data.count;
  533. if(status.favourited == true) {
  534. status.favourited = false;
  535. } else {
  536. status.favourited = true;
  537. }
  538. }).catch(err => {
  539. swal('Error', 'Something went wrong, please try again later.', 'error');
  540. });
  541. },
  542. shareStatus(status, $event) {
  543. if($('body').hasClass('loggedIn') == false) {
  544. return;
  545. }
  546. axios.post('/i/share', {
  547. item: status.id
  548. }).then(res => {
  549. status.reblogs_count = res.data.count;
  550. if(status.reblogged == true) {
  551. status.reblogged = false;
  552. } else {
  553. status.reblogged = true;
  554. }
  555. }).catch(err => {
  556. swal('Error', 'Something went wrong, please try again later.', 'error');
  557. });
  558. },
  559. timestampFormat(timestamp) {
  560. let ts = new Date(timestamp);
  561. return ts.toDateString() + ' ' + ts.toLocaleTimeString();
  562. },
  563. editUrl(status) {
  564. return status.url + '/edit';
  565. },
  566. redirect(url) {
  567. window.location.href = url;
  568. return;
  569. },
  570. replyUrl(status) {
  571. let username = this.profile.username;
  572. let id = status.account.id == this.profile.id ? status.id : status.in_reply_to_id;
  573. return '/p/' + username + '/' + id;
  574. },
  575. mentionUrl(status) {
  576. let username = status.account.username;
  577. let id = status.id;
  578. return '/p/' + username + '/' + id;
  579. },
  580. statusOwner(status) {
  581. let sid = status.account.id;
  582. let uid = this.profile.id;
  583. if(sid == uid) {
  584. return true;
  585. } else {
  586. return false;
  587. }
  588. },
  589. fetchStatusComments(status, card) {
  590. axios.get('/api/v2/status/'+status.id+'/replies')
  591. .then(res => {
  592. let comments = card.querySelectorAll('.comments')[0];
  593. let data = res.data;
  594. data.forEach(function(i, k) {
  595. let username = document.createElement('a');
  596. username.classList.add('font-weight-bold');
  597. username.classList.add('text-dark');
  598. username.classList.add('mr-2');
  599. username.setAttribute('href', i.account.url);
  600. username.textContent = i.account.username;
  601. let text = document.createElement('span');
  602. text.innerHTML = i.content;
  603. let comment = document.createElement('p');
  604. comment.classList.add('read-more');
  605. comment.classList.add('mb-0');
  606. comment.appendChild(username);
  607. comment.appendChild(text);
  608. comments.appendChild(comment);
  609. });
  610. }).catch(err => {
  611. })
  612. },
  613. muteProfile(status = null) {
  614. if($('body').hasClass('loggedIn') == false) {
  615. return;
  616. }
  617. let id = this.profileId;
  618. axios.post('/i/mute', {
  619. type: 'user',
  620. item: id
  621. }).then(res => {
  622. swal('Success', 'You have successfully muted ' + this.profile.acct, 'success');
  623. }).catch(err => {
  624. swal('Error', 'Something went wrong. Please try again later.', 'error');
  625. });
  626. },
  627. blockProfile(status = null) {
  628. if($('body').hasClass('loggedIn') == false) {
  629. return;
  630. }
  631. let id = this.profileId;
  632. axios.post('/i/block', {
  633. type: 'user',
  634. item: id
  635. }).then(res => {
  636. swal('Success', 'You have successfully blocked ' + this.profile.acct, 'success');
  637. }).catch(err => {
  638. swal('Error', 'Something went wrong. Please try again later.', 'error');
  639. });
  640. },
  641. deletePost(status, index) {
  642. if($('body').hasClass('loggedIn') == false || status.account.id !== this.profile.id) {
  643. return;
  644. }
  645. axios.post('/i/delete', {
  646. type: 'status',
  647. item: status.id
  648. }).then(res => {
  649. this.feed.splice(index,1);
  650. swal('Success', 'You have successfully deleted this post', 'success');
  651. }).catch(err => {
  652. swal('Error', 'Something went wrong. Please try again later.', 'error');
  653. });
  654. },
  655. commentSubmit(status, $event) {
  656. if($('body').hasClass('loggedIn') == false) {
  657. return;
  658. }
  659. let id = status.id;
  660. let form = $event.target;
  661. let input = $(form).find('input[name="comment"]');
  662. let comment = input.val();
  663. let comments = form.parentElement.parentElement.getElementsByClassName('comments')[0];
  664. axios.post('/i/comment', {
  665. item: id,
  666. comment: comment
  667. }).then(res => {
  668. input.val('');
  669. input.blur();
  670. let username = document.createElement('a');
  671. username.classList.add('font-weight-bold');
  672. username.classList.add('text-dark');
  673. username.classList.add('mr-2');
  674. username.setAttribute('href', this.user.url);
  675. username.textContent = this.user.username;
  676. let text = document.createElement('span');
  677. text.innerHTML = comment;
  678. let wrapper = document.createElement('p');
  679. wrapper.classList.add('read-more');
  680. wrapper.classList.add('mb-0');
  681. wrapper.appendChild(username);
  682. wrapper.appendChild(text);
  683. comments.insertBefore(wrapper, comments.firstChild);
  684. });
  685. },
  686. statusModal(status) {
  687. this.modalStatus = status;
  688. this.$refs.statusModalRef.show();
  689. },
  690. masonryOrientation(status) {
  691. let o = status.media_attachments[0].orientation;
  692. if(!o) {
  693. o = 'square';
  694. }
  695. return o;
  696. },
  697. followProfile() {
  698. if($('body').hasClass('loggedIn') == false) {
  699. return;
  700. }
  701. axios.post('/i/follow', {
  702. item: this.profileId
  703. }).then(res => {
  704. if(this.relationship.following) {
  705. this.profile.followers_count--;
  706. if(this.profile.locked == true) {
  707. window.location.href = '/';
  708. }
  709. } else {
  710. this.profile.followers_count++;
  711. }
  712. this.relationship.following = !this.relationship.following;
  713. });
  714. },
  715. followingModal() {
  716. if($('body').hasClass('loggedIn') == false) {
  717. window.location.href = encodeURI('/login?next=/' + this.profile.username + '/');
  718. return;
  719. }
  720. if(this.profileSettings.following.list == false) {
  721. return;
  722. }
  723. if(this.following.length > 0) {
  724. this.$refs.followingModal.show();
  725. return;
  726. }
  727. axios.get('/api/v1/accounts/'+this.profile.id+'/following', {
  728. params: {
  729. page: this.followingCursor
  730. }
  731. })
  732. .then(res => {
  733. this.following = res.data;
  734. this.followingCursor++;
  735. if(res.data.length < 10) {
  736. this.followingMore = false;
  737. }
  738. });
  739. this.$refs.followingModal.show();
  740. },
  741. followersModal() {
  742. if($('body').hasClass('loggedIn') == false) {
  743. window.location.href = encodeURI('/login?next=/' + this.profile.username + '/');
  744. return;
  745. }
  746. if(this.profileSettings.followers.list == false) {
  747. return;
  748. }
  749. if(this.followers.length > 0) {
  750. this.$refs.followerModal.show();
  751. return;
  752. }
  753. axios.get('/api/v1/accounts/'+this.profile.id+'/followers', {
  754. params: {
  755. page: this.followerCursor
  756. }
  757. })
  758. .then(res => {
  759. this.followers = res.data;
  760. this.followerCursor++;
  761. if(res.data.length < 10) {
  762. this.followerMore = false;
  763. }
  764. })
  765. this.$refs.followerModal.show();
  766. },
  767. followingLoadMore() {
  768. if($('body').hasClass('loggedIn') == false) {
  769. window.location.href = encodeURI('/login?next=/' + this.profile.username + '/');
  770. return;
  771. }
  772. axios.get('/api/v1/accounts/'+this.profile.id+'/following', {
  773. params: {
  774. page: this.followingCursor
  775. }
  776. })
  777. .then(res => {
  778. if(res.data.length > 0) {
  779. this.following.push(...res.data);
  780. this.followingCursor++;
  781. }
  782. if(res.data.length < 10) {
  783. this.followingMore = false;
  784. }
  785. });
  786. },
  787. followersLoadMore() {
  788. if($('body').hasClass('loggedIn') == false) {
  789. return;
  790. }
  791. axios.get('/api/v1/accounts/'+this.profile.id+'/followers', {
  792. params: {
  793. page: this.followerCursor
  794. }
  795. })
  796. .then(res => {
  797. if(res.data.length > 0) {
  798. this.followers.push(...res.data);
  799. this.followerCursor++;
  800. }
  801. if(res.data.length < 10) {
  802. this.followerMore = false;
  803. }
  804. });
  805. },
  806. visitorMenu() {
  807. if($('body').hasClass('loggedIn') == false) {
  808. return;
  809. }
  810. this.$refs.visitorContextMenu.show();
  811. }
  812. }
  813. }
  814. </script>