Skip to content

Commit bdec36a

Browse files
committed
修正:
1、进行历史消息解析时,如果使用普通历史消息源而非Android Auto历史消息源,整个历史记录的ticker都错误使用了当前消息的ticker; 2、进行历史消息解析时,如果使用Android Auto历史消息源,群友ID错误的使用了该群友的昵称而非群昵称
1 parent 22721fd commit bdec36a

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

src/main/java/com/oasisfeng/nevo/decorators/wechat/MessagingBuilder.java

+14-12
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,14 @@ class MessagingBuilder {
8787
return null;
8888
}
8989

90-
final LongSparseArray<CharSequence> lines = new LongSparseArray<>(MAX_NUM_HISTORICAL_LINES);
90+
final LongSparseArray<CharSequence> tickerArray = new LongSparseArray<>(MAX_NUM_HISTORICAL_LINES);
91+
final LongSparseArray<CharSequence> textArray = new LongSparseArray<>(MAX_NUM_HISTORICAL_LINES);
9192
CharSequence text;
9293
int count = 0, num_lines_with_colon = 0;
9394
final String redundant_prefix = title.toString() + SENDER_MESSAGE_SEPARATOR;
9495
for (final StatusBarNotification each : archive) {
9596
final Notification notification = each.getNotification();
97+
tickerArray.put(notification.when, notification.tickerText);
9698
final Bundle its_extras = notification.extras;
9799
final CharSequence its_title = its_extras.getCharSequence(Notification.EXTRA_TITLE);
98100
if (! title.equals(its_title)) {
@@ -111,27 +113,28 @@ class MessagingBuilder {
111113
if (trimmed_text.toString().startsWith(redundant_prefix)) // Remove redundant prefix
112114
trimmed_text = trimmed_text.subSequence(redundant_prefix.length(), trimmed_text.length());
113115
else if (trimmed_text.toString().indexOf(SENDER_MESSAGE_SEPARATOR) > 0) num_lines_with_colon ++;
114-
lines.put(notification.when, trimmed_text);
116+
textArray.put(notification.when, trimmed_text);
115117
} else {
116118
count = 1;
117-
lines.put(notification.when, text = its_text);
119+
textArray.put(notification.when, text = its_text);
118120
if (text.toString().indexOf(SENDER_MESSAGE_SEPARATOR) > 0) num_lines_with_colon ++;
119121
}
120122
}
121123
n.number = count;
122-
if (lines.size() == 0) {
124+
if (textArray.size() == 0) {
123125
Log.w(TAG, "No lines extracted, expected " + count);
124126
return null;
125127
}
126128

127129
final MessagingStyle messaging = new MessagingStyle(mUserSelf);
128-
final boolean sender_inline = num_lines_with_colon == lines.size();
129-
for (int i = 0, size = lines.size(); i < size; i++) // All lines have colon in text
130-
messaging.addMessage(buildMessage(conversation, lines.keyAt(i), n.tickerText, lines.valueAt(i), sender_inline ? null : title.toString()));
130+
final boolean sender_inline = num_lines_with_colon == textArray.size();
131+
for (int i = 0, size = textArray.size(); i < size; i++) { // All lines have colon in text
132+
messaging.addMessage(buildMessage(conversation, textArray.keyAt(i), tickerArray.valueAt(i), textArray.valueAt(i), sender_inline ? null : title.toString()));
133+
}
131134
return messaging;
132135
}
133136

134-
@Nullable MessagingStyle buildFromExtender(final Conversation conversation, final MutableStatusBarNotification sbn) {
137+
@Nullable MessagingStyle buildFromExtender(final Conversation conversation, final MutableStatusBarNotification sbn, final CharSequence title, final List<StatusBarNotification> archive) {
135138
final MutableNotification n = sbn.getNotification();
136139
final Notification.CarExtender extender = new Notification.CarExtender(n);
137140
final CarExtender.UnreadConversation convs = extender.getUnreadConversation();
@@ -156,9 +159,8 @@ class MessagingBuilder {
156159
Log.e(TAG, "Error parsing reply intent.", e);
157160
}
158161

159-
final MessagingStyle messaging = new MessagingStyle(mUserSelf);
160-
final Message[] messages = WeChatMessage.buildFromCarConversation(conversation, convs);
161-
for (final Message message : messages) messaging.addMessage(message);
162+
final MessagingStyle messaging = buildFromArchive(conversation, n, title, archive);
163+
final List<Message> messages = messaging.getMessages();
162164

163165
final PendingIntent on_read = convs.getReadPendingIntent();
164166
if (on_read != null) mMarkReadPendingIntents.put(sbn.getKey(), on_read); // Mapped by evolved key,
@@ -178,7 +180,7 @@ class MessagingBuilder {
178180
n.addAction(reply_action.build());
179181

180182
if (conversation.isGroupChat() && mPreferences.getBoolean(mPrefKeyMentionAction, false)) {
181-
final Person last_sender = messages[messages.length - 1].getPerson();
183+
final Person last_sender = messages.get(messages.size() - 1).getPerson();
182184
if (last_sender != null && last_sender != mUserSelf) {
183185
final String label = "@" + last_sender.getName(), prefix = "@" + Conversation.getOriginalName(last_sender) + MENTION_SEPARATOR;
184186
n.addAction(new Action.Builder(null, label, proxyDirectReply(sbn, on_reply, remote_input, input_history, prefix))

src/main/java/com/oasisfeng/nevo/decorators/wechat/WeChatDecorator.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ public class WeChatDecorator extends NevoDecoratorService {
141141
else if (channel_id == null) n.setChannelId(CHANNEL_MESSAGE); // WeChat versions targeting O+ have its own channel for message
142142
}
143143

144-
MessagingStyle messaging = mMessagingBuilder.buildFromExtender(conversation, evolving);
144+
MessagingStyle messaging = mMessagingBuilder.buildFromExtender(conversation, evolving, title, getArchivedNotifications(evolving.getOriginalKey(), MAX_NUM_ARCHIVED)); // build message from android auto
145145
if (messaging == null) // EXTRA_TEXT will be written in buildFromArchive()
146146
messaging = mMessagingBuilder.buildFromArchive(conversation, n, title, getArchivedNotifications(evolving.getOriginalKey(), MAX_NUM_ARCHIVED));
147147
if (messaging == null) return;

0 commit comments

Comments
 (0)