diff --git a/ts/models/conversation.ts b/ts/models/conversation.ts index 0547270bc..7fd073f49 100644 --- a/ts/models/conversation.ts +++ b/ts/models/conversation.ts @@ -287,8 +287,6 @@ export class ConversationModel extends Backbone.Model { const isPrivate = this.isPrivate(); const weAreAdmin = this.isAdmin(ourNumber); const weAreModerator = this.isModerator(ourNumber); // only used for sogs - const isMe = this.isMe(); - const isTyping = !!this.typingTimer; const currentNotificationSetting = this.get('triggerNotificationsFor'); const priorityFromDb = this.get('priority'); @@ -311,9 +309,17 @@ export class ConversationModel extends Backbone.Model { if (isPrivate) { toRet.isPrivate = true; + if (this.typingTimer) { + toRet.isTyping = true; + } + if (this.isMe()) { + toRet.isMe = true; + } + const foundContact = SessionUtilContact.getContactCached(this.id); - if (!toRet.activeAt && foundContact && isFinite(foundContact.createdAt)) { - toRet.activeAt = foundContact.createdAt; + + if (!toRet.activeAt && foundContact && isFinite(foundContact.createdAtSeconds)) { + toRet.activeAt = foundContact.createdAtSeconds * 1000; // active at is in ms } } @@ -325,15 +331,9 @@ export class ConversationModel extends Backbone.Model { toRet.weAreModerator = true; } - if (isMe) { - toRet.isMe = true; - } if (isPublic) { toRet.isPublic = true; } - if (isTyping) { - toRet.isTyping = true; - } if (avatarPath) { toRet.avatarPath = avatarPath; @@ -346,6 +346,28 @@ export class ConversationModel extends Backbone.Model { toRet.currentNotificationSetting = currentNotificationSetting; } + if (this.get('displayNameInProfile')) { + toRet.displayNameInProfile = this.get('displayNameInProfile'); + } + if (this.get('nickname')) { + toRet.nickname = this.get('nickname'); + } + if (BlockedNumberController.isBlocked(this.id)) { + toRet.isBlocked = true; + } + if (this.get('didApproveMe')) { + toRet.didApproveMe = this.get('didApproveMe'); + } + if (this.get('isApproved')) { + toRet.isApproved = this.get('isApproved'); + } + if (this.get('expireTimer')) { + toRet.expireTimer = this.get('expireTimer'); + } + if (this.get('markedAsUnread')) { + toRet.isMarkedUnread = this.get('markedAsUnread'); + } + // const foundCommunity = SessionUtilUserGroups.getCommunityByConvoIdCached(this.id); // const foundLegacyGroup = SessionUtilUserGroups.getLegacyGroupCached(this.id); // const foundVolatileInfo = SessionUtilConvoInfoVolatile.getVolatileInfoCached(this.id); @@ -380,30 +402,6 @@ export class ConversationModel extends Backbone.Model { // toRet.expireTimer = foundContact.expirationTimerSeconds; // } // } else { - if (this.get('displayNameInProfile')) { - toRet.displayNameInProfile = this.get('displayNameInProfile'); - } - - if (this.get('nickname')) { - toRet.nickname = this.get('nickname'); - } - - if (BlockedNumberController.isBlocked(this.id)) { - toRet.isBlocked = true; - } - - if (this.get('didApproveMe')) { - toRet.didApproveMe = this.get('didApproveMe'); - } - - if (this.get('isApproved')) { - toRet.isApproved = this.get('isApproved'); - } - - if (this.get('expireTimer')) { - toRet.expireTimer = this.get('expireTimer'); - } - // } // // -- Handle the group fields from the wrapper and the database -- // if (foundLegacyGroup) { @@ -418,22 +416,23 @@ export class ConversationModel extends Backbone.Model { // if (foundLegacyGroup.priority) { // toRet.priority = foundLegacyGroup.priority; // } - /*} else*/ if (this.isClosedGroup()) { + // } + + // those are values coming only from both the DB or the wrapper. Currently we display the data from the DB + if (this.isClosedGroup()) { toRet.members = this.get('members') || []; toRet.groupAdmins = this.getGroupAdmins(); - toRet.displayNameInProfile = this.get('displayNameInProfile'); - toRet.expireTimer = this.get('expireTimer'); } // those are values coming only from the DB when this is a closed group if (this.isClosedGroup()) { if (this.get('isKickedFromGroup')) { - toRet.isKickedFromGroup = !!this.get('isKickedFromGroup'); + toRet.isKickedFromGroup = this.get('isKickedFromGroup'); } if (this.get('left')) { - toRet.left = !!this.get('left'); + toRet.left = this.get('left'); } - + // to be dropped once we get rid of the legacy closed groups const zombies = this.get('zombies') || []; if (zombies?.length) { toRet.zombies = uniq(zombies); @@ -451,10 +450,6 @@ export class ConversationModel extends Backbone.Model { // if (foundVolatileInfo.unread) { // toRet.isMarkedUnread = foundVolatileInfo.unread; // } - // } else { - if (this.get('markedAsUnread')) { - toRet.isMarkedUnread = this.get('markedAsUnread'); - } // } // -- Handle the field stored only in memory for all types of conversation-- @@ -468,7 +463,7 @@ export class ConversationModel extends Backbone.Model { } } - // -- Handle the last message status, if needed -- + // -- Handle the last message status, if present -- const lastMessageText = this.get('lastMessage'); if (lastMessageText && lastMessageText.length) { const lastMessageStatus = this.get('lastMessageStatus'); @@ -2273,13 +2268,11 @@ export async function commitConversationAndRefreshWrapper(id: string) { await SessionUtilUserGroups.insertGroupsFromDBIntoWrapperAndRefresh(convo.id); } break; - case 'ConvoInfoVolatileConfig': if (SessionUtilConvoInfoVolatile.isConvoToStoreInWrapper(convo)) { await SessionUtilConvoInfoVolatile.insertConvoFromDBIntoWrapperAndRefresh(convo.id); } break; - default: assertUnreachable( variant, diff --git a/ts/receiver/configMessage.ts b/ts/receiver/configMessage.ts index 76f2bd942..1f739ea2f 100644 --- a/ts/receiver/configMessage.ts +++ b/ts/receiver/configMessage.ts @@ -161,12 +161,12 @@ async function handleContactsUpdate(result: IncomingConfResult): Promise { private deleteJobsByIdentifier(identifiers: Array) { identifiers.forEach(identifier => { const jobIndex = this.jobsScheduled.findIndex(f => f.persistedData.identifier === identifier); - window.log.info( + window.log.debug( `removing job ${jobToLogId( this.jobRunnerType, this.jobsScheduled[jobIndex] diff --git a/ts/session/utils/job_runners/jobs/ConfigurationSyncDumpJob.ts b/ts/session/utils/job_runners/jobs/ConfigurationSyncDumpJob.ts index a4e9cf169..616ac2fa5 100644 --- a/ts/session/utils/job_runners/jobs/ConfigurationSyncDumpJob.ts +++ b/ts/session/utils/job_runners/jobs/ConfigurationSyncDumpJob.ts @@ -15,6 +15,10 @@ import { PersistedJob, RunJobResult, } from '../PersistedJob'; +import { SessionUtilUserProfile } from '../../libsession/libsession_utils_user_profile'; +import { SessionUtilContact } from '../../libsession/libsession_utils_contacts'; +import { SessionUtilUserGroups } from '../../libsession/libsession_utils_user_groups'; +import { SessionUtilConvoInfoVolatile } from '../../libsession/libsession_utils_convo_info_volatile'; const defaultMsBetweenRetries = DURATION.SECONDS * 5; const defaultMaxAttempts = 2; @@ -93,7 +97,6 @@ class ConfigurationSyncDumpJob extends PersistedJob const variant = LibSessionUtil.requiredUserVariants[index]; switch (variant) { case 'UserConfig': - await LibSessionUtil.insertUserProfileIntoWrapper(us); + await SessionUtilUserProfile.insertUserProfileIntoWrapper(us); break; case 'ContactsConfig': - await LibSessionUtil.insertAllContactsIntoContactsWrapper(); + await SessionUtilContact.insertAllContactsIntoContactsWrapper(); break; case 'UserGroupsConfig': - await LibSessionUtil.insertAllUserGroupsIntoWrapper(); + await SessionUtilUserGroups.insertAllUserGroupsIntoWrapper(); break; case 'ConvoInfoVolatileConfig': - await LibSessionUtil.insertAllConvoInfoVolatileIntoWrapper(); + await SessionUtilConvoInfoVolatile.insertAllConvoInfoVolatileIntoWrapper(); break; default: assertUnreachable(variant, `ConfigurationSyncDumpJob unhandled variant: "${variant}"`); diff --git a/ts/session/utils/libsession/libsession_utils.ts b/ts/session/utils/libsession/libsession_utils.ts index ac6b6d255..ee529d02c 100644 --- a/ts/session/utils/libsession/libsession_utils.ts +++ b/ts/session/utils/libsession/libsession_utils.ts @@ -10,10 +10,6 @@ import { GetNetworkTime } from '../../apis/snode_api/getNetworkTime'; import { SnodeNamespaces } from '../../apis/snode_api/namespaces'; import { SharedConfigMessage } from '../../messages/outgoing/controlMessage/SharedConfigMessage'; import { ConfigurationSync } from '../job_runners/jobs/ConfigurationSyncJob'; -import { SessionUtilContact } from './libsession_utils_contacts'; -import { SessionUtilConvoInfoVolatile } from './libsession_utils_convo_info_volatile'; -import { SessionUtilUserGroups } from './libsession_utils_user_groups'; -import { SessionUtilUserProfile } from './libsession_utils_user_profile'; const requiredUserVariants: Array = [ 'UserConfig', @@ -107,8 +103,9 @@ async function pendingChangesForPubkey(pubkey: string): Promise m.id); - window.log.debug(`ContactsWrapper keep tracks of ${idsToInsert.length} contacts`); + window.log.debug(`ContactsWrapper keep tracks of ${idsToInsert.length} contacts: ${idsToInsert}`); for (let index = 0; index < idsToInsert.length; index++) { const id = idsToInsert[index]; diff --git a/ts/session/utils/libsession/libsession_utils_convo_info_volatile.ts b/ts/session/utils/libsession/libsession_utils_convo_info_volatile.ts index a5c479b36..65e050823 100644 --- a/ts/session/utils/libsession/libsession_utils_convo_info_volatile.ts +++ b/ts/session/utils/libsession/libsession_utils_convo_info_volatile.ts @@ -98,7 +98,7 @@ async function insertConvoFromDBIntoWrapperAndRefresh(convoId: string): Promise< ? timestampFromDbMs : 0; - console.info( + window.log.debug( `convoInfoVolatile:insert "${convoId}";lastMessageReadTimestamp:${lastReadMessageTimestamp};forcedUnread:${isForcedUnread}...` ); diff --git a/ts/session/utils/libsession/libsession_utils_user_groups.ts b/ts/session/utils/libsession/libsession_utils_user_groups.ts index 473fdc072..2d63dd322 100644 --- a/ts/session/utils/libsession/libsession_utils_user_groups.ts +++ b/ts/session/utils/libsession/libsession_utils_user_groups.ts @@ -107,7 +107,7 @@ async function insertGroupsFromDBIntoWrapperAndRefresh(convoId: string): Promise }); try { - console.info(`inserting into usergroup wrapper "${wrapperComm.fullUrl}"...`); + window.log.debug(`inserting into usergroup wrapper "${wrapperComm.fullUrl}"...`); // this does the create or the update of the matching existing community await UserGroupsWrapperActions.setCommunityByFullUrl( wrapperComm.fullUrl, @@ -135,7 +135,7 @@ async function insertGroupsFromDBIntoWrapperAndRefresh(convoId: string): Promise }); try { - console.info(`inserting into usergroup wrapper "${foundConvo.id}"... }`); + window.log.debug(`inserting into usergroup wrapper "${foundConvo.id}"... }`); // this does the create or the update of the matching existing legacy group await UserGroupsWrapperActions.setLegacyGroup(wrapperLegacyGroup); diff --git a/ts/types/sqlSharedTypes.ts b/ts/types/sqlSharedTypes.ts index e124eacb8..9cb852381 100644 --- a/ts/types/sqlSharedTypes.ts +++ b/ts/types/sqlSharedTypes.ts @@ -1,6 +1,6 @@ import { from_hex } from 'libsodium-wrappers-sumo'; import { isArray, isEmpty, isEqual } from 'lodash'; -import { ContactInfo, LegacyGroupInfo, LegacyGroupMemberInfo } from 'session_util_wrapper'; +import { ContactInfoSet, LegacyGroupInfo, LegacyGroupMemberInfo } from 'session_util_wrapper'; import { OpenGroupV2Room } from '../data/opengroups'; import { ConversationAttributes } from '../models/conversationAttributes'; import { OpenGroupRequestCommonType } from '../session/apis/open_group_api/opengroupV2/ApiUtil'; @@ -40,7 +40,6 @@ export type ConfigDumpRow = { variant: ConfigWrapperObjectTypes; // the variant this entry is about. (user pr, contacts, ...) publicKey: string; // either our pubkey if a dump for our own swarm or the closed group pubkey data: Uint8Array; // the blob returned by libsession.dump() call - // we might need to add a `seqno` field here. }; export type ConfigDumpRowWithoutData = Pick; @@ -128,8 +127,8 @@ export function getContactInfoFromDBValues({ dbProfileUrl: string | undefined; dbProfileKey: string | undefined; expirationTimerSeconds: number | undefined; -}): ContactInfo { - const wrapperContact: ContactInfo = { +}): ContactInfoSet { + const wrapperContact: ContactInfoSet = { id, approved: !!dbApproved, approvedMe: !!dbApprovedMe, @@ -145,7 +144,6 @@ export function getContactInfoFromDBValues({ !!expirationTimerSeconds && isFinite(expirationTimerSeconds) && expirationTimerSeconds > 0 ? 'disappearAfterSend' : 'off', - createdAt: 0, // this is actually unused as the wrapper keep the value as it is currently stored (this is a created at timestamp, no need to update it) }; if ( @@ -232,7 +230,7 @@ export function getLegacyGroupInfoFromDBValues({ members: wrappedMembers, encPubkey: !isEmpty(encPubkeyHex) ? from_hex(encPubkeyHex) : new Uint8Array(), encSeckey: !isEmpty(encSeckeyHex) ? from_hex(encSeckeyHex) : new Uint8Array(), - joinedAt: lastJoinedTimestamp, + joinedAtSeconds: Math.floor(lastJoinedTimestamp / 1000), }; return legacyGroup; diff --git a/ts/util/logging.ts b/ts/util/logging.ts index 63a3ca016..dbe854bd5 100644 --- a/ts/util/logging.ts +++ b/ts/util/logging.ts @@ -110,7 +110,7 @@ const development = window && window?.getEnvironment && window?.getEnvironment() // The Bunyan API: https://github.com/trentm/node-bunyan#log-method-api function logAtLevel(level: string, prefix: string, ...args: any) { - if (prefix === 'DEBUG' && window.sessionFeatureFlags.useDebugLogging) { + if (prefix === 'DEBUG' && !window.sessionFeatureFlags.useDebugLogging) { return; } if (development) { diff --git a/ts/webworker/workers/browser/libsession_worker_interface.ts b/ts/webworker/workers/browser/libsession_worker_interface.ts index d285e77c9..30d23f57e 100644 --- a/ts/webworker/workers/browser/libsession_worker_interface.ts +++ b/ts/webworker/workers/browser/libsession_worker_interface.ts @@ -5,7 +5,7 @@ import { ConfigWrapperObjectTypes, LibSessionWorkerFunctions } from './libsessio import { BaseWrapperActionsCalls, - ContactInfo, + ContactInfoSet, ContactsWrapperActionsCalls, ConvoInfoVolatileWrapperActionsCalls, LegacyGroupInfo, @@ -139,7 +139,7 @@ export const ContactsWrapperActions: ContactsWrapperActionsCalls = { ReturnType >, - set: async (contact: ContactInfo) => + set: async (contact: ContactInfoSet) => callLibSessionWorker(['ContactsConfig', 'set', contact]) as Promise< ReturnType >,