Set profile name

pull/1138/head
Vincent 5 years ago
parent 9c7f5b2c09
commit 19cf4fa54b

@ -87,9 +87,6 @@
); );
} }
console.log('[vince] Creating conversation with id:', id);
if (!this._initialFetchComplete) { if (!this._initialFetchComplete) {
throw new Error( throw new Error(
'ConversationController.get() needs complete initial fetch' 'ConversationController.get() needs complete initial fetch'
@ -197,12 +194,6 @@
conversations.remove(conversation); conversations.remove(conversation);
}, },
getOrCreateAndWait(id, type) { getOrCreateAndWait(id, type) {
const ourNumber = textsecure.storage.user.getNumber();
if (id !== ourNumber) {
console.log('[vince][core] getOrCreateAndWaiting.. with source:', id);
}
return this._initialPromise.then(() => { return this._initialPromise.then(() => {
const conversation = this.getOrCreate(id, type); const conversation = this.getOrCreate(id, type);

@ -246,11 +246,6 @@
this.messageCollection.forEach(m => m.trigger('change')); this.messageCollection.forEach(m => m.trigger('change'));
}, },
async acceptFriendRequest() { async acceptFriendRequest() {
console.log(`[vince][fr] accepting friend request from conversations.js`);
console.log('[vince][fr] this.id:', this.id);
console.log(`[vince][fr] primary pubkey`, this.getPrimaryDevicePubKey());
// Friend request messages are always send to primary device conversation // Friend request messages are always send to primary device conversation
const messages = await window.Signal.Data.getMessagesByConversation( const messages = await window.Signal.Data.getMessagesByConversation(
this.id, this.id,
@ -260,24 +255,7 @@
type: 'friend-request', type: 'friend-request',
} }
); );
const priamryMessages = await window.Signal.Data.getMessagesByConversation(
this.getPrimaryDevicePubKey(),
{
limit: 1,
MessageCollection: Whisper.MessageCollection,
type: 'friend-request',
}
);
console.log(`[vince][fr] messages: `, messages);
console.log(`[vince][fr] Primary messages: `, priamryMessages);
// LAST MODEL IS POINTING TO THE PRIMARY DEVICE'S LASTMODEL. NOT SECONDARY FOR A2 --> B
const lastMessageModel = messages.at(0); const lastMessageModel = messages.at(0);
if (lastMessageModel) { if (lastMessageModel) {
lastMessageModel.acceptFriendRequest(); lastMessageModel.acceptFriendRequest();
@ -1014,7 +992,7 @@
const allDevices = await libloki.storage.getAllDevicePubKeysForPrimaryPubKey( const allDevices = await libloki.storage.getAllDevicePubKeysForPrimaryPubKey(
this.getPrimaryDevicePubKey() this.getPrimaryDevicePubKey()
); );
if (!allDevices.length) { if (!allDevices.length) {
return; return;
} }
@ -1663,8 +1641,6 @@
FriendRequestStatusEnum.pendingSend FriendRequestStatusEnum.pendingSend
); );
// Always share our profileKey in the friend request // Always share our profileKey in the friend request
// This will get added automatically after the FR // This will get added automatically after the FR
// is accepted, via the profileSharing flag // is accepted, via the profileSharing flag
@ -1682,9 +1658,6 @@
direction: 'outgoing', direction: 'outgoing',
friendStatus: 'pending', friendStatus: 'pending',
}); });
console.log(`[vince][core] Sending FR message from conversations.js`, messageWithSchema);
} }
if (this.isPrivate()) { if (this.isPrivate()) {
@ -2490,7 +2463,6 @@
}, },
// LOKI PROFILES // LOKI PROFILES
async setNickname(nickname) { async setNickname(nickname) {
const trimmed = nickname && nickname.trim(); const trimmed = nickname && nickname.trim();
if (this.get('nickname') === trimmed) { if (this.get('nickname') === trimmed) {

@ -415,14 +415,17 @@
}, },
async acceptFriendRequest() { async acceptFriendRequest() {
const primaryDevicePubKey = this.attributes.conversationId;
if (this.get('friendStatus') !== 'pending') { if (this.get('friendStatus') !== 'pending') {
return; return;
} }
const allDevices = await libloki.storage.getAllDevicePubKeysForPrimaryPubKey( const allDevices = await libloki.storage.getAllDevicePubKeysForPrimaryPubKey(
this.attributes.conversationId primaryDevicePubKey
); );
let profileName;
const allConversationsWithUser = allDevices.map(d => ConversationController.get(d)); const allConversationsWithUser = allDevices.map(d => ConversationController.get(d));
allConversationsWithUser.forEach(conversation => { allConversationsWithUser.forEach(conversation => {
// If we somehow received an old friend request (e.g. after having restored // If we somehow received an old friend request (e.g. after having restored
@ -435,8 +438,16 @@
return; return;
} }
profileName = conversation.getProfileName() || profileName;
conversation.onAcceptFriendRequest(); conversation.onAcceptFriendRequest();
}); });
// If you don't have a profile name for this device, and profileName is set,
// add profileName to conversation.
const primaryConversation = allConversationsWithUser.find(c => c.id === primaryDevicePubKey)
if (!primaryConversation.getProfileName() && profileName) {
await primaryConversation.setNickname(profileName);
}
await window.Signal.Data.saveMessage(this.attributes, { await window.Signal.Data.saveMessage(this.attributes, {
Message: Whisper.Message, Message: Whisper.Message,

@ -180,6 +180,8 @@ export const _getLeftPaneLists = (
return filteredGroup as T; return filteredGroup as T;
}; };
const friends: Array<ConversationType> = filterToPrimary(allFriends); const friends: Array<ConversationType> = filterToPrimary(allFriends);
const receivedFriendsRequest: Array< const receivedFriendsRequest: Array<
ConversationListItemPropsType ConversationListItemPropsType
@ -188,6 +190,17 @@ export const _getLeftPaneLists = (
ConversationListItemPropsType ConversationListItemPropsType
> = filterToPrimary(allSentFriendsRequest); > = filterToPrimary(allSentFriendsRequest);
console.log('[vince][friends] allReceivedFriendsRequest:', allReceivedFriendsRequest);
console.log('[vince][friends] receivedFriendsRequest:', receivedFriendsRequest);
console.log('[vince][friends] allSentFriendsRequest:', allSentFriendsRequest);
console.log('[vince][friends] sentFriendsRequest:', sentFriendsRequest);
console.log('[vince][friends] allFriends:', allFriends);
console.log('[vince][friends] friends:', friends);
return { return {
conversations, conversations,
archivedConversations, archivedConversations,

Loading…
Cancel
Save