ProfileService.kt 3.94 KB
Newer Older
1
/*
2
 * Copyright 2020 The Matrix.org Foundation C.I.C.
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

Benoît Marty's avatar
Benoît Marty committed
18
package org.matrix.android.sdk.api.session.profile
19

20
import android.net.Uri
21
import androidx.lifecycle.LiveData
22
import org.matrix.android.sdk.api.auth.UserInteractiveAuthInterceptor
Benoît Marty's avatar
Benoît Marty committed
23
24
25
import org.matrix.android.sdk.api.session.identity.ThreePid
import org.matrix.android.sdk.api.util.JsonDict
import org.matrix.android.sdk.api.util.Optional
26

ganfra's avatar
ganfra committed
27
28
29
/**
 * This interface defines methods to handling profile information. It's implemented at the session level.
 */
30
31
32
33
34
35
36
interface ProfileService {

    companion object Constants {
        const val DISPLAY_NAME_KEY = "displayname"
        const val AVATAR_URL_KEY = "avatar_url"
    }

ganfra's avatar
ganfra committed
37
    /**
38
     * Return the current display name for this user
ganfra's avatar
ganfra committed
39
40
41
     * @param userId the userId param to look for
     *
     */
42
    suspend fun getDisplayName(userId: String): Optional<String>
43

44
45
46
47
48
    /**
     * Update the display name for this user
     * @param userId the userId to update the display name of
     * @param newDisplayName the new display name of the user
     */
49
    suspend fun setDisplayName(userId: String, newDisplayName: String)
50

51
52
53
54
55
56
    /**
     * Update the avatar for this user
     * @param userId the userId to update the avatar of
     * @param newAvatarUri the new avatar uri of the user
     * @param fileName the fileName of selected image
     */
57
    suspend fun updateAvatar(userId: String, newAvatarUri: Uri, fileName: String)
58

ganfra's avatar
ganfra committed
59
60
61
62
63
    /**
     * Return the current avatarUrl for this user.
     * @param userId the userId param to look for
     *
     */
64
    suspend fun getAvatarUrl(userId: String): Optional<String>
65

ganfra's avatar
ganfra committed
66
67
68
    /**
     * Get the combined profile information for this user.
     * This may return keys which are not limited to displayname or avatar_url.
Onuray Sahin's avatar
Onuray Sahin committed
69
     * If server is configured as limit_profile_requests_to_users_who_share_rooms: true then response can be HTTP 403.
ganfra's avatar
ganfra committed
70
71
72
     * @param userId the userId param to look for
     *
     */
73
    suspend fun getProfile(userId: String): JsonDict
74
75
76
77
78
79
80
81

    /**
     * Get the current user 3Pids
     */
    fun getThreePids(): List<ThreePid>

    /**
     * Get the current user 3Pids Live
82
     * @param refreshData set to true to fetch data from the homeserver
83
     */
84
    fun getThreePidsLive(refreshData: Boolean): LiveData<List<ThreePid>>
85
86
87
88
89
90
91
92
93
94
95
96
97
98

    /**
     * Get the pending 3Pids, i.e. ThreePids that have requested a token, but not yet validated by the user.
     */
    fun getPendingThreePids(): List<ThreePid>

    /**
     * Get the pending 3Pids Live
     */
    fun getPendingThreePidsLive(): LiveData<List<ThreePid>>

    /**
     * Add a 3Pids. This is the first step to add a ThreePid to an account. Then the threePid will be added to the pending threePid list.
     */
99
    suspend fun addThreePid(threePid: ThreePid)
100

Benoit Marty's avatar
Benoit Marty committed
101
102
103
    /**
     * Validate a code received by text message
     */
104
    suspend fun submitSmsCode(threePid: ThreePid.Msisdn, code: String)
Benoit Marty's avatar
Benoit Marty committed
105

106
107
108
    /**
     * Finalize adding a 3Pids. Call this method once the user has validated that he owns the ThreePid
     */
109
110
    suspend fun finalizeAddingThreePid(threePid: ThreePid,
                                       userInteractiveAuthInterceptor: UserInteractiveAuthInterceptor)
111

112
    /**
Benoit Marty's avatar
Benoit Marty committed
113
     * Cancel adding a threepid. It will remove locally stored data about this ThreePid
114
     */
115
    suspend fun cancelAddingThreePid(threePid: ThreePid)
116

117
    /**
Benoit Marty's avatar
Benoit Marty committed
118
     * Remove a 3Pid from the Matrix account.
119
     */
120
    suspend fun deleteThreePid(threePid: ThreePid)
121
}