From 8c726fd7451d0b0fa516e0df65cedafe8051a4b0 Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Tue, 25 May 2021 13:19:34 +1000 Subject: [PATCH] reupload avatar every 10 days --- background.html | 4 +- js/background.js | 22 ++---- libtextsecure/crypto.d.ts | 1 + preload.js | 1 + ts/components/Avatar.tsx | 6 +- ts/components/session/ActionsPanel.tsx | 96 +++++++++++++++++++++++++- ts/data/data.ts | 1 + ts/models/conversation.ts | 22 +----- 8 files changed, 112 insertions(+), 41 deletions(-) diff --git a/background.html b/background.html index 7d02dfdb6..58cf594e8 100644 --- a/background.html +++ b/background.html @@ -10,7 +10,7 @@
diff --git a/ts/data/data.ts b/ts/data/data.ts index d87f130b8..c5c4fb5d7 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/models/conversation.ts b/ts/models/conversation.ts index aa92d145a..f347cc5c3 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; @@ -778,23 +777,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; @@ -1223,11 +1205,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; }