Skip to content

Commit 3655e50

Browse files
Merge pull request #838 from Adamant-im/dev
v4.10.6
2 parents 2a5ceeb + 71e4102 commit 3655e50

File tree

11 files changed

+193
-107
lines changed

11 files changed

+193
-107
lines changed

android/app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ android {
77
applicationId "im.adamant.adamantmessengerpwa"
88
minSdkVersion rootProject.ext.minSdkVersion
99
targetSdkVersion rootProject.ext.targetSdkVersion
10-
versionCode 4105
11-
versionName "4.10.5"
10+
versionCode 4106
11+
versionName "4.10.6"
1212
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1313
aaptOptions {
1414
// Files and dirs to omit from the packaged assets dir, modified to accommodate modern web apps.

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "adamant-im",
3-
"version": "4.10.5",
3+
"version": "4.10.6",
44
"type": "module",
55
"author": "ADAMANT Foundation <devs@adamant.im>",
66
"license": "GPLv3",

src/components/AChat/AChatAttachment/AChatFile.vue

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ import IconFile from '@/components/icons/common/IconFile.vue'
8080
import { useStore } from 'vuex'
8181
import { AChatFileLoader } from './AChatFileLoader'
8282
import { mdiImageOff } from '@mdi/js'
83-
import { useConsiderOffline } from '@/hooks/useConsiderOffline'
8483
8584
const className = 'a-chat-file'
8685
const classes = {
@@ -121,9 +120,6 @@ const isImage = computed(() => {
121120
return ['jpg', 'jpeg', 'png'].includes(props.file.extension!)
122121
})
123122
124-
const { consideredOffline } = useConsiderOffline()
125-
126-
127123
const fileName = computed(() =>
128124
isLocalFile(props.file) ? props.file.file.name : props.file.name || 'UNNAMED'
129125
)
@@ -150,10 +146,6 @@ const fileSize = computed(() => {
150146
151147
const uploadProgress = computed(() => {
152148
if (isLocalFile(props.file)) {
153-
if (consideredOffline.value) {
154-
return 0;
155-
}
156-
157149
return store.getters['attachment/getUploadProgress'](props.file.file.cid)
158150
}
159151

src/hooks/useConsiderOffline.ts

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1-
import { computed } from 'vue'
2-
import { useStore } from 'vuex'
1+
import { computed, watch } from 'vue'
2+
import { GetterTree, useStore } from 'vuex'
33
import { NodeStatusResult } from '@/lib/nodes/abstract.node'
4+
import { RootState } from '@/store/types'
45

5-
export function useConsiderOffline() {
6-
const store = useStore()
6+
export function useConsiderOffline(options?: { getters: GetterTree<any, RootState> }) {
7+
const getters = options?.getters ?? useStore().getters
78

8-
const isOnline = computed(() => store.getters['isOnline'])
9+
const isOnline = computed(() => getters['isOnline'])
910

10-
const admNodes = computed<NodeStatusResult[]>(() => store.getters['nodes/adm'])
11-
const coinNodes = computed<NodeStatusResult[]>(() => store.getters['nodes/coins'])
12-
const servicesNodes = computed<NodeStatusResult[]>(() => store.getters['services/services'])
13-
const ipfsNodes = computed<NodeStatusResult[]>(() => store.getters['nodes/ipfs'])
11+
const admNodes = computed<NodeStatusResult[]>(() => getters['nodes/adm'])
12+
const coinNodes = computed<NodeStatusResult[]>(() => getters['nodes/coins'])
13+
const servicesNodes = computed<NodeStatusResult[]>(() => getters['services/services'])
14+
const ipfsNodes = computed<NodeStatusResult[]>(() => getters['nodes/ipfs'])
1415

1516
const allNodes = computed<NodeStatusResult[]>(() => [
1617
...admNodes.value,
@@ -43,7 +44,29 @@ export function useConsiderOffline() {
4344
return !anyNodeOnline.value || everyNodeDisabled.value
4445
})
4546

47+
const offlineHandlers = new Set<() => void>()
48+
49+
const subscribeOffline = (callback: () => void) => {
50+
offlineHandlers.add(callback)
51+
52+
return () => {
53+
offlineHandlers.delete(callback)
54+
}
55+
}
56+
57+
const unsubscribeOffline = (callback: () => void) => {
58+
offlineHandlers.delete(callback)
59+
}
60+
61+
watch(consideredOffline, (isOffline) => {
62+
if (isOffline) {
63+
offlineHandlers.forEach((cb) => cb())
64+
}
65+
})
66+
4667
return {
47-
consideredOffline
68+
consideredOffline,
69+
subscribeOffline,
70+
unsubscribeOffline
4871
}
4972
}

src/hooks/useResendPendingMessages.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ type PendingMessage = {
99
timeout: ReturnType<typeof setTimeout>
1010
type: number
1111
files?: FileData[]
12+
cids?: [string, string | undefined][]
1213
}
1314

1415
export function useResendPendingMessages() {
@@ -48,6 +49,7 @@ export function useResendPendingMessages() {
4849
.dispatch('chat/resendAttachment', {
4950
recipientId: msg.recipientId,
5051
files: msg.files,
52+
cids: msg.cids,
5153
messageId: id
5254
})
5355
.then((res) => {

src/lib/adamant-api/asset.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -201,23 +201,21 @@ export interface AttachmentAsset {
201201
* AIP-18: https://github.com/Adamant-im/AIPs/pull/54/files
202202
* @param {Array<FileData>} files
203203
* @param {string} [comment] Optional comment associated with the transaction
204-
* @param {Array<[string]>} [cids] List of files IDs after uploading to IPFS. ID of original file and ID of preview go one by one.
204+
* @param {Array<[string, string][]>} [cids] List of files IDs after uploading to IPFS. First element is the ID of original file, second is ID of preview.
205205
*/
206206
export function attachmentAsset(
207207
files: FileData[],
208208
comment?: string,
209-
cids?: string[]
209+
cids?: [string, string][]
210210
): AttachmentAsset {
211211
return {
212212
files: files.map(({ file, width, height, cid, preview, encoded }, index) => {
213-
const cidsChunk = index * 2
214-
215213
const name = extractFileName(file.name)
216214
const extension = extractFileExtension(file.name)!
217215
const resolution: FileAsset['resolution'] = width && height ? [width, height] : undefined
218216

219-
const fileCid = (cids && cids[cidsChunk]) || cid
220-
const previewCid = (cids && cids[cidsChunk + 1]) || preview?.cid
217+
const fileCid = cids?.[index]?.[0] || cid
218+
const previewCid = cids?.[index]?.[1] || preview?.cid
221219

222220
return {
223221
mimeType: file.type,

src/lib/files/upload.ts

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,31 @@
11
import { FileData } from './types'
22
import ipfs from '@/lib/nodes/ipfs'
33

4-
export async function uploadFiles(
5-
files: FileData[],
6-
onUploadProgress?: (progress: number) => void
4+
export async function uploadFile(
5+
file: FileData,
6+
onUploadProgress?: (progress: number) => void,
7+
signal?: AbortSignal
78
) {
89
const formData = new FormData()
910

10-
for (const file of files) {
11-
const blob = new Blob([file.encoded.binary], { type: 'application/octet-stream' })
12-
formData.append('files', blob, file.file.name)
11+
const blob = new Blob([file.encoded.binary], { type: 'application/octet-stream' })
12+
formData.append('files', blob, file.file.name)
1313

14-
if (file.preview) {
15-
const blob = new Blob([file.preview.encoded.binary], { type: 'application/octet-stream' })
16-
formData.append('files', blob, 'preview-' + file.file.name)
17-
}
14+
if (file.preview) {
15+
const blob = new Blob([file.preview.encoded.binary], { type: 'application/octet-stream' })
16+
formData.append('files', blob, 'preview-' + file.file.name)
1817
}
1918

2019
onUploadProgress?.(0) // set initial progress to 0
21-
const response = await ipfs.upload(formData, (progress) => {
22-
const percentCompleted = Math.round((progress.loaded * 100) / (progress.total || 0))
23-
24-
onUploadProgress?.(percentCompleted)
25-
})
20+
const response = await ipfs.upload(
21+
formData,
22+
(progress) => {
23+
const percentCompleted = Math.round((progress.loaded * 100) / (progress.total || 0))
24+
25+
onUploadProgress?.(percentCompleted)
26+
},
27+
signal
28+
)
2629

2730
return response
2831
}

src/lib/nodes/ipfs/IpfsClient.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,20 @@ export class IpfsClient extends Client<IpfsNode> {
2828
})
2929
}
3030

31-
async upload(payload: FormData, onUploadProgress?: (progressEvent: AxiosProgressEvent) => void) {
31+
async upload(
32+
payload: FormData,
33+
onUploadProgress?: (progressEvent: AxiosProgressEvent) => void,
34+
signal?: AbortSignal
35+
) {
3236
return this.request({
3337
method: 'post',
3438
url: '/api/file/upload',
3539
payload,
3640
headers: {
3741
'Content-Type': 'multipart/form-data'
3842
},
39-
onUploadProgress
43+
onUploadProgress,
44+
signal
4045
})
4146
}
4247

src/lib/nodes/ipfs/IpfsNode.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export type RequestConfig<P extends Payload> = {
2525
payload?: P
2626
onUploadProgress?: (progress: AxiosProgressEvent) => void
2727
responseType?: ResponseType
28+
signal?: AbortSignal
2829
}
2930

3031
/**
@@ -50,7 +51,7 @@ export class IpfsNode extends Node<AxiosInstance> {
5051
* accepts `ApiNode` as a first argument and returns an object.
5152
*/
5253
request<P extends Payload = Payload, R = any>(cfg: RequestConfig<P>): Promise<R> {
53-
const { url, headers, method = 'get', payload, onUploadProgress } = cfg
54+
const { url, headers, method = 'get', payload, signal, onUploadProgress } = cfg
5455

5556
const config: AxiosRequestConfig = {
5657
url,
@@ -60,6 +61,7 @@ export class IpfsNode extends Node<AxiosInstance> {
6061
[method === 'get' ? 'params' : 'data']:
6162
typeof payload === 'function' ? payload(this) : payload,
6263
responseType: cfg.responseType,
64+
signal,
6365
onUploadProgress
6466
}
6567

@@ -117,7 +119,7 @@ export class IpfsNode extends Node<AxiosInstance> {
117119
protected async checkHealth() {
118120
const time = Date.now()
119121
const { timestamp } = await this.fetchNodeInfo()
120-
this.height = timestamp;
122+
this.height = timestamp
121123

122124
return {
123125
height: this.height,
@@ -127,9 +129,10 @@ export class IpfsNode extends Node<AxiosInstance> {
127129

128130
formatHeight(height: number): string {
129131
return super.formatHeight(
130-
Number(Math.ceil(height / 1000)
131-
.toString()
132-
.substring(2)
132+
Number(
133+
Math.ceil(height / 1000)
134+
.toString()
135+
.substring(2)
133136
)
134137
)
135138
}

0 commit comments

Comments
 (0)