fix: include profile in message request response
This commit is contained in:
parent
f6c6fe01a4
commit
84f2ce777a
|
@ -37,7 +37,9 @@ message Unsend {
|
||||||
|
|
||||||
message MessageRequestResponse {
|
message MessageRequestResponse {
|
||||||
// @required
|
// @required
|
||||||
required bool isApproved = 1;
|
required bool isApproved = 1;
|
||||||
|
optional bytes profileKey = 2;
|
||||||
|
optional DataMessage.LokiProfile profile = 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
message Content {
|
message Content {
|
||||||
|
|
|
@ -908,7 +908,7 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
|
||||||
|
|
||||||
const messageRequestResponseParams: MessageRequestResponseParams = {
|
const messageRequestResponseParams: MessageRequestResponseParams = {
|
||||||
timestamp,
|
timestamp,
|
||||||
// lokiProfile: UserUtils.getOurProfile(), // we can't curently include our profile in that response
|
lokiProfile: UserUtils.getOurProfile(),
|
||||||
};
|
};
|
||||||
|
|
||||||
const messageRequestResponse = new MessageRequestResponse(messageRequestResponseParams);
|
const messageRequestResponse = new MessageRequestResponse(messageRequestResponseParams);
|
||||||
|
|
|
@ -27,6 +27,7 @@ import {
|
||||||
} from '../interactions/conversations/unsendingInteractions';
|
} from '../interactions/conversations/unsendingInteractions';
|
||||||
import { ConversationTypeEnum } from '../models/conversationAttributes';
|
import { ConversationTypeEnum } from '../models/conversationAttributes';
|
||||||
import { findCachedBlindedMatchOrLookupOnAllServers } from '../session/apis/open_group_api/sogsv3/knownBlindedkeys';
|
import { findCachedBlindedMatchOrLookupOnAllServers } from '../session/apis/open_group_api/sogsv3/knownBlindedkeys';
|
||||||
|
import { appendFetchAvatarAndProfileJob } from './userProfileImageUpdates';
|
||||||
|
|
||||||
export async function handleSwarmContentMessage(envelope: EnvelopePlus, messageHash: string) {
|
export async function handleSwarmContentMessage(envelope: EnvelopePlus, messageHash: string) {
|
||||||
try {
|
try {
|
||||||
|
@ -604,6 +605,11 @@ async function handleMessageRequestResponse(
|
||||||
messageRequestResponse: SignalService.MessageRequestResponse
|
messageRequestResponse: SignalService.MessageRequestResponse
|
||||||
) {
|
) {
|
||||||
const { isApproved } = messageRequestResponse;
|
const { isApproved } = messageRequestResponse;
|
||||||
|
if (!isApproved) {
|
||||||
|
window?.log?.error('handleMessageRequestResponse: isApproved is false -- dropping message.');
|
||||||
|
await removeFromCache(envelope);
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (!messageRequestResponse) {
|
if (!messageRequestResponse) {
|
||||||
window?.log?.error('handleMessageRequestResponse: Invalid parameters -- dropping message.');
|
window?.log?.error('handleMessageRequestResponse: Invalid parameters -- dropping message.');
|
||||||
await removeFromCache(envelope);
|
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 || conversationToApprove.didApproveMe() === isApproved) {
|
||||||
if (conversationToApprove) {
|
if (conversationToApprove) {
|
||||||
await conversationToApprove.commit();
|
await conversationToApprove.commit();
|
||||||
|
|
|
@ -1,18 +1,47 @@
|
||||||
|
import ByteBuffer from 'bytebuffer';
|
||||||
|
import { isEmpty } from 'lodash';
|
||||||
import { SignalService } from '../../../../protobuf';
|
import { SignalService } from '../../../../protobuf';
|
||||||
|
import { LokiProfile } from '../../../../types/Message';
|
||||||
import { ContentMessage } from '../ContentMessage';
|
import { ContentMessage } from '../ContentMessage';
|
||||||
import { MessageParams } from '../Message';
|
import { MessageParams } from '../Message';
|
||||||
|
|
||||||
// tslint:disable-next-line: no-empty-interface
|
// tslint:disable-next-line: no-empty-interface
|
||||||
export interface MessageRequestResponseParams extends MessageParams {}
|
export interface MessageRequestResponseParams extends MessageParams {
|
||||||
|
lokiProfile?: LokiProfile;
|
||||||
|
}
|
||||||
|
|
||||||
export class MessageRequestResponse extends ContentMessage {
|
export class MessageRequestResponse extends ContentMessage {
|
||||||
// we actually send a response only if it is an accept
|
// we actually send a response only if it is an accept
|
||||||
// private readonly isApproved: boolean;
|
// private readonly isApproved: boolean;
|
||||||
|
private readonly profileKey?: Uint8Array;
|
||||||
|
private readonly displayName?: string;
|
||||||
|
private readonly avatarPointer?: string;
|
||||||
|
|
||||||
constructor(params: MessageRequestResponseParams) {
|
constructor(params: MessageRequestResponseParams) {
|
||||||
super({
|
super({
|
||||||
timestamp: params.timestamp,
|
timestamp: params.timestamp,
|
||||||
} as MessageRequestResponseParams);
|
} 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 {
|
public contentProto(): SignalService.Content {
|
||||||
|
@ -22,8 +51,27 @@ export class MessageRequestResponse extends ContentMessage {
|
||||||
}
|
}
|
||||||
|
|
||||||
public messageRequestResponseProto(): SignalService.MessageRequestResponse {
|
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({
|
return new SignalService.MessageRequestResponse({
|
||||||
isApproved: true,
|
isApproved: true,
|
||||||
|
profileKey,
|
||||||
|
profile,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import ByteBuffer from 'bytebuffer';
|
import ByteBuffer from 'bytebuffer';
|
||||||
|
import { isEmpty } from 'lodash';
|
||||||
import { DataMessage } from '..';
|
import { DataMessage } from '..';
|
||||||
import { SignalService } from '../../../../protobuf';
|
import { SignalService } from '../../../../protobuf';
|
||||||
import { LokiProfile } from '../../../../types/Message';
|
import { LokiProfile } from '../../../../types/Message';
|
||||||
|
@ -108,7 +109,12 @@ export class VisibleMessage extends DataMessage {
|
||||||
}
|
}
|
||||||
|
|
||||||
this.displayName = params.lokiProfile && params.lokiProfile.displayName;
|
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.preview = params.preview;
|
||||||
this.reaction = params.reaction;
|
this.reaction = params.reaction;
|
||||||
this.syncTarget = params.syncTarget;
|
this.syncTarget = params.syncTarget;
|
||||||
|
@ -149,6 +155,7 @@ export class VisibleMessage extends DataMessage {
|
||||||
}
|
}
|
||||||
dataMessage.profile = profile;
|
dataMessage.profile = profile;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.profileKey && this.profileKey.length) {
|
if (this.profileKey && this.profileKey.length) {
|
||||||
dataMessage.profileKey = this.profileKey;
|
dataMessage.profileKey = this.profileKey;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue