Show notifications when a user's profile name changes
This commit is contained in:
parent
2f015863ca
commit
d75eee015f
44 changed files with 749 additions and 194 deletions
|
@ -479,6 +479,7 @@
|
|||
typingContact: typingContact ? typingContact.format() : null,
|
||||
lastUpdated: this.get('timestamp'),
|
||||
name: this.get('name'),
|
||||
firstName: this.get('profileName'),
|
||||
profileName: this.getProfileName(),
|
||||
timestamp,
|
||||
inboxPosition,
|
||||
|
@ -1081,9 +1082,43 @@
|
|||
id,
|
||||
})
|
||||
);
|
||||
|
||||
this.trigger('newmessage', model);
|
||||
},
|
||||
|
||||
async addProfileChange(profileChange, conversationId) {
|
||||
const message = {
|
||||
conversationId: this.id,
|
||||
type: 'profile-change',
|
||||
sent_at: Date.now(),
|
||||
received_at: Date.now(),
|
||||
unread: true,
|
||||
changedId: conversationId || this.id,
|
||||
profileChange,
|
||||
};
|
||||
|
||||
const id = await window.Signal.Data.saveMessage(message, {
|
||||
Message: Whisper.Message,
|
||||
});
|
||||
const model = MessageController.register(
|
||||
id,
|
||||
new Whisper.Message({
|
||||
...message,
|
||||
id,
|
||||
})
|
||||
);
|
||||
|
||||
this.trigger('newmessage', model);
|
||||
|
||||
if (this.isPrivate()) {
|
||||
ConversationController.getAllGroupsInvolvingId(this.id).then(groups => {
|
||||
_.forEach(groups, group => {
|
||||
group.addProfileChange(profileChange, this.id);
|
||||
});
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
async onReadMessage(message, readAt) {
|
||||
// We mark as read everything older than this message - to clean up old stuff
|
||||
// still marked unread in the database. If the user generally doesn't read in
|
||||
|
@ -2489,8 +2524,28 @@
|
|||
);
|
||||
|
||||
// encode
|
||||
const profileFamilyName = family ? stringFromBytes(family) : null;
|
||||
const profileName = given ? stringFromBytes(given) : null;
|
||||
const profileFamilyName = family ? stringFromBytes(family) : null;
|
||||
|
||||
// check for changes
|
||||
const oldName = this.getProfileName();
|
||||
const newName = Util.combineNames(profileName, profileFamilyName);
|
||||
const hadPreviousName = Boolean(oldName);
|
||||
|
||||
// Note that we compare the combined names to ensure that we don't present the exact
|
||||
// same before/after string, even if someone is moving from just first name to
|
||||
// first/last name in their profile data.
|
||||
const nameChanged = oldName !== newName;
|
||||
|
||||
if (!this.isMe() && hadPreviousName && nameChanged) {
|
||||
const change = {
|
||||
type: 'name',
|
||||
oldName,
|
||||
newName,
|
||||
};
|
||||
|
||||
this.addProfileChange(change);
|
||||
}
|
||||
|
||||
// set
|
||||
this.set({ profileName, profileFamilyName });
|
||||
|
|
|
@ -183,6 +183,11 @@
|
|||
type: 'callHistory',
|
||||
data: this.getPropsForCallHistory(),
|
||||
};
|
||||
} else if (this.isProfileChange()) {
|
||||
return {
|
||||
type: 'profileChange',
|
||||
data: this.getPropsForProfileChange(),
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
|
@ -364,6 +369,9 @@
|
|||
isCallHistory() {
|
||||
return this.get('type') === 'call-history';
|
||||
},
|
||||
isProfileChange() {
|
||||
return this.get('type') === 'profile-change';
|
||||
},
|
||||
|
||||
// Props for each message type
|
||||
getPropsForUnsupportedMessage() {
|
||||
|
@ -508,6 +516,16 @@
|
|||
callHistoryDetails: this.get('callHistoryDetails'),
|
||||
};
|
||||
},
|
||||
getPropsForProfileChange() {
|
||||
const change = this.get('profileChange');
|
||||
const changedId = this.get('changedId');
|
||||
|
||||
return {
|
||||
changedContact: this.findAndFormatContact(changedId),
|
||||
change,
|
||||
};
|
||||
},
|
||||
|
||||
getAttachmentsForMessage() {
|
||||
const sticker = this.get('sticker');
|
||||
if (sticker && sticker.data) {
|
||||
|
@ -856,6 +874,17 @@
|
|||
if (this.isUnsupportedMessage()) {
|
||||
return i18n('message--getDescription--unsupported-message');
|
||||
}
|
||||
if (this.isProfileChange()) {
|
||||
const change = this.get('profileChange');
|
||||
const changedId = this.get('changedId');
|
||||
const changedContact = this.findAndFormatContact(changedId);
|
||||
|
||||
return Signal.Util.getStringForProfileChange(
|
||||
change,
|
||||
changedContact,
|
||||
i18n
|
||||
);
|
||||
}
|
||||
if (this.isTapToView()) {
|
||||
if (this.isErased()) {
|
||||
return i18n('message--getDescription--disappearing-media');
|
||||
|
@ -884,7 +913,9 @@
|
|||
if (groupUpdate.left === 'You') {
|
||||
return i18n('youLeftTheGroup');
|
||||
} else if (groupUpdate.left) {
|
||||
return i18n('leftTheGroup', this.getNameForNumber(groupUpdate.left));
|
||||
return i18n('leftTheGroup', [
|
||||
this.getNameForNumber(groupUpdate.left),
|
||||
]);
|
||||
}
|
||||
|
||||
if (!fromContact) {
|
||||
|
@ -894,7 +925,7 @@
|
|||
if (fromContact.isMe()) {
|
||||
messages.push(i18n('youUpdatedTheGroup'));
|
||||
} else {
|
||||
messages.push(i18n('updatedTheGroup', fromContact.getTitle()));
|
||||
messages.push(i18n('updatedTheGroup', [fromContact.getTitle()]));
|
||||
}
|
||||
|
||||
if (groupUpdate.joined && groupUpdate.joined.length) {
|
||||
|
@ -907,10 +938,11 @@
|
|||
|
||||
if (joinedContacts.length > 1) {
|
||||
messages.push(
|
||||
i18n(
|
||||
'multipleJoinedTheGroup',
|
||||
_.map(joinedWithoutMe, contact => contact.getTitle()).join(', ')
|
||||
)
|
||||
i18n('multipleJoinedTheGroup', [
|
||||
_.map(joinedWithoutMe, contact => contact.getTitle()).join(
|
||||
', '
|
||||
),
|
||||
])
|
||||
);
|
||||
|
||||
if (joinedWithoutMe.length < joinedContacts.length) {
|
||||
|
@ -925,14 +957,14 @@
|
|||
messages.push(i18n('youJoinedTheGroup'));
|
||||
} else {
|
||||
messages.push(
|
||||
i18n('joinedTheGroup', joinedContacts[0].getTitle())
|
||||
i18n('joinedTheGroup', [joinedContacts[0].getTitle()])
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (groupUpdate.name) {
|
||||
messages.push(i18n('titleIsNow', groupUpdate.name));
|
||||
messages.push(i18n('titleIsNow', [groupUpdate.name]));
|
||||
}
|
||||
if (groupUpdate.avatarUpdated) {
|
||||
messages.push(i18n('updatedGroupAvatar'));
|
||||
|
@ -965,18 +997,16 @@
|
|||
return i18n('disappearingMessagesDisabled');
|
||||
}
|
||||
|
||||
return i18n(
|
||||
'timerSetTo',
|
||||
Whisper.ExpirationTimerOptions.getAbbreviated(expireTimer || 0)
|
||||
);
|
||||
return i18n('timerSetTo', [
|
||||
Whisper.ExpirationTimerOptions.getAbbreviated(expireTimer || 0),
|
||||
]);
|
||||
}
|
||||
if (this.isKeyChange()) {
|
||||
const identifier = this.get('key_changed');
|
||||
const conversation = this.findContact(identifier);
|
||||
return i18n(
|
||||
'safetyNumberChangedGroup',
|
||||
conversation ? conversation.getTitle() : null
|
||||
);
|
||||
return i18n('safetyNumberChangedGroup', [
|
||||
conversation ? conversation.getTitle() : null,
|
||||
]);
|
||||
}
|
||||
const contacts = this.get('contact');
|
||||
if (contacts && contacts.length) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue