Skip to content

Commit

Permalink
Allow other apps to register message actions
Browse files Browse the repository at this point in the history
Signed-off-by: Marco Ambrosini <marcoambrosini@pm.me>
  • Loading branch information
marcoambrosini committed Jan 26, 2021
1 parent 10669b7 commit 1914498
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/components/MessagesList/MessagesGroup/Message/Message.vue
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,16 @@ the main body of the message as well as a quote.
@click.stop="handleReply">
{{ t('spreed', 'Reply') }}
</ActionButton>
<template
v-for="action in messageActions">
<ActionButton
:key="action.label"
icon="action.icon"
:close-after-click="true"
@click="action.callback">
{{ action.label }}
</ActionButton>
</template>
</Actions>
</div>
</div>
Expand Down Expand Up @@ -429,6 +439,10 @@ export default {
return t('spreed', 'You can not send messages to this conversation at the moment')
},
messageActions() {
return this.$store.getters.messageActions
},
},
watch: {
Expand Down
12 changes: 12 additions & 0 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,15 @@ Sidebar.prototype.close = function() {
Object.assign(window.OCA.Files, {
Sidebar: new Sidebar(),
})

if (!window.OCA.Talk) {
window.OCA.Talk = {}
}
window.OCA.Talk.registerMessageAction = (label, callback, icon) => {
const messageAction = {
label,
callback,
icon,
}
store.dispatch('addMessageAction', messageAction)
}
2 changes: 2 additions & 0 deletions src/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import sidebarStore from './sidebarStore'
import talkHashStore from './talkHashStore'
import tokenStore from './tokenStore'
import windowVisibilityStore from './windowVisibilityStore'
import messageActionsStore from './messageActionsStore'

Vue.use(Vuex)

Expand All @@ -57,6 +58,7 @@ export default new Store({
talkHashStore,
tokenStore,
windowVisibilityStore,
messageActionsStore,
},

mutations,
Expand Down
44 changes: 44 additions & 0 deletions src/store/messageActionsStore.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
* @copyright Copyright (c) 2020 Marco Ambrosini <marcoambrosini@pm.me>
*
* @author Marco Ambrosini <marcoambrosini@pm.me>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
const state = {
messageActions: [],
}

const getters = {
messageActions: (state) => {
return state.messageActions
},
}

const mutations = {
addMessageAction(state, messageAction) {
state.messageActions.push(messageAction)
},
}

const actions = {
addMessageAction({ commit }, messageAction) {
commit('addMessageAction', messageAction)
},
}

export default { state, mutations, getters, actions }

0 comments on commit 1914498

Please sign in to comment.