handle clearing profileName correctly, support multidevice profiles better, use getLokiProfile()

pull/827/head
Ryan Tharp 5 years ago
parent 192fb3e382
commit 60259ab0bb

@ -109,17 +109,27 @@ class LokiAppDotNetServerAPI {
JSON.stringify(objToSign) JSON.stringify(objToSign)
); );
*/ */
let pName = profileName;
// You cannot use null to clear the profile name
// the name key has to be set to know what value we want changed
if (pName === undefined || pName === null) {
pName = '';
}
const res = await this.serverRequest('users/me', { const res = await this.serverRequest('users/me', {
method: 'PATCH', method: 'PATCH',
objBody: { objBody: {
name: profileName, name: pName,
}, },
}); });
// no big deal if it fails... // no big deal if it fails...
if (res.err || !res.response || !res.response.data) { if (res.err || !res.response || !res.response.data) {
if (res.err) { if (res.err) {
log.error(`setProfileName Error ${res.err}`); log.error(
`setProfileName Error ${res.err} ${res.statusCode}`,
this.baseServerUrl
);
} }
return []; return [];
} }
@ -204,10 +214,12 @@ class LokiAppDotNetServerAPI {
tokenRes.response.data.user tokenRes.response.data.user
) { ) {
// get our profile name // get our profile name
// FIXME: should this be window.storage.get('primaryDevicePubKey')? // this should be primaryDevicePubKey
const ourNumber = textsecure.storage.user.getNumber(); // because the rest of the profile system uses that...
const ourNumber = window.storage.get('primaryDevicePubKey');
const profileConvo = ConversationController.get(ourNumber); const profileConvo = ConversationController.get(ourNumber);
const profileName = profileConvo.getProfileName(); const profile = profileConvo.getLokiProfile();
const profileName = profile && profile.displayName;
// if doesn't match, write it to the network // if doesn't match, write it to the network
if (tokenRes.response.data.user.name !== profileName) { if (tokenRes.response.data.user.name !== profileName) {
// update our profile name if it got out of sync // update our profile name if it got out of sync
@ -468,7 +480,10 @@ class LokiAppDotNetServerAPI {
try { try {
response = JSON.parse(txtResponse); response = JSON.parse(txtResponse);
} catch (e) { } catch (e) {
log.warn(`_sendToProxy Could not parse outer JSON [${txtResponse}]`); log.warn(
`_sendToProxy Could not parse outer JSON [${txtResponse}]`,
endpoint
);
} }
if (response.meta && response.meta.code === 200) { if (response.meta && response.meta.code === 200) {
@ -487,13 +502,17 @@ class LokiAppDotNetServerAPI {
try { try {
response = options.textResponse ? respStr : JSON.parse(respStr); response = options.textResponse ? respStr : JSON.parse(respStr);
} catch (e) { } catch (e) {
log.warn(`_sendToProxy Could not parse inner JSON [${respStr}]`, endpoint); log.warn(
`_sendToProxy Could not parse inner JSON [${respStr}]`,
endpoint
);
} }
} else { } else {
log.warn( log.warn(
'file server secure_rpc gave an non-200 response: ', 'file server secure_rpc gave an non-200 response: ',
response, response,
` txtResponse[${txtResponse}]` ` txtResponse[${txtResponse}]`,
endpoint
); );
} }
return { result, txtResponse, response }; return { result, txtResponse, response };
@ -1000,15 +1019,17 @@ class LokiPublicChannelAPI {
const res = await this.serverRequest( const res = await this.serverRequest(
`loki/v1/channels/${this.channelId}/moderators` `loki/v1/channels/${this.channelId}/moderators`
); );
// FIXME: should this be window.storage.get('primaryDevicePubKey')? const ourNumberDevice = textsecure.storage.user.getNumber();
const ourNumber = textsecure.storage.user.getNumber(); const ourNumberProfile = window.storage.get('primaryDevicePubKey');
// Get the list of moderators if no errors occurred // Get the list of moderators if no errors occurred
const moderators = !res.err && res.response && res.response.moderators; const moderators = !res.err && res.response && res.response.moderators;
// if we encountered problems then we'll keep the old mod status // if we encountered problems then we'll keep the old mod status
if (moderators) { if (moderators) {
this.modStatus = moderators.includes(ourNumber); this.modStatus =
moderators.includes(ourNumberProfile) ||
moderators.includes(ourNumberDevice);
} }
await this.conversation.setModerators(moderators || []); await this.conversation.setModerators(moderators || []);
@ -1411,8 +1432,8 @@ class LokiPublicChannelAPI {
let pendingMessages = []; let pendingMessages = [];
// get our profile name // get our profile name
// FIXME: should this be window.storage.get('primaryDevicePubKey')? const ourNumberProfile = window.storage.get('primaryDevicePubKey');
const ourNumber = textsecure.storage.user.getNumber(); const ourNumberDevice = textsecure.storage.user.getNumber();
let lastProfileName = false; let lastProfileName = false;
// the signature forces this to be async // the signature forces this to be async
@ -1485,7 +1506,7 @@ class LokiPublicChannelAPI {
const from = adnMessage.user.name || 'Anonymous'; // profileName const from = adnMessage.user.name || 'Anonymous'; // profileName
// if us // if us
if (pubKey === ourNumber) { if (pubKey === ourNumberProfile || pubKey === ourNumberDevice) {
// update the last name we saw from ourself // update the last name we saw from ourself
lastProfileName = from; lastProfileName = from;
} }
@ -1635,7 +1656,7 @@ class LokiPublicChannelAPI {
const slaveKey = messageData.source; const slaveKey = messageData.source;
// prevent our own device sent messages from coming back in // prevent our own device sent messages from coming back in
if (slaveKey === ourNumber) { if (slaveKey === ourNumberDevice) {
// we originally sent these // we originally sent these
return; return;
} }
@ -1666,7 +1687,7 @@ class LokiPublicChannelAPI {
// if we received one of our own messages // if we received one of our own messages
if (lastProfileName !== false) { if (lastProfileName !== false) {
// get current profileName // get current profileName
const profileConvo = ConversationController.get(ourNumber); const profileConvo = ConversationController.get(ourNumberProfile);
const profileName = profileConvo.getProfileName(); const profileName = profileConvo.getProfileName();
// check to see if it out of sync // check to see if it out of sync
if (profileName !== lastProfileName) { if (profileName !== lastProfileName) {

Loading…
Cancel
Save