Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(federation): chatting prerequisite #11517

Merged
merged 4 commits into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/components/LeftSidebar/ConversationsList/Conversation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@
{{ conversationInformation }}
</template>
</template>
<template v-if="isPublic || isGroup" #details>
<LinkIcon v-if="isPublic" :size="16" />
<template v-if="isFederated || isPublic || isGroup" #details>
<WebIcon v-if="isFederated" :size="16" />
<LinkIcon v-else-if="isPublic" :size="16" />
<AccountMultipleIcon v-else-if="isGroup" :size="16" />
</template>
<template v-if="!isSearchResult" #actions>
Expand Down Expand Up @@ -149,6 +150,7 @@ import EyeOffOutline from 'vue-material-design-icons/EyeOffOutline.vue'
import EyeOutline from 'vue-material-design-icons/EyeOutline.vue'
import LinkIcon from 'vue-material-design-icons/Link.vue'
import Star from 'vue-material-design-icons/Star.vue'
import WebIcon from 'vue-material-design-icons/Web.vue'

import { showError } from '@nextcloud/dialogs'
import { emit } from '@nextcloud/event-bus'
Expand Down Expand Up @@ -183,6 +185,7 @@ export default {
EyeOutline,
LinkIcon,
Star,
WebIcon,
},

props: {
Expand Down Expand Up @@ -239,6 +242,10 @@ export default {
return this.item.participantType !== PARTICIPANT.TYPE.USER_SELF_JOINED
},

isFederated() {
return !!this.item.remoteServer
},

isPublic() {
return this.item.type === CONVERSATION.TYPE.PUBLIC
},
Expand Down
6 changes: 2 additions & 4 deletions src/components/NewMessage/NewMessage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,6 @@ import { CONVERSATION, PARTICIPANT, PRIVACY } from '../../constants.js'
import { EventBus } from '../../services/EventBus.js'
import { shareFile } from '../../services/filesSharingServices.js'
import { searchPossibleMentions } from '../../services/mentionsService.js'
import { editMessage } from '../../services/messagesService.js'
import { useChatExtrasStore } from '../../stores/chatExtras.js'
import { useSettingsStore } from '../../stores/settings.js'
import { fetchClipboardContent } from '../../utils/clipboard.js'
Expand Down Expand Up @@ -692,12 +691,11 @@ export default {

async handleEdit() {
try {
const response = await editMessage({
await this.$store.dispatch('editMessage', {
token: this.token,
messageId: this.messageToEdit.id,
updatedMessage: this.text.trim()
updatedMessage: this.text.trim(),
})
this.$store.dispatch('processMessage', { token: this.token, message: response.data.ocs.data })
this.chatExtrasStore.removeMessageIdToEdit(this.token)
this.resetTypingIndicator()
} catch {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,15 @@ export default {
},
addableRemotes() {
return this.searchResults.filter((item) => item.source === 'remotes')
// TODO remove when Federation feature is ready
.concat(OC.debug
? this.addableUsers.map(user => ({
...user,
id: user.id + '@' + window.location.host,
label: user.id + '@' + window.location.host,
source: 'remotes',
}))
: [])
},

displaySearchHint() {
Expand Down
82 changes: 49 additions & 33 deletions src/services/messagesService.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,16 @@ import { generateOcsUrl } from '@nextcloud/router'
* @param {object} options options;
*/
const fetchMessages = async function({ token, lastKnownMessageId, includeLastKnown, limit = 100 }, options) {
return axios.get(generateOcsUrl('apps/spreed/api/v1/chat/{token}', { token }), Object.assign(options, {
return axios.get(generateOcsUrl('apps/spreed/api/v1/chat/{token}', { token }, options), {
...options,
params: {
setReadMarker: 0,
lookIntoFuture: 0,
lastKnownMessageId,
limit,
includeLastKnown: includeLastKnown ? 1 : 0,
},
}))
})
}

/**
Expand All @@ -60,7 +61,8 @@ const fetchMessages = async function({ token, lastKnownMessageId, includeLastKno
* @param {object} options options
*/
const lookForNewMessages = async ({ token, lastKnownMessageId, limit = 100 }, options) => {
return axios.get(generateOcsUrl('apps/spreed/api/v1/chat/{token}', { token }), Object.assign(options, {
return axios.get(generateOcsUrl('apps/spreed/api/v1/chat/{token}', { token }, options), {
...options,
params: {
setReadMarker: 0,
lookIntoFuture: 1,
Expand All @@ -69,7 +71,7 @@ const lookForNewMessages = async ({ token, lastKnownMessageId, limit = 100 }, op
includeLastKnown: 0,
markNotificationsAsRead: 0,
},
}))
})
}

/**
Expand All @@ -84,11 +86,12 @@ const lookForNewMessages = async ({ token, lastKnownMessageId, limit = 100 }, op
* @param {object} options options;
*/
const getMessageContext = async function({ token, messageId, limit = 50 }, options) {
return axios.get(generateOcsUrl('apps/spreed/api/v1/chat/{token}/{messageId}/context', { token, messageId }), Object.assign(options, {
return axios.get(generateOcsUrl('apps/spreed/api/v1/chat/{token}/{messageId}/context', { token, messageId }, options), {
...options,
params: {
limit,
},
}))
})
}

/**
Expand All @@ -104,7 +107,7 @@ const getMessageContext = async function({ token, messageId, limit = 50 }, optio
* @param {boolean} param1.silent whether the message should trigger a notifications
*/
const postNewMessage = async function({ token, message, actorDisplayName, referenceId, parent }, { silent, ...options }) {
return axios.post(generateOcsUrl('apps/spreed/api/v1/chat/{token}', { token }), {
return axios.post(generateOcsUrl('apps/spreed/api/v1/chat/{token}', { token }, options), {
message,
actorDisplayName,
referenceId,
Expand All @@ -119,9 +122,25 @@ const postNewMessage = async function({ token, message, actorDisplayName, refere
* @param {object} param0 The message object that is destructured
* @param {string} param0.token The conversation token
* @param {string} param0.id The id of the message to be deleted
* @param {object} options request options
*/
const deleteMessage = async function({ token, id }) {
return axios.delete(generateOcsUrl('apps/spreed/api/v1/chat/{token}/{id}', { token, id }))
const deleteMessage = async function({ token, id }, options) {
return axios.delete(generateOcsUrl('apps/spreed/api/v1/chat/{token}/{id}', { token, id }, options), options)
}

/**
* Edit a message text / file share caption.
*
* @param {object} param0 The destructured payload
* @param {string} param0.token The conversation token
* @param {string} param0.messageId The message id
* @param {string} param0.updatedMessage The modified text of the message / file share caption
* @param {object} options request options
*/
const editMessage = async function({ token, messageId, updatedMessage }, options) {
return axios.put(generateOcsUrl('apps/spreed/api/v1/chat/{token}/{messageId}', { token, messageId }, options), {
message: updatedMessage,
}, options)
}

/**
Expand All @@ -133,66 +152,63 @@ const deleteMessage = async function({ token, id }) {
* @param {string} data.objectId object id
* @param {string} data.metaData JSON metadata of the rich object encoded as string
* @param {string} data.referenceId generated reference id, leave empty to generate it based on the other args
* @param {object} options request options
*/
const postRichObjectToConversation = async function(token, { objectType, objectId, metaData, referenceId }) {
const postRichObjectToConversation = async function(token, { objectType, objectId, metaData, referenceId }, options) {
if (!referenceId) {
const tempId = 'richobject-' + objectType + '-' + objectId + '-' + token + '-' + (new Date().getTime())
referenceId = Hex.stringify(SHA256(tempId))
}
return axios.post(generateOcsUrl('apps/spreed/api/v1/chat/{token}/share', { token }), {
return axios.post(generateOcsUrl('apps/spreed/api/v1/chat/{token}/share', { token }, options), {
objectType,
objectId,
metaData,
referenceId,
})
}, options)
}

/**
* Updates the last read message id
*
* @param {string} token The token of the conversation to be removed from favorites
* @param {number} lastReadMessage id of the last read message to set
* @param {object} options request options
*/
const updateLastReadMessage = async function(token, lastReadMessage) {
return axios.post(generateOcsUrl('apps/spreed/api/v1/chat/{token}/read', { token }), {
const updateLastReadMessage = async function(token, lastReadMessage, options) {
return axios.post(generateOcsUrl('apps/spreed/api/v1/chat/{token}/read', { token }, options), {
lastReadMessage,
})
}, options)
}

const addReactionToMessage = async function(token, messageId, selectedEmoji) {
return axios.post(generateOcsUrl('apps/spreed/api/v1/reaction/{token}/{messageId}', { token, messageId }), {
const addReactionToMessage = async function(token, messageId, selectedEmoji, options) {
return axios.post(generateOcsUrl('apps/spreed/api/v1/reaction/{token}/{messageId}', { token, messageId }, options), {
reaction: selectedEmoji,
})
}, options)
}

const removeReactionFromMessage = async function(token, messageId, selectedEmoji) {
return axios.delete(generateOcsUrl('apps/spreed/api/v1/reaction/{token}/{messageId}', { token, messageId }), {
const removeReactionFromMessage = async function(token, messageId, selectedEmoji, options) {
return axios.delete(generateOcsUrl('apps/spreed/api/v1/reaction/{token}/{messageId}', { token, messageId }, options), {
...options,
params: {
reaction: selectedEmoji,
},
})
}

const getReactionsDetails = async function(token, messageId) {
return axios.get(generateOcsUrl('apps/spreed/api/v1/reaction/{token}/{messageId}', { token, messageId }))
}

const editMessage = async function({ token, messageId, updatedMessage }, options) {
return axios.put(generateOcsUrl('apps/spreed/api/v1/chat/{token}/{messageId}', { token, messageId }), {
message: updatedMessage,
}, options)
const getReactionsDetails = async function(token, messageId, options) {
return axios.get(generateOcsUrl('apps/spreed/api/v1/reaction/{token}/{messageId}', { token, messageId }, options), options)
}

const getTranslationLanguages = async function() {
return axios.get(generateOcsUrl('/translation/languages'))
const getTranslationLanguages = async function(options) {
return axios.get(generateOcsUrl('/translation/languages', undefined, options), options)
}

const translateText = async function(text, fromLanguage, toLanguage) {
return axios.post(generateOcsUrl('/translation/translate'), {
const translateText = async function(text, fromLanguage, toLanguage, options) {
return axios.post(generateOcsUrl('/translation/translate', undefined, options), {
text,
fromLanguage,
toLanguage,
})
}, options)
}

export {
Expand Down
Loading
Loading