feat: move some the convomodel.get attributes to functions

this is because we need to be able to override what is returned by what
is in the redux lib slice if needed (libsession data overrides what is
in the DB for groupv3)
pull/2873/head
Audric Ackermann 2 years ago
parent 46e3675c45
commit 197383a52f

@ -63,7 +63,7 @@ export const MessageAvatar = (props: Props) => {
// public chat but session id not blinded. disable showing user details if we do not have an active convo with that user. // public chat but session id not blinded. disable showing user details if we do not have an active convo with that user.
// an unactive convo with that user means that we never chatted with that id directyly, but only through a sogs // an unactive convo with that user means that we never chatted with that id directyly, but only through a sogs
const convoWithSender = getConversationController().get(sender); const convoWithSender = getConversationController().get(sender);
if (!convoWithSender || !convoWithSender.get('active_at')) { if (!convoWithSender || !convoWithSender.getActiveAt()) {
// for some time, we might still get some unblinded messages, as in message sent unblinded because // for some time, we might still get some unblinded messages, as in message sent unblinded because
// * older clients still send unblinded message and those are allowed by sogs if they doesn't enforce blinding // * older clients still send unblinded message and those are allowed by sogs if they doesn't enforce blinding
// * new clients still send unblinded message and those are allowed by sogs if it doesn't enforce blinding // * new clients still send unblinded message and those are allowed by sogs if it doesn't enforce blinding

@ -73,13 +73,13 @@ const submitForClosedGroup = async (convoId: string, pubkeys: Array<string>) =>
// closed group chats // closed group chats
const ourPK = UserUtils.getOurPubKeyStrFromCache(); const ourPK = UserUtils.getOurPubKeyStrFromCache();
// we only care about real members. If a member is currently a zombie we have to be able to add him back // we only care about real members. If a member is currently a zombie we have to be able to add him back
let existingMembers = convo.get('members') || []; let existingMembers = convo.getGroupMembers() || [];
// at least make sure it's an array // at least make sure it's an array
if (!Array.isArray(existingMembers)) { if (!Array.isArray(existingMembers)) {
existingMembers = []; existingMembers = [];
} }
existingMembers = _.compact(existingMembers); existingMembers = _.compact(existingMembers);
const existingZombies = convo.get('zombies') || []; const existingZombies = convo.getGroupZombies() || [];
const newMembers = pubkeys.filter(d => !existingMembers.includes(d)); const newMembers = pubkeys.filter(d => !existingMembers.includes(d));
if (newMembers.length > 0) { if (newMembers.length > 0) {

@ -138,8 +138,8 @@ async function onSubmit(convoId: string, membersAfterUpdate: Array<string>) {
// We consider that the admin ALWAYS wants to remove zombies (actually they should be removed // We consider that the admin ALWAYS wants to remove zombies (actually they should be removed
// automatically by him when the LEFT message is received) // automatically by him when the LEFT message is received)
const existingMembers = convoFound.get('members') || []; const existingMembers = convoFound.getGroupMembers() || [];
const existingZombies = convoFound.get('zombies') || []; const existingZombies = convoFound.getGroupZombies() || [];
const allExistingMembersWithZombies = _.uniq(existingMembers.concat(existingZombies)); const allExistingMembersWithZombies = _.uniq(existingMembers.concat(existingZombies));
@ -168,7 +168,7 @@ async function onSubmit(convoId: string, membersAfterUpdate: Array<string>) {
void initiateClosedGroupUpdate( void initiateClosedGroupUpdate(
convoId, convoId,
convoFound.get('displayNameInProfile') || 'Unknown', convoFound.getRealSessionUsername() || 'Unknown',
filteredMembers filteredMembers
); );
} }

@ -76,7 +76,7 @@ export class UpdateGroupNameDialog extends React.Component<Props, State> {
objectUrl: newAvatarObjecturl, objectUrl: newAvatarObjecturl,
}); });
} else { } else {
const members = this.convo.get('members') || []; const members = this.convo.getGroupMembers() || [];
void initiateClosedGroupUpdate(this.convo.id, trimmedGroupName, members); void initiateClosedGroupUpdate(this.convo.id, trimmedGroupName, members);
} }

@ -205,7 +205,7 @@ export async function showUpdateGroupNameByConvoId(conversationId: string) {
// make sure all the members' convo exists so we can add or remove them // make sure all the members' convo exists so we can add or remove them
await Promise.all( await Promise.all(
conversation conversation
.get('members') .getGroupMembers()
.map(m => getConversationController().getOrCreateAndWait(m, ConversationTypeEnum.PRIVATE)) .map(m => getConversationController().getOrCreateAndWait(m, ConversationTypeEnum.PRIVATE))
); );
} }
@ -218,7 +218,7 @@ export async function showUpdateGroupMembersByConvoId(conversationId: string) {
// make sure all the members' convo exists so we can add or remove them // make sure all the members' convo exists so we can add or remove them
await Promise.all( await Promise.all(
conversation conversation
.get('members') .getGroupMembers()
.map(m => getConversationController().getOrCreateAndWait(m, ConversationTypeEnum.PRIVATE)) .map(m => getConversationController().getOrCreateAndWait(m, ConversationTypeEnum.PRIVATE))
); );
} }
@ -310,7 +310,7 @@ export async function setNotificationForConvoId(
) { ) {
const conversation = getConversationController().get(conversationId); const conversation = getConversationController().get(conversationId);
const existingSettings = conversation.get('triggerNotificationsFor'); const existingSettings = conversation.getNotificationsFor();
if (existingSettings !== selected) { if (existingSettings !== selected) {
conversation.set({ triggerNotificationsFor: selected }); conversation.set({ triggerNotificationsFor: selected });
await conversation.commit(); await conversation.commit();
@ -403,7 +403,7 @@ export async function uploadOurAvatar(newAvatarDecrypted?: ArrayBuffer) {
const ourConvoProfileKey = const ourConvoProfileKey =
getConversationController() getConversationController()
.get(UserUtils.getOurPubKeyStrFromCache()) .get(UserUtils.getOurPubKeyStrFromCache())
?.get('profileKey') || null; ?.getProfileKey() || null;
profileKey = ourConvoProfileKey ? fromHexToArray(ourConvoProfileKey) : null; profileKey = ourConvoProfileKey ? fromHexToArray(ourConvoProfileKey) : null;
if (!profileKey) { if (!profileKey) {
@ -452,7 +452,7 @@ export async function uploadOurAvatar(newAvatarDecrypted?: ArrayBuffer) {
}); });
// Replace our temporary image with the attachment pointer from the server: // Replace our temporary image with the attachment pointer from the server:
ourConvo.set('avatarInProfile', undefined); ourConvo.set('avatarInProfile', undefined);
const displayName = ourConvo.get('displayNameInProfile'); const displayName = ourConvo.getRealSessionUsername();
// write the profileKey even if it did not change // write the profileKey even if it did not change
ourConvo.set({ profileKey: toHex(profileKey) }); ourConvo.set({ profileKey: toHex(profileKey) });
@ -480,8 +480,8 @@ export async function uploadOurAvatar(newAvatarDecrypted?: ArrayBuffer) {
); );
} }
return { return {
avatarPointer: ourConvo.get('avatarPointer'), avatarPointer: ourConvo.getAvatarPointer(),
profileKey: ourConvo.get('profileKey'), profileKey: ourConvo.getProfileKey(),
}; };
} }

@ -117,6 +117,7 @@ import { SessionUtilUserProfile } from '../session/utils/libsession/libsession_u
import { ReduxSogsRoomInfos } from '../state/ducks/sogsRoomInfo'; import { ReduxSogsRoomInfos } from '../state/ducks/sogsRoomInfo';
import { import {
getLibGroupAdminsOutsideRedux, getLibGroupAdminsOutsideRedux,
getLibGroupMembersOutsideRedux,
getLibGroupNameOutsideRedux, getLibGroupNameOutsideRedux,
} from '../state/selectors/groups'; } from '../state/selectors/groups';
import { import {
@ -262,7 +263,7 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
* For instance, all of the conversations created when receiving a community are not active, until we start directly talking with them (or they do). * For instance, all of the conversations created when receiving a community are not active, until we start directly talking with them (or they do).
*/ */
public isActive() { public isActive() {
return Boolean(this.get('active_at')); return Boolean(this.getActiveAt());
} }
/** /**
@ -273,7 +274,7 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
* - a legacy group is kept visible if we leave it, until we explicitely delete it. At that time, it is removed completely and not marked hidden * - a legacy group is kept visible if we leave it, until we explicitely delete it. At that time, it is removed completely and not marked hidden
*/ */
public isHidden() { public isHidden() {
const priority = this.get('priority') || CONVERSATION_PRIORITIES.default; const priority = this.getPriority();
return this.isPrivate() && priority === CONVERSATION_PRIORITIES.hidden; return this.isPrivate() && priority === CONVERSATION_PRIORITIES.hidden;
} }
@ -281,6 +282,14 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
await deleteExternalFilesOfConversation(this.attributes); await deleteExternalFilesOfConversation(this.attributes);
} }
public getPriority() {
return this.get('priority') || CONVERSATION_PRIORITIES.default;
}
public getNotificationsFor() {
return this.get('triggerNotificationsFor');
}
public getConversationModelProps(): ReduxConversationType { public getConversationModelProps(): ReduxConversationType {
const isPublic = this.isPublic(); const isPublic = this.isPublic();
@ -288,14 +297,14 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
const isPrivate = this.isPrivate(); const isPrivate = this.isPrivate();
const weAreAdmin = this.weAreAdminUnblinded(); const weAreAdmin = this.weAreAdminUnblinded();
const currentNotificationSetting = this.get('triggerNotificationsFor'); const currentNotificationSetting = this.getNotificationsFor();
const priorityFromDb = this.get('priority'); const priorityFromDb = this.getPriority();
// To reduce the redux store size, only set fields which cannot be undefined. // To reduce the redux store size, only set fields which cannot be undefined.
// For instance, a boolean can usually be not set if false, etc // For instance, a boolean can usually be not set if false, etc
const toRet: ReduxConversationType = { const toRet: ReduxConversationType = {
id: this.id as string, id: this.id as string,
activeAt: this.get('active_at'), activeAt: this.getActiveAt(),
type: this.get('type'), type: this.get('type'),
}; };
@ -347,8 +356,8 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
toRet.currentNotificationSetting = currentNotificationSetting; toRet.currentNotificationSetting = currentNotificationSetting;
} }
if (this.get('displayNameInProfile')) { if (this.getRealSessionUsername()) {
toRet.displayNameInProfile = this.get('displayNameInProfile'); toRet.displayNameInProfile = this.getRealSessionUsername();
} }
if (this.get('nickname')) { if (this.get('nickname')) {
toRet.nickname = this.get('nickname'); toRet.nickname = this.get('nickname');
@ -367,7 +376,7 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
} }
// those are values coming only from both the DB or the wrapper. Currently we display the data from the DB // those are values coming only from both the DB or the wrapper. Currently we display the data from the DB
if (this.isClosedGroup()) { if (this.isClosedGroup()) {
toRet.members = this.get('members') || []; toRet.members = this.getGroupMembers() || [];
} }
// those are values coming only from both the DB or the wrapper. Currently we display the data from the DB // those are values coming only from both the DB or the wrapper. Currently we display the data from the DB
@ -378,14 +387,14 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
// those are values coming only from the DB when this is a closed group // those are values coming only from the DB when this is a closed group
if (this.isClosedGroup()) { if (this.isClosedGroup()) {
if (this.get('isKickedFromGroup')) { if (this.isKickedFromGroup()) {
toRet.isKickedFromGroup = this.get('isKickedFromGroup'); toRet.isKickedFromGroup = this.isKickedFromGroup();
} }
if (this.get('left')) { if (this.isLeft()) {
toRet.left = this.get('left'); toRet.left = this.isLeft();
} }
// to be dropped once we get rid of the legacy closed groups // to be dropped once we get rid of the legacy closed groups
const zombies = this.get('zombies') || []; const zombies = this.getGroupZombies() || [];
if (zombies?.length) { if (zombies?.length) {
toRet.zombies = uniq(zombies); toRet.zombies = uniq(zombies);
} }
@ -656,7 +665,7 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
isApproved: this.isApproved(), isApproved: this.isApproved(),
isBlocked: this.isBlocked(), isBlocked: this.isBlocked(),
isPrivate: this.isPrivate(), isPrivate: this.isPrivate(),
activeAt: this.get('active_at'), activeAt: this.getActiveAt(),
didApproveMe: this.didApproveMe(), didApproveMe: this.didApproveMe(),
}); });
} }
@ -671,7 +680,7 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
didApproveMe: this.didApproveMe() || false, didApproveMe: this.didApproveMe() || false,
isBlocked: this.isBlocked() || false, isBlocked: this.isBlocked() || false,
isPrivate: this.isPrivate() || false, isPrivate: this.isPrivate() || false,
activeAt: this.get('active_at') || 0, activeAt: this.getActiveAt() || 0,
}); });
} }
@ -1094,7 +1103,7 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
this.set({ avatarInProfile: newProfile.avatarPath }); this.set({ avatarInProfile: newProfile.avatarPath });
changes = true; changes = true;
} }
const existingImageId = this.get('avatarImageId'); const existingImageId = this.getAvatarImageId();
if (existingImageId !== newProfile.avatarImageId) { if (existingImageId !== newProfile.avatarImageId) {
this.set({ avatarImageId: newProfile.avatarImageId }); this.set({ avatarImageId: newProfile.avatarImageId });
@ -1128,6 +1137,18 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
return this.isPrivate() ? this.get('nickname') || undefined : undefined; return this.isPrivate() ? this.get('nickname') || undefined : undefined;
} }
public getAvatarImageId(): number | undefined {
return this.isPublic() ? this.get('avatarImageId') || undefined : undefined;
}
public getProfileKey(): string | undefined {
return this.get('profileKey');
}
public getAvatarPointer(): string | undefined {
return this.get('avatarPointer');
}
/** /**
* @returns `getNickname` if a private convo and a nickname is set, or `getRealSessionUsername` * @returns `getNickname` if a private convo and a nickname is set, or `getRealSessionUsername`
*/ */
@ -1196,7 +1217,7 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
priority: number, priority: number,
shouldCommit: boolean = true shouldCommit: boolean = true
): Promise<boolean> { ): Promise<boolean> {
if (priority !== this.get('priority')) { if (priority !== this.getPriority()) {
this.set({ this.set({
priority, priority,
}); });
@ -1229,7 +1250,7 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
if (!this.isPrivate()) { if (!this.isPrivate()) {
return; return;
} }
const priority = this.get('priority'); const priority = this.getPriority();
if (priority >= CONVERSATION_PRIORITIES.default) { if (priority >= CONVERSATION_PRIORITIES.default) {
this.set({ priority: CONVERSATION_PRIORITIES.hidden }); this.set({ priority: CONVERSATION_PRIORITIES.hidden });
if (shouldCommit) { if (shouldCommit) {
@ -1244,7 +1265,7 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
* A pinned cannot be hidden, as the it is all based on the same priority values. * A pinned cannot be hidden, as the it is all based on the same priority values.
*/ */
public async unhideIfNeeded(shouldCommit: boolean = true) { public async unhideIfNeeded(shouldCommit: boolean = true) {
const priority = this.get('priority'); const priority = this.getPriority();
if (isFinite(priority) && priority < CONVERSATION_PRIORITIES.default) { if (isFinite(priority) && priority < CONVERSATION_PRIORITIES.default) {
this.set({ priority: CONVERSATION_PRIORITIES.default }); this.set({ priority: CONVERSATION_PRIORITIES.default });
if (shouldCommit) { if (shouldCommit) {
@ -1445,7 +1466,7 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
const profileKeyHex = toHex(profileKey); const profileKeyHex = toHex(profileKey);
// profileKey is a string so we can compare it directly // profileKey is a string so we can compare it directly
if (this.get('profileKey') !== profileKeyHex) { if (this.getProfileKey() !== profileKeyHex) {
this.set({ this.set({
profileKey: profileKeyHex, profileKey: profileKeyHex,
}); });
@ -1457,7 +1478,7 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
} }
public hasMember(pubkey: string) { public hasMember(pubkey: string) {
return includes(this.get('members'), pubkey); return includes(this.getGroupMembers(), pubkey);
} }
public hasReactions() { public hasReactions() {
@ -1488,7 +1509,7 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
} }
public isPinned() { public isPinned() {
const priority = this.get('priority'); const priority = this.getPriority();
return isFinite(priority) && priority > CONVERSATION_PRIORITIES.default; return isFinite(priority) && priority > CONVERSATION_PRIORITIES.default;
} }
@ -1519,7 +1540,7 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
return window.i18n('you'); return window.i18n('you');
} }
const profileName = this.get('displayNameInProfile'); const profileName = this.getRealSessionUsername();
return profileName || PubKey.shorten(pubkey); return profileName || PubKey.shorten(pubkey);
} }
@ -1587,7 +1608,7 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
} }
// make sure the notifications are not muted for this convo (and not the source convo) // make sure the notifications are not muted for this convo (and not the source convo)
const convNotif = this.get('triggerNotificationsFor'); const convNotif = this.getNotificationsFor();
if (convNotif === 'disabled') { if (convNotif === 'disabled') {
window?.log?.info('notifications disabled for convo', this.idForLogging()); window?.log?.info('notifications disabled for convo', this.idForLogging());
return; return;
@ -1644,7 +1665,7 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
const conversationId = this.id; const conversationId = this.id;
// make sure the notifications are not muted for this convo (and not the source convo) // make sure the notifications are not muted for this convo (and not the source convo)
const convNotif = this.get('triggerNotificationsFor'); const convNotif = this.getNotificationsFor();
if (convNotif === 'disabled') { if (convNotif === 'disabled') {
window?.log?.info( window?.log?.info(
'notifyIncomingCall: notifications disabled for convo', 'notifyIncomingCall: notifications disabled for convo',
@ -1704,6 +1725,60 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
return groupAdmins && groupAdmins.length > 0 ? groupAdmins : []; return groupAdmins && groupAdmins.length > 0 ? groupAdmins : [];
} }
public isKickedFromGroup(): boolean {
if (this.isClosedGroup()) {
if (this.isClosedGroupV3()) {
console.info('isKickedFromGroup using lib todo'); // debugger
}
return !!this.get('isKickedFromGroup');
}
return false;
}
public isLeft(): boolean {
if (this.isClosedGroup()) {
if (this.isClosedGroupV3()) {
console.info('isLeft using lib todo'); // debugger
}
return !!this.get('left');
}
return false;
}
public getActiveAt(): number | undefined {
return this.get('active_at');
}
public getLastJoinedTimestamp(): number {
if (this.isClosedGroup()) {
return this.get('lastJoinedTimestamp') || 0;
}
return 0;
}
public getGroupMembers(): Array<string> {
if (this.isClosedGroup()) {
if (this.isClosedGroupV3()) {
return getLibGroupMembersOutsideRedux(this.id);
}
const members = this.get('members');
return members && members.length > 0 ? members : [];
}
return [];
}
public getGroupZombies(): Array<string> {
if (this.isClosedGroup()) {
// closed group with 03 prefix does not have the concepts of zombies
if (this.isClosedGroupV3()) {
return [];
}
const zombies = this.get('zombies');
return zombies && zombies.length > 0 ? zombies : [];
}
return [];
}
private async sendMessageJob(message: MessageModel, expireTimer: number | undefined) { private async sendMessageJob(message: MessageModel, expireTimer: number | undefined) {
try { try {
const { body, attachments, preview, quote, fileIdsToLink } = await message.uploadData(); const { body, attachments, preview, quote, fileIdsToLink } = await message.uploadData();
@ -1919,7 +1994,7 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
} }
private async bouncyUpdateLastMessage() { private async bouncyUpdateLastMessage() {
if (!this.id || !this.get('active_at') || this.isHidden()) { if (!this.id || !this.getActiveAt() || this.isHidden()) {
return; return;
} }
const messages = await Data.getLastMessagesByConversation(this.id, 1, true); const messages = await Data.getLastMessagesByConversation(this.id, 1, true);
@ -2336,7 +2411,7 @@ export class ConversationCollection extends Backbone.Collection<ConversationMode
constructor(models?: Array<ConversationModel>) { constructor(models?: Array<ConversationModel>) {
super(models); super(models);
this.comparator = (m: ConversationModel) => { this.comparator = (m: ConversationModel) => {
return -(m.get('active_at') || 0); return -(m.getActiveAt() || 0);
}; };
} }
} }
@ -2379,7 +2454,7 @@ export function hasValidIncomingRequestValues({
isBlocked: boolean; isBlocked: boolean;
isPrivate: boolean; isPrivate: boolean;
didApproveMe: boolean; didApproveMe: boolean;
activeAt: number; activeAt: number | undefined;
}): boolean { }): boolean {
// if a convo is not active, it means we didn't get any messages nor sent any. // if a convo is not active, it means we didn't get any messages nor sent any.
const isActive = activeAt && isFinite(activeAt) && activeAt > 0; const isActive = activeAt && isFinite(activeAt) && activeAt > 0;

@ -436,7 +436,7 @@ export class MessageModel extends Backbone.Model<MessageAttributes> {
return undefined; return undefined;
} }
if (this.getConversation()?.get('left')) { if (this.getConversation()?.isLeft()) {
return 'sent'; return 'sent';
} }

@ -303,7 +303,7 @@ export async function handleNewClosedGroup(
if (groupConvo) { if (groupConvo) {
// if we did not left this group, just add the keypair we got if not already there // if we did not left this group, just add the keypair we got if not already there
if (!groupConvo.get('isKickedFromGroup') && !groupConvo.get('left')) { if (!groupConvo.isKickedFromGroup() && !groupConvo.isLeft()) {
const ecKeyPairAlreadyExistingConvo = new ECKeyPair( const ecKeyPairAlreadyExistingConvo = new ECKeyPair(
encryptionKeyPair!.publicKey, encryptionKeyPair!.publicKey,
encryptionKeyPair!.privateKey encryptionKeyPair!.privateKey
@ -542,7 +542,7 @@ async function performIfValid(
} }
// Check that the message isn't from before the group was created // Check that the message isn't from before the group was created
let lastJoinedTimestamp = convo.get('lastJoinedTimestamp'); let lastJoinedTimestamp = convo.getLastJoinedTimestamp();
// might happen for existing groups // might happen for existing groups
if (!lastJoinedTimestamp) { if (!lastJoinedTimestamp) {
const aYearAgo = Date.now() - 1000 * 60 * 24 * 365; const aYearAgo = Date.now() - 1000 * 60 * 24 * 365;
@ -562,7 +562,7 @@ async function performIfValid(
} }
// Check that the sender is a member of the group (before the update) // Check that the sender is a member of the group (before the update)
const oldMembers = convo.get('members') || []; const oldMembers = convo.getGroupMembers() || [];
if (!oldMembers.includes(sender)) { if (!oldMembers.includes(sender)) {
window?.log?.error( window?.log?.error(
`Error: closed group: ignoring closed group update message from non-member. ${sender} is not a current member.` `Error: closed group: ignoring closed group update message from non-member. ${sender} is not a current member.`
@ -600,7 +600,7 @@ async function handleClosedGroupNameChanged(
const newName = groupUpdate.name; const newName = groupUpdate.name;
window?.log?.info(`Got a group update for group ${envelope.source}, type: NAME_CHANGED`); window?.log?.info(`Got a group update for group ${envelope.source}, type: NAME_CHANGED`);
if (newName !== convo.get('displayNameInProfile')) { if (newName !== convo.getRealSessionUsername()) {
const groupDiff: ClosedGroup.GroupDiff = { const groupDiff: ClosedGroup.GroupDiff = {
newName, newName,
}; };
@ -628,7 +628,7 @@ async function handleClosedGroupMembersAdded(
) { ) {
const { members: addedMembersBinary } = groupUpdate; const { members: addedMembersBinary } = groupUpdate;
const addedMembers = (addedMembersBinary || []).map(toHex); const addedMembers = (addedMembersBinary || []).map(toHex);
const oldMembers = convo.get('members') || []; const oldMembers = convo.getGroupMembers() || [];
const membersNotAlreadyPresent = addedMembers.filter(m => !oldMembers.includes(m)); const membersNotAlreadyPresent = addedMembers.filter(m => !oldMembers.includes(m));
window?.log?.info(`Got a group update for group ${envelope.source}, type: MEMBERS_ADDED`); window?.log?.info(`Got a group update for group ${envelope.source}, type: MEMBERS_ADDED`);
@ -696,7 +696,7 @@ async function handleClosedGroupMembersRemoved(
shouldOnlyAddUpdateMessage: boolean // set this to true to not apply the change to the convo itself, just add the update in the conversation shouldOnlyAddUpdateMessage: boolean // set this to true to not apply the change to the convo itself, just add the update in the conversation
) { ) {
// Check that the admin wasn't removed // Check that the admin wasn't removed
const currentMembers = convo.get('members'); const currentMembers = convo.getGroupMembers();
// removedMembers are all members in the diff // removedMembers are all members in the diff
const removedMembers = groupUpdate.members.map(toHex); const removedMembers = groupUpdate.members.map(toHex);
// effectivelyRemovedMembers are the members which where effectively on this group before the update // effectivelyRemovedMembers are the members which where effectively on this group before the update
@ -755,7 +755,7 @@ async function handleClosedGroupMembersRemoved(
} }
// Update the group // Update the group
const zombies = convo.get('zombies').filter(z => membersAfterUpdate.includes(z)); const zombies = convo.getGroupZombies().filter(z => membersAfterUpdate.includes(z));
if (!shouldOnlyAddUpdateMessage) { if (!shouldOnlyAddUpdateMessage) {
convo.set({ members: membersAfterUpdate }); convo.set({ members: membersAfterUpdate });
@ -767,7 +767,7 @@ async function handleClosedGroupMembersRemoved(
} }
function isUserAZombie(convo: ConversationModel, user: PubKey) { function isUserAZombie(convo: ConversationModel, user: PubKey) {
return convo.get('zombies').includes(user.key); return convo.getGroupZombies().includes(user.key);
} }
/** /**
@ -779,7 +779,7 @@ function addMemberToZombies(
userToAdd: PubKey, userToAdd: PubKey,
convo: ConversationModel convo: ConversationModel
): boolean { ): boolean {
const zombies = convo.get('zombies'); const zombies = convo.getGroupZombies();
const isAlreadyZombie = isUserAZombie(convo, userToAdd); const isAlreadyZombie = isUserAZombie(convo, userToAdd);
if (isAlreadyZombie) { if (isAlreadyZombie) {
@ -799,7 +799,7 @@ function removeMemberFromZombies(
userToAdd: PubKey, userToAdd: PubKey,
convo: ConversationModel convo: ConversationModel
): boolean { ): boolean {
const zombies = convo.get('zombies'); const zombies = convo.getGroupZombies();
const isAlreadyAZombie = isUserAZombie(convo, userToAdd); const isAlreadyAZombie = isUserAZombie(convo, userToAdd);
if (!isAlreadyAZombie) { if (!isAlreadyAZombie) {
@ -840,7 +840,7 @@ async function handleClosedGroupMemberLeft(
const didAdminLeave = convo.getGroupAdmins().includes(sender) || false; const didAdminLeave = convo.getGroupAdmins().includes(sender) || false;
// If the admin leaves the group is disbanded // If the admin leaves the group is disbanded
// otherwise, we remove the sender from the list of current members in this group // otherwise, we remove the sender from the list of current members in this group
const oldMembers = convo.get('members') || []; const oldMembers = convo.getGroupMembers() || [];
const newMembers = oldMembers.filter(s => s !== sender); const newMembers = oldMembers.filter(s => s !== sender);
window?.log?.info(`Got a group update for group ${envelope.source}, type: MEMBER_LEFT`); window?.log?.info(`Got a group update for group ${envelope.source}, type: MEMBER_LEFT`);

@ -320,7 +320,7 @@ async function handleContactsUpdate() {
changes = true; changes = true;
} }
const currentPriority = contactConvo.get('priority'); const currentPriority = contactConvo.getPriority();
if (wrapperConvo.priority !== currentPriority) { if (wrapperConvo.priority !== currentPriority) {
if (wrapperConvo.priority === CONVERSATION_PRIORITIES.hidden) { if (wrapperConvo.priority === CONVERSATION_PRIORITIES.hidden) {
window.log.info( window.log.info(
@ -348,7 +348,7 @@ async function handleContactsUpdate() {
// } // }
// we want to set the active_at to the created_at timestamp if active_at is unset, so that it shows up in our list. // we want to set the active_at to the created_at timestamp if active_at is unset, so that it shows up in our list.
if (!contactConvo.get('active_at') && wrapperConvo.createdAtSeconds) { if (!contactConvo.getActiveAt() && wrapperConvo.createdAtSeconds) {
contactConvo.set({ active_at: wrapperConvo.createdAtSeconds * 1000 }); contactConvo.set({ active_at: wrapperConvo.createdAtSeconds * 1000 });
changes = true; changes = true;
} }
@ -542,6 +542,7 @@ async function handleLegacyGroupUpdate(latestEnvelopeTimestamp: number) {
const members = fromWrapper.members.map(m => m.pubkeyHex); const members = fromWrapper.members.map(m => m.pubkeyHex);
const admins = fromWrapper.members.filter(m => m.isAdmin).map(m => m.pubkeyHex); const admins = fromWrapper.members.filter(m => m.isAdmin).map(m => m.pubkeyHex);
const activeAt = legacyGroupConvo.getActiveAt();
// then for all the existing legacy group in the wrapper, we need to override the field of what we have in the DB with what is in the wrapper // then for all the existing legacy group in the wrapper, we need to override the field of what we have in the DB with what is in the wrapper
// We only set group admins on group creation // We only set group admins on group creation
const groupDetails: ClosedGroup.GroupInfo = { const groupDetails: ClosedGroup.GroupInfo = {
@ -550,9 +551,8 @@ async function handleLegacyGroupUpdate(latestEnvelopeTimestamp: number) {
members, members,
admins, admins,
activeAt: activeAt:
!!legacyGroupConvo.get('active_at') && !!activeAt && activeAt < latestEnvelopeTimestamp
legacyGroupConvo.get('active_at') < latestEnvelopeTimestamp ? legacyGroupConvo.getActiveAt()
? legacyGroupConvo.get('active_at')
: latestEnvelopeTimestamp, : latestEnvelopeTimestamp,
}; };
@ -560,7 +560,7 @@ async function handleLegacyGroupUpdate(latestEnvelopeTimestamp: number) {
let changes = await legacyGroupConvo.setPriorityFromWrapper(fromWrapper.priority, false); let changes = await legacyGroupConvo.setPriorityFromWrapper(fromWrapper.priority, false);
const existingTimestampMs = legacyGroupConvo.get('lastJoinedTimestamp'); const existingTimestampMs = legacyGroupConvo.getLastJoinedTimestamp();
const existingJoinedAtSeconds = Math.floor(existingTimestampMs / 1000); const existingJoinedAtSeconds = Math.floor(existingTimestampMs / 1000);
if (existingJoinedAtSeconds !== fromWrapper.joinedAtSeconds) { if (existingJoinedAtSeconds !== fromWrapper.joinedAtSeconds) {
legacyGroupConvo.set({ legacyGroupConvo.set({
@ -581,7 +581,7 @@ async function handleLegacyGroupUpdate(latestEnvelopeTimestamp: number) {
// changes = true; // changes = true;
// } // }
// start polling for this group if we haven't left it yet. The wrapper does not store this info for legacy group so we check from the DB entry instead // start polling for this group if we haven't left it yet. The wrapper does not store this info for legacy group so we check from the DB entry instead
if (!legacyGroupConvo.get('isKickedFromGroup') && !legacyGroupConvo.get('left')) { if (!legacyGroupConvo.isKickedFromGroup() && !legacyGroupConvo.isLeft()) {
getSwarmPollingInstance().addGroupId(PubKey.cast(fromWrapper.pubkeyHex)); getSwarmPollingInstance().addGroupId(PubKey.cast(fromWrapper.pubkeyHex));
// save the encryption keypair if needed // save the encryption keypair if needed

@ -695,7 +695,7 @@ async function handleMessageRequestResponse(
unblindedConvoId, unblindedConvoId,
ConversationTypeEnum.PRIVATE ConversationTypeEnum.PRIVATE
); );
let mostRecentActiveAt = Math.max(...compact(convosToMerge.map(m => m.get('active_at')))); let mostRecentActiveAt = Math.max(...compact(convosToMerge.map(m => m.getActiveAt())));
if (!isFinite(mostRecentActiveAt) || mostRecentActiveAt <= 0) { if (!isFinite(mostRecentActiveAt) || mostRecentActiveAt <= 0) {
mostRecentActiveAt = toNumber(envelope.timestamp); mostRecentActiveAt = toNumber(envelope.timestamp);
} }
@ -710,11 +710,11 @@ async function handleMessageRequestResponse(
if (convosToMerge.length) { if (convosToMerge.length) {
// merge fields we care by hand // merge fields we care by hand
conversationToApprove.set({ conversationToApprove.set({
profileKey: convosToMerge[0].get('profileKey'), profileKey: convosToMerge[0].getProfileKey(),
displayNameInProfile: convosToMerge[0].get('displayNameInProfile'), displayNameInProfile: convosToMerge[0].getRealSessionUsername(),
avatarInProfile: convosToMerge[0].get('avatarInProfile'), avatarInProfile: convosToMerge[0].get('avatarInProfile'),
avatarPointer: convosToMerge[0].get('avatarPointer'), // don't set the avatar pointer avatarPointer: convosToMerge[0].getAvatarPointer(), // don't set the avatar pointer
// nickname might be set already in conversationToApprove, so don't overwrite it // nickname might be set already in conversationToApprove, so don't overwrite it
}); });

@ -312,7 +312,7 @@ async function handleRegularMessage(
} }
} }
const conversationActiveAt = conversation.get('active_at'); const conversationActiveAt = conversation.getActiveAt();
if ( if (
!conversationActiveAt || !conversationActiveAt ||
conversation.isHidden() || conversation.isHidden() ||
@ -422,7 +422,7 @@ export async function handleMessageJob(
// to their source message. // to their source message.
conversation.set({ conversation.set({
active_at: Math.max(conversation.get('active_at'), messageModel.get('sent_at') || 0), active_at: Math.max(conversation.getActiveAt() || 0, messageModel.get('sent_at') || 0),
}); });
// this is a throttled call and will only run once every 1 sec at most // this is a throttled call and will only run once every 1 sec at most
conversation.updateLastMessage(); conversation.updateLastMessage();

@ -92,7 +92,7 @@ export async function sogsV3FetchPreviewAndSaveIt(roomInfos: OpenGroupV2RoomWith
if (!convo) { if (!convo) {
return; return;
} }
let existingImageId = convo.get('avatarImageId'); let existingImageId = convo.getAvatarImageId();
if (existingImageId === imageIdNumber) { if (existingImageId === imageIdNumber) {
// return early as the imageID about to be downloaded the one already set as avatar is the same. // return early as the imageID about to be downloaded the one already set as avatar is the same.
return; return;
@ -117,7 +117,7 @@ export async function sogsV3FetchPreviewAndSaveIt(roomInfos: OpenGroupV2RoomWith
if (!convo) { if (!convo) {
return; return;
} }
existingImageId = convo.get('avatarImageId'); existingImageId = convo.getAvatarImageId();
if (existingImageId !== imageIdNumber && isFinite(imageIdNumber)) { if (existingImageId !== imageIdNumber && isFinite(imageIdNumber)) {
// we have to trigger an update // we have to trigger an update
// write the file to the disk (automatically encrypted), // write the file to the disk (automatically encrypted),

@ -143,7 +143,7 @@ export class SwarmPolling {
if (!convo) { if (!convo) {
return SWARM_POLLING_TIMEOUT.INACTIVE; return SWARM_POLLING_TIMEOUT.INACTIVE;
} }
const activeAt = convo.get('active_at'); const activeAt = convo.getActiveAt();
if (!activeAt) { if (!activeAt) {
return SWARM_POLLING_TIMEOUT.INACTIVE; return SWARM_POLLING_TIMEOUT.INACTIVE;
} }
@ -437,10 +437,10 @@ export class SwarmPolling {
const closedGroupsOnly = convos.filter( const closedGroupsOnly = convos.filter(
(c: ConversationModel) => (c: ConversationModel) =>
c.isClosedGroup() && !c.isBlocked() && !c.get('isKickedFromGroup') && !c.get('left') c.isClosedGroup() && !c.isBlocked() && !c.isKickedFromGroup() && !c.isLeft()
); );
closedGroupsOnly.forEach((c: any) => { closedGroupsOnly.forEach((c) => {
this.addGroupId(new PubKey(c.id)); this.addGroupId(new PubKey(c.id));
}); });
} }

@ -473,7 +473,7 @@ async function leaveClosedGroup(groupId: string, fromSyncMessage: boolean) {
} else { } else {
// otherwise, just the exclude ourself from the members and trigger an update with this // otherwise, just the exclude ourself from the members and trigger an update with this
convo.set({ left: true }); convo.set({ left: true });
members = (convo.get('members') || []).filter((m: string) => m !== ourNumber); members = (convo.getGroupMembers() || []).filter((m: string) => m !== ourNumber);
admins = convo.getGroupAdmins(); admins = convo.getGroupAdmins();
} }
convo.set({ members }); convo.set({ members });

@ -73,7 +73,7 @@ export async function initiateClosedGroupUpdate(
name: groupName, name: groupName,
members, members,
// remove from the zombies list the zombies not which are not in the group anymore // remove from the zombies list the zombies not which are not in the group anymore
zombies: convo.get('zombies')?.filter(z => members.includes(z)), zombies: convo.getGroupZombies()?.filter(z => members.includes(z)),
activeAt: Date.now(), activeAt: Date.now(),
expireTimer: convo.get('expireTimer'), expireTimer: convo.get('expireTimer'),
}; };
@ -180,12 +180,12 @@ export async function addUpdateMessage(
function buildGroupDiff(convo: ConversationModel, update: GroupInfo): GroupDiff { function buildGroupDiff(convo: ConversationModel, update: GroupInfo): GroupDiff {
const groupDiff: GroupDiff = {}; const groupDiff: GroupDiff = {};
if (convo.get('displayNameInProfile') !== update.name) { if (convo.getRealSessionUsername() !== update.name) {
groupDiff.newName = update.name; groupDiff.newName = update.name;
} }
const oldMembers = convo.get('members'); const oldMembers = convo.getGroupMembers();
const oldZombies = convo.get('zombies'); const oldZombies = convo.getGroupZombies();
const oldMembersWithZombies = _.uniq(oldMembers.concat(oldZombies)); const oldMembersWithZombies = _.uniq(oldMembers.concat(oldZombies));
const newMembersWithZombiesLeft = _.uniq(update.members.concat(update.zombies || [])); const newMembersWithZombiesLeft = _.uniq(update.members.concat(update.zombies || []));

@ -68,7 +68,7 @@ export async function initiateOpenGroupUpdate(
contentType: MIME.IMAGE_UNKNOWN, // contentType is mostly used to generate previews and screenshot. We do not care for those in this case. contentType: MIME.IMAGE_UNKNOWN, // contentType is mostly used to generate previews and screenshot. We do not care for those in this case.
}); });
await convo.setSessionProfile({ await convo.setSessionProfile({
displayName: groupName || convo.get('displayNameInProfile') || window.i18n('unknown'), displayName: groupName || convo.getRealSessionUsername() || window.i18n('unknown'),
avatarPath: upgraded.path, avatarPath: upgraded.path,
avatarImageId, avatarImageId,
}); });

@ -21,7 +21,7 @@ async function updateOurProfileSync(
} }
await updateProfileOfContact(us, displayName, profileUrl, profileKey); await updateProfileOfContact(us, displayName, profileUrl, profileKey);
if (priority !== null && ourConvo.get('priority') !== priority) { if (priority !== null && ourConvo.getPriority() !== priority) {
ourConvo.set('priority', priority); ourConvo.set('priority', priority);
await ourConvo.commit(); await ourConvo.commit();
} }
@ -43,7 +43,7 @@ async function updateProfileOfContact(
return; return;
} }
let changes = false; let changes = false;
const existingDisplayName = conversation.get('displayNameInProfile'); const existingDisplayName = conversation.getRealSessionUsername();
// avoid setting the display name to an invalid value // avoid setting the display name to an invalid value
if (existingDisplayName !== displayName && !isEmpty(displayName)) { if (existingDisplayName !== displayName && !isEmpty(displayName)) {
@ -55,8 +55,8 @@ async function updateProfileOfContact(
let avatarChanged = false; let avatarChanged = false;
// trust whatever we get as an update. It either comes from a shared config wrapper or one of that user's message. But in any case we should trust it, even if it gets resetted. // trust whatever we get as an update. It either comes from a shared config wrapper or one of that user's message. But in any case we should trust it, even if it gets resetted.
const prevPointer = conversation.get('avatarPointer'); const prevPointer = conversation.getAvatarPointer();
const prevProfileKey = conversation.get('profileKey'); const prevProfileKey = conversation.getProfileKey();
// we have to set it right away and not in the async download job, as the next .commit will save it to the // we have to set it right away and not in the async download job, as the next .commit will save it to the
// database and wrapper (and we do not want to override anything in the wrapper's content // database and wrapper (and we do not want to override anything in the wrapper's content

@ -103,10 +103,10 @@ export function getOurProfile(): LokiProfile | undefined {
// in their primary device's conversation // in their primary device's conversation
const ourNumber = Storage.get('primaryDevicePubKey') as string; const ourNumber = Storage.get('primaryDevicePubKey') as string;
const ourConversation = getConversationController().get(ourNumber); const ourConversation = getConversationController().get(ourNumber);
const ourProfileKeyHex = ourConversation.get('profileKey'); const ourProfileKeyHex = ourConversation.getProfileKey();
const profileKeyAsBytes = ourProfileKeyHex ? fromHexToArray(ourProfileKeyHex) : null; const profileKeyAsBytes = ourProfileKeyHex ? fromHexToArray(ourProfileKeyHex) : null;
const avatarPointer = ourConversation.get('avatarPointer'); const avatarPointer = ourConversation.getAvatarPointer();
const displayName = ourConversation.getRealSessionUsername() || 'Anonymous'; const displayName = ourConversation.getRealSessionUsername() || 'Anonymous';
return { return {
displayName, displayName,

@ -1144,7 +1144,7 @@ export async function handleCallTypeOffer(
// show a notification // show a notification
const callerConvo = getConversationController().get(sender); const callerConvo = getConversationController().get(sender);
const convNotif = callerConvo?.get('triggerNotificationsFor') || 'disabled'; const convNotif = callerConvo?.getNotificationsFor() || 'disabled';
if (convNotif === 'disabled') { if (convNotif === 'disabled') {
window?.log?.info('notifications disabled for convo', ed25519Str(sender)); window?.log?.info('notifications disabled for convo', ed25519Str(sender));
} else if (callerConvo) { } else if (callerConvo) {

@ -35,8 +35,8 @@ export function shouldAddAvatarDownloadJob({ conversationId }: { conversationId:
window.log.warn('shouldAddAvatarDownloadJob can only be used for private convos currently'); window.log.warn('shouldAddAvatarDownloadJob can only be used for private convos currently');
return false; return false;
} }
const prevPointer = conversation.get('avatarPointer'); const prevPointer = conversation.getAvatarPointer();
const profileKey = conversation.get('profileKey'); const profileKey = conversation.getProfileKey();
const hasNoAvatar = isEmpty(prevPointer) || isEmpty(profileKey); const hasNoAvatar = isEmpty(prevPointer) || isEmpty(profileKey);
if (hasNoAvatar) { if (hasNoAvatar) {
@ -116,8 +116,8 @@ class AvatarDownloadJob extends PersistedJob<AvatarDownloadPersistedData> {
return RunJobResult.PermanentFailure; return RunJobResult.PermanentFailure;
} }
let changes = false; let changes = false;
const toDownloadPointer = conversation.get('avatarPointer'); const toDownloadPointer = conversation.getAvatarPointer();
const toDownloadProfileKey = conversation.get('profileKey'); const toDownloadProfileKey = conversation.getProfileKey();
// if there is an avatar and profileKey for that user ('', null and undefined excluded), download, decrypt and save the avatar locally. // if there is an avatar and profileKey for that user ('', null and undefined excluded), download, decrypt and save the avatar locally.
if (toDownloadPointer && toDownloadProfileKey) { if (toDownloadPointer && toDownloadProfileKey) {

@ -49,12 +49,12 @@ async function insertContactFromDBIntoWrapperAndRefresh(id: string): Promise<voi
const dbName = foundConvo.getRealSessionUsername() || undefined; const dbName = foundConvo.getRealSessionUsername() || undefined;
const dbNickname = foundConvo.getNickname(); const dbNickname = foundConvo.getNickname();
const dbProfileUrl = foundConvo.get('avatarPointer') || undefined; const dbProfileUrl = foundConvo.getAvatarPointer() || undefined;
const dbProfileKey = foundConvo.get('profileKey') || undefined; const dbProfileKey = foundConvo.getProfileKey() || undefined;
const dbApproved = foundConvo.isApproved(); const dbApproved = foundConvo.isApproved();
const dbApprovedMe = foundConvo.didApproveMe(); const dbApprovedMe = foundConvo.didApproveMe();
const dbBlocked = foundConvo.isBlocked(); const dbBlocked = foundConvo.isBlocked();
const priority = foundConvo.get('priority') || 0; const priority = foundConvo.getPriority() || 0;
// expiration timer is not tracked currently but will be once disappearing message is merged into userconfig // expiration timer is not tracked currently but will be once disappearing message is merged into userconfig
// const expirationTimerSeconds = foundConvo.get('expireTimer') || 0; // const expirationTimerSeconds = foundConvo.get('expireTimer') || 0;

@ -29,8 +29,8 @@ function isLegacyGroupToStoreInWrapper(convo: ConversationModel): boolean {
!convo.isPublic() && !convo.isPublic() &&
convo.id.startsWith('05') && // new closed groups won't start with 05 convo.id.startsWith('05') && // new closed groups won't start with 05
convo.isActive() && convo.isActive() &&
!convo.get('isKickedFromGroup') && !convo.isKickedFromGroup() &&
!convo.get('left') !convo.isLeft()
); );
} }
@ -99,7 +99,7 @@ async function insertGroupsFromDBIntoWrapperAndRefresh(convoId: string): Promise
); );
const wrapperComm = getCommunityInfoFromDBValues({ const wrapperComm = getCommunityInfoFromDBValues({
priority: foundConvo.get('priority'), priority: foundConvo.getPriority(),
fullUrl, fullUrl,
}); });
@ -120,14 +120,14 @@ async function insertGroupsFromDBIntoWrapperAndRefresh(convoId: string): Promise
const encryptionKeyPair = await Data.getLatestClosedGroupEncryptionKeyPair(convoId); const encryptionKeyPair = await Data.getLatestClosedGroupEncryptionKeyPair(convoId);
const wrapperLegacyGroup = getLegacyGroupInfoFromDBValues({ const wrapperLegacyGroup = getLegacyGroupInfoFromDBValues({
id: foundConvo.id, id: foundConvo.id,
priority: foundConvo.get('priority'), priority: foundConvo.getPriority(),
members: foundConvo.get('members') || [], members: foundConvo.getGroupMembers() || [],
groupAdmins: foundConvo.getGroupAdmins(), groupAdmins: foundConvo.getGroupAdmins(),
// expireTimer: foundConvo.get('expireTimer'), // expireTimer: foundConvo.get('expireTimer'),
displayNameInProfile: foundConvo.get('displayNameInProfile'), displayNameInProfile: foundConvo.getRealSessionUsername(),
encPubkeyHex: encryptionKeyPair?.publicHex || '', encPubkeyHex: encryptionKeyPair?.publicHex || '',
encSeckeyHex: encryptionKeyPair?.privateHex || '', encSeckeyHex: encryptionKeyPair?.privateHex || '',
lastJoinedTimestamp: foundConvo.get('lastJoinedTimestamp') || 0, lastJoinedTimestamp: foundConvo.getLastJoinedTimestamp(),
}); });
try { try {

@ -18,10 +18,10 @@ async function insertUserProfileIntoWrapper(convoId: string) {
throw new Error('insertUserProfileIntoWrapper needs a ourConvo to exist'); throw new Error('insertUserProfileIntoWrapper needs a ourConvo to exist');
} }
const dbName = ourConvo.get('displayNameInProfile') || ''; const dbName = ourConvo.getRealSessionUsername() || '';
const dbProfileUrl = ourConvo.get('avatarPointer') || ''; const dbProfileUrl = ourConvo.getAvatarPointer() || '';
const dbProfileKey = fromHexToArray(ourConvo.get('profileKey') || ''); const dbProfileKey = fromHexToArray(ourConvo.getProfileKey() || '');
const priority = ourConvo.get('priority') || CONVERSATION_PRIORITIES.default; const priority = ourConvo.getPriority() || CONVERSATION_PRIORITIES.default;
const areBlindedMsgRequestEnabled = !!Storage.get(SettingsKey.hasBlindedMsgRequestsEnabled); const areBlindedMsgRequestEnabled = !!Storage.get(SettingsKey.hasBlindedMsgRequestsEnabled);

@ -138,7 +138,7 @@ const getActiveOpenGroupV2CompleteUrls = async (
): Promise<Array<string>> => { ): Promise<Array<string>> => {
// Filter open groups v2 // Filter open groups v2
const openGroupsV2ConvoIds = convos const openGroupsV2ConvoIds = convos
.filter(c => !!c.get('active_at') && c.isOpenGroupV2() && !c.get('left')) .filter(c => !!c.getActiveAt() && c.isOpenGroupV2() && !c.isLeft())
.map(c => c.id) as Array<string>; .map(c => c.id) as Array<string>;
const urls = await Promise.all( const urls = await Promise.all(
@ -161,13 +161,13 @@ const getValidClosedGroups = async (convos: Array<ConversationModel>) => {
// Filter Closed/Medium groups // Filter Closed/Medium groups
const closedGroupModels = convos.filter( const closedGroupModels = convos.filter(
c => c =>
!!c.get('active_at') && !!c.getActiveAt() &&
c.isClosedGroup() && c.isClosedGroup() &&
c.get('members')?.includes(ourPubKey) && c.getGroupMembers()?.includes(ourPubKey) &&
!c.get('left') && !c.isLeft() &&
!c.get('isKickedFromGroup') && !c.isKickedFromGroup() &&
!c.isBlocked() && !c.isBlocked() &&
c.get('displayNameInProfile') c.getRealSessionUsername()
); );
const closedGroups = await Promise.all( const closedGroups = await Promise.all(
@ -180,8 +180,8 @@ const getValidClosedGroups = async (convos: Array<ConversationModel>) => {
return new ConfigurationMessageClosedGroup({ return new ConfigurationMessageClosedGroup({
publicKey: groupPubKey, publicKey: groupPubKey,
name: c.get('displayNameInProfile') || '', name: c.getRealSessionUsername() || '',
members: c.get('members') || [], members: c.getGroupMembers() || [],
admins: c.getGroupAdmins(), admins: c.getGroupAdmins(),
encryptionKeyPair: ECKeyPair.fromHexKeyPair(fetchEncryptionKeyPair), encryptionKeyPair: ECKeyPair.fromHexKeyPair(fetchEncryptionKeyPair),
}); });
@ -199,7 +199,7 @@ const getValidContacts = (convos: Array<ConversationModel>) => {
// blindedId are synced with the outbox logic. // blindedId are synced with the outbox logic.
const contactsModels = convos.filter( const contactsModels = convos.filter(
c => c =>
!!c.get('active_at') && !!c.getActiveAt() &&
c.getRealSessionUsername() && c.getRealSessionUsername() &&
c.isPrivate() && c.isPrivate() &&
c.isApproved() && c.isApproved() &&
@ -208,7 +208,7 @@ const getValidContacts = (convos: Array<ConversationModel>) => {
const contacts = contactsModels.map(c => { const contacts = contactsModels.map(c => {
try { try {
const profileKey = c.get('profileKey'); const profileKey = c.getProfileKey();
let profileKeyForContact = null; let profileKeyForContact = null;
if (typeof profileKey === 'string') { if (typeof profileKey === 'string') {
// this will throw if the profileKey is not in hex. // this will throw if the profileKey is not in hex.
@ -237,7 +237,7 @@ const getValidContacts = (convos: Array<ConversationModel>) => {
return new ConfigurationMessageContact({ return new ConfigurationMessageContact({
publicKey: c.id as string, publicKey: c.id as string,
displayName: c.getRealSessionUsername() || 'Anonymous', displayName: c.getRealSessionUsername() || 'Anonymous',
profilePictureURL: c.get('avatarPointer'), profilePictureURL: c.getAvatarPointer(),
profileKey: !profileKeyForContact?.length ? undefined : profileKeyForContact, profileKey: !profileKeyForContact?.length ? undefined : profileKeyForContact,
isApproved: c.isApproved(), isApproved: c.isApproved(),
isBlocked: c.isBlocked(), isBlocked: c.isBlocked(),
@ -268,10 +268,10 @@ export const getCurrentConfigurationMessage = async (
const ourProfileKeyHex = const ourProfileKeyHex =
getConversationController() getConversationController()
.get(UserUtils.getOurPubKeyStrFromCache()) .get(UserUtils.getOurPubKeyStrFromCache())
?.get('profileKey') || null; ?.getProfileKey() || null;
const profileKey = ourProfileKeyHex ? fromHexToArray(ourProfileKeyHex) : undefined; const profileKey = ourProfileKeyHex ? fromHexToArray(ourProfileKeyHex) : undefined;
const profilePicture = ourConvo?.get('avatarPointer') || undefined; const profilePicture = ourConvo?.getAvatarPointer() || undefined;
const displayName = ourConvo?.getRealSessionUsername() || 'Anonymous'; // this should never be undefined, but well... const displayName = ourConvo?.getRealSessionUsername() || 'Anonymous'; // this should never be undefined, but well...
const activeOpenGroups = [...opengroupV2CompleteUrls]; const activeOpenGroups = [...opengroupV2CompleteUrls];

Loading…
Cancel
Save