From df6c3dd84ad99037121d861a13bbbd41d07b3277 Mon Sep 17 00:00:00 2001 From: Sarah Jamie Lewis Date: Thu, 8 Jul 2021 12:55:26 -0700 Subject: [PATCH] Upgrade Cwtch to v0.9.2 Also prevent NPE during delete contact state --- go.mod | 2 +- go.sum | 4 ++-- lib.go | 54 +++++++++++++++++++++++++++++------------------------- 3 files changed, 32 insertions(+), 28 deletions(-) diff --git a/go.mod b/go.mod index fa4e1c6..f25f6b2 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module git.openprivacy.ca/flutter/libcwtch-go go 1.15 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/log v1.0.2 golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c // indirect diff --git a/go.sum b/go.sum index 93f2d2c..06acf8a 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,5 @@ -cwtch.im/cwtch v0.9.1 h1:xv883HaHxZhSXOCsOmuXJiKZoS3GoxQ4zictS4vRWGM= -cwtch.im/cwtch v0.9.1/go.mod h1:EwUUVWIU4OAcz0HmHUxaY4orzKH6ZiNXaVI8y/5UP5k= +cwtch.im/cwtch v0.9.2 h1:daDJPDWJ3uwRZ/UYPkmhpxxA/G8/FtFAQwbIGhM24ng= +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/go.mod h1:qMFTdmDZITc1BLP1jSW0gVpLmvpg+Zjsh5ek8StwbFE= git.openprivacy.ca/openprivacy/bine v0.0.4 h1:CO7EkGyz+jegZ4ap8g5NWRuDHA/56KKvGySR6OBPW+c= diff --git a/lib.go b/lib.go index d1a4637..64af745 100644 --- a/lib.go +++ b/lib.go @@ -543,36 +543,40 @@ func GetMessage(profileOnion, handle string, message_index int) string { profile := application.GetPeer(profileOnion) ph := utils.NewPeerHelper(profile) if ph.IsGroup(handle) { - // If we are safely within the limits of the timeline just grab the message at the index.. - if len(profile.GetGroup(handle).Timeline.Messages) > message_index { - message.Message = profile.GetGroup(handle).Timeline.Messages[message_index] - message.ContactImage = ph.GetProfilePic(message.Message.PeerID) - } 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] + if profile.GetGroup(handle) != nil { + // If we are safely within the limits of the timeline just grab the message at the index.. + if len(profile.GetGroup(handle).Timeline.Messages) > message_index { + message.Message = profile.GetGroup(handle).Timeline.Messages[message_index] 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..") + // 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 { - // If we are safely within the limits of the timeline just grab the message at the index.. - if len(profile.GetContact(handle).Timeline.Messages) > message_index { - message.Message = profile.GetContact(handle).Timeline.Messages[message_index] - message.ContactImage = ph.GetProfilePic(handle) - } else { - // Otherwise Send a counter resync event...this shouldn't really happen for p2p messages so we - // throw an error. - log.Errorf("peerpeercontact getmessage out of range; sending counter resync just in case") - eventHandler.Push(event.NewEvent(event.MessageCounterResync, map[event.Field]string{ - event.Identity: profileOnion, - event.RemotePeer: handle, - event.Data: strconv.Itoa(len(profile.GetContact(handle).Timeline.Messages)), - })) + if profile.GetContact(handle) != nil { + // If we are safely within the limits of the timeline just grab the message at the index.. + if len(profile.GetContact(handle).Timeline.Messages) > message_index { + message.Message = profile.GetContact(handle).Timeline.Messages[message_index] + message.ContactImage = ph.GetProfilePic(handle) + } else { + // Otherwise Send a counter resync event...this shouldn't really happen for p2p messages so we + // throw an error. + log.Errorf("peerpeercontact getmessage out of range; sending counter resync just in case") + eventHandler.Push(event.NewEvent(event.MessageCounterResync, map[event.Field]string{ + event.Identity: profileOnion, + event.RemotePeer: handle, + event.Data: strconv.Itoa(len(profile.GetContact(handle).Timeline.Messages)), + })) + } } } }