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';
const StyledNoticeBanner = styled(Flex)`
position: relative;
background-color: var(--primary-color);
color: var(--black-color);
font-size: var(--font-size-md);
@ -15,14 +14,13 @@ const StyledNoticeBanner = styled(Flex)`
cursor: pointer;
.session-icon-button {
position: absolute;
right: var(--margins-sm);
pointer-events: none;
}
`;
const StyledText = styled.span`
margin-right: var(--margins-xl);
margin-right: var(--margins-sm);
`;
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)
${StyledRootDialog} & {
background-color: unset;
color: var(--orange-color);
color: var(--text-primary-color);
max-width: 300px;
}
`;

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

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

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

@ -134,7 +134,6 @@ export const OverlayClosedGroupV2 = () => {
async function onEnterPressed() {
setGroupNameError(undefined);
setGroupName('');
if (isCreatingGroup) {
window?.log?.warn('Closed group creation already in progress');
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)
const originNameToBlock =
alsoBlock && !!conversationIdOrigin
? ConvoHub.use().get(conversationIdOrigin)?.getContactProfileNameOrShortenedPubKey()
? ConvoHub.use().get(conversationIdOrigin)?.getNicknameOrRealUsernameOrPlaceholder()
: null;
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
* version of the contact pubkey.
* Throws an error if called on a group convo.
* For a private convo, returns nickname || ('You' || userDisplayName) || shortened(pk)
* Throws an error if called on a no-private convo.
*
*/
public getContactProfileNameOrShortenedPubKey() {

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

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

@ -24,7 +24,7 @@ export function getTimerNotificationStr({
const timespanText = TimerOptions.getName(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
if (isLegacyDisappearingModeEnabled(expirationMode)) {

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

@ -150,6 +150,14 @@ const initNewGroupInWrapper = createAsyncThunk(
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++) {
const member = uniqMembers[index];
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);
if (!membersFromWrapper || isEmpty(membersFromWrapper)) {
throw new Error(

@ -51,7 +51,7 @@ export const oceanDark: ThemeColorVariables = {
'--button-outline-border-hover-color': 'var(--text-primary-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-text-color': 'var(--text-primary-color)',
'--button-solid-text-hover-color': 'var(--text-primary-color)',

Loading…
Cancel
Save