Skip to content

Commit

Permalink
Merge pull request #440 from 0xPolygonID/chore/credential-proposal-in…
Browse files Browse the repository at this point in the history
…teraction

added credential proposal to interaction
  • Loading branch information
Emanuel Muroni authored Sep 18, 2024
2 parents c2553c8 + dec04cf commit f632b15
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ enum InteractionType {
revocation,
update,
authRequest,
credentialProposal,
}

enum InteractionState {
Expand All @@ -19,6 +20,7 @@ class InteractionBaseEntity {
final InteractionState state;
final int timestamp;
final String message;
final String? to;

InteractionBaseEntity({
required this.id,
Expand All @@ -27,12 +29,14 @@ class InteractionBaseEntity {
this.state = InteractionState.received,
required this.timestamp,
required this.message,
required this.to,
});

factory InteractionBaseEntity.fromJson(Map<String, dynamic> json) {
return InteractionBaseEntity(
id: json['id'],
from: json['from'],
to: json['to'],
type: InteractionType.values.firstWhere((type) =>
type.name == json['type'] || type.toString() == json['type']),
state: InteractionState.values.firstWhere((type) =>
Expand All @@ -49,11 +53,12 @@ class InteractionBaseEntity {
'state': state.toString(),
'timestamp': timestamp,
'message': message,
'to': to,
};

@override
String toString() =>
"[InteractionBaseEntity] {id: $id, from: $from, type: $type, state: $state, timestamp: $timestamp, message: $message}";
"[InteractionBaseEntity] {id: $id, from: $from, type: $type, state: $state, timestamp: $timestamp, message: $message, to: $to}";

@override
bool operator ==(Object other) =>
Expand All @@ -65,7 +70,8 @@ class InteractionBaseEntity {
type == other.type &&
state == other.state &&
timestamp == other.timestamp &&
message == other.message;
message == other.message &&
to == other.to;

@override
int get hashCode => runtimeType.hashCode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class InteractionEntity extends InteractionBaseEntity {
InteractionEntity({
required super.id,
required super.from,
required super.to,
required this.genesisDid,
required this.profileNonce,
required super.type,
Expand All @@ -19,6 +20,7 @@ class InteractionEntity extends InteractionBaseEntity {
return InteractionEntity(
id: json['id'],
from: json['from'],
to: json['to'],
genesisDid: json['genesisDid'],
profileNonce: BigInt.parse(json['profileNonce']),
type: InteractionType.values.firstWhere((type) =>
Expand Down Expand Up @@ -48,6 +50,7 @@ class InteractionEntity extends InteractionBaseEntity {
runtimeType == other.runtimeType &&
id == other.id &&
from == other.from &&
to == other.to &&
genesisDid == other.genesisDid &&
profileNonce == other.profileNonce &&
type == other.type &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class UpdateInteractionUseCase
timestamp: interactionToBeUpdated.timestamp,
message: interactionToBeUpdated.message,
state: param.state ?? interactionToBeUpdated.state,
to: interactionToBeUpdated.to,
);
return _addInteractionUseCase.execute(
param: AddInteractionParam(
Expand All @@ -91,6 +92,7 @@ class UpdateInteractionUseCase
timestamp: interactionToBeUpdated.timestamp,
message: interactionToBeUpdated.message,
state: param.state ?? interactionToBeUpdated.state,
to: interactionToBeUpdated.to,
))
.then((interaction) => _addInteractionUseCase.execute(
param: AddInteractionParam(interaction: interaction)))
Expand Down
37 changes: 21 additions & 16 deletions test/common/iden3comm_mocks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -292,14 +292,16 @@ class Iden3commMocks {

static List<InteractionEntity> interactionEntities = [
InteractionEntity(
id: CommonMocks.intValues[0].toString(),
from: CommonMocks.did,
genesisDid: CommonMocks.did,
profileNonce: CommonMocks.nonce,
type: InteractionType.offer,
timestamp: 0,
message: CommonMocks.message,
state: InteractionState.opened),
id: CommonMocks.intValues[0].toString(),
from: CommonMocks.did,
genesisDid: CommonMocks.did,
profileNonce: CommonMocks.nonce,
type: InteractionType.offer,
timestamp: 0,
message: CommonMocks.message,
state: InteractionState.opened,
to: CommonMocks.did,
),
InteractionEntity(
id: CommonMocks.intValues[1].toString(),
from: CommonMocks.did,
Expand All @@ -309,15 +311,18 @@ class Iden3commMocks {
timestamp: 0,
message: CommonMocks.message,
state: InteractionState.received,
to: CommonMocks.did,
),
InteractionEntity(
id: CommonMocks.intValues[2].toString(),
from: CommonMocks.did,
genesisDid: CommonMocks.did,
profileNonce: CommonMocks.nonce,
type: InteractionType.offer,
timestamp: 0,
message: CommonMocks.message,
state: InteractionState.accepted),
id: CommonMocks.intValues[2].toString(),
from: CommonMocks.did,
genesisDid: CommonMocks.did,
profileNonce: CommonMocks.nonce,
type: InteractionType.offer,
timestamp: 0,
message: CommonMocks.message,
state: InteractionState.accepted,
to: CommonMocks.did,
),
];
}

0 comments on commit f632b15

Please sign in to comment.