Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F85630255
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Size
11 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/src/components/delete_button/delete_button.js b/src/components/delete_button/delete_button.js
index 200e2c0f1e..867869148b 100644
--- a/src/components/delete_button/delete_button.js
+++ b/src/components/delete_button/delete_button.js
@@ -1,17 +1,20 @@
+import Statuses from '../../services/new_api/statuses.js'
const DeleteButton = {
props: [ 'status' ],
methods: {
- deleteStatus () {
+ async deleteStatus () {
+ const store = this.$store
const confirmed = window.confirm('Do you really want to delete this status?')
+
if (confirmed) {
- this.$store.dispatch('deleteStatus', { id: this.status.id })
+ Statuses.delete({ store, params: this.status })
}
}
},
computed: {
currentUser () { return this.$store.state.users.currentUser },
- canDelete () { return this.currentUser && this.status.account.id === this.currentUser.id }
+ canDelete () { return (this.currentUser && this.status.account.id === this.currentUser.id) || (this.currentUser.pleroma.is_admin) || (this.currentUser.pleroma.is_moderator) }
}
}
export default DeleteButton
diff --git a/src/modules/notifications.js b/src/modules/notifications.js
index 409fb423d6..4646491570 100644
--- a/src/modules/notifications.js
+++ b/src/modules/notifications.js
@@ -1,31 +1,37 @@
import { map, each, merge, uniq } from 'lodash'
import Vue from 'vue'
const notifications = {
state: {
notifications: {},
visibleNotificationIds: []
},
mutations: {
addNewNotificationsTwo (state, newNotifications) {
each(newNotifications, (notification) => {
Vue.set(state.notifications, notification.id, merge(state.notifications[notification.id] || {}, notification))
})
},
setVisibleNotifications (state, { notificationIds }) {
state.visibleNotificationIds = notificationIds
+ },
+ deleteNotificationByStatusId ({ commit, state }, statusId) {
+ console.log(statusId)
}
},
actions: {
async addNewNotificationsTwo ({ commit, state }, { notifications }) {
const newUsers = map(notifications, 'account')
commit('addNewUsers', newUsers)
commit('addNewNotificationsTwo', notifications)
const newNotificationIds = map(notifications, 'id')
const notificationIds = uniq([...newNotificationIds, ...state.visibleNotificationIds])
commit('setVisibleNotifications', { notificationIds })
+ },
+ deleteNotificationByStatusId ({ commit, state }, statusId) {
+ commit('deleteNotificationByStatusId', statusId)
}
}
}
export default notifications
diff --git a/src/modules/statuses.js b/src/modules/statuses.js
index 6388c3b571..6d7de03157 100644
--- a/src/modules/statuses.js
+++ b/src/modules/statuses.js
@@ -1,104 +1,115 @@
-import { take, filter, each, merge, clone, map, uniq } from 'lodash'
+import { take, filter, each, merge, clone, map, uniq, without } from 'lodash'
import Vue from 'vue'
const defaultTimeline = {
statusIds: [],
visibleStatusIds: [],
loading: false,
links: {},
newStatusCount: 0
}
const defaultState = {
statuses: {},
timelines: {},
contexts: {}
}
const statuses = {
state: defaultState,
mutations: {
addNewStatuses (state, newStatuses) {
each(newStatuses, (status) => {
Vue.set(state.statuses, status.id, merge(state.statuses[status.id] || {}, status))
})
},
addStatusesToTimeline (state, { timelineName, statusIds }) {
let timeline = state.timelines[timelineName]
// Dynamically create timeline if we don't have it yet.
if (!timeline) {
timeline = clone(defaultTimeline)
Vue.set(state.timelines, timelineName, timeline)
}
// Prepend the new statusIds before the old ones.
timeline.statusIds = uniq(statusIds.concat(timeline.statusIds))
timeline.newStatusCount = timeline.newStatusCount + statusIds.length
},
setVisibleStatusesForTimeline (state, { timelineName, statusIds }) {
const timeline = state.timelines[timelineName]
timeline.visibleStatusIds = statusIds
timeline.newStatusCount = 0
},
setContext (state, { id, context }) {
Vue.set(state.contexts, id, context)
},
setPrevLinkForTimeline (state, { link, timelineName }) {
const timeline = state.timelines[timelineName]
timeline.links = { ...(timeline.links || {}), prev: link }
},
setNextLinkForTimeline (state, { link, timelineName }) {
const timeline = state.timelines[timelineName]
timeline.links = { ...(timeline.links || {}), next: link }
+ },
+ deleteStatusById (state, id) {
+ each(state.timelines, (timeline) => {
+ console.log(id)
+
+ timeline.statusIds = without(timeline.statusIds, id)
+ timeline.visibleStatusIds = without(timeline.visibleStatusIds, id)
+ })
}
},
actions: {
// Makes all availabe statuses visible. Should maybe be restricted.
showNewStatusesForTimeline ({ commit, state }, { timelineName }) {
const timeline = state.timelines[timelineName]
commit('setVisibleStatusesForTimeline', { timelineName, statusIds: clone(take(timeline.statusIds, 100)) })
},
showOldStatusesForTimeline ({ commit, state }, { timelineName, statuses }) {
const timeline = state.timelines[timelineName]
const statusIds = map(statuses, 'id')
commit('setVisibleStatusesForTimeline', { timelineName, statusIds: [...timeline.visibleStatusIds, ...statusIds] })
},
addNewStatus ({ commit, state }, { status }) {
commit('addNewUsers', [status.account])
commit('addNewStatuses', [status])
if (status.reblog) {
commit('addNewUsers', [status.reblog.account])
commit('addNewStatuses', [status.reblog])
}
},
addNewStatusesToTimeline ({ commit, state, dispatch }, { statuses, timelineName, showImmediately = false }) {
const newUsers = map(statuses, 'account')
commit('addNewUsers', newUsers)
const reblogs = map(filter(statuses, 'reblog'), 'reblog')
commit('addNewStatuses', reblogs)
const newRebloggedUsers = map(reblogs, 'account')
commit('addNewUsers', newRebloggedUsers)
commit('addNewStatuses', statuses)
const statusIds = map(statuses, 'id')
commit('addStatusesToTimeline', { timelineName, statusIds })
if (showImmediately) {
commit('setVisibleStatusesForTimeline', { timelineName, statusIds })
}
dispatch('fetchMissingRepliedUsers', { statuses })
},
addNewStatusesToContext ({ commit, state }, { context, status }) {
const statuses = [...context.ancestors, ...context.descendants]
const newUsers = map(statuses, 'account')
commit('addNewUsers', newUsers)
commit('addNewStatuses', statuses)
const idContext = {
descendants: map(context.descendants, 'id'),
ancestors: map(context.ancestors, 'id')
}
commit('setContext', { id: status.id, context: idContext })
+ },
+ deleteStatusById ({ commit, state }, id) {
+ commit('deleteStatusById', id)
}
}
}
export default statuses
diff --git a/src/services/new_api/statuses.js b/src/services/new_api/statuses.js
index 3b6007488c..69ede16543 100644
--- a/src/services/new_api/statuses.js
+++ b/src/services/new_api/statuses.js
@@ -1,62 +1,69 @@
import utils from './utils.js'
const Statuses = {
context ({ store, params: { id } }) {
return utils.request({
store,
url: `/api/v1/statuses/${id}/context`
}).then((data) => data.json())
},
get ({ store, params: { id } }) {
return utils.request({
store,
url: `/api/v1/statuses/${id}`
}).then((data) => data.json())
},
async post ({ store, params }) {
const res = await utils.request({
store,
url: '/api/v1/statuses',
method: 'POST',
body: JSON.stringify(params),
headers: {
'Content-Type': 'application/json'
}
})
return res.json()
},
async favourite ({ store, params: { id } }) {
const res = await utils.request({
method: 'POST',
store,
url: `/api/v1/statuses/${id}/favourite`
})
return res.json()
},
async unfavourite ({ store, params: { id } }) {
const res = await utils.request({
method: 'POST',
store,
url: `/api/v1/statuses/${id}/unfavourite`
})
return res.json()
},
async reblog ({ store, params: { id } }) {
const res = await utils.request({
method: 'POST',
store,
url: `/api/v1/statuses/${id}/reblog`
})
return res.json()
},
async unreblog ({ store, params: { id } }) {
const res = await utils.request({
method: 'POST',
store,
url: `/api/v1/statuses/${id}/unreblog`
})
return res.json()
+ },
+ delete ({ store, params: { id } }) {
+ utils.request({
+ method: 'DELETE',
+ store,
+ url: `/api/v1/statuses/${id}`
+ })
}
}
export default Statuses
diff --git a/src/services/timeline_fetcher/timeline_fetcher.service.js b/src/services/timeline_fetcher/timeline_fetcher.service.js
index 4a664d1e19..ab2b2b4d11 100644
--- a/src/services/timeline_fetcher/timeline_fetcher.service.js
+++ b/src/services/timeline_fetcher/timeline_fetcher.service.js
@@ -1,89 +1,93 @@
import Timelines from '../new_api/timelines.js'
import Users from '../new_api/users.js'
const streamTimeline = ({ timelineName, store }) => {
const rootState = store.rootState || store.state
const timelines = {
publicAndExternal: 'public',
public: 'public:local',
home: 'user'
}
let url = `${rootState.instance.server}/api/v1/streaming?stream=${timelines[timelineName]}`.replace('http', 'ws')
let status = ''
if (rootState.oauth.token) {
url = `${url}&access_token=${rootState.oauth.token}`
}
let socket = null
const stop = () => socket.close()
const connect = () => {
status = ''
socket = new window.WebSocket(url)
socket.addEventListener('message', (event) => {
if (event.data === '') { return }
const data = JSON.parse(event.data)
console.log(data.event)
if (data.event === 'update') {
const status = JSON.parse(data.payload)
store.dispatch('addNewStatusesToTimeline', { statuses: [status], timelineName })
}
if (data.event === 'notification') {
const notification = JSON.parse(data.payload)
store.dispatch('addNewNotificationsTwo', { notifications: [notification] })
}
+ if (data.event === 'delete') {
+ store.dispatch('deleteStatusById', data.payload)
+ store.dispatch('deleteNotificationByStatusId', data.payload)
+ }
})
socket.onopen = () => {
status = 'connected'
}
socket.onclose = () => {
status = 'closed'
}
}
const getStatus = () => (status)
return {
connect,
stop,
getStatus
}
}
const TimelineFetcher = {
async create (store, { type, params = {}, timelineName }) {
// Initial fetch, directly
let tf
switch (type) {
case 'public':
tf = Timelines.public
break
case 'user':
tf = Users.statuses
break
case 'home':
tf = Timelines.home
break
}
const { statuses, links } = await tf({ store, params })
store.dispatch('addNewStatusesToTimeline', { statuses, timelineName, showImmediately: true })
store.commit('setPrevLinkForTimeline', { link: links.prev, timelineName })
store.commit('setNextLinkForTimeline', { link: links.next, timelineName })
// Streaming, reactivate later
const socket = streamTimeline({ store, timelineName })
console.log(socket)
socket.connect()
// Next fetch uses the link headers
const fetcher = async () => {
store.dispatch('fetchPrevForTimeline', { timelineName })
}
return setInterval(fetcher, 10000)
}
}
export default TimelineFetcher
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Sun, Aug 9, 11:28 AM (1 d, 12 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1724495
Default Alt Text
(11 KB)
Attached To
Mode
rPUFE pleroma-fe-upstream
Attached
Detach File
Event Timeline
Log In to Comment