mirror of
https://github.com/oxen-io/session-desktop.git
synced 2023-12-14 02:12:57 +01:00
fix: include profile in message request response
This commit is contained in:
parent
f6c6fe01a4
commit
84f2ce777a
5 changed files with 75 additions and 4 deletions
|
@ -37,7 +37,9 @@ message Unsend {
|
|||
|
||||
message MessageRequestResponse {
|
||||
// @required
|
||||
required bool isApproved = 1;
|
||||
required bool isApproved = 1;
|
||||
optional bytes profileKey = 2;
|
||||
optional DataMessage.LokiProfile profile = 3;
|
||||
}
|
||||
|
||||
message Content {
|
||||
|
|
|
@ -908,7 +908,7 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
|
|||
|
||||
const messageRequestResponseParams: MessageRequestResponseParams = {
|
||||
timestamp,
|
||||
// lokiProfile: UserUtils.getOurProfile(), // we can't curently include our profile in that response
|
||||
lokiProfile: UserUtils.getOurProfile(),
|
||||
};
|
||||
|
||||
const messageRequestResponse = new MessageRequestResponse(messageRequestResponseParams);
|
||||
|
|
|
@ -27,6 +27,7 @@ import {
|
|||
} from '../interactions/conversations/unsendingInteractions';
|
||||
import { ConversationTypeEnum } from '../models/conversationAttributes';
|
||||
import { findCachedBlindedMatchOrLookupOnAllServers } from '../session/apis/open_group_api/sogsv3/knownBlindedkeys';
|
||||
import { appendFetchAvatarAndProfileJob } from './userProfileImageUpdates';
|
||||
|
||||
export async function handleSwarmContentMessage(envelope: EnvelopePlus, messageHash: string) {
|
||||
try {
|
||||
|
@ -604,6 +605,11 @@ async function handleMessageRequestResponse(
|
|||
messageRequestResponse: SignalService.MessageRequestResponse
|
||||
) {
|
||||
const { isApproved } = messageRequestResponse;
|
||||
if (!isApproved) {
|
||||
window?.log?.error('handleMessageRequestResponse: isApproved is false -- dropping message.');
|
||||
await removeFromCache(envelope);
|
||||
return;
|
||||
}
|
||||
if (!messageRequestResponse) {
|
||||
window?.log?.error('handleMessageRequestResponse: Invalid parameters -- dropping message.');
|
||||
await removeFromCache(envelope);
|
||||
|
@ -674,6 +680,14 @@ async function handleMessageRequestResponse(
|
|||
}
|
||||
}
|
||||
|
||||
if (messageRequestResponse.profile && !isEmpty(messageRequestResponse.profile)) {
|
||||
void appendFetchAvatarAndProfileJob(
|
||||
conversationToApprove,
|
||||
messageRequestResponse.profile,
|
||||
messageRequestResponse.profileKey
|
||||
);
|
||||
}
|
||||
|
||||
if (!conversationToApprove || conversationToApprove.didApproveMe() === isApproved) {
|
||||
if (conversationToApprove) {
|
||||
await conversationToApprove.commit();
|
||||
|
|
|
@ -1,18 +1,47 @@
|
|||
import ByteBuffer from 'bytebuffer';
|
||||
import { isEmpty } from 'lodash';
|
||||
import { SignalService } from '../../../../protobuf';
|
||||
import { LokiProfile } from '../../../../types/Message';
|
||||
import { ContentMessage } from '../ContentMessage';
|
||||
import { MessageParams } from '../Message';
|
||||
|
||||
// tslint:disable-next-line: no-empty-interface
|
||||
export interface MessageRequestResponseParams extends MessageParams {}
|
||||
export interface MessageRequestResponseParams extends MessageParams {
|
||||
lokiProfile?: LokiProfile;
|
||||
}
|
||||
|
||||
export class MessageRequestResponse extends ContentMessage {
|
||||
// we actually send a response only if it is an accept
|
||||
// private readonly isApproved: boolean;
|
||||
private readonly profileKey?: Uint8Array;
|
||||
private readonly displayName?: string;
|
||||
private readonly avatarPointer?: string;
|
||||
|
||||
constructor(params: MessageRequestResponseParams) {
|
||||
super({
|
||||
timestamp: params.timestamp,
|
||||
} as MessageRequestResponseParams);
|
||||
|
||||
if (params.lokiProfile && params.lokiProfile.profileKey) {
|
||||
if (
|
||||
params.lokiProfile.profileKey instanceof Uint8Array ||
|
||||
(params.lokiProfile.profileKey as any) instanceof ByteBuffer
|
||||
) {
|
||||
this.profileKey = new Uint8Array(params.lokiProfile.profileKey);
|
||||
} else {
|
||||
this.profileKey = new Uint8Array(
|
||||
ByteBuffer.wrap(params.lokiProfile.profileKey).toArrayBuffer()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
this.displayName = params.lokiProfile && params.lokiProfile.displayName;
|
||||
|
||||
// no need to iclude the avatarPointer if there is no profileKey associated with it.
|
||||
this.avatarPointer =
|
||||
params.lokiProfile?.avatarPointer && !isEmpty(this.profileKey)
|
||||
? params.lokiProfile.avatarPointer
|
||||
: undefined;
|
||||
}
|
||||
|
||||
public contentProto(): SignalService.Content {
|
||||
|
@ -22,8 +51,27 @@ export class MessageRequestResponse extends ContentMessage {
|
|||
}
|
||||
|
||||
public messageRequestResponseProto(): SignalService.MessageRequestResponse {
|
||||
let profileKey: Uint8Array | undefined;
|
||||
let profile: SignalService.DataMessage.LokiProfile | undefined;
|
||||
if (this.avatarPointer || this.displayName) {
|
||||
profile = new SignalService.DataMessage.LokiProfile();
|
||||
|
||||
if (this.avatarPointer) {
|
||||
profile.profilePicture = this.avatarPointer;
|
||||
}
|
||||
|
||||
if (this.displayName) {
|
||||
profile.displayName = this.displayName;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.profileKey && this.profileKey.length) {
|
||||
profileKey = this.profileKey;
|
||||
}
|
||||
return new SignalService.MessageRequestResponse({
|
||||
isApproved: true,
|
||||
profileKey,
|
||||
profile,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import ByteBuffer from 'bytebuffer';
|
||||
import { isEmpty } from 'lodash';
|
||||
import { DataMessage } from '..';
|
||||
import { SignalService } from '../../../../protobuf';
|
||||
import { LokiProfile } from '../../../../types/Message';
|
||||
|
@ -108,7 +109,12 @@ export class VisibleMessage extends DataMessage {
|
|||
}
|
||||
|
||||
this.displayName = params.lokiProfile && params.lokiProfile.displayName;
|
||||
this.avatarPointer = params.lokiProfile && params.lokiProfile.avatarPointer;
|
||||
// no need to iclude the avatarPointer if there is no profileKey associated with it.
|
||||
this.avatarPointer =
|
||||
params.lokiProfile?.avatarPointer && !isEmpty(this.profileKey)
|
||||
? params.lokiProfile.avatarPointer
|
||||
: undefined;
|
||||
|
||||
this.preview = params.preview;
|
||||
this.reaction = params.reaction;
|
||||
this.syncTarget = params.syncTarget;
|
||||
|
@ -149,6 +155,7 @@ export class VisibleMessage extends DataMessage {
|
|||
}
|
||||
dataMessage.profile = profile;
|
||||
}
|
||||
|
||||
if (this.profileKey && this.profileKey.length) {
|
||||
dataMessage.profileKey = this.profileKey;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue