Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load chat username/icon from current session, not persisted data #180981

Merged
merged 1 commit into from Apr 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -54,10 +54,17 @@ export class InteractiveRequestModel implements IInteractiveRequestModel {
return this._id;
}

public get username(): string {
return this._session.requesterUsername;
}

public get avatarIconUri(): URI | undefined {
return this._session.requesterAvatarIconUri;
}

constructor(
public readonly message: string | IInteractiveSessionReplyFollowup,
public readonly username: string,
public readonly avatarIconUri?: URI) {
private readonly _session: InteractiveSessionModel,
public readonly message: string | IInteractiveSessionReplyFollowup) {
this._id = 'request_' + InteractiveRequestModel.nextId++;
}
}
Expand Down Expand Up @@ -105,11 +112,17 @@ export class InteractiveResponseModel extends Disposable implements IInteractive
return this._session.providerId;
}

public get username(): string {
return this._session.responderUsername;
}

public get avatarIconUri(): URI | undefined {
return this._session.responderAvatarIconUri;
}

constructor(
private _response: IMarkdownString,
private readonly _session: InteractiveSessionModel,
public readonly username: string,
public readonly avatarIconUri?: URI,
private _isComplete: boolean = false,
private _isCanceled = false,
private _vote?: InteractiveSessionVoteDirection,
Expand Down Expand Up @@ -193,7 +206,7 @@ export interface ISerializableInteractiveSessionData {
providerState: any;
}

export type IInteractiveSessionChangeEvent = IInteractiveSessionAddRequestEvent | IInteractiveSessionAddResponseEvent | IInteractiveSessionClearEvent;
export type IInteractiveSessionChangeEvent = IInteractiveSessionAddRequestEvent | IInteractiveSessionAddResponseEvent | IInteractiveSessionInitEvent;

export interface IInteractiveSessionAddRequestEvent {
kind: 'addRequest';
Expand All @@ -205,8 +218,8 @@ export interface IInteractiveSessionAddResponseEvent {
response: IInteractiveResponseModel;
}

export interface IInteractiveSessionClearEvent {
kind: 'clear';
export interface IInteractiveSessionInitEvent {
kind: 'initialize';
}

export class InteractiveSessionModel extends Disposable implements IInteractiveSessionModel {
Expand Down Expand Up @@ -255,16 +268,37 @@ export class InteractiveSessionModel extends Disposable implements IInteractiveS
return this._creationDate;
}

get requesterUsername(): string {
return this._session?.requesterUsername ?? this.initialData?.requesterUsername ?? '';
}

get responderUsername(): string {
return this._session?.responderUsername ?? this.initialData?.responderUsername ?? '';
}

private readonly _initialRequesterAvatarIconUri: URI | undefined;
get requesterAvatarIconUri(): URI | undefined {
return this._session?.requesterAvatarIconUri ?? this._initialRequesterAvatarIconUri;
}

private readonly _initialResponderAvatarIconUri: URI | undefined;
get responderAvatarIconUri(): URI | undefined {
return this._session?.responderAvatarIconUri ?? this._initialResponderAvatarIconUri;
}

constructor(
public readonly providerId: string,
initialData: ISerializableInteractiveSessionData | undefined,
private readonly initialData: ISerializableInteractiveSessionData | undefined,
@ILogService private readonly logService: ILogService
) {
super();
this._sessionId = initialData ? initialData.sessionId : generateUuid();
this._requests = initialData ? this._deserialize(initialData) : [];
this._providerState = initialData ? initialData.providerState : undefined;
this._creationDate = initialData?.creationDate ?? Date.now();

this._initialRequesterAvatarIconUri = initialData?.requesterAvatarIconUri && URI.revive(initialData.requesterAvatarIconUri);
this._initialResponderAvatarIconUri = initialData?.responderAvatarIconUri && URI.revive(initialData.responderAvatarIconUri);
}

private _deserialize(obj: ISerializableInteractiveSessionData): InteractiveRequestModel[] {
Expand All @@ -280,9 +314,9 @@ export class InteractiveSessionModel extends Disposable implements IInteractiveS
}

return requests.map((raw: ISerializableInteractiveSessionRequestData) => {
const request = new InteractiveRequestModel(raw.message, obj.requesterUsername, obj.requesterAvatarIconUri && URI.revive(obj.requesterAvatarIconUri));
const request = new InteractiveRequestModel(this, raw.message);
if (raw.response || raw.responseErrorDetails) {
request.response = new InteractiveResponseModel(new MarkdownString(raw.response), this, obj.responderUsername, obj.responderAvatarIconUri && URI.revive(obj.responderAvatarIconUri), true, raw.isCanceled, raw.vote, raw.providerResponseId, raw.responseErrorDetails, raw.followups);
request.response = new InteractiveResponseModel(new MarkdownString(raw.response), this, true, raw.isCanceled, raw.vote, raw.providerResponseId, raw.responseErrorDetails, raw.followups);
}
return request;
});
Expand All @@ -307,18 +341,13 @@ export class InteractiveSessionModel extends Disposable implements IInteractiveS
this.logService.trace('InteractiveSessionModel#acceptNewSessionState');
}));
}
this._onDidChange.fire({ kind: 'initialize' });
}

waitForInitialization(): Promise<void> {
return this._isInitializedDeferred.p;
}

clear(): void {
this._requests.forEach(r => r.response?.dispose());
this._requests = [];
this._onDidChange.fire({ kind: 'clear' });
}

getRequests(): InteractiveRequestModel[] {
return this._requests;
}
Expand All @@ -328,8 +357,8 @@ export class InteractiveSessionModel extends Disposable implements IInteractiveS
throw new Error('addRequest: No session');
}

const request = new InteractiveRequestModel(message, this._session.requesterUsername, this._session.requesterAvatarIconUri);
request.response = new InteractiveResponseModel(new MarkdownString(''), this, this._session.responderUsername, this._session.responderAvatarIconUri);
const request = new InteractiveRequestModel(this, message);
request.response = new InteractiveResponseModel(new MarkdownString(''), this);

this._requests.push(request);
this._onDidChange.fire({ kind: 'addRequest', request });
Expand All @@ -342,7 +371,7 @@ export class InteractiveSessionModel extends Disposable implements IInteractiveS
}

if (!request.response) {
request.response = new InteractiveResponseModel(new MarkdownString(''), this, this._session.responderUsername, this._session.responderAvatarIconUri);
request.response = new InteractiveResponseModel(new MarkdownString(''), this);
}

if (request.response.isComplete) {
Expand All @@ -368,7 +397,7 @@ export class InteractiveSessionModel extends Disposable implements IInteractiveS
}

if (!request.response) {
request.response = new InteractiveResponseModel(new MarkdownString(''), this, this._session.responderUsername, this._session.responderAvatarIconUri);
request.response = new InteractiveResponseModel(new MarkdownString(''), this);
}

request.response.complete(rawResponse.errorDetails);
Expand Down
Expand Up @@ -119,10 +119,7 @@ export class InteractiveSessionViewModel extends Disposable implements IInteract

this._register(_model.onDidDispose(() => this._onDidDisposeModel.fire()));
this._register(_model.onDidChange(e => {
if (e.kind === 'clear') {
this._items.length = 0;
this._onDidChange.fire();
} else if (e.kind === 'addRequest') {
if (e.kind === 'addRequest') {
this._items.push(new InteractiveRequestViewModel(e.request));
if (e.request.response) {
this.onAddResponse(e.request.response);
Expand Down