Merge pull request 'Upgrade Cwtch to v0.9.2' (#13) from bugfix into trunk
continuous-integration/drone/push Build is passing Details

Reviewed-on: #13
Reviewed-by: Dan Ballard <dan@openprivacy.ca>
This commit is contained in:
Dan Ballard 2021-07-08 13:20:30 -07:00
commit 41ae09d763
3 changed files with 32 additions and 28 deletions

2
go.mod
View File

@ -3,7 +3,7 @@ module git.openprivacy.ca/flutter/libcwtch-go
go 1.15 go 1.15
require ( require (
cwtch.im/cwtch v0.9.1 cwtch.im/cwtch v0.9.2
git.openprivacy.ca/openprivacy/connectivity v1.4.5 git.openprivacy.ca/openprivacy/connectivity v1.4.5
git.openprivacy.ca/openprivacy/log v1.0.2 git.openprivacy.ca/openprivacy/log v1.0.2
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c // indirect golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c // indirect

4
go.sum
View File

@ -1,5 +1,5 @@
cwtch.im/cwtch v0.9.1 h1:xv883HaHxZhSXOCsOmuXJiKZoS3GoxQ4zictS4vRWGM= cwtch.im/cwtch v0.9.2 h1:daDJPDWJ3uwRZ/UYPkmhpxxA/G8/FtFAQwbIGhM24ng=
cwtch.im/cwtch v0.9.1/go.mod h1:EwUUVWIU4OAcz0HmHUxaY4orzKH6ZiNXaVI8y/5UP5k= cwtch.im/cwtch v0.9.2/go.mod h1:EwUUVWIU4OAcz0HmHUxaY4orzKH6ZiNXaVI8y/5UP5k=
git.openprivacy.ca/cwtch.im/tapir v0.4.4 h1:KyuTVmr9GYptTCeR7JDODjmhBBbnIBf9V3NSC4+6bHc= git.openprivacy.ca/cwtch.im/tapir v0.4.4 h1:KyuTVmr9GYptTCeR7JDODjmhBBbnIBf9V3NSC4+6bHc=
git.openprivacy.ca/cwtch.im/tapir v0.4.4/go.mod h1:qMFTdmDZITc1BLP1jSW0gVpLmvpg+Zjsh5ek8StwbFE= git.openprivacy.ca/cwtch.im/tapir v0.4.4/go.mod h1:qMFTdmDZITc1BLP1jSW0gVpLmvpg+Zjsh5ek8StwbFE=
git.openprivacy.ca/openprivacy/bine v0.0.4 h1:CO7EkGyz+jegZ4ap8g5NWRuDHA/56KKvGySR6OBPW+c= git.openprivacy.ca/openprivacy/bine v0.0.4 h1:CO7EkGyz+jegZ4ap8g5NWRuDHA/56KKvGySR6OBPW+c=

54
lib.go
View File

@ -543,36 +543,40 @@ func GetMessage(profileOnion, handle string, message_index int) string {
profile := application.GetPeer(profileOnion) profile := application.GetPeer(profileOnion)
ph := utils.NewPeerHelper(profile) ph := utils.NewPeerHelper(profile)
if ph.IsGroup(handle) { if ph.IsGroup(handle) {
// If we are safely within the limits of the timeline just grab the message at the index.. if profile.GetGroup(handle) != nil {
if len(profile.GetGroup(handle).Timeline.Messages) > message_index { // If we are safely within the limits of the timeline just grab the message at the index..
message.Message = profile.GetGroup(handle).Timeline.Messages[message_index] if len(profile.GetGroup(handle).Timeline.Messages) > message_index {
message.ContactImage = ph.GetProfilePic(message.Message.PeerID) message.Message = profile.GetGroup(handle).Timeline.Messages[message_index]
} else {
// Message Index Request exceeded Timeline, most likely reason is this is a request for an
// unacknowledged sent message (it can take a many seconds for a message to be confirmed in the worst
// case).
offset := message_index - len(profile.GetGroup(handle).Timeline.Messages)
if len(profile.GetGroup(handle).UnacknowledgedMessages) > offset {
message.Message = profile.GetGroup(handle).UnacknowledgedMessages[offset]
message.ContactImage = ph.GetProfilePic(message.Message.PeerID) message.ContactImage = ph.GetProfilePic(message.Message.PeerID)
} else { } else {
log.Errorf("Couldn't find message in timeline or unacked messages, probably transient threading issue, but logging for visibility..") // Message Index Request exceeded Timeline, most likely reason is this is a request for an
// unacknowledged sent message (it can take a many seconds for a message to be confirmed in the worst
// case).
offset := message_index - len(profile.GetGroup(handle).Timeline.Messages)
if len(profile.GetGroup(handle).UnacknowledgedMessages) > offset {
message.Message = profile.GetGroup(handle).UnacknowledgedMessages[offset]
message.ContactImage = ph.GetProfilePic(message.Message.PeerID)
} else {
log.Errorf("Couldn't find message in timeline or unacked messages, probably transient threading issue, but logging for visibility..")
}
} }
} }
} else { } else {
// If we are safely within the limits of the timeline just grab the message at the index.. if profile.GetContact(handle) != nil {
if len(profile.GetContact(handle).Timeline.Messages) > message_index { // If we are safely within the limits of the timeline just grab the message at the index..
message.Message = profile.GetContact(handle).Timeline.Messages[message_index] if len(profile.GetContact(handle).Timeline.Messages) > message_index {
message.ContactImage = ph.GetProfilePic(handle) message.Message = profile.GetContact(handle).Timeline.Messages[message_index]
} else { message.ContactImage = ph.GetProfilePic(handle)
// Otherwise Send a counter resync event...this shouldn't really happen for p2p messages so we } else {
// throw an error. // Otherwise Send a counter resync event...this shouldn't really happen for p2p messages so we
log.Errorf("peerpeercontact getmessage out of range; sending counter resync just in case") // throw an error.
eventHandler.Push(event.NewEvent(event.MessageCounterResync, map[event.Field]string{ log.Errorf("peerpeercontact getmessage out of range; sending counter resync just in case")
event.Identity: profileOnion, eventHandler.Push(event.NewEvent(event.MessageCounterResync, map[event.Field]string{
event.RemotePeer: handle, event.Identity: profileOnion,
event.Data: strconv.Itoa(len(profile.GetContact(handle).Timeline.Messages)), event.RemotePeer: handle,
})) event.Data: strconv.Itoa(len(profile.GetContact(handle).Timeline.Messages)),
}))
}
} }
} }
} }