-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #616 from HenrikJannsen/chat_domain_improvements
Chat domain improvements
- Loading branch information
Showing
86 changed files
with
2,024 additions
and
3,638 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
chat/src/main/java/bisq/chat/channel/BasePrivateChannel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* This file is part of Bisq. | ||
* | ||
* Bisq is free software: you can redistribute it and/or modify it | ||
* under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or (at | ||
* your option) any later version. | ||
* | ||
* Bisq 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 Affero General Public | ||
* License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with Bisq. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package bisq.chat.channel; | ||
|
||
import bisq.chat.message.BasePrivateChatMessage; | ||
import bisq.common.data.ByteArray; | ||
import bisq.common.data.Pair; | ||
import bisq.common.observable.ObservableArray; | ||
import bisq.user.identity.UserIdentity; | ||
import bisq.user.profile.UserProfile; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.Getter; | ||
import lombok.ToString; | ||
|
||
import java.util.Comparator; | ||
import java.util.List; | ||
|
||
@Getter | ||
@ToString(callSuper = true) | ||
@EqualsAndHashCode(callSuper = true, onlyExplicitlyIncluded = true) | ||
public abstract class BasePrivateChannel<T extends BasePrivateChatMessage> extends Channel<T> { | ||
|
||
public static String createChannelName(Pair<String, String> userIds) { | ||
String userId1 = userIds.getFirst(); | ||
String userId2 = userIds.getSecond(); | ||
if (userId1.compareTo(userId2) < 0) { | ||
return userId1 + "-" + userId2; | ||
} else { | ||
return userId2 + "-" + userId1; | ||
} | ||
} | ||
|
||
protected final UserIdentity myUserIdentity; | ||
|
||
// We persist the messages as they are NOT persisted in the P2P data store. | ||
protected final ObservableArray<T> chatMessages = new ObservableArray<>(); | ||
|
||
public BasePrivateChannel(ChannelDomain channelDomain, | ||
String channelName, | ||
UserIdentity myUserIdentity, | ||
List<T> chatMessages, | ||
ChannelNotificationType channelNotificationType) { | ||
super(channelDomain, channelName, channelNotificationType); | ||
|
||
this.myUserIdentity = myUserIdentity; | ||
this.chatMessages.addAll(chatMessages); | ||
this.chatMessages.sort(Comparator.comparing((T e) -> new ByteArray(e.serialize()))); | ||
} | ||
|
||
public abstract UserProfile getPeer(); | ||
} |
Oops, something went wrong.