fix: use nickname for group update messages if available

pull/3281/head
Audric Ackermann 10 months ago
parent 85749eb10a
commit 64a3360def
No known key found for this signature in database

@ -5,7 +5,6 @@ import { SessionIconButton, SessionIconType } from './icon';
import { StyledRootDialog } from './dialog/StyledRootDialog'; import { StyledRootDialog } from './dialog/StyledRootDialog';
const StyledNoticeBanner = styled(Flex)` const StyledNoticeBanner = styled(Flex)`
position: relative;
background-color: var(--primary-color); background-color: var(--primary-color);
color: var(--black-color); color: var(--black-color);
font-size: var(--font-size-md); font-size: var(--font-size-md);
@ -15,14 +14,13 @@ const StyledNoticeBanner = styled(Flex)`
cursor: pointer; cursor: pointer;
.session-icon-button { .session-icon-button {
position: absolute;
right: var(--margins-sm); right: var(--margins-sm);
pointer-events: none; pointer-events: none;
} }
`; `;
const StyledText = styled.span` const StyledText = styled.span`
margin-right: var(--margins-xl); margin-right: var(--margins-sm);
`; `;
type NoticeBannerProps = { type NoticeBannerProps = {
@ -65,7 +63,7 @@ const StyledGroupInviteBanner = styled(Flex)`
// when part a a dialog, invert it and make it narrower (as the dialog grows to make it fit) // when part a a dialog, invert it and make it narrower (as the dialog grows to make it fit)
${StyledRootDialog} & { ${StyledRootDialog} & {
background-color: unset; background-color: unset;
color: var(--orange-color); color: var(--text-primary-color);
max-width: 300px; max-width: 300px;
} }
`; `;

@ -34,7 +34,7 @@ const Mention = (props: MentionProps) => {
return ( return (
<StyledMentionAnother> <StyledMentionAnother>
@{foundConvo?.getContactProfileNameOrShortenedPubKey() || PubKey.shorten(props.text)} @{foundConvo?.getNicknameOrRealUsernameOrPlaceholder() || PubKey.shorten(props.text)}
</StyledMentionAnother> </StyledMentionAnother>
); );
}; };

@ -46,7 +46,7 @@ export const ClickToTrustSender = (props: { messageId: string }) => {
i18nMessage: { i18nMessage: {
token: 'attachmentsAutoDownloadModalDescription', token: 'attachmentsAutoDownloadModalDescription',
args: { args: {
conversation_name: convo.getContactProfileNameOrShortenedPubKey(), conversation_name: convo.getNicknameOrRealUsernameOrPlaceholder(),
}, },
}, },
closeTheme: SessionButtonColor.Danger, closeTheme: SessionButtonColor.Danger,

@ -127,7 +127,7 @@ const InviteContactsDialogInner = (props: Props) => {
const isGroupV2 = useSelectedIsGroupV2(); const isGroupV2 = useSelectedIsGroupV2();
const [shareHistory, setShareHistory] = useState(false); const [shareHistory, setShareHistory] = useState(false);
const { uniqueValues: selectedContacts, addTo, removeFrom } = useSet<string>(); const { uniqueValues: selectedContacts, addTo, removeFrom, empty } = useSet<string>();
if (isPrivate) { if (isPrivate) {
throw new Error('InviteContactsDialogInner must be a group'); throw new Error('InviteContactsDialogInner must be a group');
@ -144,27 +144,28 @@ const InviteContactsDialogInner = (props: Props) => {
}; };
const onClickOK = () => { const onClickOK = () => {
if (selectedContacts.length > 0) { if (selectedContacts.length <= 0) {
if (isPublic) { closeDialog();
void submitForOpenGroup(conversationId, selectedContacts); return;
} else {
if (PubKey.is03Pubkey(conversationId)) {
const forcedAsPubkeys = selectedContacts as Array<PubkeyType>;
const action = groupInfoActions.currentDeviceGroupMembersChange({
addMembersWithoutHistory: shareHistory ? [] : forcedAsPubkeys,
addMembersWithHistory: shareHistory ? forcedAsPubkeys : [],
removeMembers: [],
groupPk: conversationId,
alsoRemoveMessages: false,
});
dispatch(action as any);
return;
}
void submitForClosedGroup(conversationId, selectedContacts);
}
} }
if (isPublic) {
closeDialog(); void submitForOpenGroup(conversationId, selectedContacts);
return;
}
if (PubKey.is03Pubkey(conversationId)) {
const forcedAsPubkeys = selectedContacts as Array<PubkeyType>;
const action = groupInfoActions.currentDeviceGroupMembersChange({
addMembersWithoutHistory: shareHistory ? [] : forcedAsPubkeys,
addMembersWithHistory: shareHistory ? forcedAsPubkeys : [],
removeMembers: [],
groupPk: conversationId,
alsoRemoveMessages: false,
});
dispatch(action as any);
empty();
return;
}
void submitForClosedGroup(conversationId, selectedContacts);
}; };
useKey((event: KeyboardEvent) => { useKey((event: KeyboardEvent) => {
@ -182,7 +183,7 @@ const InviteContactsDialogInner = (props: Props) => {
const hasContacts = validContactsForInvite.length > 0; const hasContacts = validContactsForInvite.length > 0;
return ( return (
<SessionWrapperModal title={titleText} onClose={closeDialog}> <SessionWrapperModal title={titleText} onClose={closeDialog} showExitIcon={true}>
{hasContacts && isGroupV2 && <GroupInviteRequiredVersionBanner />} {hasContacts && isGroupV2 && <GroupInviteRequiredVersionBanner />}
<SpacerLG /> <SpacerLG />

@ -134,7 +134,6 @@ export const OverlayClosedGroupV2 = () => {
async function onEnterPressed() { async function onEnterPressed() {
setGroupNameError(undefined); setGroupNameError(undefined);
setGroupName('');
if (isCreatingGroup) { if (isCreatingGroup) {
window?.log?.warn('Closed group creation already in progress'); window?.log?.warn('Closed group creation already in progress');
return; return;

@ -268,7 +268,7 @@ export const declineConversationWithConfirm = ({
// restoring from seed we might not have the sender of that invite, so we need to take care of not having one (and not block) // restoring from seed we might not have the sender of that invite, so we need to take care of not having one (and not block)
const originNameToBlock = const originNameToBlock =
alsoBlock && !!conversationIdOrigin alsoBlock && !!conversationIdOrigin
? ConvoHub.use().get(conversationIdOrigin)?.getContactProfileNameOrShortenedPubKey() ? ConvoHub.use().get(conversationIdOrigin)?.getNicknameOrRealUsernameOrPlaceholder()
: null; : null;
const convoName = ConvoHub.use().get(conversationId)?.getNicknameOrRealUsernameOrPlaceholder(); const convoName = ConvoHub.use().get(conversationId)?.getNicknameOrRealUsernameOrPlaceholder();

@ -1817,9 +1817,8 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
} }
/** /**
* For a private convo, returns the loki profile name if set, or a shortened * For a private convo, returns nickname || ('You' || userDisplayName) || shortened(pk)
* version of the contact pubkey. * Throws an error if called on a no-private convo.
* Throws an error if called on a group convo.
* *
*/ */
public getContactProfileNameOrShortenedPubKey() { public getContactProfileNameOrShortenedPubKey() {

@ -14,15 +14,15 @@ function usAndXOthers(arr: Array<string>) {
export function getKickedGroupUpdateStr( export function getKickedGroupUpdateStr(
kicked: Array<string>, kicked: Array<string>,
groupName: string _groupName: string
): LocalizerComponentPropsObject { ): LocalizerComponentPropsObject {
const { others, us } = usAndXOthers(kicked); const { others, us } = usAndXOthers(kicked);
const othersNames = others.map(ConvoHub.use().getContactProfileNameOrShortenedPubKey); const othersNames = others.map(ConvoHub.use().getNicknameOrRealUsernameOrPlaceholder);
if (us) { if (us) {
switch (others.length) { switch (others.length) {
case 0: case 0:
return { token: 'groupRemovedYou', args: { group_name: groupName } }; return { token: 'groupRemovedYouGeneral' };
case 1: case 1:
return { token: 'groupRemovedYouTwo', args: { other_name: othersNames[0] } }; return { token: 'groupRemovedYouTwo', args: { other_name: othersNames[0] } };
default: default:
@ -66,7 +66,7 @@ export function getLeftGroupUpdateChangeStr(left: Array<string>): LocalizerCompo
: { : {
token: 'groupMemberLeft', token: 'groupMemberLeft',
args: { args: {
name: ConvoHub.use().getContactProfileNameOrShortenedPubKey(others[0]), name: ConvoHub.use().getNicknameOrRealUsernameOrPlaceholder(others[0]),
}, },
}; };
} }
@ -78,7 +78,7 @@ export function getJoinedGroupUpdateChangeStr(
_groupName: string _groupName: string
): LocalizerComponentPropsObject { ): LocalizerComponentPropsObject {
const { others, us } = usAndXOthers(joined); const { others, us } = usAndXOthers(joined);
const othersNames = others.map(ConvoHub.use().getContactProfileNameOrShortenedPubKey); const othersNames = others.map(ConvoHub.use().getNicknameOrRealUsernameOrPlaceholder);
if (groupv2) { if (groupv2) {
if (us) { if (us) {
@ -164,7 +164,7 @@ export function getPromotedGroupUpdateChangeStr(
joined: Array<string> joined: Array<string>
): LocalizerComponentPropsObject { ): LocalizerComponentPropsObject {
const { others, us } = usAndXOthers(joined); const { others, us } = usAndXOthers(joined);
const othersNames = others.map(ConvoHub.use().getContactProfileNameOrShortenedPubKey); const othersNames = others.map(ConvoHub.use().getNicknameOrRealUsernameOrPlaceholder);
if (us) { if (us) {
switch (othersNames.length) { switch (othersNames.length) {

@ -343,16 +343,16 @@ export class MessageModel extends Backbone.Model<MessageAttributes> {
) as DataExtractionNotificationMsg; ) as DataExtractionNotificationMsg;
if (dataExtraction.type === SignalService.DataExtractionNotification.Type.SCREENSHOT) { if (dataExtraction.type === SignalService.DataExtractionNotification.Type.SCREENSHOT) {
return window.i18n.stripped('screenshotTaken', { return window.i18n.stripped('screenshotTaken', {
name: ConvoHub.use().getContactProfileNameOrShortenedPubKey(dataExtraction.source), name: ConvoHub.use().getNicknameOrRealUsernameOrPlaceholder(dataExtraction.source),
}); });
} }
return window.i18n.stripped('attachmentsMediaSaved', { return window.i18n.stripped('attachmentsMediaSaved', {
name: ConvoHub.use().getContactProfileNameOrShortenedPubKey(dataExtraction.source), name: ConvoHub.use().getNicknameOrRealUsernameOrPlaceholder(dataExtraction.source),
}); });
} }
if (this.isCallNotification()) { if (this.isCallNotification()) {
const name = ConvoHub.use().getContactProfileNameOrShortenedPubKey( const name = ConvoHub.use().getNicknameOrRealUsernameOrPlaceholder(
this.get('conversationId') this.get('conversationId')
); );
const callNotificationType = this.get('callNotificationType'); const callNotificationType = this.get('callNotificationType');
@ -448,7 +448,7 @@ export class MessageModel extends Backbone.Model<MessageAttributes> {
(pubkeysInDesc || []).forEach((pubkeyWithAt: string) => { (pubkeysInDesc || []).forEach((pubkeyWithAt: string) => {
const pubkey = pubkeyWithAt.slice(1); const pubkey = pubkeyWithAt.slice(1);
const isUS = isUsAnySogsFromCache(pubkey); const isUS = isUsAnySogsFromCache(pubkey);
const displayName = ConvoHub.use().getContactProfileNameOrShortenedPubKey(pubkey); const displayName = ConvoHub.use().getNicknameOrRealUsernameOrPlaceholder(pubkey);
if (isUS) { if (isUS) {
bodyMentionsMappedToNames = bodyMentionsMappedToNames?.replace( bodyMentionsMappedToNames = bodyMentionsMappedToNames?.replace(
pubkeyWithAt, pubkeyWithAt,

@ -24,7 +24,7 @@ export function getTimerNotificationStr({
const timespanText = TimerOptions.getName(timespanSeconds || 0); const timespanText = TimerOptions.getName(timespanSeconds || 0);
const disabled = !timespanSeconds || timespanSeconds <= 0; const disabled = !timespanSeconds || timespanSeconds <= 0;
const authorName = ConvoHub.use().getContactProfileNameOrShortenedPubKey(author); const authorName = ConvoHub.use().getNicknameOrRealUsernameOrPlaceholder(author);
// TODO: legacy messages support will be removed in a future release // TODO: legacy messages support will be removed in a future release
if (isLegacyDisappearingModeEnabled(expirationMode)) { if (isLegacyDisappearingModeEnabled(expirationMode)) {

@ -160,12 +160,12 @@ class ConvoController {
return conversation; return conversation;
} }
public getContactProfileNameOrShortenedPubKey(pubKey: string): string { public getNicknameOrRealUsernameOrPlaceholder(pubKey: string): string {
const conversation = ConvoHub.use().get(pubKey); const conversation = ConvoHub.use().get(pubKey);
if (!conversation) { if (!conversation) {
return pubKey; return pubKey;
} }
return conversation.getContactProfileNameOrShortenedPubKey(); return conversation.getNicknameOrRealUsernameOrPlaceholder();
} }
public async getOrCreateAndWait( public async getOrCreateAndWait(

@ -150,6 +150,14 @@ const initNewGroupInWrapper = createAsyncThunk(
groupEd25519Pubkey: toFixedUint8ArrayOfLength(groupEd2519Pk, 32).buffer, groupEd25519Pubkey: toFixedUint8ArrayOfLength(groupEd2519Pk, 32).buffer,
}); });
const infos = await MetaGroupWrapperActions.infoGet(groupPk);
if (!infos) {
throw new Error(`getInfos of ${groupPk} returned empty result even if it was just init.`);
}
// if the name exceeds libsession-util max length for group name, the name will be saved truncated
infos.name = groupName;
await MetaGroupWrapperActions.infoSet(groupPk, infos);
for (let index = 0; index < uniqMembers.length; index++) { for (let index = 0; index < uniqMembers.length; index++) {
const member = uniqMembers[index]; const member = uniqMembers[index];
const convoMember = ConvoHub.use().get(member); const convoMember = ConvoHub.use().get(member);
@ -173,13 +181,6 @@ const initNewGroupInWrapper = createAsyncThunk(
} }
} }
const infos = await MetaGroupWrapperActions.infoGet(groupPk);
if (!infos) {
throw new Error(`getInfos of ${groupPk} returned empty result even if it was just init.`);
}
infos.name = groupName;
await MetaGroupWrapperActions.infoSet(groupPk, infos);
const membersFromWrapper = await MetaGroupWrapperActions.memberGetAll(groupPk); const membersFromWrapper = await MetaGroupWrapperActions.memberGetAll(groupPk);
if (!membersFromWrapper || isEmpty(membersFromWrapper)) { if (!membersFromWrapper || isEmpty(membersFromWrapper)) {
throw new Error( throw new Error(

@ -51,7 +51,7 @@ export const oceanDark: ThemeColorVariables = {
'--button-outline-border-hover-color': 'var(--text-primary-color)', '--button-outline-border-hover-color': 'var(--text-primary-color)',
'--button-outline-disabled-color': 'var(--disabled-color)', '--button-outline-disabled-color': 'var(--disabled-color)',
'--button-solid-background-color': 'var(--background-secondary-color)', '--button-solid-background-color': THEMES.OCEAN_DARK.COLOR1,
'--button-solid-background-hover-color': THEMES.OCEAN_DARK.COLOR4, '--button-solid-background-hover-color': THEMES.OCEAN_DARK.COLOR4,
'--button-solid-text-color': 'var(--text-primary-color)', '--button-solid-text-color': 'var(--text-primary-color)',
'--button-solid-text-hover-color': 'var(--text-primary-color)', '--button-solid-text-hover-color': 'var(--text-primary-color)',

Loading…
Cancel
Save