diff --git a/ts/data/data.ts b/ts/data/data.ts
index d11731b36..275926369 100644
--- a/ts/data/data.ts
+++ b/ts/data/data.ts
@@ -60,6 +60,7 @@ export type ServerToken = {
};
export const hasSyncedInitialConfigurationItem = 'hasSyncedInitialConfigurationItem';
+export const lastAvatarUploadTimestamp = 'lastAvatarUploadTimestamp';
const channelsToMake = {
shutdown,
diff --git a/ts/fileserver/FileServerApiV2.ts b/ts/fileserver/FileServerApiV2.ts
index 642eba13a..1a161590b 100644
--- a/ts/fileserver/FileServerApiV2.ts
+++ b/ts/fileserver/FileServerApiV2.ts
@@ -4,9 +4,14 @@ import { parseStatusCodeFromOnionRequest } from '../opengroup/opengroupV2/OpenGr
import { fromArrayBufferToBase64, fromBase64ToArrayBuffer } from '../session/utils/String';
// tslint:disable-next-line: no-http-string
-export const fileServerV2URL = 'http://88.99.175.227';
-export const fileServerV2PubKey =
+export const oldFileServerV2URL = 'http://88.99.175.227';
+export const oldFileServerV2PubKey =
'7cb31905b55cd5580c686911debf672577b3fb0bff81df4ce2d5c4cb3a7aaa69';
+// tslint:disable-next-line: no-http-string
+export const fileServerV2URL = 'http://filev2.getsession.org';
+
+export const fileServerV2PubKey =
+ 'da21e1d886c6fbaea313f75298bd64aab03a97ce985b46bb2dad9f2089c8ee59';
export type FileServerV2Request = {
method: 'GET' | 'POST' | 'DELETE' | 'PUT';
@@ -14,6 +19,7 @@ export type FileServerV2Request = {
// queryParams are used for post or get, but not the same way
queryParams?: Record
;
headers?: Record;
+ isOldV2server?: boolean; // to remove in a few days
};
const FILES_ENDPOINT = 'files';
@@ -67,7 +73,8 @@ export const uploadFileToFsV2 = async (
* @returns the data as an Uint8Array or null
*/
export const downloadFileFromFSv2 = async (
- fileIdOrCompleteUrl: string
+ fileIdOrCompleteUrl: string,
+ isOldV2server: boolean
): Promise => {
let fileId = fileIdOrCompleteUrl;
if (!fileIdOrCompleteUrl) {
@@ -75,13 +82,19 @@ export const downloadFileFromFSv2 = async (
return null;
}
- const completeUrlPrefix = `${fileServerV2URL}/${FILES_ENDPOINT}/`;
- if (fileIdOrCompleteUrl.startsWith(completeUrlPrefix)) {
- fileId = fileId.substr(completeUrlPrefix.length);
+ const oldCompleteUrlPrefix = `${oldFileServerV2URL}/${FILES_ENDPOINT}/`;
+ const newCompleteUrlPrefix = `${fileServerV2URL}/${FILES_ENDPOINT}/`;
+
+ if (fileIdOrCompleteUrl.startsWith(newCompleteUrlPrefix)) {
+ fileId = fileId.substr(newCompleteUrlPrefix.length);
+ } else if (fileIdOrCompleteUrl.startsWith(oldCompleteUrlPrefix)) {
+ fileId = fileId.substr(oldCompleteUrlPrefix.length);
}
+
const request: FileServerV2Request = {
method: 'GET',
endpoint: `${FILES_ENDPOINT}/${fileId}`,
+ isOldV2server,
};
const result = await sendApiV2Request(request);
@@ -119,7 +132,11 @@ export const buildUrl = (request: FileServerV2Request | OpenGroupV2Request): URL
if (isOpenGroupV2Request(request)) {
rawURL = `${request.server}/${request.endpoint}`;
} else {
- rawURL = `${fileServerV2URL}/${request.endpoint}`;
+ if (request.isOldV2server) {
+ rawURL = `${oldFileServerV2URL}/${request.endpoint}`;
+ } else {
+ rawURL = `${fileServerV2URL}/${request.endpoint}`;
+ }
}
if (request.method === 'GET') {
diff --git a/ts/models/conversation.ts b/ts/models/conversation.ts
index c90402ca6..f98259e7d 100644
--- a/ts/models/conversation.ts
+++ b/ts/models/conversation.ts
@@ -179,7 +179,6 @@ export class ConversationModel extends Backbone.Model {
//start right away the function is called, and wait 1sec before calling it again
this.markRead = _.debounce(this.markReadBouncy, 1000, { leading: true });
// Listening for out-of-band data updates
- this.on('ourAvatarChanged', avatar => this.updateAvatarOnPublicChat(avatar));
this.typingRefreshTimer = null;
this.typingPauseTimer = null;
@@ -783,23 +782,6 @@ export class ConversationModel extends Backbone.Model {
return null;
}
- public async updateAvatarOnPublicChat({ url, profileKey }: any) {
- if (!this.isPublic()) {
- return;
- }
- // Always share avatars on PublicChat
-
- if (profileKey && typeof profileKey !== 'string') {
- // eslint-disable-next-line no-param-reassign
- // tslint:disable-next-line: no-parameter-reassignment
- profileKey = fromArrayBufferToBase64(profileKey);
- }
- const serverAPI = await window.lokiPublicChatAPI.findOrCreateServer(this.get('server'));
- if (!serverAPI) {
- return;
- }
- await serverAPI.setAvatar(url, profileKey);
- }
public async bouncyUpdateLastMessage() {
if (!this.id) {
return;
@@ -1227,11 +1209,11 @@ export class ConversationModel extends Backbone.Model {
// Not sure if we care about updating the database
}
- public async setProfileAvatar(avatar: any, avatarHash?: string) {
+ public async setProfileAvatar(avatar: null | { path: string }, avatarHash?: string) {
const profileAvatar = this.get('avatar');
const existingHash = this.get('avatarHash');
let shouldCommit = false;
- if (profileAvatar !== avatar) {
+ if (!_.isEqual(profileAvatar, avatar)) {
this.set({ avatar });
shouldCommit = true;
}
diff --git a/ts/opengroup/opengroupV2/OpenGroupAPIV2.ts b/ts/opengroup/opengroupV2/OpenGroupAPIV2.ts
index c39c40cc2..6303ae261 100644
--- a/ts/opengroup/opengroupV2/OpenGroupAPIV2.ts
+++ b/ts/opengroup/opengroupV2/OpenGroupAPIV2.ts
@@ -58,7 +58,7 @@ const getDestinationPubKey = async (
}
} else {
// this is a fileServer call
- return FSv2.fileServerV2PubKey;
+ return request.isOldV2server ? FSv2.oldFileServerV2PubKey : FSv2.fileServerV2PubKey;
}
};
diff --git a/ts/receiver/attachments.ts b/ts/receiver/attachments.ts
index 57d845009..1e690e734 100644
--- a/ts/receiver/attachments.ts
+++ b/ts/receiver/attachments.ts
@@ -23,18 +23,19 @@ export async function downloadAttachment(attachment: any) {
serverUrl
);
// is it an attachment hosted on the file server v2 ?
+ const defaultFsOldV2 = _.startsWith(serverUrl, FSv2.oldFileServerV2URL);
const defaultFsV2 = _.startsWith(serverUrl, FSv2.fileServerV2URL);
let res: ArrayBuffer | null = null;
- if (defaultFsV2) {
+ if (defaultFsV2 || defaultFsOldV2) {
let attachmentId = attachment.id;
if (!attachmentId) {
// try to get the fileId from the end of the URL
attachmentId = attachment.url;
}
window?.log?.info('Download v2 file server attachment');
- res = await FSv2.downloadFileFromFSv2(attachmentId);
+ res = await FSv2.downloadFileFromFSv2(attachmentId, defaultFsOldV2);
} else {
window.log.warn(
'downloadAttachment attachment is neither opengroup attachment nor fsv2... Dropping it'
diff --git a/ts/test/types/Attachment_test.ts b/ts/test/types/Attachment_test.ts
index 55bf2dd56..a30fc03bc 100644
--- a/ts/test/types/Attachment_test.ts
+++ b/ts/test/types/Attachment_test.ts
@@ -47,7 +47,7 @@ describe('Attachment', () => {
contentType: MIME.VIDEO_QUICKTIME,
};
const actual = Attachment.getSuggestedFilename({ attachment });
- const expected = 'session-attachment.mov';
+ const expected = 'funny-cat.mov';
assert.strictEqual(actual, expected);
});
it('should generate a filename without timestamp but with an index', () => {
@@ -60,7 +60,7 @@ describe('Attachment', () => {
attachment,
index: 3,
});
- const expected = 'session-attachment_003.mov';
+ const expected = 'funny-cat.mov';
assert.strictEqual(actual, expected);
});
it('should generate a filename with an extension if contentType is not setup', () => {
@@ -73,7 +73,7 @@ describe('Attachment', () => {
attachment,
index: 3,
});
- const expected = 'session-attachment_003.ini';
+ const expected = 'funny-cat.ini';
assert.strictEqual(actual, expected);
});
@@ -87,7 +87,7 @@ describe('Attachment', () => {
attachment,
index: 3,
});
- const expected = 'session-attachment_003.txt';
+ const expected = 'funny-cat.txt';
assert.strictEqual(actual, expected);
});
it('should generate a filename with an extension if contentType is json', () => {
@@ -100,7 +100,7 @@ describe('Attachment', () => {
attachment,
index: 3,
});
- const expected = 'session-attachment_003.json';
+ const expected = 'funny-cat.json';
assert.strictEqual(actual, expected);
});
});
@@ -116,14 +116,14 @@ describe('Attachment', () => {
attachment,
timestamp,
});
- const expected = 'session-attachment-2000-01-01-000000.mov';
+ const expected = 'funny-cat.mov';
assert.strictEqual(actual, expected);
});
});
context('for attachment with index', () => {
- it('should generate a filename based on timestamp', () => {
+ it('should generate a filename based on timestamp if filename is not set', () => {
const attachment: Attachment.AttachmentType = {
- fileName: 'funny-cat.mov',
+ fileName: '',
url: 'funny-cat.mov',
contentType: MIME.VIDEO_QUICKTIME,
};
@@ -136,6 +136,22 @@ describe('Attachment', () => {
const expected = 'session-attachment-1970-01-01-000000_003.mov';
assert.strictEqual(actual, expected);
});
+
+ it('should generate a filename based on filename if present', () => {
+ const attachment: Attachment.AttachmentType = {
+ fileName: 'funny-cat.mov',
+ url: 'funny-cat.mov',
+ contentType: MIME.VIDEO_QUICKTIME,
+ };
+ const timestamp = new Date(new Date(0).getTimezoneOffset() * 60 * 1000);
+ const actual = Attachment.getSuggestedFilename({
+ attachment,
+ timestamp,
+ index: 3,
+ });
+ const expected = 'funny-cat.mov';
+ assert.strictEqual(actual, expected);
+ });
});
});
diff --git a/ts/types/Attachment.ts b/ts/types/Attachment.ts
index b162c267a..cdb632a37 100644
--- a/ts/types/Attachment.ts
+++ b/ts/types/Attachment.ts
@@ -334,6 +334,9 @@ export const getSuggestedFilename = ({
timestamp?: number | Date;
index?: number;
}): string => {
+ if (attachment.fileName?.length > 3) {
+ return attachment.fileName;
+ }
const prefix = 'session-attachment';
const suffix = timestamp ? moment(timestamp).format('-YYYY-MM-DD-HHmmss') : '';
const fileType = getFileExtension(attachment);