forked from wireapp/wire-webapp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConversationGenerator.ts
129 lines (119 loc) · 4.2 KB
/
ConversationGenerator.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/*
* Wire
* Copyright (C) 2023 Wire Swiss GmbH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://www.gnu.org/licenses/.
*
*/
import {ConnectionStatus} from '@wireapp/api-client/lib/connection/';
import {
CONVERSATION_TYPE,
CONVERSATION_ACCESS_ROLE,
Conversation as BackendConversation,
Member,
} from '@wireapp/api-client/lib/conversation/';
import {RECEIPT_MODE} from '@wireapp/api-client/lib/conversation/data';
import {ConversationProtocol} from '@wireapp/api-client/lib/conversation/NewConversation';
import {QualifiedId} from '@wireapp/api-client/lib/user';
import {LegalHoldStatus} from '@wireapp/core/lib/conversation/content';
import {ConnectionEntity} from 'src/script/connection/ConnectionEntity';
import {ConversationDatabaseData, ConversationMapper} from 'src/script/conversation/ConversationMapper';
import {ConversationStatus} from 'src/script/conversation/ConversationStatus';
import {ConversationVerificationState} from 'src/script/conversation/ConversationVerificationState';
import {Conversation} from 'src/script/entity/Conversation';
import {User} from 'src/script/entity/User';
import {createUuid} from 'Util/uuid';
interface GenerateAPIConversationParams {
id?: QualifiedId;
type?: CONVERSATION_TYPE;
protocol?: ConversationProtocol;
overwites?: Partial<ConversationDatabaseData>;
name?: string;
groupId?: string;
}
export function generateAPIConversation({
id = {id: createUuid(), domain: 'test.wire.link'},
type = CONVERSATION_TYPE.REGULAR,
protocol = ConversationProtocol.PROTEUS,
overwites = {},
name,
}: GenerateAPIConversationParams): BackendConversation {
return {
id: id.id,
name,
type: type,
protocol: protocol,
qualified_id: id,
access: [],
verification_state: ConversationVerificationState.UNVERIFIED,
mlsVerificationState: ConversationVerificationState.UNVERIFIED,
receipt_mode: RECEIPT_MODE.ON,
team_id: '',
status: ConversationStatus.CURRENT_MEMBER,
is_guest: false,
archived_state: false,
readonly_state: null,
archived_timestamp: 0,
last_event_timestamp: 0,
last_read_timestamp: 0,
last_server_timestamp: 0,
cleared_timestamp: 0,
ephemeral_timer: 0,
roles: {},
muted_state: 0,
muted_timestamp: 0,
others: [],
qualified_others: [],
legal_hold_status: LegalHoldStatus.DISABLED,
global_message_timer: 0,
group_id: '',
cipher_suite: 0,
epoch: 0,
domain: id.domain,
creator: '',
access_role: [CONVERSATION_ACCESS_ROLE.TEAM_MEMBER],
members: {others: [], self: {} as Member},
...overwites,
};
}
interface GenerateConversationParams extends GenerateAPIConversationParams {
users?: User[];
status?: ConnectionStatus;
}
export function generateConversation({
type = CONVERSATION_TYPE.REGULAR,
status = ConnectionStatus.ACCEPTED,
protocol = ConversationProtocol.PROTEUS,
id,
name,
groupId = 'groupId',
users = [],
overwites = {},
}: GenerateConversationParams = {}): Conversation {
const apiConversation = generateAPIConversation({id, type, protocol, name, overwites});
const conversation = ConversationMapper.mapConversations([apiConversation as ConversationDatabaseData])[0];
const connectionEntity = new ConnectionEntity();
connectionEntity.conversationId = conversation.qualifiedId;
connectionEntity.status(status);
conversation.connection(connectionEntity);
conversation.type(type);
if ([ConversationProtocol.MLS, ConversationProtocol.MIXED].includes(protocol)) {
conversation.groupId = groupId;
}
if (users) {
conversation.participating_user_ets(users);
conversation.participating_user_ids(users.map(user => user.qualifiedId));
}
return conversation;
}