include PartType in CallLog

This commit is contained in:
Daniel Gultsch 2023-02-23 19:01:16 +01:00
parent 63bfbfb40a
commit 63df518c19
No known key found for this signature in database
GPG key ID: F43D18AD2A0982C2
3 changed files with 77 additions and 15 deletions

View file

@ -52,6 +52,7 @@ import im.conversations.android.xmpp.model.jmi.Reject;
import im.conversations.android.xmpp.model.jmi.Retract; import im.conversations.android.xmpp.model.jmi.Retract;
import im.conversations.android.xmpp.model.stanza.Iq; import im.conversations.android.xmpp.model.stanza.Iq;
import im.conversations.android.xmpp.model.stanza.Message; import im.conversations.android.xmpp.model.stanza.Message;
import java.time.Duration;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
@ -179,8 +180,7 @@ public class JingleRtpConnection extends AbstractJingleConnection
private final Queue<PeerConnection.PeerConnectionState> stateHistory = new LinkedList<>(); private final Queue<PeerConnection.PeerConnectionState> stateHistory = new LinkedList<>();
private final RtpSessionNotification rtpSessionNotification; private final RtpSessionNotification rtpSessionNotification;
private ScheduledFuture<?> ringingTimeoutFuture; private ScheduledFuture<?> ringingTimeoutFuture;
private final CallLogTransformation.Builder callLogTransformationBuilder = private final CallLogTransformation.Builder callLogTransformationBuilder;
new CallLogTransformation.Builder();
private final ListenableFuture<Boolean> remoteHasVideoFeature; private final ListenableFuture<Boolean> remoteHasVideoFeature;
public JingleRtpConnection( public JingleRtpConnection(
@ -194,6 +194,9 @@ public class JingleRtpConnection extends AbstractJingleConnection
this.remoteHasVideoFeature = this.remoteHasVideoFeature =
getManager(DiscoManager.class) getManager(DiscoManager.class)
.hasFeatureAsync(Entity.presence(id.with), Namespace.JINGLE_FEATURE_VIDEO); .hasFeatureAsync(Entity.presence(id.with), Namespace.JINGLE_FEATURE_VIDEO);
final Jid to = isInitiator() ? id.with : connection.getBoundAddress();
this.callLogTransformationBuilder =
new CallLogTransformation.Builder(id.with, to, initiator, id.sessionId);
} }
private static State reasonToState(Reason reason) { private static State reasonToState(Reason reason) {
@ -1347,7 +1350,7 @@ public class JingleRtpConnection extends AbstractJingleConnection
private void acceptedOnOtherDevice(final String serverMsgId) { private void acceptedOnOtherDevice(final String serverMsgId) {
if (serverMsgId != null) { if (serverMsgId != null) {
this.callLogTransformationBuilder.setServerMsgId(serverMsgId); this.callLogTransformationBuilder.setStanzaId(serverMsgId);
} }
this.callLogTransformationBuilder.setCarbon( this.callLogTransformationBuilder.setCarbon(
true); // indicate that call was accepted on other device true); // indicate that call was accepted on other device
@ -1388,7 +1391,7 @@ public class JingleRtpConnection extends AbstractJingleConnection
this.rtpSessionNotification.cancelIncomingCallNotification(); this.rtpSessionNotification.cancelIncomingCallNotification();
this.finish(); this.finish();
if (serverMsgId != null) { if (serverMsgId != null) {
this.callLogTransformationBuilder.setServerMsgId(serverMsgId); this.callLogTransformationBuilder.setStanzaId(serverMsgId);
} }
this.callLogTransformationBuilder.setCarbon( this.callLogTransformationBuilder.setCarbon(
true); // indicate that call was rejected on other device true); // indicate that call was rejected on other device
@ -1448,7 +1451,7 @@ public class JingleRtpConnection extends AbstractJingleConnection
this.proposedMedia = Sets.newHashSet(media); this.proposedMedia = Sets.newHashSet(media);
})) { })) {
if (serverMsgId != null) { if (serverMsgId != null) {
this.callLogTransformationBuilder.setServerMsgId(serverMsgId); this.callLogTransformationBuilder.setStanzaId(serverMsgId);
} }
startRinging(); startRinging();
} else { } else {
@ -1502,7 +1505,7 @@ public class JingleRtpConnection extends AbstractJingleConnection
if (isInitiator()) { if (isInitiator()) {
if (transition(State.PROCEED)) { if (transition(State.PROCEED)) {
if (serverMsgId != null) { if (serverMsgId != null) {
this.callLogTransformationBuilder.setServerMsgId(serverMsgId); this.callLogTransformationBuilder.setStanzaId(serverMsgId);
} }
final Integer remoteDeviceId = proceed.getDeviceId(); final Integer remoteDeviceId = proceed.getDeviceId();
if (isOmemoEnabled()) { if (isOmemoEnabled()) {
@ -1561,7 +1564,7 @@ public class JingleRtpConnection extends AbstractJingleConnection
+ serverMsgId + serverMsgId
+ ")"); + ")");
if (serverMsgId != null) { if (serverMsgId != null) {
this.callLogTransformationBuilder.setServerMsgId(serverMsgId); this.callLogTransformationBuilder.setStanzaId(serverMsgId);
} }
if (target == State.RETRACTED) { if (target == State.RETRACTED) {
this.callLogTransformationBuilder.markUnread(); this.callLogTransformationBuilder.markUnread();
@ -2618,17 +2621,20 @@ public class JingleRtpConnection extends AbstractJingleConnection
} }
private void writeLogMessageSuccess(final long duration) { private void writeLogMessageSuccess(final long duration) {
this.callLogTransformationBuilder.setDuration(duration); this.callLogTransformationBuilder.setMedia(getMedia());
// this.message.setBody(new RtpSessionStatus(true, duration).toString()); this.callLogTransformationBuilder.setDuration(Duration.ofMillis(duration));
this.writeMessage(); this.writeMessage();
} }
private void writeLogMessageMissed() { private void writeLogMessageMissed() {
// this.message.setBody(new RtpSessionStatus(false, 0).toString()); this.callLogTransformationBuilder.setIsMissedCall();
this.writeMessage(); this.writeMessage();
} }
private void writeMessage() { private void writeMessage() {
final CallLogTransformation callLogTransformation =
this.callLogTransformationBuilder.build();
LOGGER.info("writing log message to DB {}", callLogTransformation);
// TODO write CallLogEntry to DB // TODO write CallLogEntry to DB
} }

View file

@ -4,5 +4,8 @@ public enum PartType {
TEXT, TEXT,
FILE, FILE,
RETRACTION, RETRACTION,
MODERATION MODERATION,
VIDEO_CALL,
AUDIO_CALL,
MISSED_CALL
} }

View file

@ -1,13 +1,18 @@
package im.conversations.android.transformer; package im.conversations.android.transformer;
import com.google.common.base.MoreObjects;
import eu.siacs.conversations.xmpp.jingle.Media;
import im.conversations.android.database.model.PartType;
import im.conversations.android.xmpp.model.stanza.Message; import im.conversations.android.xmpp.model.stanza.Message;
import java.time.Duration; import java.time.Duration;
import java.time.Instant; import java.time.Instant;
import java.util.Set;
import org.jxmpp.jid.Jid; import org.jxmpp.jid.Jid;
public class CallLogTransformation extends Transformation { public class CallLogTransformation extends Transformation {
public final Duration duration; public final Duration duration;
public final PartType partType;
private CallLogTransformation( private CallLogTransformation(
final Instant receivedAt, final Instant receivedAt,
@ -16,23 +21,71 @@ public class CallLogTransformation extends Transformation {
final Jid remote, final Jid remote,
final String messageId, final String messageId,
final String stanzaId, final String stanzaId,
final Duration duration) { final Duration duration,
final PartType partType) {
super(receivedAt, to, from, remote, Message.Type.NORMAL, messageId, stanzaId, null); super(receivedAt, to, from, remote, Message.Type.NORMAL, messageId, stanzaId, null);
this.duration = duration; this.duration = duration;
this.partType = partType;
}
@Override
public String toString() {
return MoreObjects.toStringHelper(this)
.add("duration", duration)
.add("partType", partType)
.add("receivedAt", receivedAt)
.add("to", to)
.add("from", from)
.add("remote", remote)
.add("type", type)
.add("messageId", messageId)
.add("stanzaId", stanzaId)
.add("occupantId", occupantId)
.toString();
} }
public static class Builder { public static class Builder {
public void setServerMsgId(String serverMsgId) {} private final Instant receivedAt;
private final Jid to;
private final Jid from;
private final Jid remote;
private final String messageId;
private String stanzaId;
private Duration duration;
private PartType partType;
public Builder(final Jid remote, final Jid to, final Jid from, final String sessionId) {
this.receivedAt = Instant.now();
this.remote = remote;
this.to = to;
this.from = from;
this.messageId = sessionId;
}
public void setStanzaId(final String stanzaId) {
this.stanzaId = stanzaId;
}
public void setCarbon(boolean b) {} public void setCarbon(boolean b) {}
public void markUnread() {} public void markUnread() {}
public void setDuration(long duration) {} public void setDuration(final Duration duration) {
this.duration = duration;
}
public void setIsMissedCall() {
this.duration = Duration.ZERO;
}
public void setMedia(final Set<Media> media) {
this.partType = Media.audioOnly(media) ? PartType.AUDIO_CALL : PartType.VIDEO_CALL;
}
public CallLogTransformation build() { public CallLogTransformation build() {
return new CallLogTransformation(null, null, null, null, null, null, null); return new CallLogTransformation(
receivedAt, to, from, remote, messageId, stanzaId, duration, partType);
} }
} }
} }