Skip to content

Commit 84f2ce7

Browse files
committed
fix: include profile in message request response
1 parent f6c6fe0 commit 84f2ce7

File tree

5 files changed

+75
-4
lines changed

5 files changed

+75
-4
lines changed

protos/SignalService.proto

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ message Unsend {
3737

3838
message MessageRequestResponse {
3939
// @required
40-
required bool isApproved = 1;
40+
required bool isApproved = 1;
41+
optional bytes profileKey = 2;
42+
optional DataMessage.LokiProfile profile = 3;
4143
}
4244

4345
message Content {

ts/models/conversation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -908,7 +908,7 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
908908

909909
const messageRequestResponseParams: MessageRequestResponseParams = {
910910
timestamp,
911-
// lokiProfile: UserUtils.getOurProfile(), // we can't curently include our profile in that response
911+
lokiProfile: UserUtils.getOurProfile(),
912912
};
913913

914914
const messageRequestResponse = new MessageRequestResponse(messageRequestResponseParams);

ts/receiver/contentMessage.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import {
2727
} from '../interactions/conversations/unsendingInteractions';
2828
import { ConversationTypeEnum } from '../models/conversationAttributes';
2929
import { findCachedBlindedMatchOrLookupOnAllServers } from '../session/apis/open_group_api/sogsv3/knownBlindedkeys';
30+
import { appendFetchAvatarAndProfileJob } from './userProfileImageUpdates';
3031

3132
export async function handleSwarmContentMessage(envelope: EnvelopePlus, messageHash: string) {
3233
try {
@@ -604,6 +605,11 @@ async function handleMessageRequestResponse(
604605
messageRequestResponse: SignalService.MessageRequestResponse
605606
) {
606607
const { isApproved } = messageRequestResponse;
608+
if (!isApproved) {
609+
window?.log?.error('handleMessageRequestResponse: isApproved is false -- dropping message.');
610+
await removeFromCache(envelope);
611+
return;
612+
}
607613
if (!messageRequestResponse) {
608614
window?.log?.error('handleMessageRequestResponse: Invalid parameters -- dropping message.');
609615
await removeFromCache(envelope);
@@ -674,6 +680,14 @@ async function handleMessageRequestResponse(
674680
}
675681
}
676682

683+
if (messageRequestResponse.profile && !isEmpty(messageRequestResponse.profile)) {
684+
void appendFetchAvatarAndProfileJob(
685+
conversationToApprove,
686+
messageRequestResponse.profile,
687+
messageRequestResponse.profileKey
688+
);
689+
}
690+
677691
if (!conversationToApprove || conversationToApprove.didApproveMe() === isApproved) {
678692
if (conversationToApprove) {
679693
await conversationToApprove.commit();

ts/session/messages/outgoing/controlMessage/MessageRequestResponse.ts

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,47 @@
1+
import ByteBuffer from 'bytebuffer';
2+
import { isEmpty } from 'lodash';
13
import { SignalService } from '../../../../protobuf';
4+
import { LokiProfile } from '../../../../types/Message';
25
import { ContentMessage } from '../ContentMessage';
36
import { MessageParams } from '../Message';
47

58
// tslint:disable-next-line: no-empty-interface
6-
export interface MessageRequestResponseParams extends MessageParams {}
9+
export interface MessageRequestResponseParams extends MessageParams {
10+
lokiProfile?: LokiProfile;
11+
}
712

813
export class MessageRequestResponse extends ContentMessage {
914
// we actually send a response only if it is an accept
1015
// private readonly isApproved: boolean;
16+
private readonly profileKey?: Uint8Array;
17+
private readonly displayName?: string;
18+
private readonly avatarPointer?: string;
1119

1220
constructor(params: MessageRequestResponseParams) {
1321
super({
1422
timestamp: params.timestamp,
1523
} as MessageRequestResponseParams);
24+
25+
if (params.lokiProfile && params.lokiProfile.profileKey) {
26+
if (
27+
params.lokiProfile.profileKey instanceof Uint8Array ||
28+
(params.lokiProfile.profileKey as any) instanceof ByteBuffer
29+
) {
30+
this.profileKey = new Uint8Array(params.lokiProfile.profileKey);
31+
} else {
32+
this.profileKey = new Uint8Array(
33+
ByteBuffer.wrap(params.lokiProfile.profileKey).toArrayBuffer()
34+
);
35+
}
36+
}
37+
38+
this.displayName = params.lokiProfile && params.lokiProfile.displayName;
39+
40+
// no need to iclude the avatarPointer if there is no profileKey associated with it.
41+
this.avatarPointer =
42+
params.lokiProfile?.avatarPointer && !isEmpty(this.profileKey)
43+
? params.lokiProfile.avatarPointer
44+
: undefined;
1645
}
1746

1847
public contentProto(): SignalService.Content {
@@ -22,8 +51,27 @@ export class MessageRequestResponse extends ContentMessage {
2251
}
2352

2453
public messageRequestResponseProto(): SignalService.MessageRequestResponse {
54+
let profileKey: Uint8Array | undefined;
55+
let profile: SignalService.DataMessage.LokiProfile | undefined;
56+
if (this.avatarPointer || this.displayName) {
57+
profile = new SignalService.DataMessage.LokiProfile();
58+
59+
if (this.avatarPointer) {
60+
profile.profilePicture = this.avatarPointer;
61+
}
62+
63+
if (this.displayName) {
64+
profile.displayName = this.displayName;
65+
}
66+
}
67+
68+
if (this.profileKey && this.profileKey.length) {
69+
profileKey = this.profileKey;
70+
}
2571
return new SignalService.MessageRequestResponse({
2672
isApproved: true,
73+
profileKey,
74+
profile,
2775
});
2876
}
2977
}

ts/session/messages/outgoing/visibleMessage/VisibleMessage.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import ByteBuffer from 'bytebuffer';
2+
import { isEmpty } from 'lodash';
23
import { DataMessage } from '..';
34
import { SignalService } from '../../../../protobuf';
45
import { LokiProfile } from '../../../../types/Message';
@@ -108,7 +109,12 @@ export class VisibleMessage extends DataMessage {
108109
}
109110

110111
this.displayName = params.lokiProfile && params.lokiProfile.displayName;
111-
this.avatarPointer = params.lokiProfile && params.lokiProfile.avatarPointer;
112+
// no need to iclude the avatarPointer if there is no profileKey associated with it.
113+
this.avatarPointer =
114+
params.lokiProfile?.avatarPointer && !isEmpty(this.profileKey)
115+
? params.lokiProfile.avatarPointer
116+
: undefined;
117+
112118
this.preview = params.preview;
113119
this.reaction = params.reaction;
114120
this.syncTarget = params.syncTarget;
@@ -149,6 +155,7 @@ export class VisibleMessage extends DataMessage {
149155
}
150156
dataMessage.profile = profile;
151157
}
158+
152159
if (this.profileKey && this.profileKey.length) {
153160
dataMessage.profileKey = this.profileKey;
154161
}

0 commit comments

Comments
 (0)